49 void check_maca(
void);
52 void set_power(uint8_t power);
53 void set_channel(uint8_t chan);
55 extern uint8_t (*get_lqi)(void);
59 void set_demodulator_type(uint8_t demod);
62 extern volatile uint8_t fcs_mode;
63 #define set_fcs_mode(x) fcs_mode = (x)
67 extern volatile uint8_t prm_mode;
68 #define set_prm_mode(x) prm_mode = (x)
71 void tx_packet(
volatile packet_t *p);
72 volatile packet_t* rx_packet(
void);
73 volatile packet_t* get_free_packet(
void);
74 void maca_free_packet(
volatile packet_t *p);
75 void free_all_packets(
void);
77 extern volatile packet_t *rx_head, *tx_head;
78 extern volatile uint32_t maca_entry;
80 extern void maca_rx_callback(
volatile packet_t *p)
__attribute__((weak));
81 extern void maca_tx_callback(
volatile packet_t *p)
__attribute__((weak));
85 void reset_maca(
void);
87 void flyback_init(
void);
88 void ResumeMACASync(
void);
90 uint32_t init_from_flash(uint32_t addr);
94 extern volatile uint8_t maca_pwr;
96 #define MAX_PACKET_SIZE (MAX_PAYLOAD_SIZE + 2)
100 #define MACA_BASE (0x80004000)
101 #define MACA_RESET ((volatile uint32_t *) (MACA_BASE+0x04))
102 #define MACA_RANDOM ((volatile uint32_t *) (MACA_BASE+0x08))
103 #define MACA_CONTROL ((volatile uint32_t *) (MACA_BASE+0x0c))
108 #define PRECOUNT_MASK bit_mask(4,PRECOUNT)
129 #define MODE_MASK bit_mask(2,MACA_MODE)
131 #define NO_SLOT_CCA 1
135 #define SEQUENCE_MASK bit_mask(3,SEQUENCE)
138 #define MACA_STATUS ((volatile uint32_t *) (MACA_BASE+0x10))
140 #define STATUS_TIMEOUT 15
145 #define CODE_MASK bit_mask(4,CODE)
148 #define CODE_TIMEOUT 1
149 #define CHANNEL_BUSY 2
155 #define EXT_TIMEOUT 8
156 #define EXT_PND_TIMEOUT 9
157 #define PLL_UNLOCK 12
158 #define EXTERNAL_ABORT 13
159 #define NOT_COMPLETED 14
160 #define DMA_BUS_ERROR 15
163 #define MACA_FRMPND ((volatile uint32_t *) (MACA_BASE+0x14))
164 #define MACA_TMREN ((volatile uint32_t *) (MACA_BASE+0x40))
165 #define MACA_TMRDIS ((volatile uint32_t *) (MACA_BASE+0x44))
166 #define MACA_CLK ((volatile uint32_t *) (MACA_BASE+0x48))
167 #define MACA_STARTCLK ((volatile uint32_t *) (MACA_BASE+0x4c))
168 #define MACA_CPLCLK ((volatile uint32_t *) (MACA_BASE+0x50))
169 #define MACA_SFTCLK ((volatile uint32_t *) (MACA_BASE+0x54))
170 #define MACA_CLKOFFSET ((volatile uint32_t *) (MACA_BASE+0x58))
171 #define MACA_RELCLK ((volatile uint32_t *) (MACA_BASE+0x5c))
172 #define MACA_CPLTIM ((volatile uint32_t *) (MACA_BASE+0x60))
173 #define MACA_SLOTOFFSET ((volatile uint32_t *) (MACA_BASE+0x64))
174 #define MACA_TIMESTAMP ((volatile uint32_t *) (MACA_BASE+0x68))
175 #define MACA_DMARX ((volatile uint32_t *) (MACA_BASE+0x80))
176 #define MACA_DMATX ((volatile uint32_t *) (MACA_BASE+0x84))
177 #define MACA_DMAPOLL ((volatile uint32_t *) (MACA_BASE+0x88))
178 #define MACA_TXLEN ((volatile uint32_t *) (MACA_BASE+0x8c))
179 #define MACA_TXSEQNR ((volatile uint32_t *) (MACA_BASE+0x90))
180 #define MACA_SETRXLVL ((volatile uint32_t *) (MACA_BASE+0x94))
181 #define MACA_GETRXLVL ((volatile uint32_t *) (MACA_BASE+0x98))
182 #define MACA_IRQ ((volatile uint32_t *) (MACA_BASE+0xc0))
183 #define MACA_CLRIRQ ((volatile uint32_t *) (MACA_BASE+0xc4))
184 #define MACA_SETIRQ ((volatile uint32_t *) (MACA_BASE+0xc8))
185 #define MACA_MASKIRQ ((volatile uint32_t *) (MACA_BASE+0xcc))
186 #define MACA_MACPANID ((volatile uint32_t *) (MACA_BASE+0x100))
187 #define MACA_MAC16ADDR ((volatile uint32_t *) (MACA_BASE+0x104))
188 #define MACA_MAC64HI ((volatile uint32_t *) (MACA_BASE+0x108))
189 #define MACA_MAC64LO ((volatile uint32_t *) (MACA_BASE+0x10c))
190 #define MACA_FLTREJ ((volatile uint32_t *) (MACA_BASE+0x110))
191 #define MACA_CLKDIV ((volatile uint32_t *) (MACA_BASE+0x114))
192 #define MACA_WARMUP ((volatile uint32_t *) (MACA_BASE+0x118))
193 #define MACA_PREAMBLE ((volatile uint32_t *) (MACA_BASE+0x11c))
194 #define MACA_WHITESEED ((volatile uint32_t *) (MACA_BASE+0x120))
195 #define MACA_FRAMESYNC0 ((volatile uint32_t *) (MACA_BASE+0x124))
196 #define MACA_FRAMESYNC1 ((volatile uint32_t *) (MACA_BASE+0x128))
197 #define MACA_TXACKDELAY ((volatile uint32_t *) (MACA_BASE+0x140))
198 #define MACA_RXACKDELAY ((volatile uint32_t *) (MACA_BASE+0x144))
199 #define MACA_EOFDELAY ((volatile uint32_t *) (MACA_BASE+0x148))
200 #define MACA_CCADELAY ((volatile uint32_t *) (MACA_BASE+0x14c))
201 #define MACA_RXEND ((volatile uint32_t *) (MACA_BASE+0x150))
202 #define MACA_TXCCADELAY ((volatile uint32_t *) (MACA_BASE+0x154))
203 #define MACA_KEY3 ((volatile uint32_t *) (MACA_BASE+0x158))
204 #define MACA_KEY2 ((volatile uint32_t *) (MACA_BASE+0x15c))
205 #define MACA_KEY1 ((volatile uint32_t *) (MACA_BASE+0x160))
206 #define MACA_KEY0 ((volatile uint32_t *) (MACA_BASE+0x164))
207 #define MACA_OPTIONS ((volatile uint32_t *) (MACA_BASE+0x180))
215 #define control_pre_count (7<<16)
216 #define control_rst_slot (1<<15)
217 #define control_role (1<<13)
218 #define control_nofc (1<<12)
219 #define control_prm (1<<11)
220 #define control_relative (1<<10)
221 #define control_asap (1<<9)
222 #define control_bcn (1<<8)
223 #define control_auto (1<<7)
224 #define control_lfsr (1<<6)
226 #define gMACA_Clock_DIV_c 95
247 cc_ext_pnd_timeout = 9,
251 cc_cc_external_abort= 13,
252 cc_not_completed = 14,
258 control_mode_no_cca = 0,
259 control_mode_non_slotted = (1<<3),
260 control_mode_slotted = (1<<4)
265 control_seq_abort = 1,
266 control_seq_wait = 2,
269 control_seq_txpoll = 5,
274 #define maca_version (*((volatile uint32_t *)(0x80004000)))
275 #define maca_reset (*((volatile uint32_t *)(0x80004004)))
276 #define maca_random (*((volatile uint32_t *)(0x80004008)))
277 #define maca_control (*((volatile uint32_t *)(0x8000400c)))
278 #define maca_status (*((volatile uint32_t *)(0x80004010)))
279 #define maca_frmpnd (*((volatile uint32_t *)(0x80004014)))
281 #define maca_edvalue (*((volatile uint32_t *)(0x8000401c)))
282 #define maca_tmren (*((volatile uint32_t *)(0x80004040)))
283 #define maca_tmrdis (*((volatile uint32_t *)(0x80004044)))
284 #define maca_clk (*((volatile uint32_t *)(0x80004048)))
285 #define maca_startclk (*((volatile uint32_t *)(0x8000404c)))
286 #define maca_cplclk (*((volatile uint32_t *)(0x80004050)))
287 #define maca_sftclk (*((volatile uint32_t *)(0x80004054)))
288 #define maca_clkoffset (*((volatile uint32_t *)(0x80004058)))
289 #define maca_relclk (*((volatile uint32_t *)(0x8000405c)))
290 #define maca_cpltim (*((volatile uint32_t *)(0x80004060)))
291 #define maca_slotoffset (*((volatile uint32_t *)(0x80004064)))
292 #define maca_timestamp (*((volatile uint32_t *)(0x80004068)))
293 #define maca_dmarx (*((volatile uint32_t *)(0x80004080)))
294 #define maca_dmatx (*((volatile uint32_t *)(0x80004084)))
295 #define maca_dmatxpoll (*((volatile uint32_t *)(0x80004088)))
296 #define maca_txlen (*((volatile uint32_t *)(0x8000408c)))
297 #define maca_txseqnr (*((volatile uint32_t *)(0x80004090)))
298 #define maca_setrxlvl (*((volatile uint32_t *)(0x80004094)))
299 #define maca_getrxlvl (*((volatile uint32_t *)(0x80004098)))
300 #define maca_irq (*((volatile uint32_t *)(0x800040c0)))
301 #define maca_clrirq (*((volatile uint32_t *)(0x800040c4)))
302 #define maca_setirq (*((volatile uint32_t *)(0x800040c8)))
303 #define maca_maskirq (*((volatile uint32_t *)(0x800040cc)))
304 #define maca_panid (*((volatile uint32_t *)(0x80004100)))
305 #define maca_addr16 (*((volatile uint32_t *)(0x80004104)))
306 #define maca_maca64hi (*((volatile uint32_t *)(0x80004108)))
307 #define maca_maca64lo (*((volatile uint32_t *)(0x8000410c)))
308 #define maca_fltrej (*((volatile uint32_t *)(0x80004110)))
309 #define maca_divider (*((volatile uint32_t *)(0x80004114)))
310 #define maca_warmup (*((volatile uint32_t *)(0x80004118)))
311 #define maca_preamble (*((volatile uint32_t *)(0x8000411c)))
312 #define maca_whiteseed (*((volatile uint32_t *)(0x80004120)))
313 #define maca_framesync (*((volatile uint32_t *)(0x80004124)))
314 #define maca_framesync2 (*((volatile uint32_t *)(0x80004128)))
315 #define maca_txackdelay (*((volatile uint32_t *)(0x80004140)))
316 #define maca_rxackdelay (*((volatile uint32_t *)(0x80004144)))
317 #define maca_eofdelay (*((volatile uint32_t *)(0x80004148)))
318 #define maca_ccadelay (*((volatile uint32_t *)(0x8000414c)))
319 #define maca_rxend (*((volatile uint32_t *)(0x80004150)))
320 #define maca_txccadelay (*((volatile uint32_t *)(0x80004154)))
321 #define maca_key3 (*((volatile uint32_t *)(0x80004158)))
322 #define maca_key2 (*((volatile uint32_t *)(0x80004158)))
323 #define maca_key1 (*((volatile uint32_t *)(0x80004158)))
324 #define maca_key0 (*((volatile uint32_t *)(0x80004158)))
327 typedef union maca_version_reg_tag
332 uint32_t RESERVED1:8;
334 uint32_t RESERVED2:8;
337 } maca_version_reg_t;
339 #define maca_version_reg_st ((maca_version_reg_t)(maca_version))
342 typedef union maca_reset_reg_tag
346 uint32_t RESERVED:30;
353 #define maca_reset_reg_st ((maca_reset_reg_t)(maca_reset))
380 #define maca_control_ism (1<<20)
381 #define maca_control_zigbee (~maca_control_ism)
383 #define maca_ctrl_reg_st ((maca_ctrl_reg_t *)(&maca_reset))
384 #define _set_maca_test_mode(x) (maca_ctrl_reg_st->Bits.TM = x)
385 #define _set_maca_sequence(x) (maca_ctrl_reg_st->Bits.SEQUENCE = x)
386 #define _set_maca_asap(x) (maca_ctrl_reg_st->Bits.ASAP = x)
389 #define MACA_CTRL_ZIGBEE_MODE (0)
390 #define MACA_CTRL_ISM_MODE (1)
391 #define MACA_CTRL_PRM_NORMAL_MODE (0)
392 #define MACA_CTRL_PRM_PROMISCUOUS_MODE (1)
393 #define MACA_CTRL_BCN_ALL (0)
394 #define MACA_CTRL_BCN_BEACON (1)
395 #define MACA_CTRL_TM_NORMAL (0)
396 #define MACA_CTRL_TM_TEST (1)
397 #define MACA_CTRL_MODE_NO_CCA (0)
398 #define MACA_CTRL_MODE_NON_SLOTTED (1)
399 #define MACA_CTRL_MODE_SLOTTED (2)
401 typedef enum maca_freq_chann_tag
424 enum maca_complete_code {
427 maca_cc_channel_busy = 2,
428 maca_cc_crc_fail = 3,
432 maca_cc_late_start = 7,
433 maca_cc_ext_timeout = 8,
434 maca_cc_ext_pnd_timeout = 9,
438 maca_cc_cc_external_abort= 13,
439 maca_cc_not_completed = 14,
440 maca_cc_bus_error = 15
445 maca_ctrl_seq_nop = 0,
446 maca_ctrl_seq_abort = 1,
447 maca_ctrl_seq_wait = 2,
448 maca_ctrl_seq_tx = 3,
449 maca_ctrl_seq_rx = 4,
450 maca_ctrl_seq_txpoll = 5,
451 maca_ctrl_seq_cca = 6,
456 enum maca_ctrl_modes {
457 maca_ctrl_mode_no_cca = 0,
458 maca_ctrl_mode_non_slotted_csma_ca = 1,
459 maca_ctrl_mode_slotted_csma_ca = 2,
463 enum maca_ctrl_bits {
477 maca_ctrl_pre_count = 16,
489 maca_irq_sftclk = 10,
498 enum maca_reset_bits {
500 maca_reset_clkon = 1,
504 enum maca_tmren_bits {
510 enum maca_status_bits {
511 maca_status_ovr = 12,
512 maca_status_busy = 13,
513 maca_status_crc = 14,
517 #define action_complete_irq() bit_is_set(*MACA_IRQ,maca_irq_acpl)
518 #define filter_failed_irq() bit_is_set(*MACA_IRQ,maca_irq_flt)
519 #define checksum_failed_irq() bit_is_set(*MACA_IRQ,maca_irq_crc)
520 #define data_indication_irq() bit_is_set(*MACA_IRQ,maca_irq_di)
521 #define softclock_irq() bit_is_set(*MACA_IRQ,maca_irq_sftclk)
522 #define poll_irq() bit_is_set(*MACA_IRQ,maca_irq_poll)
524 #define status_is_not_completed() ((*MACA_STATUS & 0xffff) == maca_cc_not_completed)
525 #define status_is_success() ((*MACA_STATUS & 0xffff) == maca_cc_success)
527 #define SMAC_MACA_CNTL_INIT_STATE ( control_prm | control_nofc | control_mode_non_slotted )
529 #define MACA_WRITE(reg, src) (reg = src)
530 #define MACA_READ(reg) reg
void __attribute__((interrupt))
This ISR handles most of the business interacting with the 1-wire bus.
#define RST
Pin number that corresponds to the RST pin.
radio_status_t radio_init(bool cal_rc_osc, hal_rx_start_isr_event_handler_t rx_event, hal_trx_end_isr_event_handler_t trx_end_event, radio_rx_callback rx_callback)
Initialize the Transceiver Access Toolbox and lower layers.