/** **************************************************************************************** * * @file uart.h * * @brief UART Driver for HCI over UART operation. * * Copyright (C) RivieraWaves 2009-2015 * * **************************************************************************************** */ #ifndef _UART_H_ #define _UART_H_ /** **************************************************************************************** * @defgroup UART UART * @ingroup DRIVERS * @brief UART driver * * @{ * **************************************************************************************** */ /* * INCLUDE FILES **************************************************************************************** */ #include // standard boolean definitions #include // standard integer functions #define VIRTUAL_UART_H4TL 1 #define UART_FIFO_MAX_COUNT 300 /* * ENUMERATION DEFINITIONS ***************************************************************************************** */ typedef enum _UART_CMD_STATE { UART_CMD_STATE_HEAD, UART_CMD_STATE_OPCODE_ONE, UART_CMD_STATE_OPCODE_TWO, UART_CMD_STATE_LENGTH, UART_CMD_STATE_CMD, UART_CMD_STATE_CMD_FLASH, UART_CMD_STATE_LENGTH_FLASH_LEN0, UART_CMD_STATE_LENGTH_FLASH_LEN1, UART_CMD_STATE_LENGTH_FLASH_SCMD, UART_CMD_STATE_PAYLOAD, UART_CMD_STATE_ERROR_ONE, UART_CMD_STATE_ERROR_TWO, UART_CMD_STATE_ERROR_THREE, UART_CMD_STATE_ERROR_FOUR, UART_CMD_STATE_PACKET, }UART_CMD_STATE; #if (VIRTUAL_UART_H4TL == 1) #define HCI_DATA_BUF_SIZE 300 #define HCI_DATA_TYPE_CMD 0x01 #define HCI_DATA_TYPE_EVENT 0x02 struct hci_cmd_event_data { // call back function pointer void (*callback)(void*,uint16_t); //Dumy data pointer uint8_t data_buff[HCI_DATA_BUF_SIZE]; uint32_t data_len; }; #endif /* TX and RX channel class holding data used for asynchronous read and write data * transactions */ /// UART TX RX Channel struct uart_txrxchannel { uint32_t size; uint8_t *bufptr; /// call back function pointer void (*callback) (void*, uint8_t); /// Dummy data pointer returned to callback when operation is over. void* dummy; }; /// UART environment structure struct uart_env_tag { /// tx channel struct uart_txrxchannel tx; /// rx channel struct uart_txrxchannel rx; /// error detect uint8_t errordetect; /// external wakeup bool ext_wakeup; uint8_t *uart_tx_buf; uint8_t *uart_rx_buf; uint32_t uart_tx_length; uint32_t uart_rx_length; uint8_t uart_tx_enable; uint8_t uart_rx_enable; }; /* * FUNCTION DECLARATIONS **************************************************************************************** */ #if (BLE_TEST_MODE_SUPPORT) /** **************************************************************************************** * @brief Initializes the UART to default values. ***************************************************************************************** */ void uart_init(void); #endif // (BLE_TEST_MODE_SUPPORT) #ifndef CFG_ROM /** **************************************************************************************** * @brief Enable UART flow. ***************************************************************************************** */ void uart_flow_on(void); /** **************************************************************************************** * @brief Disable UART flow. ***************************************************************************************** */ bool uart_flow_off(void); #endif //CFG_ROM /** **************************************************************************************** * @brief Finish current UART transfers ***************************************************************************************** */ void uart_finish_transfers(void); /** **************************************************************************************** * @brief Starts a data reception. * * @param[out] bufptr Pointer to the RX buffer * @param[in] size Size of the expected reception * @param[in] callback Pointer to the function called back when transfer finished * @param[in] dummy Dummy data pointer returned to callback when reception is finished ***************************************************************************************** */ void uart_read(uint8_t *bufptr, uint32_t size, void (*callback) (void*, uint8_t), void* dummy); /** **************************************************************************************** * @brief Starts a data transmission. * * @param[in] bufptr Pointer to the TX buffer * @param[in] size Size of the transmission * @param[in] callback Pointer to the function called back when transfer finished * @param[in] dummy Dummy data pointer returned to callback when transmission is finished ***************************************************************************************** */ void uart_write(uint8_t *bufptr, uint32_t size, void (*callback) (void*, uint8_t), void* dummy); #if defined(CFG_ROM) /** **************************************************************************************** * @brief Poll UART on reception and transmission. * * This function is used to poll UART for reception and transmission. * It is used when IRQ are not used to detect incoming bytes. ***************************************************************************************** */ void uart_poll(void); #endif //CFG_ROM /** **************************************************************************************** * @brief Serves the data transfer interrupt requests. * * It clears the requests and executes the appropriate callback function. ***************************************************************************************** */ void uart_isr(void); void hci_data_init(uint8_t type); void host_get_event_cbReg(void(*callback)(void*,uint16_t)); void host_send_cmd(uint8_t *bufptr,uint16_t length); void uart_h4tl_data_switch(void); void uart_send(void *buff,uint16_t len); /// @} UART #endif /* _UART_H_ */