InPlay API
in_ble_sdr.h
1 
13 #ifndef IN_BLE_SDR_H
14 #define IN_BLE_SDR_H
15 
16 #include "in_mmap.h"
17 
18 /*
19  * Enumeration
20  ****************************************************************************************
21  */
22 
23 enum sdr_mode
24 {
25  MODE_ADDRESSLESS=0x2,
26  MODE_BROADCAST = 0x3,
27  MODE_PRIVATE = 0x6,
28 };
29 
30 enum sdr_phy_rate
31 {
32  PHY_RATE_1M = 0,
33  PHY_RATE_2M = 1,
34  PHY_RATE_CODED_125K = 2,
35  PHY_RATE_CODED_500K = 3,
36 };
37 
38 enum sdr_rx_status
39 {
41  SDR_RX_STATUS_NOERR = 0,
43  SDR_RX_STATUS_CRCERR = 0x1,
45  SDR_RX_STATUS_SYNCERR = 0x2,
46 };
47 
48 enum sdr_error
49 {
50  SDR_ERR_OK = 0,
51  SDR_ERR_INVALID_PARAM = -1,
52  SDR_ERR_TX_DATA_ALLOC = -2,
53  SDR_ERR_TX_DESC_ALLOC = -3,
54  SDR_ERR_RX_DATA_ALLOC = -4,
55  SDR_ERR_RX_DESC_ALLOC = -5,
56  SDR_ERR_TX_NOACK = -6,
57  SDR_ERR_OS = -7,
58  SDR_ERR_NOT_READY = -8,
59  SDR_ERR_ABORT = -9,
60 };
61 
62 typedef struct {
64  uint8_t status;
66  uint8_t phy_rate;
68  uint8_t ch_idx;
70  uint8_t rxlen;
72  uint8_t *rxbuf;
74  uint16_t sa;
75  uint16_t da;
77  int rssi;
78 } rx_param_t;
79 
80 /*
81  * Inline
82  ****************************************************************************************
83  */
84 
85 static __inline void sdr_abort(uint8_t pulse_width)
86 {
87  uint32_t reg = IPMAC_REG_BLE_ABORT_REQ_CTL_BLE_ABORT_REQ|
88  ((pulse_width & IPMAC_REG_BLE_ABORT_REQ_CTL_BLE_ABORT_PULSE_DUR_MASK) << IPMAC_REG_BLE_ABORT_REQ_CTL_BLE_ABORT_PULSE_DUR_SHIFT) |
89  IPMAC_REG_BLE_ABORT_REQ_CTL_BLE_ABORT_ERROR_FLAG_SET;
90  WR_WORD(IPMAC_REG_BLE_ABORT_REQ, reg);
91 }
92 
93 static __inline uint32_t sdr_misc_read(void)
94 {
95  return RD_WORD(IPMAC_REG_SDR_MISC_CTRL);
96 }
97 
98 static __inline void sdr_misc_ctl(int en, int no_ts, int no_fine_ts, int match_da, int match_sa, int slv_sbt, int mstr_abt)
99 {
100  uint32_t reg = RD_WORD(IPMAC_REG_SDR_MISC_CTRL);
101 
102  if (en)
103  reg |= IPMAC_REG_SDR_MISC_CTRL_CTL_SDR_EN;
104  else
105  reg &= ~IPMAC_REG_SDR_MISC_CTRL_CTL_SDR_EN;
106 
107  if (no_ts)
108  reg |= IPMAC_REG_SDR_MISC_CTRL_CTL_SDR_IGNORE_TIMESTAMP;
109  else
110  reg &= ~IPMAC_REG_SDR_MISC_CTRL_CTL_SDR_IGNORE_TIMESTAMP;
111 
112  if (no_fine_ts)
113  reg |= IPMAC_REG_SDR_MISC_CTRL_CTL_SDR_IGNORE_TIMESTAMP_FINE;
114  else
115  reg &= ~IPMAC_REG_SDR_MISC_CTRL_CTL_SDR_IGNORE_TIMESTAMP_FINE;
116 
117  if (match_da)
118  reg |= IPMAC_REG_SDR_MISC_CTRL_CTL_SDR_MATCHING_DEST_ADDR;
119  else
120  reg &= ~IPMAC_REG_SDR_MISC_CTRL_CTL_SDR_MATCHING_DEST_ADDR;
121 
122  if (match_sa)
123  reg |= IPMAC_REG_SDR_MISC_CTRL_CTL_SDR_MATCHING_SRC_ADDR ;
124  else
125  reg &= ~IPMAC_REG_SDR_MISC_CTRL_CTL_SDR_MATCHING_SRC_ADDR;
126 
127  if (slv_sbt)
128  reg |= IPMAC_REG_SDR_MISC_CTRL_CTL_SDR_SLV_ABORT_EVT_SINGLE_CRCERR ;
129  else
130  reg &= ~IPMAC_REG_SDR_MISC_CTRL_CTL_SDR_SLV_ABORT_EVT_SINGLE_CRCERR;
131 
132  if (mstr_abt)
133  reg |= IPMAC_REG_SDR_MISC_CTRL_CTL_SDR_MSTR_ABORT_EVT_SINGLE_CRCERR ;
134  else
135  reg &= ~IPMAC_REG_SDR_MISC_CTRL_CTL_SDR_MSTR_ABORT_EVT_SINGLE_CRCERR;
136 
137  WR_WORD(IPMAC_REG_SDR_MISC_CTRL, reg);
138 }
139 
140 static __inline void sdr_misc_write(uint32_t reg)
141 {
142  WR_WORD(IPMAC_REG_SDR_MISC_CTRL, reg);
143 }
144 
145 static __inline void sdr_restart_ctl(int no_match, int sigl_match, uint32_t us)
146 {
147  uint32_t reg = RD_WORD(IPMAC_REG_SDR_RESTART_DUE_TO_RX_ADDR_MISMATCH);
148 
149  if (no_match)
150  reg |= IPMAC_REG_SDR_RESTART_DUE_TO_RX_ADDR_MISMATCH_CTL_SDR_RESTART_DUE_TO_RX_ADDR_MISMATCH;
151  else
152  reg &= ~IPMAC_REG_SDR_RESTART_DUE_TO_RX_ADDR_MISMATCH_CTL_SDR_RESTART_DUE_TO_RX_ADDR_MISMATCH;
153 
154  if (sigl_match)
155  reg |= IPMAC_REG_SDR_RESTART_DUE_TO_RX_ADDR_MISMATCH_CTL_SDR_RESTART_DUE_TO_RX_ADDR_MISMATCH_SINGLE;
156  else
157  reg &= ~IPMAC_REG_SDR_RESTART_DUE_TO_RX_ADDR_MISMATCH_CTL_SDR_RESTART_DUE_TO_RX_ADDR_MISMATCH_SINGLE;
158 
159  reg &= ~IPMAC_REG_SDR_RESTART_DUE_TO_RX_ADDR_MISMATCH_CTL_SDR_RESTART_DUE_TO_RX_ADDR_MISMATCH_IDLE_LMT;
160  reg |= (us & IPMAC_REG_SDR_RESTART_DUE_TO_RX_ADDR_MISMATCH_CTL_SDR_RESTART_DUE_TO_RX_ADDR_MISMATCH_IDLE_LMT_MASK) <<
161  IPMAC_REG_SDR_RESTART_DUE_TO_RX_ADDR_MISMATCH_CTL_SDR_RESTART_DUE_TO_RX_ADDR_MISMATCH_IDLE_LMT_SHIFT;
162 
163  WR_WORD(IPMAC_REG_SDR_RESTART_DUE_TO_RX_ADDR_MISMATCH, reg);
164 
165 }
166 
167 static __inline void sdr_rx_da_ctl(uint16_t da, uint16_t mask)
168 {
169  uint32_t reg = da | (mask << IPMAC_REG_SDR_DEST_ADDR_TO_MATCH_CTL_SDR_DEST_ADDR_MATCH_MASK_SHIFT);
170  WR_WORD(IPMAC_REG_SDR_DEST_ADDR_TO_MATCH, reg);
171 }
172 
173 static __inline void sdr_rx_sa_ctl(int idx, uint16_t sa, uint16_t mask)
174 {
175  uint32_t reg = sa | (mask << IPMAC_REG_SDR_SRC_ADDR_TO_MATCH_0_CTL_SDR_SRC_ADDR_0_MATCH_MASK_SHIFT);
176  WR_WORD((IPMAC_REG_SDR_SRC_ADDR_TO_MATCH_0 + idx * 4), reg);
177 }
178 
179 static __inline uint16_t sdr_tx_da_addr(void)
180 {
181  return ((RD_WORD(IPMAC_REG_SDR_TX_ADDR) >> IPMAC_REG_SDR_TX_ADDR_STS_SDR_TX_DEST_ADDR_SHIFT) & IPMAC_REG_SDR_TX_ADDR_STS_SDR_TX_DEST_ADDR_MASK);
182 }
183 
184 static __inline uint16_t sdr_tx_sa_addr(void)
185 {
186  return (RD_WORD(IPMAC_REG_SDR_TX_ADDR) & IPMAC_REG_SDR_TX_ADDR_STS_SDR_TX_SRC_ADDR_MASK);
187 }
188 
189 static __inline uint16_t sdr_rx_da_addr(void)
190 {
191  return ((RD_WORD(IPMAC_REG_SDR_RX_ADDR) >> IPMAC_REG_SDR_RX_ADDR_STS_SDR_RX_DEST_ADDR_SHIFT) & IPMAC_REG_SDR_RX_ADDR_STS_SDR_RX_DEST_ADDR_MASK);
192 }
193 
194 static __inline uint16_t sdr_rx_sa_addr(void)
195 {
196  return (RD_WORD(IPMAC_REG_SDR_RX_ADDR) & IPMAC_REG_SDR_RX_ADDR_STS_SDR_RX_SRC_ADDR_MASK);
197 }
198 
199 static __inline void sdr_ignore_timestamp(int en)
200 {
201  if (en)
202  WR_WORD(IPMAC_REG_SDR_MISC_CTRL, (IPMAC_REG_SDR_MISC_CTRL_CTL_SDR_EN|IPMAC_REG_SDR_MISC_CTRL_CTL_SDR_IGNORE_TIMESTAMP|IPMAC_REG_SDR_MISC_CTRL_CTL_SDR_IGNORE_TIMESTAMP_FINE));
203  else
204  WR_WORD(IPMAC_REG_SDR_MISC_CTRL, 0);
205 }
206 
207 /*
208  * APIs
209  ****************************************************************************************
210  */
211 
223 int sdr_init(void *pv);
224 
235 void sdr_deinit(void *pv);
236 
262 int sdr_mstr_to_slv(char mode, uint32_t aa, char chn, char txr, char rxr, uint16_t mst_a, uint16_t slv_a, uint16_t rx_da_mask, uint16_t tx_len, uint8_t *tx_buf, uint16_t *actual_tx_bytes, void *arg, void(*rx_callback)(void *arg, rx_param_t *para));
263 
300 int sdr_slv_to_mstr(char mode, int slv_ack, uint32_t aa, char chn, char txr, char rxr, uint16_t rxw_sz, uint16_t slv_a, uint16_t rx_da_mask, char nb_mstr, uint16_t mst_a[8], uint16_t mst_a_mask[8], uint16_t tx_len[8], uint8_t *tx_buf[8], uint16_t actual_tx_bytes_array[8], void *arg, void(*rx_callback)(void *arg, rx_param_t *para));
301 
302 #endif
303