/* Global timer initialization */\r
void tdma_init(void)\r
{\r
+ static int tdma_init_done = 0;\r
+ if (tdma_init_done)\r
+ return;\r
+\r
// Enable DMA Cock\r
SIM->SCGC5 |= SIM_SCGC5_PORTA_MASK;\r
SIM->SCGC5 |= SIM_SCGC5_PORTC_MASK;\r
// Start timers\r
PIT->CHANNEL[0].TCTRL |= PIT_TCTRL_TEN_MASK;\r
PIT->CHANNEL[1].TCTRL |= PIT_TCTRL_TEN_MASK;\r
+\r
+ // Done\r
+ tdma_init_done = 1;\r
}\r
\r
/* DMA Functions */\r
\r
int irqc = mode == PullUp ? 1 : 2;\r
\r
+ // Initialize global registers\r
+ tdma_init();\r
+\r
// Allocate port\r
tdma_t *port = &tdma_ports[chan];\r
\r
\r
for (int i = 0; port->dma->dsr & DMA_DSR_BCR_BCR_MASK; i++)\r
if (i > wait)\r
- return 0;\r
+ return;\r
\r
// Disable DMA Mux\r
port->mux->cfg &= DMAMUX_CHCFG_ENBL_MASK;\r
| ((uint64_t)~tml) << 0;\r
\r
// Convert to nanoseconds\r
- return clocks * 1000 / 24;\r
+ return clocks * 125 / 3;\r
}\r
\r
void tdma_debug(tdma_t *port)\r