ATY_LIB V2_102_230218
ATY_LIB for general devices or ALGO
 
Loading...
Searching...
No Matches
xl2400.h
Go to the documentation of this file.
1// Copyright 2021 IOsetting <iosetting(at)outlook.com>
2//
3// Licensed under the Apache License, Version 2.0 (the "License");
4// you may not use this file except in compliance with the License.
5// You may obtain a copy of the License at
6//
7// http://www.apache.org/licenses/LICENSE-2.0
8//
9// Unless required by applicable law or agreed to in writing, software
10// distributed under the License is distributed on an "AS IS" BASIS,
11// WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied.
12// See the License for the specific language governing permissions and
13// limitations under the License.
14
15#ifndef __FW_XL2400_H__
16#define __FW_XL2400_H__
17
18#include "fw_hal.h"
19#include "string.h"
20
21#define XL2400_CSN P35
22#define XL2400_SCK P32
23#define XL2400_MOSI P34
24
25#define XL2400_PLOAD_WIDTH 32 // Payload width
29/****************** SPI REGISTER ********************/
30#define XL2400_CMD_R_REGISTER 0x00 // [000A AAAA] Register read
31#define XL2400_CMD_W_REGISTER 0x20 // [001A AAAA] Register write
32#define XL2400_CMD_R_RX_PAYLOAD 0x61 // Read RX payload
33#define XL2400_CMD_W_TX_PAYLOAD 0xA0 // Write TX payload
34#define XL2400_CMD_FLUSH_TX 0xE1 // Flush TX FIFO
35#define XL2400_CMD_FLUSH_RX 0xE2 // Flush RX FIFO
36#define XL2400_CMD_REUSE_TX_PL 0xE3 // Reuse TX Payload
37#define XL2400_CMD_ACTIVATE 0x50 // ACTIVATE
38#define XL2400_CMD_DEACTIVATE 0x50 // DEACTIVATE
39#define XL2400_CMD_RST_FSPI 0x53 // RESET
40#define XL2400_CMD_R_RX_PL_WID 0x60 // Read width of RX data
41#define XL2400_CMD_W_ACK_PAYLOAD 0xA8 // Data with ACK
42#define XL2400_CMD_W_TX_PAYLOAD_NOACK 0xB0 // TX Payload no ACK Request
43#define XL2400_CMD_NOP 0xFF // No operation (used for reading status register)
44
45/******************CONTROL REGISTER ******************/
46#define XL2400_REG_CFG_TOP 0x00 // Configuration register, 20 bits
47#define XL2400_REG_EN_AA 0x01 // Enable "Auto acknowledgment"
48#define XL2400_REG_EN_RXADDR 0x02 // Enable RX addresses
49#define XL2400_REG_SETUP_AW 0x03 // Setup of address widths
50#define XL2400_REG_SETUP_RETR 0x04 // Setup of automatic re-transmit, 30 bits
51#define XL2400_REG_RF_CH 0x05 // RF channel, 22 bits
52#define XL2400_REG_RF_SETUP 0x06 // RF setup, 16 bits
53#define XL2400_REG_STATUS 0x07 // Status
54#define XL2400_REG_OBSERVE_TX 0x08 // Transmit observe register, 32 bits
55#define XL2400_REG_RSSI 0x09 // Data output and RSSI, 14 bits
56#define XL2400_REG_RX_ADDR_P0 0x0A // Receive address data pipe 0, 40 bits
57#define XL2400_REG_RX_ADDR_P1 0x0B // Receive address data pipe 1, 40 bits
58#define XL2400_REG_RX_ADDR_P2_P5 0x0C // Receive address data pipe 2~5, 32 bits
59#define XL2400_REG_BER_RESULT 0x0D // BER(PN9) test result, 64 bits
60#define XL2400_REG_AGC_SETTING 0x0E // AGC settings, 32 bits
61#define XL2400_REG_PGA_SETTING 0x0F // PGA settings, 39 bits
62#define XL2400_REG_TX_ADDR 0x10 // Transmit address, 40 bits
63#define XL2400_REG_RX_PW_PX 0x11 // Number of bytes in RX payload in data pipe 0 ~ pipe 5, 48 bits
64#define XL2400_REG_ANALOG_CFG0 0x12 // Analog config 0, 128 bits
65#define XL2400_REG_ANALOG_CFG1 0x13 // Analog config 1, 128 bits
66#define XL2400_REG_ANALOG_CFG2 0x14 // Analog config 2, 128 bits
67#define XL2400_REG_ANALOG_CFG3 0x15 // Analog config 3, 128 bits
68#define XL2400_REG_FIFO_STATUS 0x17 // FIFO status, 20 bits
69#define XL2400_REG_RSSIREC 0x18 // RSSI recorder feature, 32 bits
70#define XL2400_REG_TXPROC_CFG 0x19 // TX Process configuration, 29 bits
71#define XL2400_REG_RXPROC_CFG 0x1A // RX Process configuration, 40 bits
72#define XL2400_REG_DYNPD 0x1C // Enable dynamic payload length
73#define XL2400_REG_FEATURE 0x1D // Feature config
74#define XL2400_REG_RAMP_CFG 0x1E // PA Ramp Configuration, 88 bits
75
76
77/**************************** CONFIGs ************************************/
78
79#define XL2400_PL_WIDTH_MAX 64 // Max payload width
80#define XL2400_RF_10DB 0x3F
81#define XL2400_RF_9DB 0x38
82#define XL2400_RF_8DB 0x34
83#define XL2400_RF_7DB 0x30
84#define XL2400_RF_6DB 0x2C // 250Kbps Maximum
85#define XL2400_RF_5DB 0x28
86#define XL2400_RF_4DB 0x24
87#define XL2400_RF_3DB 0x20
88#define XL2400_RF_2DB 0x14
89#define XL2400_RF_0DB 0x10 // 1Mbps Maximum
90#define XL2400_RF__2DB 0x0C
91#define XL2400_RF__6DB 0x08
92#define XL2400_RF__12DB 0x04
93#define XL2400_RF__18DB 0x02
94#define XL2400_RF__24DB 0x01
95#define XL2400_RF_DR_1M 0x02 // 1Mbps
96#define XL2400_RF_DR_250K 0x22 // 250Kbps
97
98#define RX_DR_FLAG 0X40 // Data ready
99#define TX_DS_FLAG 0X20 // Data sent
100#define RX_TX_CMP_FLAG 0X60 // Data sent & acked
101#define MAX_RT_FLAG 0X10 // Max retried
102
103#define XL2400_TEST_ADDR "XL240"
104
105
106/******************* FUNCTION DECLARE *******************/
109
110void XL2400_WriteFromBuf(uint8_t reg, const uint8_t *pBuf, uint8_t len);
111void XL2400_ReadToBuf(uint8_t reg, uint8_t len);
112void XL2400_WriteBack(uint8_t reg, uint8_t len);
113
114void XL2400_CE_Low(void);
115void XL2400_CE_High(void);
116
118
119void XL2400_Init(void);
120void XL2400_SetChannel(uint8_t channel);
121
122void XL2400_SetTxAddress(uint8_t *address);
123void XL2400_SetRxAddress(uint8_t *address);
124void XL2400_SetPower(uint8_t power);
125
126void XL2400_Sleep(void);
127void XL2400_WakeUp(void);
128
130
131void XL2400_SetTxMode(void);
132void XL2400_SetRxMode(void);
133
134uint8_t XL2400_Tx(uint8_t *ucPayload, uint8_t length);
135uint8_t XL2400_Rx(void);
136
138void XL2400_ClearStatus(void);
139void XL2400_FlushRxTX(void);
140void XL2400_CarrierTest(void);
142
143#endif
value
Definition: DS18B20_ATY.c:216
unsigned char uint8_t
Definition: fw_types.h:18
void XL2400_SetTxMode(void)
Definition: xl2400.c:266
void XL2400_FlushRxTX(void)
Definition: xl2400.c:337
void XL2400_SetRxAddress(uint8_t *address)
Definition: xl2400.c:203
uint8_t XL2400_Rx(void)
Definition: xl2400.c:306
void XL2400_WriteReg(uint8_t reg, uint8_t value)
Definition: xl2400.c:72
void XL2400_SetTxAddress(uint8_t *address)
Definition: xl2400.c:197
void XL2400_WriteFromBuf(uint8_t reg, const uint8_t *pBuf, uint8_t len)
Definition: xl2400.c:90
void XL2400_SetPower(uint8_t power)
Definition: xl2400.c:208
uint8_t XL2400_ReadStatus(void)
Definition: xl2400.c:325
void XL2400_WakeUp(void)
Definition: xl2400.c:226
void XL2400_CarrierTest(void)
Definition: xl2400.c:343
uint8_t XL2400_ReadReg(uint8_t reg)
Definition: xl2400.c:80
uint8_t XL2400_PrintStatus(void)
Definition: xl2400.c:357
void XL2400_Init(void)
Definition: xl2400.c:141
void XL2400_SetChannel(uint8_t channel)
Definition: xl2400.c:181
void XL2400_SetRxMode(void)
Definition: xl2400.c:275
void XL2400_CE_High(void)
Definition: xl2400.c:121
void XL2400_CE_Low(void)
Definition: xl2400.c:114
void XL2400_ReadToBuf(uint8_t reg, uint8_t *pBuf, uint8_t len)
Definition: xl2400.c:102
uint8_t XL2400_Tx(uint8_t *ucPayload, uint8_t length)
Definition: xl2400.c:285
uint8_t XL2400_SPI_Test(void)
Definition: xl2400.c:128
uint8_t XL2400_RxCalibrate(void)
Definition: xl2400.c:236
void XL2400_ClearStatus(void)
Definition: xl2400.c:330
void XL2400_Sleep(void)
Definition: xl2400.c:215
void XL2400_WriteBack(uint8_t reg, uint8_t len)
Definition: xl2400.c:57