/** Output NMEA sentence to all USARTs configured in NMEA mode. * The message is also sent to all dispatchers registered with * ::nmea_dispatcher_register. * \param s The NMEA sentence to output. */ static void nmea_output(char *s, size_t size) { /* Global interrupt disable to avoid concurrency/reentrancy problems. */ __asm__("CPSID i;"); if ((ftdi_usart.mode == NMEA) && usart_claim(&ftdi_state, NMEA_MODULE)) { usart_write_dma(&ftdi_state.tx, (u8 *)s, size); usart_release(&ftdi_state); } if ((uarta_usart.mode == NMEA) && usart_claim(&uarta_state, NMEA_MODULE)) { usart_write_dma(&uarta_state.tx, (u8 *)s, size); usart_release(&uarta_state); } if ((uartb_usart.mode == NMEA) && usart_claim(&uartb_state, NMEA_MODULE)) { usart_write_dma(&uartb_state.tx, (u8 *)s, size); usart_release(&uartb_state); } __asm__("CPSIE i;"); /* Re-enable interrupts. */ for (struct nmea_dispatcher *d = nmea_dispatchers_head; d; d = d->next) d->send(s, size); }
/** Output NMEA sentence to all USARTs configured in NMEA mode. * \param s The NMEA sentence to output. */ void nmea_output(char *s) { /* Global interrupt disable to avoid concurrency/reentrancy problems. */ __asm__("CPSID i;"); if (ftdi_usart.mode == NMEA) usart_write_dma(&ftdi_tx_state, (u8 *)s, strlen(s)); if (uarta_usart.mode == NMEA) usart_write_dma(&uarta_tx_state, (u8 *)s, strlen(s)); if (uartb_usart.mode == NMEA) usart_write_dma(&uartb_tx_state, (u8 *)s, strlen(s)); __asm__("CPSIE i;"); /* Re-enable interrupts. */ }
int main(void) { for (u32 i = 0; i < 600000; i++) __asm__("nop"); led_setup(); rcc_clock_setup_hse_3v3(&hse_16_368MHz_in_65_472MHz_out_3v3); usart_setup_common(); usart_tx_dma_setup(); /*printf("\n\nFirmware info - git: " GIT_VERSION ", built: " __DATE__ " " __TIME__ "\n");*/ /*printf("--- USART DMA TEST ---\n");*/ #define MAX_TX ((u32)(USART_TX_BUFFER_LEN*1.2)) u8 guard_below[30]; u8 buff_out[MAX_TX]; u8 guard_above[30]; u32 len; for (u8 i=0; i<30; i++) { guard_below[i] = 0; guard_above[i] = 0; } for (u32 i=0; i<MAX_TX; i++) buff_out[i] = (u8)i; while(1) { /* Random transmit length. */ len = (u32)rand() % MAX_TX; while (len) len -= usart_write_dma(buff_out, len); /* Check the guards for buffer over/underrun. */ for (u8 i=0; i<30; i++) { if (guard_below[i] != 0) screaming_death(); if (guard_above[i] != 0) screaming_death(); } /* Introduce some timing jitter. */ for (u32 i = 0; i < ((u32)rand() % 10000); i++) __asm__("nop"); } while (1); return 0; }