/** * \brief Configure USART in synchronous mode. * * \param ul_ismaster 1 for master, 0 for slave. * \param ul_baudrate Baudrate for synchronous communication. * */ static void configure_usart(uint32_t ul_ismaster, uint32_t ul_baudrate) { sam_usart_opt_t usart_console_settings = { 0, US_MR_CHRL_8_BIT, US_MR_PAR_NO, US_MR_NBSTOP_1_BIT, US_MR_CHMODE_NORMAL, /* This field is only used in IrDA mode. */ 0 }; usart_console_settings.baudrate = ul_baudrate; /* Enable the peripheral clock in the PMC. */ sysclk_enable_peripheral_clock(BOARD_ID_USART); /* Configure USART in SYNC. master or slave mode. */ if (ul_ismaster) { usart_init_sync_master(BOARD_USART, &usart_console_settings, sysclk_get_peripheral_hz()); } else { usart_init_sync_slave(BOARD_USART, &usart_console_settings); } /* Disable all the interrupts. */ usart_disable_interrupt(BOARD_USART, ALL_INTERRUPT_MASK); /* Enable TX & RX function. */ usart_enable_tx(BOARD_USART); usart_enable_rx(BOARD_USART); /* Configure and enable interrupt of USART. */ NVIC_EnableIRQ(USART_IRQn); }
void uart_open(uint8_t port) { Usart* usart = get_usart(port); if (0 == port) { // IO is initialized in board init // Enable interrupt with priority higher than USB NVIC_SetPriority((IRQn_Type) USART_ID_0, USART_INT_LEVEL_0); NVIC_EnableIRQ((IRQn_Type) USART_ID_0); NVIC_SetPriority((IRQn_Type) USART_ID_1, USART_INT_LEVEL_1); NVIC_EnableIRQ((IRQn_Type) USART_ID_1); // Initialize it in RS232 mode. pmc_enable_periph_clk(USART_ID_0); USART_ENABLE_0(); } else if (1 == port) { // IO is initialized in board init // Enable interrupt with priority higher than USB NVIC_SetPriority((IRQn_Type) USART_ID_1, USART_INT_LEVEL_1); NVIC_EnableIRQ((IRQn_Type) USART_ID_1); // Initialize it in RS232 mode. pmc_enable_periph_clk(USART_ID_1); USART_ENABLE_1(); } else { return; } if (usart_init_rs232(usart, &usart_options, sysclk_get_peripheral_hz())) { return; } // Enable both RX and TX usart_enable_tx(usart); usart_enable_rx(usart); // Enable interrupts usart_enable_interrupt(usart, US_IER_RXRDY | US_IER_TXRDY); }
/** * \brief USART RS485 mode configuration. * * Configure USART in RS485 mode, asynchronous, 8 bits, 1 stop bit, * no parity, 256000 bauds and enable its transmitter and receiver. */ static void configure_usart(void) { const sam_usart_opt_t usart_console_settings = { BOARD_USART_BAUDRATE, US_MR_CHRL_8_BIT, US_MR_PAR_NO, US_MR_NBSTOP_1_BIT, US_MR_CHMODE_NORMAL, /* This field is only used in IrDA mode. */ 0 }; /* Enable the peripheral clock in the PMC. */ sysclk_enable_peripheral_clock(BOARD_ID_USART); /* Configure USART in RS485 mode. */ usart_init_rs485(BOARD_USART, &usart_console_settings, sysclk_get_cpu_hz()); /* Disable all the interrupts. */ usart_disable_interrupt(BOARD_USART, ALL_INTERRUPT_MASK); /* Enable TX & RX function. */ usart_enable_tx(BOARD_USART); usart_enable_rx(BOARD_USART); /* Configure and enable interrupt of USART. */ NVIC_EnableIRQ(USART_IRQn); }
/** * \brief Initializes a ISO7816 interface device. * * \param p_usart_opt Pointer to an ISO7816 instance. * \param ul_mck USART module input clock frequency. * \param ul_rst_pin_idx Control smart card RST pin index. */ void iso7816_init(const usart_iso7816_opt_t *p_usart_opt, uint32_t ul_mck, uint32_t ul_rst_pin_idx) { /* Pin RST of ISO7816 initialize. */ gs_ul_rst_pin_idx = ul_rst_pin_idx; #if defined(SMART_CARD_USING_GPIO) gpio_set_pin_low(gs_ul_rst_pin_idx); #elif defined(SMART_CARD_USING_IOPORT) ioport_set_pin_level(gs_ul_rst_pin_idx, IOPORT_PIN_LEVEL_LOW); #endif /* Init the global variable for ISO7816. */ g_ul_clk = ul_mck; usart_init_iso7816(ISO7816_USART, p_usart_opt, g_ul_clk); /* Disable interrupts. */ usart_disable_interrupt(ISO7816_USART, 0xffffffff); /* Write the Timeguard Register. */ usart_set_tx_timeguard(ISO7816_USART, 5); /* Enable TX and RX. */ usart_enable_rx(ISO7816_USART); usart_enable_tx(ISO7816_USART); }
static void reconfigure_console(uint32_t ul_mck, uint32_t ul_baudrate) { sam_usart_opt_t uart_serial_options; uart_serial_options.baudrate = ul_baudrate, uart_serial_options.char_length = CONF_UART_CHAR_LENGTH, uart_serial_options.parity_type = US_MR_PAR_NO; uart_serial_options.stop_bits = CONF_UART_STOP_BITS, uart_serial_options.channel_mode= US_MR_CHMODE_NORMAL, uart_serial_options.irda_filter = 0, /* Configure PMC */ flexcom_enable(CONF_FLEXCOM); flexcom_set_opmode(CONF_FLEXCOM, FLEXCOM_USART); /* Configure PIO */ pio_configure_pin_group(CONF_UART_PIO, CONF_PINS_UART, CONF_PINS_UART_FLAGS); /* Configure UART */ usart_init_rs232(CONF_UART, &uart_serial_options, ul_mck); /* Enable the receiver and transmitter. */ usart_enable_tx(CONF_UART); usart_enable_rx(CONF_UART); }
/** * \brief USART RS485 mode configuration. * * Configure USART in RS485 mode, asynchronous, 8 bits, 1 stop bit, * no parity, 256000 bauds and enable its transmitter and receiver. */ void configure_usart(void) { const sam_usart_opt_t usart_console_settings = { BOARD_USART_BAUDRATE, US_MR_CHRL_8_BIT, US_MR_PAR_NO, US_MR_NBSTOP_1_BIT, US_MR_CHMODE_NORMAL, /* This field is only used in IrDA mode. */ 0 }; /* Enable the peripheral clock in the PMC. */ sysclk_enable_peripheral_clock(BOARD_ID_USART); /* Configure USART in RS485 mode. */ //jsi 7feb16 we want rs232 not rs485 for our application usart_init_rs485(BOARD_USART, &usart_console_settings, //jsi 7feb16 we want rs232 not rs485 for our application sysclk_get_cpu_hz()); usart_init_rs232(BOARD_USART, &usart_console_settings, sysclk_get_cpu_hz()); /* enable transmitter timeguard, 4 bit period delay. */ usart_set_tx_timeguard(BOARD_USART, 4); /* Disable all the interrupts. */ usart_disable_interrupt(BOARD_USART, ALL_INTERRUPT_MASK); /* Enable TX & RX function. */ usart_enable_tx(BOARD_USART); usart_enable_rx(BOARD_USART); /* Configure and enable interrupt of USART. */ NVIC_EnableIRQ(USART_IRQn); }
/** * \brief Set up a USART in SPI master mode device. * * The returned device descriptor structure must be passed to the driver * whenever that device should be used as current slave device. * * \param p_usart Base address of the USART instance. * \param device Pointer to usart device struct that should be initialized. * \param flags USART configuration flags. Common flags for all * implementations are the usart modes, which should be SPI_MODE_0, * SPI_MODE_1, SPI_MODE_2, SPI_MODE_3. * \param baud_rate Baud rate for communication with slave device in Hz. * \param sel_id Board specific select id. */ void usart_spi_setup_device(Usart *p_usart, struct usart_spi_device *device, spi_flags_t flags, unsigned long baud_rate, board_spi_select_id_t sel_id) { usart_spi_opt_t opt; /* avoid Cppcheck Warning */ UNUSED(device); UNUSED(sel_id); /* Basic usart SPI configuration. */ opt.baudrate = baud_rate; opt.char_length = US_MR_CHRL_8_BIT; opt.spi_mode = flags; opt.channel_mode = US_MR_CHMODE_NORMAL; /* Initialize the USART module as SPI master. */ #if (SAM4L) usart_init_spi_master(p_usart, &opt, sysclk_get_pba_hz()); #else usart_init_spi_master(p_usart, &opt, sysclk_get_peripheral_hz()); #endif usart_enable_rx(p_usart); usart_enable_tx(p_usart); }
void init_Usart (void) { ioport_set_pin_dir(PIO_PA21_IDX,IOPORT_DIR_INPUT); ioport_set_pin_dir(PIO_PB4_IDX,IOPORT_DIR_OUTPUT); const sam_usart_opt_t usart_console_settings = { USART_SERIAL_BAUDRATE, USART_SERIAL_CHAR_LENGTH, USART_SERIAL_PARITY, USART_SERIAL_STOP_BIT, US_MR_CHMODE_NORMAL }; #if SAM4L sysclk_enable_peripheral_clock(USART_SERIAL); #else sysclk_enable_peripheral_clock(USART_SERIAL_ID); #endif usart_init_rs232(USART_SERIAL, &usart_console_settings, sysclk_get_main_hz()/2); usart_enable_tx(USART_SERIAL); usart_enable_rx(USART_SERIAL); // how to enable an interrupt( use three steps ):use these functions: -usart_enable_interrupt- Then -NVIC_EnableIRQ(USART_SERIAL_IRQ);- & Then add this function void USART_SERIAL_ISR_HANDLER(void) usart_enable_interrupt(USART_SERIAL, US_IER_RXRDY); NVIC_EnableIRQ(USART_SERIAL_IRQ); }
void bm_print_clear(void) { usart_enable_tx(BM_USART_USART); usart_putchar(BM_USART_USART, BM_MSG_START_PATTERN); usart_putchar(BM_USART_USART, 3 /* length */); usart_putchar(BM_USART_USART, BM_PRINT_CLEAR); usart_putchar(BM_USART_USART, BM_MSG_STOP_PATTERN); while (!usart_is_tx_empty(BM_USART_USART)); usart_disable_tx(BM_USART_USART); }
void uart_rx_notify(uint8_t port) { Usart* usart = get_usart(port); // If UART is open if (usart_get_interrupt_mask(usart) & US_IMR_RXRDY) { // Enable UART TX interrupt to send a new value usart_enable_tx(usart); usart_enable_interrupt(usart, US_IER_TXRDY); } }
/** * \brief Disable receiver and Enable transmitter. */ static void func_transmitter(void) { /* Configure the TXD pin as peripheral. */ pio_configure_pin(PIN_USART_TXD_IDX, PIN_USART_TXD_FLAGS); /* Disable Receiver. */ usart_disable_rx(BOARD_USART); /* Enable transmitter. */ usart_enable_tx(BOARD_USART); }
void uart_rx_notify(uint8_t port) { UNUSED(port); // If UART is open if (usart_get_interrupt_mask(USART_BASE) & US_IMR_RXRDY) { // Enable UART TX interrupt to send a new value usart_enable_tx(USART_BASE); usart_enable_interrupt(USART_BASE, US_IER_TXRDY); } }
void bm_mouse_pointer_ctrl(bool state) { usart_enable_tx(BM_USART_USART); usart_putchar(BM_USART_USART, BM_MSG_START_PATTERN); usart_putchar(BM_USART_USART, 4 /* length */); usart_putchar(BM_USART_USART, BM_POINTER_CTRL); usart_putchar(BM_USART_USART, state); usart_putchar(BM_USART_USART, BM_MSG_STOP_PATTERN); while (!usart_is_tx_empty(BM_USART_USART)); usart_disable_tx(BM_USART_USART); }
void bm_led_tgl(uint32_t led) { usart_enable_tx(BM_USART_USART); usart_putchar(BM_USART_USART, BM_MSG_START_PATTERN); usart_putchar(BM_USART_USART, 4 /* length */); usart_putchar(BM_USART_USART, BM_LED_TGL); usart_putchar(BM_USART_USART, led); usart_putchar(BM_USART_USART, BM_MSG_STOP_PATTERN); while (!usart_is_tx_empty(BM_USART_USART)); usart_disable_tx(BM_USART_USART); }
/* * See the serial.h header file. */ xComPortHandle xSerialPortInitMinimal( unsigned long ulWantedBaud, unsigned portBASE_TYPE uxQueueLength ) { uint32_t ulChar; xComPortHandle xReturn; const sam_usart_opt_t xUSARTSettings = { ulWantedBaud, US_MR_CHRL_8_BIT, US_MR_PAR_NO, US_MR_NBSTOP_1_BIT, US_MR_CHMODE_NORMAL, 0 /* Only used in IrDA mode. */ }; /* Create the queues used to hold Rx/Tx characters. */ xRxedChars = xQueueCreate( uxQueueLength, ( unsigned portBASE_TYPE ) sizeof( signed char ) ); xCharsForTx = xQueueCreate( uxQueueLength + 1, ( unsigned portBASE_TYPE ) sizeof( signed char ) ); /* If the queues were created correctly then setup the serial port hardware. */ if( ( xRxedChars != serINVALID_QUEUE ) && ( xCharsForTx != serINVALID_QUEUE ) ) { /* Enable the peripheral clock in the PMC. */ pmc_enable_periph_clk( serPMC_USART_ID ); /* Configure USART in serial mode. */ usart_init_rs232( serUSART_PORT, &xUSARTSettings, sysclk_get_cpu_hz() ); /* Disable all the interrupts. */ usart_disable_interrupt( serUSART_PORT, serMASK_ALL_INTERRUPTS ); /* Enable the receiver and transmitter. */ usart_enable_tx( serUSART_PORT ); usart_enable_rx( serUSART_PORT ); /* Clear any characters before enabling interrupt. */ usart_getchar( serUSART_PORT, &ulChar ); /* Enable Rx end interrupt. */ usart_enable_interrupt( serUSART_PORT, US_IER_RXRDY ); /* Configure and enable interrupt of USART. */ NVIC_SetPriority( serUSART_IRQ, configLIBRARY_MAX_SYSCALL_INTERRUPT_PRIORITY ); NVIC_EnableIRQ( serUSART_IRQ ); } else { xReturn = ( xComPortHandle ) 0; } /* This demo file only supports a single port but we have to return something to comply with the standard demo header file. */ return xReturn; }
void bm_pullup_twi(bool state) { usart_enable_tx(BM_USART_USART); usart_putchar(BM_USART_USART, BM_MSG_START_PATTERN); usart_putchar(BM_USART_USART, 4 /* length */); usart_putchar(BM_USART_USART, BM_PULLUP_TWI); usart_putchar(BM_USART_USART, state); usart_putchar(BM_USART_USART, BM_MSG_STOP_PATTERN); while (!usart_is_tx_empty(BM_USART_USART)); usart_disable_tx(BM_USART_USART); }
static void configure_console(void) { sysclk_enable_peripheral_clock(PRINTF_USART_ID); //const usart_serial_options_t uart_serial_options = { .baudrate = CONF_UART_BAUDRATE, .paritytype = CONF_UART_PARITY, }; const usart_serial_options_t uart_serial_options = { .baudrate = USART_BAUDRATE, .charlength = USART_CHAR_LENGTH, .paritytype = USART_PARITY, .stopbits = false //US_MR_CHMODE_NORMAL }; usart_serial_init(PRINTF_USART, &uart_serial_options); stdio_serial_init(PRINTF_USART, &uart_serial_options); usart_enable_tx(PRINTF_USART); usart_enable_rx(PRINTF_USART); } int main(void) { sysclk_init(); board_init(); configure_console(); printf("CPH BaseStation v%d\r\n", 1); printf("create_uart_cli_task\r\n"); create_uart_cli_task(CONSOLE_UART, mainUART_CLI_TASK_STACK_SIZE, mainUART_CLI_TASK_PRIORITY); // printf("create_dialer_task\r\n"); // create_dialer_task(mainDIALER_TASK_STACK_SIZE, mainDIALER_TASK_PRIORITY); printf("create_comm_task\r\n"); create_comm_task(mainCOMM_TASK_STACK_SIZE, mainCOMM_TASK_PRIORITY); printf("create_apptask_task\r\n"); create_app_task(mainAPPTASK_TASK_STACK_SIZE, mainAPPTASK_TASK_PRIORITY); printf("create_led_task\r\n"); create_led_task(); printf("starting task scheduler\r\n"); /* Start the scheduler. */ vTaskStartScheduler(); for (;;) { } /* Will only get here if there was insufficient memory to create the idle task. */ return 0; }
void bm_mouse_pointer_move(uint32_t x, uint32_t y) { usart_enable_tx(BM_USART_USART); usart_putchar(BM_USART_USART, BM_MSG_START_PATTERN); usart_putchar(BM_USART_USART, 5 /* length */); usart_putchar(BM_USART_USART, BM_POINTER_MOVE); usart_putchar(BM_USART_USART, x); usart_putchar(BM_USART_USART, y); usart_putchar(BM_USART_USART, BM_MSG_STOP_PATTERN); while (!usart_is_tx_empty(BM_USART_USART)); usart_disable_tx(BM_USART_USART); }
bool bm_get_mcu_current(uint32_t* sleep_mode, float* current) { uint32_t current_d; uint32_t c; usart_enable_tx(BM_USART_USART); usart_putchar(BM_USART_USART, BM_MSG_START_PATTERN); usart_putchar(BM_USART_USART, 4 /* length */); usart_putchar(BM_USART_USART, BM_MCU_GET_CURRENT); usart_putchar(BM_USART_USART, *sleep_mode); usart_putchar(BM_USART_USART, BM_MSG_STOP_PATTERN); while (!usart_is_tx_empty(BM_USART_USART)); usart_disable_tx(BM_USART_USART); usart_enable_rx(BM_USART_USART); // Check first caracter is start pattern usart_getchar(BM_USART_USART, &c); if (c == BM_MSG_STOP_PATTERN) { usart_getchar(BM_USART_USART, &c); } if (c != BM_MSG_START_PATTERN) { return false; } // Check second caracter is length usart_getchar(BM_USART_USART, &c); if (c != 8) { return false; } // Check third caracter is Current Command usart_getchar(BM_USART_USART, &c); if (c != BM_MCU_RET_CURRENT) { return false; } // Check third caracter is sleepmode usart_getchar(BM_USART_USART, &c); *sleep_mode = c; // Then read current usart_getchar(BM_USART_USART, &c); current_d = c<<24; usart_getchar(BM_USART_USART, &c); current_d |= c<<16; usart_getchar(BM_USART_USART, &c); current_d |= c<<8; usart_getchar(BM_USART_USART, &c); current_d |= c; *current = *(float*)& current_d; // Check last caracter is stop pattern usart_getchar(BM_USART_USART, &c); if (c != BM_MSG_STOP_PATTERN) { return false; } usart_disable_rx(BM_USART_USART); return true; }
/* ============================================= */ void UartBuffer_Init(void) { sysclk_enable_peripheral_clock(ID_USART0); usart_init_rs232(USART0, &usart_console_settings, sysclk_get_cpu_hz()); usart_disable_interrupt(USART0, ALL_INTERRUPT_MASK); usart_enable_tx(USART0); usart_enable_rx(USART0); usart_enable_interrupt(USART0, US_IER_RXRDY); NVIC_EnableIRQ(USART0_IRQn); TxIn = TxOut = 0; RxIn = RxOut = 0; }
static void XPROGTarget_SetTxMode(void) { /* Wait for a full cycle of the clock */ while(gpio_pin_is_high(PIN_PDIC_GPIO) && TimeoutTicksRemaining); while(gpio_pin_is_low(PIN_PDIC_GPIO) && TimeoutTicksRemaining); while(gpio_pin_is_high(PIN_PDIC_GPIO) && TimeoutTicksRemaining); usart_disable_rx(USART_PDI); usart_enable_tx(USART_PDI); gpio_configure_pin(PIN_PDIDTX_GPIO, PIN_PDIDTX_USART_FLAGS); IsSending = true; }
bool bm_get_fifo_free_size(uint16_t* free_size) { uint32_t start, length, stop, cmd_id, c; // Wait for some microseconds in order to avoid fifo overrun // delay_ms(20); usart_enable_tx(BM_USART_USART); usart_putchar(BM_USART_USART, BM_MSG_START_PATTERN); usart_putchar(BM_USART_USART, 3 /* length */); usart_putchar(BM_USART_USART, BM_MCU_GET_FIFO_FREE_SIZE); usart_putchar(BM_USART_USART, BM_MSG_STOP_PATTERN); while (!usart_is_tx_empty(BM_USART_USART)); usart_disable_tx(BM_USART_USART); usart_enable_rx(BM_USART_USART); // Check first character is start pattern usart_getchar(BM_USART_USART, &start); if (start == BM_MSG_STOP_PATTERN) { usart_getchar(BM_USART_USART, &start); } if (start != BM_MSG_START_PATTERN) { return false; } // Check second character is length usart_getchar(BM_USART_USART, &length); if (length != 5) { return false; } // Check third character is Current Command usart_getchar(BM_USART_USART, &cmd_id); if (cmd_id != BM_MCU_RET_FIFO_FREE_SIZE) { return false; } // Get Fifo free size usart_getchar(BM_USART_USART, &c); *free_size = c << 8; usart_getchar(BM_USART_USART, &c); *free_size |= c; // Check last character is stop pattern usart_getchar(BM_USART_USART, &stop); if (stop != BM_MSG_STOP_PATTERN) { return false; } usart_disable_rx(BM_USART_USART); return true; }
bool bm_get_firmware_version(uint8_t* fw_minor_version, uint8_t* fw_major_version) { uint32_t start, length, stop, cmd_id, c; // Wait for some microseconds in order to avoid fifo overrun // delay_ms(20); usart_enable_tx(BM_USART_USART); usart_putchar(BM_USART_USART, BM_MSG_START_PATTERN); usart_putchar(BM_USART_USART, 3 /* length */); usart_putchar(BM_USART_USART, BM_GET_FIRMWARE_VERSION); usart_putchar(BM_USART_USART, BM_MSG_STOP_PATTERN); while (!usart_is_tx_empty(BM_USART_USART)); usart_disable_tx(BM_USART_USART); usart_enable_rx(BM_USART_USART); // Check first character is start pattern usart_getchar(BM_USART_USART, &start); if (start == BM_MSG_STOP_PATTERN) { usart_getchar(BM_USART_USART, &start); } if (start != BM_MSG_START_PATTERN) { return false; } // Check second character is length usart_getchar(BM_USART_USART, &length); if (length != 5) { return false; } // Check third character is Current Command usart_getchar(BM_USART_USART, &cmd_id); if (cmd_id != BM_RET_FIRMWARE_VERSION) { return false; } // Get Fifo free size usart_getchar(BM_USART_USART, &c); *fw_major_version = c; usart_getchar(BM_USART_USART, &c); *fw_minor_version = c; // Check last character is stop pattern usart_getchar(BM_USART_USART, &stop); if (stop != BM_MSG_STOP_PATTERN) { return false; } usart_disable_rx(BM_USART_USART); return true; }
void bm_tgl_button(uint32_t timeout_ms) { usart_enable_tx(BM_USART_USART); usart_putchar(BM_USART_USART, BM_MSG_START_PATTERN); usart_putchar(BM_USART_USART, 7 /* length */); usart_putchar(BM_USART_USART, BM_TGL_BUTTON); usart_putchar(BM_USART_USART, timeout_ms & 0xff); usart_putchar(BM_USART_USART, (timeout_ms >> 8 ) & 0xff); usart_putchar(BM_USART_USART, (timeout_ms >> 16) & 0xff); usart_putchar(BM_USART_USART, timeout_ms >> 24); usart_putchar(BM_USART_USART, BM_MSG_STOP_PATTERN); while (!usart_is_tx_empty(BM_USART_USART)); usart_disable_tx(BM_USART_USART); }
void bm_send_picouart_frame(uint8_t frame, uint32_t timeout_ms) { usart_enable_tx(BM_USART_USART); usart_putchar(BM_USART_USART, BM_MSG_START_PATTERN); usart_putchar(BM_USART_USART, 8 /* length */); usart_putchar(BM_USART_USART, BM_PICOUART_SEND); usart_putchar(BM_USART_USART, frame); usart_putchar(BM_USART_USART, timeout_ms & 0xff); usart_putchar(BM_USART_USART, (timeout_ms >> 8 ) & 0xff); usart_putchar(BM_USART_USART, (timeout_ms >> 16) & 0xff); usart_putchar(BM_USART_USART, timeout_ms >> 24); usart_putchar(BM_USART_USART, BM_MSG_STOP_PATTERN); while (!usart_is_tx_empty(BM_USART_USART)); usart_disable_tx(BM_USART_USART); }
void bm_send_mcu_status(uint32_t power_scaling, uint32_t sleep_mode, uint32_t cpu_freq, uint32_t cpu_src) { usart_enable_tx(BM_USART_USART); usart_putchar(BM_USART_USART, BM_MSG_START_PATTERN); usart_putchar(BM_USART_USART, 10 /* length */); usart_putchar(BM_USART_USART, BM_MCU_STATUS); usart_putchar(BM_USART_USART, power_scaling); usart_putchar(BM_USART_USART, sleep_mode); usart_putchar(BM_USART_USART, cpu_freq >> 24); usart_putchar(BM_USART_USART, (cpu_freq >> 16) & 0xff); usart_putchar(BM_USART_USART, (cpu_freq >> 8 ) & 0xff); usart_putchar(BM_USART_USART, cpu_freq & 0xff); usart_putchar(BM_USART_USART, cpu_src); usart_putchar(BM_USART_USART, BM_MSG_STOP_PATTERN); while (!usart_is_tx_empty(BM_USART_USART)); usart_disable_tx(BM_USART_USART); }
/** * Configure board USART communication with PC or other terminal. */ static void configure_usart(void) { static uint32_t ul_sysclk; const sam_usart_opt_t usart_console_settings = { BOARD_USART_BAUDRATE, US_MR_CHRL_8_BIT, US_MR_PAR_NO, US_MR_NBSTOP_1_BIT, US_MR_CHMODE_NORMAL, /* This field is only used in IrDA mode. */ 0 }; /* Get system clock. */ ul_sysclk = sysclk_get_cpu_hz(); /* Enable peripheral clock. */ sysclk_enable_peripheral_clock(BOARD_ID_USART); /* Configure USART. */ usart_init_hw_handshaking(BOARD_USART, &usart_console_settings, ul_sysclk); /* Disable all the interrupts. */ usart_disable_interrupt(BOARD_USART, ALL_INTERRUPT_MASK); /* Enable TX & RX function. */ usart_enable_tx(BOARD_USART); usart_enable_rx(BOARD_USART); /* Specify that stdout should not be buffered. */ #if defined(__GNUC__) setbuf(stdout, NULL); #else /* Already the case in IAR's Normal DLIB default configuration: printf() * emits one character at a time. */ #endif /* Configure and enable interrupt of USART. */ NVIC_EnableIRQ(USART_IRQn); }
/** * \brief Configure the Console. */ static void configure_console(void) { const sam_usart_opt_t usart_console_settings = { CONF_UART_BAUDRATE, CONF_UART_CHAR_LENGTH, CONF_UART_PARITY, CONF_UART_STOP_BITS, US_MR_CHMODE_NORMAL, /* This field is only used in IrDA mode. */ 0 }; /* Enable the peripheral clock in the PMC. */ sysclk_enable_peripheral_clock(CONF_UART_ID); /* Configure USART in serial mode. */ usart_init_rs232(CONF_UART, &usart_console_settings, sysclk_get_cpu_hz()); /* Enable the transmitter. */ usart_enable_tx(CONF_UART); }
/** * \brief Configure USART in normal (serial rs232) mode, asynchronous, * 8 bits, 1 stop bit, no parity, 115200 bauds and enable its transmitter * and receiver. */ static void configure_usart(void) { const sam_usart_opt_t usart_console_settings = { BOARD_USART_BAUDRATE, US_MR_CHRL_8_BIT, US_MR_PAR_NO, US_MR_NBSTOP_1_BIT, US_MR_CHMODE_NORMAL, /* This field is only used in IrDA mode. */ 0 }; /* Enable the peripheral clock in the PMC. */ sysclk_enable_peripheral_clock(BOARD_ID_USART); /* Configure USART in serial mode. */ usart_init_rs232(BOARD_USART, &usart_console_settings, sysclk_get_cpu_hz()); /* Enable the receiver and transmitter. */ usart_enable_tx(BOARD_USART); usart_enable_rx(BOARD_USART); }
void bm_print_txt(uint8_t* str, uint8_t str_length) { #define BM_PRINT_TEXT_SIZE 21 #define BM_PRINT_TEXT_DEEP 6 usart_enable_tx(BM_USART_USART); usart_putchar(BM_USART_USART, BM_MSG_START_PATTERN); usart_putchar(BM_USART_USART, BM_PRINT_TEXT_SIZE + 3 /* length */); usart_putchar(BM_USART_USART, BM_PRINT_TEXT); if (str_length < BM_PRINT_TEXT_SIZE) { for (uint8_t i=0;i<str_length;i++){ usart_putchar(BM_USART_USART, str[i]); } for (uint8_t i=0;i < BM_PRINT_TEXT_SIZE - str_length;i++){ usart_putchar(BM_USART_USART, '\0'); } } else { for (uint8_t i=0;i<BM_PRINT_TEXT_SIZE;i++){ usart_putchar(BM_USART_USART, str[i]); } } usart_putchar(BM_USART_USART, BM_MSG_STOP_PATTERN); while (!usart_is_tx_empty(BM_USART_USART)); usart_disable_tx(BM_USART_USART); }