45 #define PRINTF(...) printf(__VA_ARGS__)
48 #ifndef MACA_BOUND_CHECK
49 #define MACA_BOUND_CHECK 0
51 #if (MACA_BOUND_CHECK == 0)
52 #define BOUND_CHECK(x)
54 #define BOUND_CHECK(x) bound_check(x)
58 #define NUM_PACKETS 32
62 #define MACA_CLOCK_DIV 95
65 #define CLK_PER_BYTE 8
67 #ifndef RECV_SOFTIMEOUT
68 #define RECV_SOFTIMEOUT (1024*128*CLK_PER_BYTE)
72 #define CPL_TIMEOUT (2*128*CLK_PER_BYTE)
75 #ifndef MACA_INSERT_ACK
76 #define MACA_INSERT_ACK 1
81 #define MAC_ACK_REQUEST_FLAG 0x20
83 #define reg(x) (*(volatile uint32_t *)(x))
85 int count_packets(
void);
86 void Print_Packets(
char *s);
88 static volatile packet_t packet_pool[NUM_PACKETS];
89 static volatile packet_t *free_head, *rx_end, *tx_end, *dma_tx, *dma_rx;
94 volatile packet_t *rx_head, *tx_head;
98 static volatile packet_t dummy_ack;
102 volatile uint32_t maca_entry = 0;
110 static volatile uint8_t last_post = NO_POST;
112 volatile uint8_t fcs_mode = USE_FCS;
113 volatile uint8_t prm_mode = PROMISC;
122 void check_maca(
void) {
123 safe_irq_disable(MACA);
124 static volatile uint32_t last_time;
125 static volatile uint32_t last_entry;
128 volatile uint32_t count;
135 for(i=0; (i < 1024) && (*MACA_CLK == last_time); i++) {
continue; }
137 if(*MACA_CLK == last_time) {
138 PRINTF(
"check maca: maca_clk stopped, restarting\n");
141 *INTFRC = (1<<INT_NUM_MACA);
143 if((last_time > (*MACA_SFTCLK + RECV_SOFTIMEOUT)) &&
144 (last_time > (*MACA_CPLCLK + CPL_TIMEOUT))) {
145 PRINTF(
"check maca: complete clocks expired\n");
149 if(last_entry == maca_entry) {
150 PRINTF(
"check maca: forcing isr\n");
151 *INTFRC = (1<<INT_NUM_MACA);
156 last_entry = maca_entry;
157 last_time = *MACA_CLK;
160 if((count = count_packets()) != NUM_PACKETS) {
161 PRINTF(
"check maca: count_packets %d\n", (
int)count);
162 Print_Packets(
"check_maca");
164 for(i=0; i<NUM_PACKETS; i++) {
165 printf(
"packet 0x%lx seen %d post_tx %d get_free %d rxd %d\n",
166 (uint32_t) &packet_pool[i],
168 packet_pool[i].post_tx,
169 packet_pool[i].get_free,
173 if(bit_is_set(*NIPEND, INT_NUM_MACA)) { *INTFRC = (1 << INT_NUM_MACA); }
179 void maca_init(
void) {
186 free_head = 0; tx_head = 0; rx_head = 0; rx_end = 0; tx_end = 0; dma_tx = 0; dma_rx = 0;
190 Print_Packets(
"maca_init");
197 (NO_CCA << MACA_MODE);
200 *INTFRC = (1 << INT_NUM_MACA);
203 #define print_packets(x) Print_Packets(x)
204 void Print_Packets(
char *s) {
205 volatile packet_t *p;
207 printf(
"packet pool after %s:\n\r",s);
209 printf(
"free_head: 0x%lx ", (uint32_t) free_head);
212 printf(
"->0x%lx", (uint32_t) p);
217 printf(
"tx_head: 0x%lx ", (uint32_t) tx_head);
220 printf(
"->0x%lx", (uint32_t) p);
225 printf(
"rx_head: 0x%lx ", (uint32_t) rx_head);
228 printf(
"->0x%lx", (uint32_t) p);
232 printf(
"dma_rx: 0x%lx\n", (uint32_t) dma_rx);
233 printf(
"dma_tx: 0x%lx\n", (uint32_t) dma_tx);
237 inline void bad_packet_bounds(
void) {
238 PRINTF(
"bad packet bounds! Halting.\n");
239 while(1) {
continue; }
242 int count_packets(
void) {
243 volatile int8_t total = -1;
246 volatile packet_t *pk;
247 volatile uint8_t tx, rx, free;
250 for(i = 0; i < NUM_PACKETS; i++) {
251 packet_pool[i].seen = 0;
254 pk = tx_head; tx = 0;
256 if(pk->seen == 0) { tx++; }
260 pk = rx_head; rx = 0;
262 if(pk->seen == 0) { rx++; }
266 pk = free_head; free = 0;
268 if(pk->seen == 0) { free++; }
273 total = free + rx + tx;
274 if(dma_rx && (dma_rx->seen == 0)) { dma_rx->seen++; total++; }
275 if(dma_tx && (dma_tx->seen == 0)) { dma_tx->seen++; total++; }
281 void bound_check(
volatile packet_t *p) {
285 (p == &dummy_ack)) {
return; }
286 for(i=0; i < NUM_PACKETS; i++) {
287 if(p == &packet_pool[i]) {
return; }
297 void free_packet(
volatile packet_t *p) {
298 safe_irq_disable(MACA);
302 if(!p) { PRINTF(
"free_packet passed packet 0\n\r");
return; }
303 if(p == &dummy_ack) {
return; }
305 BOUND_CHECK(free_head);
307 p->length = 0; p->offset = 0;
308 p->left = free_head; p->right = 0;
318 BOUND_CHECK(free_head);
321 if(bit_is_set(*NIPEND, INT_NUM_MACA)) { *INTFRC = (1 << INT_NUM_MACA); }
326 volatile packet_t* get_free_packet(
void) {
327 volatile packet_t *p;
329 safe_irq_disable(MACA);
331 BOUND_CHECK(free_head);
336 free_head->right = 0;
339 BOUND_CHECK(free_head);
347 if(bit_is_set(*NIPEND, INT_NUM_MACA)) { *INTFRC = (1 << INT_NUM_MACA); }
352 void post_receive(
void) {
357 *MACA_TXLEN = (MAX_PACKET_SIZE << 16);
359 dma_rx = get_free_packet();
361 PRINTF(
"trying to fill MACA_DMARX in post_receieve but out of packet buffers\n\r");
363 *MACA_SFTCLK = *MACA_CLK + RECV_SOFTIMEOUT;
364 *MACA_TMREN = (1 << maca_tmren_sft);
372 *MACA_DMARX = (uint32_t)&(dma_rx->data[0]);
374 *MACA_SFTCLK = *MACA_CLK + RECV_SOFTIMEOUT;
375 *MACA_TMREN = (1 << maca_tmren_sft);
377 *MACA_CONTROL = ( (1 << maca_ctrl_asap) |
379 ( fcs_mode << NOFC ) |
381 #if 0 //dak says removing ctrl auto fixes the autoack checksum error --- doesn't cause a performance issue either
382 (1 << maca_ctrl_auto) |
391 volatile packet_t* rx_packet(
void) {
392 volatile packet_t *p;
393 safe_irq_disable(MACA);
395 BOUND_CHECK(rx_head);
409 if(bit_is_set(*NIPEND, INT_NUM_MACA)) { *INTFRC = (1 << INT_NUM_MACA); }
423 *MACA_TXSEQNR = dma_tx->data[2];
424 *MACA_TXLEN = (uint32_t)((dma_tx->length) + 2) | (3 << 16);
425 *MACA_DMATX = (uint32_t)&(dma_tx->data[ 0 + dma_tx->offset]);
427 dma_rx = get_free_packet();
430 PRINTF(
"trying to fill MACA_DMARX on post_tx but out of packet buffers\n\r");
436 *MACA_DMARX = (uint32_t)&(dma_rx->data[0]);
439 *MACA_TMRDIS = (1 << maca_tmren_sft) | ( 1<< maca_tmren_cpl) | ( 1 << maca_tmren_strt ) ;
443 *MACA_CPLCLK = *MACA_CLK + CPL_TIMEOUT;
445 *MACA_TMREN = (1 << maca_tmren_cpl);
448 *MACA_CONTROL = ( ( 4 << PRECOUNT) |
450 (maca_ctrl_mode_no_cca << maca_ctrl_mode) |
451 (1 << maca_ctrl_asap) |
458 void tx_packet(
volatile packet_t *p) {
459 safe_irq_disable(MACA);
463 if(!p) { PRINTF(
"tx_packet passed packet 0\n\r");
return; }
467 tx_end->left = 0; tx_end->right = 0;
474 tx_end = p; tx_end->left = 0;
478 if(bit_is_set(*NIPEND, INT_NUM_MACA)) { *INTFRC = (1 << INT_NUM_MACA); }
479 if(last_post == NO_POST) { *INTFRC = (1<<INT_NUM_MACA); }
481 if(last_post == RX_POST) { *MACA_SFTCLK = *MACA_CLK + CLK_PER_BYTE; }
485 void free_all_packets(
void) {
487 safe_irq_disable(MACA);
490 for(i=0; i<NUM_PACKETS; i++) {
491 free_packet((
volatile packet_t *)&(packet_pool[i]));
493 rx_head = 0; rx_end = 0;
494 tx_head = 0; tx_end = 0;
497 if(bit_is_set(*NIPEND, INT_NUM_MACA)) { *INTFRC = (1 << INT_NUM_MACA); }
504 void free_tx_head(
void) {
505 volatile packet_t *p;
506 safe_irq_disable(MACA);
508 BOUND_CHECK(tx_head);
511 tx_head = tx_head->left;
512 if(tx_head == 0) { tx_end = 0; }
517 if(bit_is_set(*NIPEND, INT_NUM_MACA)) { *INTFRC = (1 << INT_NUM_MACA); }
522 void add_to_rx(
volatile packet_t *p) {
523 safe_irq_disable(MACA);
527 if(!p) { PRINTF(
"add_to_rx passed packet 0\n\r");
return; }
532 rx_end->left = 0; rx_end->right = 0;
537 rx_end = p; rx_end->left = 0;
542 if(bit_is_set(*NIPEND, INT_NUM_MACA)) { *INTFRC = (1 << INT_NUM_MACA); }
547 void insert_at_rx_head(
volatile packet_t *p) {
548 safe_irq_disable(MACA);
552 if(!p) { PRINTF(
"insert_at_rx_head passed packet 0\n\r");
return; }
557 rx_end->left = 0; rx_end->right = 0;
562 rx_head = p; rx_head->left = 0;
567 if(bit_is_set(*NIPEND, INT_NUM_MACA)) { *INTFRC = (1 << INT_NUM_MACA); }
573 void decode_status(
void) {
574 volatile uint32_t code;
576 code = get_field(*MACA_STATUS,CODE);
583 PRINTF(
"maca: aborted\n\r");
590 PRINTF(
"maca: not completed\n\r");
597 PRINTF(
"maca: timeout\n\r");
604 PRINTF(
"maca: no ack\n\r");
611 PRINTF(
"maca: ext timeout\n\r");
616 case EXT_PND_TIMEOUT:
618 PRINTF(
"maca: ext pnd timeout\n\r");
630 PRINTF(
"status: %x", (
unsigned int)*MACA_STATUS);
637 void maca_isr(
void) {
643 if (bit_is_set(*MACA_STATUS, maca_status_ovr))
644 { PRINTF(
"maca overrun\n\r"); }
645 if (bit_is_set(*MACA_STATUS, maca_status_busy))
646 { PRINTF(
"maca busy\n\r"); }
647 if (bit_is_set(*MACA_STATUS, maca_status_crc))
648 { PRINTF(
"maca crc error\n\r"); }
649 if (bit_is_set(*MACA_STATUS, maca_status_to))
650 { PRINTF(
"maca timeout\n\r"); }
652 if (data_indication_irq()) {
653 *MACA_CLRIRQ = (1 << maca_irq_di);
654 dma_rx->length = *MACA_GETRXLVL - 2;
655 dma_rx->lqi = get_lqi();
656 dma_rx->rx_time = *MACA_TIMESTAMP;
659 if(prm_mode == AUTOACK && (dma_rx->data[1] & MAC_ACK_REQUEST_FLAG)) {
661 volatile uint32_t wait_clk;
662 wait_clk = *MACA_CLK + 200;
663 while(*MACA_CLK < wait_clk) {
continue; }
666 if(maca_rx_callback != 0) { maca_rx_callback(dma_rx); }
671 if (filter_failed_irq()) {
672 PRINTF(
"maca filter failed\n\r");
674 *MACA_CLRIRQ = (1 << maca_irq_flt);
676 if (checksum_failed_irq()) {
677 PRINTF(
"maca checksum failed\n\r");
679 *MACA_CLRIRQ = (1 << maca_irq_crc);
681 if (softclock_irq()) {
682 *MACA_CLRIRQ = (1 << maca_irq_sftclk);
685 *MACA_CLRIRQ = (1 << maca_irq_poll);
687 if(action_complete_irq()) {
689 if(last_post == TX_POST) {
690 tx_head->status = get_field(*MACA_STATUS,CODE);
699 if(tx_head->status == SUCCESS && (tx_head->data[0] & MAC_ACK_REQUEST_FLAG)) {
703 static volatile packet_t *ack_p;
704 if(ack_p = get_free_packet()) {
708 ack_p->data[1] = 0x02;
710 ack_p->data[3] = *MACA_TXSEQNR;
711 insert_at_rx_head(ack_p);
717 if(maca_tx_callback != 0) { maca_tx_callback(tx_head); }
723 *MACA_CLRIRQ = (1 << maca_irq_acpl);
729 { PRINTF(
"*MACA_IRQ %x\n\r", (
unsigned int)*MACA_IRQ); }
739 static uint8_t ram_values[4];
745 *MACA_CLKDIV = MACA_CLOCK_DIV;
746 *MACA_WARMUP = 0x00180012;
747 *MACA_EOFDELAY = 0x00000004;
748 *MACA_CCADELAY = 0x001a0022;
749 *MACA_TXCCADELAY = 0x00000025;
750 *MACA_FRAMESYNC0 = 0x000000A7;
751 *MACA_CLK = 0x00000008;
752 *MACA_RXACKDELAY = 30;
754 *MACA_TXACKDELAY = 68;
755 *MACA_MASKIRQ = ((1 << maca_irq_rst) |
756 (1 << maca_irq_acpl) |
758 (1 << maca_irq_flt) |
759 (1 << maca_irq_crc) |
761 (1 << maca_irq_sftclk)
763 *MACA_SLOTOFFSET = 0x00350000;
766 void reset_maca(
void)
768 volatile uint32_t cnt;
770 *MACA_RESET = (1 << maca_reset_rst);
772 for(cnt = 0; cnt < 100; cnt++) {};
774 *MACA_RESET = (1 << maca_reset_clkon);
776 *MACA_CONTROL = maca_ctrl_seq_nop;
778 for(cnt = 0; cnt < 400000; cnt++) {};
781 *MACA_CLRIRQ = 0xffff;
807 #define RF_BASE 0x80009a00
808 void flyback_init(
void) {
811 val8 = *(
volatile uint32_t *)(RF_BASE+8);
812 or = val8 | 0x0000f7df;
813 *(
volatile uint32_t *)(RF_BASE+8) = or;
814 *(
volatile uint32_t *)(RF_BASE+12) = 0x00ffffff;
815 *(
volatile uint32_t *)(RF_BASE+16) = (((uint32_t)0x00ffffff)>>12);
816 *(
volatile uint32_t *)(RF_BASE) = 16;
821 const uint32_t addr_seq1[MAX_SEQ1] = {
826 const uint32_t data_seq1[MAX_SEQ1] = {
833 const uint32_t addr_seq2[MAX_SEQ2] = {
838 const uint32_t data_seq2[MAX_SEQ2] = {
843 #define MAX_CAL3_SEQ1 3
844 const uint32_t addr_cal3_seq1[MAX_CAL3_SEQ1] = { 0x80009400,0x80009a04,0x80009a00, };
845 const uint32_t data_cal3_seq1[MAX_CAL3_SEQ1] = {0x00020017,0x8185a0a4,0x8c900025, };
847 #define MAX_CAL3_SEQ2 2
848 const uint32_t addr_cal3_seq2[MAX_CAL3_SEQ2] = { 0x80009a00,0x80009a00,};
849 const uint32_t data_cal3_seq2[MAX_CAL3_SEQ2] = { 0x8c900021,0x8c900027,};
851 #define MAX_CAL3_SEQ3 1
852 const uint32_t addr_cal3_seq3[MAX_CAL3_SEQ3] = { 0x80009a00 };
853 const uint32_t data_cal3_seq3[MAX_CAL3_SEQ3] = { 0x8c900000 };
856 const uint32_t addr_cal5[MAX_CAL5] = {
862 const uint32_t data_cal5[MAX_CAL5] = {
870 const uint32_t addr_reg_rep[MAX_DATA] = { 0x80004118,0x80009204,0x80009208,0x8000920c,0x80009210,0x80009300,0x80009304,0x80009308,0x8000930c,0x80009310,0x80009314,0x80009318,0x80009380,0x80009384,0x80009388,0x8000938c,0x80009390,0x80009394,0x8000a008,0x8000a018,0x8000a01c,0x80009424,0x80009434,0x80009438,0x8000943c,0x80009440,0x80009444,0x80009448,0x8000944c,0x80009450,0x80009460,0x80009464,0x8000947c,0x800094e0,0x800094e4,0x800094e8,0x800094ec,0x800094f0,0x800094f4,0x800094f8,0x80009470,0x8000981c,0x80009828 };
872 const uint32_t data_reg_rep[MAX_DATA] = { 0x00180012,0x00000605,0x00000504,0x00001111,0x0fc40000,0x20046000,0x4005580c,0x40075801,0x4005d801,0x5a45d800,0x4a45d800,0x40044000,0x00106000,0x00083806,0x00093807,0x0009b804,0x000db800,0x00093802,0x00000015,0x00000002,0x0000000f,0x0000aaa0,0x01002020,0x016800fe,0x8e578248,0x000000dd,0x00000946,0x0000035a,0x00100010,0x00000515,0x00397feb,0x00180358,0x00000455,0x00000001,0x00020003,0x00040014,0x00240034,0x00440144,0x02440344,0x04440544,0x0ee7fc00,0x00000082,0x0000002a };
874 void maca_off(
void) {
877 reg(0x80003048) = 0x00000f00;
879 maca_reset = maca_reset_rst;
884 reg(0x80003048) = 0x00000f78;
890 *INTFRC = (1 << INT_NUM_MACA);
915 #define _INIT_CTOV_WORD_1 0x00dfbe77
916 #define _INIT_CTOV_WORD_2 0x023126e9
917 uint8_t get_ctov( uint32_t r0, uint32_t r1 )
920 r0 = r0 * _INIT_CTOV_WORD_1;
922 r0 += _INIT_CTOV_WORD_2;
924 r0 = (uint32_t)(((int32_t)r0) >> 25);
934 for(i=0; i<MAX_SEQ1; i++) {
935 *(
volatile uint32_t *)(addr_seq1[i]) = data_seq1[i];
938 for(i=0; i<0x161a8; i++) {
continue; }
940 for(i=0; i<MAX_SEQ2; i++) {
941 *(
volatile uint32_t *)(addr_seq2[i]) = data_seq2[i];
944 *(
volatile uint32_t *)0x80009000 = 0x80050100;
946 for(i=0; i<MAX_CAL3_SEQ1; i++) {
947 *(
volatile uint32_t *)(addr_cal3_seq1[i]) = data_cal3_seq1[i];
950 for(i=0; i<0x11194; i++) {
continue; }
952 for(i=0; i<MAX_CAL3_SEQ2; i++) {
953 *(
volatile uint32_t *)(addr_cal3_seq2[i]) = data_cal3_seq2[i];
956 for(i=0; i<0x11194; i++) {
continue; }
958 for(i=0; i<MAX_CAL3_SEQ3; i++) {
959 *(
volatile uint32_t *)(addr_cal3_seq3[i]) = data_cal3_seq3[i];
962 for(i=0; i<MAX_CAL5; i++) {
963 *(
volatile uint32_t *)(addr_cal5[i]) = data_cal5[i];
966 for(i=0; i<MAX_DATA; i++) {
967 *(
volatile uint32_t *)(addr_reg_rep[i]) = data_reg_rep[i];
970 PRINTF(
"initfromflash\n\r");
972 *(
volatile uint32_t *)(0x80003048) = 0x00000f04;
973 for(i=0; i<0x161a8; i++) {
continue; }
975 *(
volatile uint32_t *)(0x80003048) = 0x00000fa4;
976 for(i=0; i<0x161a8; i++) {
continue; }
978 init_from_flash(0x1F000);
980 PRINTF(
"ram_values:\n\r");
982 PRINTF(
" 0x%02x\n\r",ram_values[i]);
985 PRINTF(
"radio_init: ctov parameter 0x%02x\n\r",ram_values[3]);
986 for(i=0; i<16; i++) {
987 ctov[i] = get_ctov(i,ram_values[3]);
988 PRINTF(
"radio_init: ctov[%d] = 0x%02x\n\r",(
int)i,ctov[i]);
994 const uint32_t PSMVAL[19] = {
1016 const uint32_t PAVAL[19] = {
1038 const uint32_t AIMVAL[19] = {
1060 #define RF_REG 0x80009400
1061 void set_demodulator_type(uint8_t demod) {
1062 uint32_t val = reg(RF_REG);
1063 if(demod == DEMOD_NCD) {
1072 #define ADDR_POW1 0x8000a014
1073 #define ADDR_POW2 ADDR_POW1 + 12
1074 #define ADDR_POW3 ADDR_POW1 + 64
1075 void set_power(uint8_t power) {
1076 safe_irq_disable(MACA);
1078 reg(ADDR_POW1) = PSMVAL[power];
1083 reg(ADDR_POW2) = 0xffffdfff & PAVAL[power];
1085 reg(ADDR_POW2) = 0x00002000 | PAVAL[power];
1088 reg(ADDR_POW3) = AIMVAL[power];
1091 if(bit_is_set(*NIPEND, INT_NUM_MACA)) { *INTFRC = (1 << INT_NUM_MACA); }
1095 const uint8_t VCODivI[16] = {
1114 const uint32_t VCODivF[16] = {
1134 #define ADDR_CHAN1 0x80009800
1135 #define ADDR_CHAN2 (ADDR_CHAN1+12)
1136 #define ADDR_CHAN3 (ADDR_CHAN1+16)
1137 #define ADDR_CHAN4 (ADDR_CHAN1+48)
1138 void set_channel(uint8_t chan) {
1139 volatile uint32_t tmp;
1140 safe_irq_disable(MACA);
1142 tmp = reg(ADDR_CHAN1);
1143 tmp = tmp & 0xbfffffff;
1144 reg(ADDR_CHAN1) = tmp;
1146 reg(ADDR_CHAN2) = VCODivI[chan];
1147 reg(ADDR_CHAN3) = VCODivF[chan];
1149 tmp = reg(ADDR_CHAN4);
1151 reg(ADDR_CHAN4) = tmp;
1153 tmp = reg(ADDR_CHAN4);
1155 reg(ADDR_CHAN4) = tmp;
1157 tmp = tmp & 0xffffe0ff;
1158 tmp = tmp | (((ctov[chan])<<8)&0x1F00);
1159 reg(ADDR_CHAN4) = tmp;
1162 if(bit_is_set(*NIPEND, INT_NUM_MACA)) { *INTFRC = (1 << INT_NUM_MACA); }
1165 uint8_t (*get_lqi)(void) = (
void *) 0x0000e04d;
1167 #define ROM_END 0x0013ffff
1168 #define ENTRY_EOF 0x00000e0f
1171 uint32_t exec_init_entry(
volatile uint32_t *entries, uint8_t *valbuf)
1173 volatile uint32_t i;
1174 if(entries[0] <= ROM_END) {
1175 if (entries[0] == 0) {
1177 PRINTF(
"init_entry: delay 0x%08x\n\r", (
unsigned int)entries[1]);
1178 for(i=0; i<entries[1]; i++) {
continue; }
1180 }
else if (entries[0] == 1) {
1182 PRINTF(
"init_entry: bit set clear 0x%08x 0x%08x 0x%08x\n\r", (
unsigned int)entries[1], (
unsigned int)entries[2], (
unsigned int)entries[3]);
1183 reg(entries[2]) = (reg(entries[2]) & ~entries[1]) | (entries[3] & entries[1]);
1185 }
else if ((entries[0] >= 16) &&
1186 (entries[0] < 0xfff1)) {
1188 PRINTF(
"init_entry: store in valbuf 0x%02x position %d\n\r",
1189 (
unsigned int)entries[1],
1190 (
unsigned int)(entries[0]>>4)-1);
1191 valbuf[(entries[0]>>4)-1] = entries[1];
1193 }
else if (entries[0] == ENTRY_EOF) {
1194 PRINTF(
"init_entry: eof ");
1198 PRINTF(
"init_entry: invaild code 0x%08x\n\r",(
unsigned int)entries[0]);
1203 PRINTF(
"init_entry: address value pair - *0x%08x = 0x%08x\n\r",
1204 (
unsigned int)entries[0],
1205 (
unsigned int)entries[1]);
1206 reg(entries[0]) = entries[1];
1212 #define FLASH_INIT_MAGIC 0x00000abc
1213 uint32_t init_from_flash(uint32_t addr) {
1216 volatile uint32_t buf[8];
1217 volatile uint32_t len;
1218 volatile uint32_t i=0,j;
1220 err = nvm_detect(gNvmInternalInterface_c, &type);
1221 PRINTF(
"nvm_detect returned type 0x%08x err 0x%02x\n\r", type, err);
1224 err = nvm_read(gNvmInternalInterface_c, type, (uint8_t *)buf, addr, 8);
1226 PRINTF(
"nvm_read returned: 0x%02x\n\r",err);
1228 for(j=0; j<4; j++) {
1229 PRINTF(
"0x%08x\n\r",(
unsigned int)buf[j]);
1232 if(buf[0] == FLASH_INIT_MAGIC) {
1233 len = buf[1] & 0x0000ffff;
1234 while(i < (len-4)) {
1235 err = nvm_read(gNvmInternalInterface_c, type, (uint8_t *)buf, addr+i, 32);
1236 i += 4*exec_init_entry(buf, ram_values);
1249 void ResumeMACASync(
void)
1251 volatile uint32_t clk, TsmRxSteps, LastWarmupStep, LastWarmupData, LastWarmdownStep, LastWarmdownData;
1253 volatile uint32_t i;
1254 safe_irq_disable(MACA);
1262 TsmRxSteps = (*((
volatile uint32_t *)(0x80009204)));
1266 LastWarmupStep = (TsmRxSteps & 0x1f) << 2;
1268 LastWarmupData = (*((
volatile uint32_t *)(0x80009300 + LastWarmupStep)));
1273 LastWarmdownStep = ((TsmRxSteps & 0x1f00) >> 8) << 2;
1275 LastWarmdownData = (*((
volatile uint32_t *)(0x80009300 + LastWarmdownStep)));
1276 (*((
volatile uint32_t *)(0x80009300 + LastWarmupStep))) = LastWarmdownData;
1279 MACA_WRITE(maca_control, 1);
1282 for (clk = maca_clk, i = 0; maca_clk - clk < 3 && i < 300; i++)
1286 MACA_WRITE(maca_control, 0);
1289 for (clk = maca_clk, i = 0; maca_clk - clk < 3 && i < 300; i++)
1294 (*((
volatile uint32_t *)(0x80009300 + LastWarmupStep))) = LastWarmupData;
1299 MACA_WRITE(maca_clrirq, 0xFFFF);