Microchip® Advanced Software Framework

hal_uart.c File Reference
#include "asf.h"
#include "hal_uart_dma.h"
#include "conf_board.h"
#include "stdio_serial.h"
#include "ioport.h"
#include "hal_tick.h"
#include "btstack_debug.h"
#include "btstack_config.h"

Macros

#define ALL_INTERRUPT_MASK   0xffffffff
 All interrupt mask. More...
 
#define DEBUG_PIN_1   PIO_PD16_IDX
 
#define DEBUG_PIN_2   PIO_PD15_IDX
 

Functions

void delay_check (uint32_t value)
 
static void dummy_handler (void)
 
void hal_uart_dma_init (void)
 Init and open device. More...
 
void hal_uart_dma_receive_block (uint8_t *data, uint16_t size)
 Receive block. More...
 
void hal_uart_dma_send_block (const uint8_t *data, uint16_t size)
 Send block. More...
 
int hal_uart_dma_set_baud (uint32_t baud)
 Set baud rate. More...
 
void hal_uart_dma_set_block_received (void(*the_block_handler)(void))
 Set callback for block received - can be called from ISR context. More...
 
void hal_uart_dma_set_block_sent (void(*the_block_handler)(void))
 Set callback for block sent - can be called from ISR context. More...
 
void hal_uart_dma_set_csr_irq_handler (void(*the_irq_handler)(void))
 Set or clear callback for CSR pulse - can be called from ISR context. More...
 
void hal_uart_dma_set_sleep (uint8_t sleep)
 Set sleep mode. More...
 
static void hal_uart_rts_high (void)
 
static void hal_uart_rts_low (void)
 
void USART_Handler (void)
 

Variables

static volatile uint16_t bytes_to_read = 0
 
static volatile uint16_t bytes_to_write = 0
 
static void(* cts_irq_handler )(void) = dummy_handler
 
static int hal_uart_dma_initialized = 0
 
static volatile uint8_t * rx_buffer_ptr = 0
 
static void(* rx_done_handler )(void) = dummy_handler
 
static volatile int rx_notify
 
static int simulate_flowcontrol
 
static volatile uint8_t * tx_buffer_ptr = 0
 
static void(* tx_done_handler )(void) = dummy_handler
 
static volatile int tx_notify
 

#define ALL_INTERRUPT_MASK   0xffffffff

All interrupt mask.

Referenced by hal_uart_dma_init().

#define DEBUG_PIN_1   PIO_PD16_IDX

Referenced by hal_uart_dma_init().

#define DEBUG_PIN_2   PIO_PD15_IDX

Referenced by hal_uart_dma_init().

void delay_check ( uint32_t  value)

References vTaskDelay().

static void dummy_handler ( void  )
static
void hal_uart_dma_receive_block ( uint8_t *  buffer,
uint16_t  len 
)

Receive block.

When done, callback set by hal_uart_dma_set_block_received must be called

Parameters
buffer
lengh

References bytes_to_read, hal_uart_rts_low(), rx_buffer_ptr, rx_notify, and usart_enable_interrupt().

void hal_uart_dma_send_block ( const uint8_t *  buffer,
uint16_t  length 
)

Send block.

When done, callback set by hal_uart_set_block_sent must be called

Parameters
buffer
lengh

References bytes_to_write, log_error, tx_buffer_ptr, tx_notify, and usart_enable_interrupt().

int hal_uart_dma_set_baud ( uint32_t  baud)

Set baud rate.

Note
During baud change, TX line should stay high and no data should be received on RX accidentally
Parameters
baudrate

References log_error, sysclk_get_peripheral_hz(), usart_disable_rx(), usart_disable_tx(), usart_enable_rx(), usart_enable_tx(), and usart_set_async_baudrate().

Referenced by btstack_uart_block_freertos_open().

void hal_uart_dma_set_block_received ( void(*)(void)  callback)

Set callback for block received - can be called from ISR context.

Parameters
callback

References rx_done_handler.

Referenced by btstack_uart_block_freertos_init().

void hal_uart_dma_set_block_sent ( void(*)(void)  callback)

Set callback for block sent - can be called from ISR context.

Parameters
callback

References tx_done_handler.

Referenced by btstack_uart_block_freertos_init().

void hal_uart_dma_set_csr_irq_handler ( void(*)(void)  csr_irq_handler)

Set or clear callback for CSR pulse - can be called from ISR context.

Parameters
csr_irq_handleror NULL to disable IRQ handler

References cts_irq_handler.

void hal_uart_dma_set_sleep ( uint8_t  sleep)

Set sleep mode.

Parameters
block_receivedcallback
static void hal_uart_rts_high ( void  )
inlinestatic

References simulate_flowcontrol.

Referenced by USART_Handler().

static void hal_uart_rts_low ( void  )
inlinestatic

volatile uint16_t bytes_to_read = 0
static
volatile uint16_t bytes_to_write = 0
static
void(* cts_irq_handler)(void) = dummy_handler
static
int hal_uart_dma_initialized = 0
static

Referenced by hal_uart_dma_init().

volatile uint8_t* rx_buffer_ptr = 0
static
void(* rx_done_handler)(void) = dummy_handler
static
volatile int rx_notify
static
int simulate_flowcontrol
static
volatile uint8_t* tx_buffer_ptr = 0
static
void(* tx_done_handler)(void) = dummy_handler
static
volatile int tx_notify
static