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 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);
92 #define MAX_PACKET_SIZE (MAX_PAYLOAD_SIZE + 2)
96 #define MACA_BASE (0x80004000)
97 #define MACA_RESET ((volatile uint32_t *) (MACA_BASE+0x04))
98 #define MACA_RANDOM ((volatile uint32_t *) (MACA_BASE+0x08))
99 #define MACA_CONTROL ((volatile uint32_t *) (MACA_BASE+0x0c))
104 #define PRECOUNT_MASK bit_mask(4,PRECOUNT)
125 #define MODE_MASK bit_mask(2,MACA_MODE)
127 #define NO_SLOT_CCA 1
131 #define SEQUENCE_MASK bit_mask(3,SEQUENCE)
134 #define MACA_STATUS ((volatile uint32_t *) (MACA_BASE+0x10))
136 #define STATUS_TIMEOUT 15
141 #define CODE_MASK bit_mask(4,CODE)
144 #define CODE_TIMEOUT 1
145 #define CHANNEL_BUSY 2
151 #define EXT_TIMEOUT 8
152 #define EXT_PND_TIMEOUT 9
153 #define PLL_UNLOCK 12
154 #define EXTERNAL_ABORT 13
155 #define NOT_COMPLETED 14
156 #define DMA_BUS_ERROR 15
159 #define MACA_FRMPND ((volatile uint32_t *) (MACA_BASE+0x14))
160 #define MACA_TMREN ((volatile uint32_t *) (MACA_BASE+0x40))
161 #define MACA_TMRDIS ((volatile uint32_t *) (MACA_BASE+0x44))
162 #define MACA_CLK ((volatile uint32_t *) (MACA_BASE+0x48))
163 #define MACA_STARTCLK ((volatile uint32_t *) (MACA_BASE+0x4c))
164 #define MACA_CPLCLK ((volatile uint32_t *) (MACA_BASE+0x50))
165 #define MACA_SFTCLK ((volatile uint32_t *) (MACA_BASE+0x54))
166 #define MACA_CLKOFFSET ((volatile uint32_t *) (MACA_BASE+0x58))
167 #define MACA_RELCLK ((volatile uint32_t *) (MACA_BASE+0x5c))
168 #define MACA_CPLTIM ((volatile uint32_t *) (MACA_BASE+0x60))
169 #define MACA_SLOTOFFSET ((volatile uint32_t *) (MACA_BASE+0x64))
170 #define MACA_TIMESTAMP ((volatile uint32_t *) (MACA_BASE+0x68))
171 #define MACA_DMARX ((volatile uint32_t *) (MACA_BASE+0x80))
172 #define MACA_DMATX ((volatile uint32_t *) (MACA_BASE+0x84))
173 #define MACA_DMAPOLL ((volatile uint32_t *) (MACA_BASE+0x88))
174 #define MACA_TXLEN ((volatile uint32_t *) (MACA_BASE+0x8c))
175 #define MACA_TXSEQNR ((volatile uint32_t *) (MACA_BASE+0x90))
176 #define MACA_SETRXLVL ((volatile uint32_t *) (MACA_BASE+0x94))
177 #define MACA_GETRXLVL ((volatile uint32_t *) (MACA_BASE+0x98))
178 #define MACA_IRQ ((volatile uint32_t *) (MACA_BASE+0xc0))
179 #define MACA_CLRIRQ ((volatile uint32_t *) (MACA_BASE+0xc4))
180 #define MACA_SETIRQ ((volatile uint32_t *) (MACA_BASE+0xc8))
181 #define MACA_MASKIRQ ((volatile uint32_t *) (MACA_BASE+0xcc))
182 #define MACA_MACPANID ((volatile uint32_t *) (MACA_BASE+0x100))
183 #define MACA_MAC16ADDR ((volatile uint32_t *) (MACA_BASE+0x104))
184 #define MACA_MAC64HI ((volatile uint32_t *) (MACA_BASE+0x108))
185 #define MACA_MAC64LO ((volatile uint32_t *) (MACA_BASE+0x10c))
186 #define MACA_FLTREJ ((volatile uint32_t *) (MACA_BASE+0x110))
187 #define MACA_CLKDIV ((volatile uint32_t *) (MACA_BASE+0x114))
188 #define MACA_WARMUP ((volatile uint32_t *) (MACA_BASE+0x118))
189 #define MACA_PREAMBLE ((volatile uint32_t *) (MACA_BASE+0x11c))
190 #define MACA_WHITESEED ((volatile uint32_t *) (MACA_BASE+0x120))
191 #define MACA_FRAMESYNC0 ((volatile uint32_t *) (MACA_BASE+0x124))
192 #define MACA_FRAMESYNC1 ((volatile uint32_t *) (MACA_BASE+0x128))
193 #define MACA_TXACKDELAY ((volatile uint32_t *) (MACA_BASE+0x140))
194 #define MACA_RXACKDELAY ((volatile uint32_t *) (MACA_BASE+0x144))
195 #define MACA_EOFDELAY ((volatile uint32_t *) (MACA_BASE+0x148))
196 #define MACA_CCADELAY ((volatile uint32_t *) (MACA_BASE+0x14c))
197 #define MACA_RXEND ((volatile uint32_t *) (MACA_BASE+0x150))
198 #define MACA_TXCCADELAY ((volatile uint32_t *) (MACA_BASE+0x154))
199 #define MACA_KEY3 ((volatile uint32_t *) (MACA_BASE+0x158))
200 #define MACA_KEY2 ((volatile uint32_t *) (MACA_BASE+0x15c))
201 #define MACA_KEY1 ((volatile uint32_t *) (MACA_BASE+0x160))
202 #define MACA_KEY0 ((volatile uint32_t *) (MACA_BASE+0x164))
203 #define MACA_OPTIONS ((volatile uint32_t *) (MACA_BASE+0x180))
211 #define control_pre_count (7<<16)
212 #define control_rst_slot (1<<15)
213 #define control_role (1<<13)
214 #define control_nofc (1<<12)
215 #define control_prm (1<<11)
216 #define control_relative (1<<10)
217 #define control_asap (1<<9)
218 #define control_bcn (1<<8)
219 #define control_auto (1<<7)
220 #define control_lfsr (1<<6)
222 #define gMACA_Clock_DIV_c 95
243 cc_ext_pnd_timeout = 9,
247 cc_cc_external_abort= 13,
248 cc_not_completed = 14,
254 control_mode_no_cca = 0,
255 control_mode_non_slotted = (1<<3),
256 control_mode_slotted = (1<<4)
261 control_seq_abort = 1,
262 control_seq_wait = 2,
265 control_seq_txpoll = 5,
270 #define maca_version (*((volatile uint32_t *)(0x80004000)))
271 #define maca_reset (*((volatile uint32_t *)(0x80004004)))
272 #define maca_random (*((volatile uint32_t *)(0x80004008)))
273 #define maca_control (*((volatile uint32_t *)(0x8000400c)))
274 #define maca_status (*((volatile uint32_t *)(0x80004010)))
275 #define maca_frmpnd (*((volatile uint32_t *)(0x80004014)))
277 #define maca_edvalue (*((volatile uint32_t *)(0x8000401c)))
278 #define maca_tmren (*((volatile uint32_t *)(0x80004040)))
279 #define maca_tmrdis (*((volatile uint32_t *)(0x80004044)))
280 #define maca_clk (*((volatile uint32_t *)(0x80004048)))
281 #define maca_startclk (*((volatile uint32_t *)(0x8000404c)))
282 #define maca_cplclk (*((volatile uint32_t *)(0x80004050)))
283 #define maca_sftclk (*((volatile uint32_t *)(0x80004054)))
284 #define maca_clkoffset (*((volatile uint32_t *)(0x80004058)))
285 #define maca_relclk (*((volatile uint32_t *)(0x8000405c)))
286 #define maca_cpltim (*((volatile uint32_t *)(0x80004060)))
287 #define maca_slotoffset (*((volatile uint32_t *)(0x80004064)))
288 #define maca_timestamp (*((volatile uint32_t *)(0x80004068)))
289 #define maca_dmarx (*((volatile uint32_t *)(0x80004080)))
290 #define maca_dmatx (*((volatile uint32_t *)(0x80004084)))
291 #define maca_dmatxpoll (*((volatile uint32_t *)(0x80004088)))
292 #define maca_txlen (*((volatile uint32_t *)(0x8000408c)))
293 #define maca_txseqnr (*((volatile uint32_t *)(0x80004090)))
294 #define maca_setrxlvl (*((volatile uint32_t *)(0x80004094)))
295 #define maca_getrxlvl (*((volatile uint32_t *)(0x80004098)))
296 #define maca_irq (*((volatile uint32_t *)(0x800040c0)))
297 #define maca_clrirq (*((volatile uint32_t *)(0x800040c4)))
298 #define maca_setirq (*((volatile uint32_t *)(0x800040c8)))
299 #define maca_maskirq (*((volatile uint32_t *)(0x800040cc)))
300 #define maca_panid (*((volatile uint32_t *)(0x80004100)))
301 #define maca_addr16 (*((volatile uint32_t *)(0x80004104)))
302 #define maca_maca64hi (*((volatile uint32_t *)(0x80004108)))
303 #define maca_maca64lo (*((volatile uint32_t *)(0x8000410c)))
304 #define maca_fltrej (*((volatile uint32_t *)(0x80004110)))
305 #define maca_divider (*((volatile uint32_t *)(0x80004114)))
306 #define maca_warmup (*((volatile uint32_t *)(0x80004118)))
307 #define maca_preamble (*((volatile uint32_t *)(0x8000411c)))
308 #define maca_whiteseed (*((volatile uint32_t *)(0x80004120)))
309 #define maca_framesync (*((volatile uint32_t *)(0x80004124)))
310 #define maca_framesync2 (*((volatile uint32_t *)(0x80004128)))
311 #define maca_txackdelay (*((volatile uint32_t *)(0x80004140)))
312 #define maca_rxackdelay (*((volatile uint32_t *)(0x80004144)))
313 #define maca_eofdelay (*((volatile uint32_t *)(0x80004148)))
314 #define maca_ccadelay (*((volatile uint32_t *)(0x8000414c)))
315 #define maca_rxend (*((volatile uint32_t *)(0x80004150)))
316 #define maca_txccadelay (*((volatile uint32_t *)(0x80004154)))
317 #define maca_key3 (*((volatile uint32_t *)(0x80004158)))
318 #define maca_key2 (*((volatile uint32_t *)(0x80004158)))
319 #define maca_key1 (*((volatile uint32_t *)(0x80004158)))
320 #define maca_key0 (*((volatile uint32_t *)(0x80004158)))
323 typedef union maca_version_reg_tag
328 uint32_t RESERVED1:8;
330 uint32_t RESERVED2:8;
333 } maca_version_reg_t;
335 #define maca_version_reg_st ((maca_version_reg_t)(maca_version))
338 typedef union maca_reset_reg_tag
342 uint32_t RESERVED:30;
349 #define maca_reset_reg_st ((maca_reset_reg_t)(maca_reset))
376 #define maca_control_ism (1<<20)
377 #define maca_control_zigbee (~maca_control_ism)
379 #define maca_ctrl_reg_st ((maca_ctrl_reg_t *)(&maca_reset))
380 #define _set_maca_test_mode(x) (maca_ctrl_reg_st->Bits.TM = x)
381 #define _set_maca_sequence(x) (maca_ctrl_reg_st->Bits.SEQUENCE = x)
382 #define _set_maca_asap(x) (maca_ctrl_reg_st->Bits.ASAP = x)
385 #define MACA_CTRL_ZIGBEE_MODE (0)
386 #define MACA_CTRL_ISM_MODE (1)
387 #define MACA_CTRL_PRM_NORMAL_MODE (0)
388 #define MACA_CTRL_PRM_PROMISCUOUS_MODE (1)
389 #define MACA_CTRL_BCN_ALL (0)
390 #define MACA_CTRL_BCN_BEACON (1)
391 #define MACA_CTRL_TM_NORMAL (0)
392 #define MACA_CTRL_TM_TEST (1)
393 #define MACA_CTRL_MODE_NO_CCA (0)
394 #define MACA_CTRL_MODE_NON_SLOTTED (1)
395 #define MACA_CTRL_MODE_SLOTTED (2)
397 typedef enum maca_freq_chann_tag
420 enum maca_complete_code {
423 maca_cc_channel_busy = 2,
424 maca_cc_crc_fail = 3,
428 maca_cc_late_start = 7,
429 maca_cc_ext_timeout = 8,
430 maca_cc_ext_pnd_timeout = 9,
434 maca_cc_cc_external_abort= 13,
435 maca_cc_not_completed = 14,
436 maca_cc_bus_error = 15
441 maca_ctrl_seq_nop = 0,
442 maca_ctrl_seq_abort = 1,
443 maca_ctrl_seq_wait = 2,
444 maca_ctrl_seq_tx = 3,
445 maca_ctrl_seq_rx = 4,
446 maca_ctrl_seq_txpoll = 5,
447 maca_ctrl_seq_cca = 6,
452 enum maca_ctrl_modes {
453 maca_ctrl_mode_no_cca = 0,
454 maca_ctrl_mode_non_slotted_csma_ca = 1,
455 maca_ctrl_mode_slotted_csma_ca = 2,
459 enum maca_ctrl_bits {
473 maca_ctrl_pre_count = 16,
485 maca_irq_sftclk = 10,
494 enum maca_reset_bits {
496 maca_reset_clkon = 1,
500 enum maca_tmren_bits {
506 enum maca_status_bits {
507 maca_status_ovr = 12,
508 maca_status_busy = 13,
509 maca_status_crc = 14,
513 #define action_complete_irq() bit_is_set(*MACA_IRQ,maca_irq_acpl)
514 #define filter_failed_irq() bit_is_set(*MACA_IRQ,maca_irq_flt)
515 #define checksum_failed_irq() bit_is_set(*MACA_IRQ,maca_irq_crc)
516 #define data_indication_irq() bit_is_set(*MACA_IRQ,maca_irq_di)
517 #define softclock_irq() bit_is_set(*MACA_IRQ,maca_irq_sftclk)
518 #define poll_irq() bit_is_set(*MACA_IRQ,maca_irq_poll)
520 #define status_is_not_completed() ((*MACA_STATUS & 0xffff) == maca_cc_not_completed)
521 #define status_is_success() ((*MACA_STATUS & 0xffff) == maca_cc_success)
523 #define SMAC_MACA_CNTL_INIT_STATE ( control_prm | control_nofc | control_mode_non_slotted )
525 #define MACA_WRITE(reg, src) (reg = src)
526 #define MACA_READ(reg) reg