This commit is contained in:
moyuhai
2026-06-09 16:39:17 +08:00
commit 41a602f89c
3057 changed files with 771495 additions and 0 deletions
@@ -0,0 +1,127 @@
/**
****************************************************************************************
*
* @file flash.h
*
* @brief Flash driver interface
*
* Copyright (C) RivieraWaves 2009-2015
*
*
****************************************************************************************
*/
#ifndef FLASH_H_
#define FLASH_H_
#include <stdint.h> // standard integer functions
/**
****************************************************************************************
* @addtogroup FLASH
* @ingroup DRIVERS
*
* @brief Flash memory driver
*
* @{
****************************************************************************************
*/
/*
* DEFINES
****************************************************************************************
*/
///Flash type code used to select the correct erasing and programming algorithm
#define FLASH_TYPE_UNKNOWN 0
#define FLASH_TYPE_INTEL_28F320C3 1
#define FLASH_TYPE_INTEL_28F800C3 2
#define FLASH_TYPE_NUMONYX_M25P128 3
///Base address of Flash on system bus
#define FLASH_BASE_ADDR 0x03000000
/*
* FUNCTION DECLARATIONS
****************************************************************************************
*/
/**
****************************************************************************************
* @brief Initialize flash driver.
****************************************************************************************
*/
void flash_init(void);
/**
****************************************************************************************
* @brief Identify the flash device.
*
* This function is used to read the flash device ID.
*
* Note: callback parameter is not used
*
* @param[out] id Pointer to id location
* @param[in] callback Callback for end of identification
* @return status 0 if operation can start successfully
****************************************************************************************
*/
uint8_t flash_identify(uint8_t* id, void (*callback)(void));
/**
****************************************************************************************
* @brief Erase a flash section.
*
* This function is used to erase a part of the flash memory.
*
* Note: callback parameter is not used
*
* @param[in] flash_type Flash type
* @param[in] offset Starting offset from the beginning of the flash device
* @param[in] size Size of the portion of flash to erase
* @param[in] callback Callback for end of erase
* @return status 0 if operation can start successfully
****************************************************************************************
*/
uint8_t flash_erase(uint8_t flash_type, uint32_t offset, uint32_t size, void (*callback)(void));
/**
****************************************************************************************
* @brief Write a flash section.
*
* This function is used to write a part of the flash memory.
*
* Note: callback parameter is not used
*
* @param[in] flash_type Flash type
* @param[in] offset Starting offset from the beginning of the flash device
* @param[in] length Size of the portion of flash to write
* @param[in] buffer Pointer on data to write
* @param[in] callback Callback for end of write
* @return status 0 if operation can start successfully
****************************************************************************************
*/
uint8_t flash_write(uint8_t flash_type, uint32_t offset, uint32_t length, uint8_t *buffer, void (*callback)(void));
/**
****************************************************************************************
* @brief Read a flash section.
*
* This function is used to read a part of the flash memory.
*
* Note: callback parameter is not used
*
* @param[in] flash_type Flash type
* @param[in] offset Starting offset from the beginning of the flash device
* @param[in] length Size of the portion of flash to read
* @param[out] buffer Pointer on data to read
* @param[in] callback Callback for end of read
* @return status 0 if operation can start successfully
****************************************************************************************
*/
uint8_t flash_read(uint8_t flash_type, uint32_t offset, uint32_t length, uint8_t *buffer, void (*callback)(void));
/// @} FLASH
#endif // FLASH_H_
@@ -0,0 +1,166 @@
/**
****************************************************************************************
*
* @file reg_access.h
*
* @brief File implementing the basic primitives for register accesses
*
* Copyright (C) RivieraWaves 2009-2015
*
*
****************************************************************************************
*/
#ifndef REG_ACCESS_H_
#define REG_ACCESS_H_
/**
****************************************************************************************
* @addtogroup REG REG_ACCESS
* @ingroup DRIVERS
*
* @brief Basic primitives for register access
*
* @{
****************************************************************************************
*/
/*
* INCLUDE FILES
****************************************************************************************
*/
#include <string.h> // string functions
#if defined(CFG_EMB)
#include "co_utils.h"
#include "em_map.h" // EM Map
#endif // defined(CFG_EMB)
/*
* DEFINES
****************************************************************************************
*/
/*
* MACROS
****************************************************************************************
*/
/// Macro to read a platform register
#define REG_PL_RD(addr) (*(volatile uint32_t *)(addr))
/// Macro to write a platform register
#define REG_PL_WR(addr, value) (*(volatile uint32_t *)(addr)) = (value)
/// Macro to read a common ip register
#define REG_IP_RD(addr) (*(volatile uint32_t *)(addr))
/// Macro to write a common ip register
#define REG_IP_WR(addr, value) (*(volatile uint32_t *)(addr)) = (value)
/// Macro to read a BLE register
#define REG_BLE_RD(addr) (*(volatile uint32_t *)(addr))
/// Macro to write a BLE register
#define REG_BLE_WR(addr, value) (*(volatile uint32_t *)(addr)) = (value)
/// Macro to read a BLE control structure field (16-bit wide)
#define EM_BLE_RD(addr) (*(volatile uint16_t *)(addr))
/// Macro to write a BLE control structure field (16-bit wide)
#define EM_BLE_WR(addr, value) (*(volatile uint16_t *)(addr)) = (value)
/// Macro to read a BT register
#define REG_BT_RD(addr) (*(volatile uint32_t *)(addr))
/// Macro to write a BT register
#define REG_BT_WR(addr, value) (*(volatile uint32_t *)(addr)) = (value)
/// Macro to read a BT control structure field (16-bit wide)
#define EM_BT_RD(addr) (*(volatile uint16_t *)(addr))
/// Macro to write a BT control structure field (16-bit wide)
#define EM_BT_WR(addr, value) (*(volatile uint16_t *)(addr)) = (value)
/// Macro to read a EM field (16-bit wide)
#define EM_RD(addr) (*(volatile uint16_t *)(addr))
/// Macro to write a EM field (16-bit wide)
#define EM_WR(addr, value) (*(volatile uint16_t *)(addr)) = (value)
/*
* FUNCTION DECLARATIONS
****************************************************************************************
*/
#if (defined(CFG_BT) || (defined(CFG_BLE) && defined(CFG_EMB)))
/// Read bytes from EM
__INLINE void em_rd(void *sys_addr, uint16_t em_addr, uint16_t len)
{
memcpy(sys_addr, (void *)(em_addr + EM_BASE_ADDR), len);
}
/// Write bytes to EM
__INLINE void em_wr(void const *sys_addr, uint16_t em_addr, uint16_t len)
{
memcpy((void *)(em_addr + EM_BASE_ADDR), sys_addr, len);
}
// copy two exchange memory area
__INLINE void em_cpy(uint16_t dst_em_addr, uint16_t src_em_addr, uint16_t len)
{
memcpy((void *)(dst_em_addr + EM_BASE_ADDR), (void *)(src_em_addr + EM_BASE_ADDR), len);
}
/// Fill an EM space with the same value
__INLINE void em_set(int value, uint16_t em_addr, uint16_t len)
{
memset((void *)(em_addr + EM_BASE_ADDR), value, len);
}
/// Read 32-bits value from EM
__INLINE uint32_t em_rd32p(uint16_t em_addr)
{
return co_read32p((void *)(em_addr + EM_BASE_ADDR));
}
/// Write 32-bits value to EM
__INLINE void em_wr32p(uint16_t em_addr, uint32_t value)
{
co_write32p((void *)(em_addr + EM_BASE_ADDR), value);
}
/// Read 24-bits value from EM
__INLINE uint32_t em_rd24p(uint16_t em_addr)
{
return co_read24p((void *)(em_addr + EM_BASE_ADDR));
}
/// Write 24-bits value to EM
__INLINE void em_wr24p(uint16_t em_addr, uint32_t value)
{
co_write24p((void *)(em_addr + EM_BASE_ADDR), value);
}
/// Read 16-bits value from EM
__INLINE uint16_t em_rd16p(uint16_t em_addr)
{
return co_read16p((void *)(em_addr + EM_BASE_ADDR));
}
/// Write 16-bits value to EM
__INLINE void em_wr16p(uint16_t em_addr, uint16_t value)
{
co_write16p((void *)(em_addr + EM_BASE_ADDR), value);
}
/// Read 8-bits value from EM
__INLINE uint8_t em_rd8p(uint16_t em_addr)
{
return *((uint8_t *)(em_addr + EM_BASE_ADDR));
}
/// Write 8-bits value to EM
__INLINE void em_wr8p(uint16_t em_addr, uint8_t value)
{
*(uint8_t *)(em_addr + EM_BASE_ADDR) = value;
}
#endif // (defined(CFG_BT) || (defined(CFG_BLE) && defined(CFG_EMB)))
/// @} REG
#endif // REG_ACCESS_H_
@@ -0,0 +1,534 @@
/**
****************************************************************************************
*
* @file uart.c
*
* @brief UART driver
*
* Copyright (C) RivieraWaves 2009-2015
*
*
****************************************************************************************
*/
/**
****************************************************************************************
* @addtogroup UART
* @{
****************************************************************************************
*/
/*
* INCLUDE FILES
****************************************************************************************
*/
#include "arch.h"
#include "compiler.h"
#include <stddef.h> // standard definition
#include <stdint.h>
// #include "xinc_reg.h"
#include "reg_access.h"
// #include "bsp_gpio.h"
// #include "bsp_uart.h"
#include "uart.h"
#include "xc_drv_uart.h"
#ifndef CFG_ROM
#include "rwip.h" // SW interface
#if (PLF_NVDS)
#include "nvds.h" // NVDS
#endif // (PLF_NVDS)
#endif // CFG_ROM
#include "dbg.h"
#include <stdio.h>
#if (BLE_TEST_MODE_SUPPORT)
/*
* DEFINES
*****************************************************************************************
*/
// /// Max baudrate supported by this UART (in bps)
// #define UART_BAUD_MAX 3500000
// /// Min baudrate supported by this UART (in bps)
// #define UART_BAUD_MIN 9600
// /// Duration of 1 byte transfer over UART (10 bits) in us (for 921600 default
// baudrate) #define UART_CHAR_DURATION 11
/*
* ENUMERATION DEFINITIONS
*****************************************************************************************
*/
/*
* STRUCT DEFINITIONS
*****************************************************************************************
*/
/*
* GLOBAL VARIABLE DEFINITIONS
****************************************************************************************
*/
/// uart environment structure
volatile static struct uart_env_tag uart_env;
volatile static uint8_t uart_rx_done = 0;
volatile static uint16_t uart_rx_index = 0;
uint8_t uart_tx_buf[UART_FIFO_MAX_COUNT];
uint8_t uart_rx_buf[UART_FIFO_MAX_COUNT];
/*
* LOCAL FUNCTION DEFINITIONS
****************************************************************************************
*/
/*
* EXPORTED FUNCTION DEFINITIONS
****************************************************************************************
*/
uint8_t uart_handle = UART1_IDX;
UART_InitCfg_t uart_cfg = {0};
void uart_init(void)
{
uart_rx_done = 0;
uart_rx_index = 0;
// Initialize RX and TX transfer callbacks
uart_env.rx.callback = NULL;
uart_env.tx.callback = NULL;
uart_env.uart_tx_buf = NULL;
uart_env.uart_rx_buf = NULL;
uart_env.uart_tx_length = 0;
uart_env.uart_rx_length = 0;
uart_env.uart_tx_enable = 0;
uart_env.uart_rx_enable = 0;
GPIO_InitCfg_t gpio_cfg = {0};
gpio_cfg.Mux = GPIO_Mux0;
gpio_cfg.Pull = GPIO_PULLUP;
gpio_cfg.Int = NOT_INT;
gpio_cfg.Pin = GPIO_16; // GPIO_16;
gpio_cfg.Dir = GPIO_DIR_OUTPUT;
gpio_cfg.FunSel = UART1_TX;
xc_gpio_init(&gpio_cfg);
gpio_cfg.Pin = GPIO_15; // GPIO_15;
gpio_cfg.Dir = GPIO_DIR_INPUT;
gpio_cfg.FunSel = UART1_RX;
xc_gpio_init(&gpio_cfg);
uart_cfg.Parity = UART_PARITY_DISABLE;
uart_cfg.StopBits = UART_TCR_STOP_1BITS;
uart_cfg.WordLength = UART_DATA_8_BITS;
uart_cfg.BaudRate = UART_BAUDRATE_115200;
uart_cfg.HardwareFlowControl = UART_HWFC_DISABLE;
xc_uart_init(uart_handle, &uart_cfg);
xc_uart_enable_rx_it(uart_handle);
if (uart_handle == UART0_IDX) {
NVIC_EnableIRQ(UART0_IRQn);
} else if (uart_handle == UART1_IDX) {
NVIC_EnableIRQ(UART1_IRQn);
}
#if (VIRTUAL_UART_H4TL == 1)
#if (BLE_APP_PRESENT)
if (0)
#endif
{
hci_data_init(HCI_DATA_TYPE_CMD | HCI_DATA_TYPE_EVENT);
host_get_event_cbReg(uart_send);
}
#endif
}
void uart_send(void *buff, uint16_t len)
{
xc_uart_send_data(uart_handle, buff, len);
}
void uart_flow_on(void)
{
// Configure modem (HW flow control enable)
}
bool uart_flow_off(void)
{
bool flow_off = true;
GLOBAL_INT_DISABLE();
do {
// Force RTS to 'flow off' via GPIO
// uart_force_rts_setf(1);
} while (0);
GLOBAL_INT_RESTORE();
return flow_off;
}
void uart_finish_transfers(void)
{
// Wait TX FIFO empty
// while(!uart_tx_fifo_empty_getf());
}
void uart_read(uint8_t *bufptr, uint32_t size,
void (*callback)(void *, uint8_t), void *dummy)
{
// Sanity check
ASSERT_ERR(bufptr != NULL);
ASSERT_ERR(size != 0);
ASSERT_ERR(callback != NULL);
uart_env.rx.callback = callback;
uart_env.rx.dummy = dummy;
uart_env.uart_rx_buf = bufptr;
uart_env.uart_rx_length = size;
uart_env.uart_rx_enable = 1;
// DEBUG("uart_env.rx.callback:%x\r\n",uart_env.rx.callback);
// DEBUG("uart_read
// len:%d,data:%02x,%02x,%02x\r\n",uart_env.uart_rx_length,uart_env.uart_rx_buf[0],uart_env.uart_rx_buf[1],uart_env.uart_rx_buf[2]);
}
void uart_write(uint8_t *bufptr, uint32_t size,
void (*callback)(void *, uint8_t), void *dummy)
{
DEBUG("HCI RSP: ");
// Sanity check
ASSERT_ERR(bufptr != NULL);
ASSERT_ERR(size != 0);
ASSERT_ERR(callback != NULL);
uart_env.tx.callback = callback;
uart_env.tx.dummy = dummy;
uart_env.uart_tx_buf = bufptr;
uart_env.uart_tx_length = size;
uart_env.uart_tx_enable = 1;
for (int i = 0; i < size; i++) {
DEBUG("%02x ", *bufptr++);
}
DEBUG("\r\n");
}
void uart_isr(void) {}
#define UART1_BASE 0x40011000
#include "Platform.h"
#define __write_hw_reg32(reg, val) ((*reg) = (val))
#define __read_hw_reg32(reg, val) ((val) = (*reg))
#define UART1_RBR ((volatile unsigned *)(UART1_BASE + 0x00))
#define UART1_THR ((volatile unsigned *)(UART1_BASE + 0x00))
#define UART1_DLL ((volatile unsigned *)(UART1_BASE + 0x00))
#define UART1_IER ((volatile unsigned *)(UART1_BASE + 0x04))
#define UART1_DLH ((volatile unsigned *)(UART1_BASE + 0x04))
#define UART1_IIR ((volatile unsigned *)(UART1_BASE + 0x08))
#define UART1_FCR ((volatile unsigned *)(UART1_BASE + 0x08))
#define UART1_TCR ((volatile unsigned *)(UART1_BASE + 0x0c))
#define UART1_MCR ((volatile unsigned *)(UART1_BASE + 0x10))
#define UART1_TSR ((volatile unsigned *)(UART1_BASE + 0x14))
#define UART1_MSR ((volatile unsigned *)(UART1_BASE + 0x18))
#define UART1_USR ((volatile unsigned *)(UART1_BASE + 0x7c))
void uart_hci_handler(void)
{
// DEBUG("UART1_Handler\r\n");
uint32_t iir = 0;
uint32_t tsr;
uint8_t data = 0;
__read_hw_reg32(UART1_IIR, iir);
// DEBUG("iWK:%x\r\n",iWK);
iir &= 0x0F;
if ((iir != 0x04) && (iir != 0x0c))
return;
if ((iir & 0x04) == 0x04) {
__read_hw_reg32(UART1_TSR, tsr);
while ((tsr & 0x01) == 0x01) {
__read_hw_reg32(UART1_RBR, data);
uart_rx_buf[uart_rx_index++] = data;
if (uart_rx_index == UART_FIFO_MAX_COUNT) {
uart_rx_index = 0;
}
__read_hw_reg32(UART1_TSR, tsr);
}
}
if ((iir & 0x0c) == 0x0c) {
__read_hw_reg32(UART1_TSR, tsr);
while ((tsr & 0x01) == 0x01) {
__read_hw_reg32(UART1_RBR, data);
uart_rx_buf[uart_rx_index++] = data;
if (uart_rx_index == UART_FIFO_MAX_COUNT) {
uart_rx_index = 0;
}
__read_hw_reg32(UART1_TSR, tsr);
}
host_send_cmd(uart_rx_buf, uart_rx_index);
uart_rx_index = 0;
}
}
void timeout_check()
{
static uint16_t count = 0;
if (uart_rx_index != 0) {
if (count++ > 3000) {
host_send_cmd(uart_rx_buf, uart_rx_index);
uart_rx_index = 0;
count = 0;
}
}
}
void uart_rx_cmd_respone(uint8_t *buff, uint8_t len)
{
uint8_t rsp_buff[32];
rsp_buff[0] = 0x04;
rsp_buff[1] = 0x0e;
rsp_buff[2] = 0x04 + len;
rsp_buff[3] = 0x01;
rsp_buff[4] = 0xe0;
rsp_buff[5] = 0xfc;
rsp_buff[6] = len;
memcpy(&rsp_buff[7], buff, len);
uart_send(rsp_buff, 7 + len);
}
void uart_rx_cmd_handler(uint8_t *buff, uint8_t len) {}
void uart_rx_handler(uint8_t value)
{
static uint8_t cmd_status = UART_CMD_STATE_HEAD;
static uint16_t index = 0;
static uint16_t length;
static uint8_t uart_cmd[32];
switch (cmd_status) {
case UART_CMD_STATE_HEAD: {
if (value == 0x01) {
cmd_status = UART_CMD_STATE_OPCODE_ONE;
} else {
cmd_status = UART_CMD_STATE_HEAD;
}
} break;
case UART_CMD_STATE_OPCODE_ONE: {
if (value == 0xe0) {
cmd_status = UART_CMD_STATE_OPCODE_TWO;
} else {
cmd_status = UART_CMD_STATE_HEAD;
}
} break;
case UART_CMD_STATE_OPCODE_TWO: {
if (value == 0xfc) {
cmd_status = UART_CMD_STATE_LENGTH;
} else {
cmd_status = UART_CMD_STATE_HEAD;
}
} break;
case UART_CMD_STATE_LENGTH: {
length = value;
if (length > 0) {
cmd_status = UART_CMD_STATE_CMD;
index = 0;
} else {
cmd_status = UART_CMD_STATE_HEAD;
}
} break;
case UART_CMD_STATE_CMD: {
uart_cmd[index++] = value;
if (index == length) {
uart_rx_cmd_handler(uart_cmd, length);
cmd_status = UART_CMD_STATE_HEAD;
}
} break;
}
}
#if (VIRTUAL_UART_H4TL == 1)
volatile struct hci_cmd_event_data host_cmd_data;
volatile struct hci_cmd_event_data host_event_data;
void hci_data_init(uint8_t type)
{
// DEBUG("hci_data_init:%x\r\n",type);
if (type & HCI_DATA_TYPE_CMD) {
host_cmd_data.callback = NULL;
memset((void *)&host_cmd_data.data_buff[0], 0, HCI_DATA_BUF_SIZE);
host_cmd_data.data_len = 0;
}
if (type & HCI_DATA_TYPE_EVENT) {
// host_event_data.callback = NULL;
memset((void *)&host_event_data.data_buff[0], 0, HCI_DATA_BUF_SIZE);
host_event_data.data_len = 0;
}
}
void host_send_cmd(uint8_t *bufptr, uint16_t length)
{
host_cmd_data.callback = NULL; // Test Only
memcpy((void *)&host_cmd_data.data_buff[0], bufptr, length);
host_cmd_data.data_len = length;
DEBUG("HCI SEND: ");
for (int i = 0; i < length; i++) {
DEBUG("%02x ", host_cmd_data.data_buff[i]);
}
DEBUG("\r\n");
}
void host_get_event(void)
{
if (host_event_data.callback != NULL) {
host_event_data.callback((void *)host_event_data.data_buff,
host_event_data.data_len);
}
hci_data_init(HCI_DATA_TYPE_EVENT);
}
void host_get_event_cbReg(void (*callback)(void *, uint16_t))
{
host_event_data.callback = callback;
}
void uart_h4tl_data_switch(void)
{
void (*callback)(void *, uint8_t) = NULL;
void *data = NULL;
uint16_t data_len = 0;
if (uart_env.uart_tx_enable || uart_env.uart_rx_enable) {
// DEBUG("uart_h4tl_data_switch:%d,%d\r\n",uart_env.uart_tx_enable,uart_env.uart_rx_enable);
}
while (uart_env.uart_tx_enable == 1) {
callback = uart_env.tx.callback;
data = uart_env.tx.dummy;
uart_env.uart_tx_enable = 0;
memcpy((void *)&host_event_data.data_buff[data_len],
uart_env.uart_tx_buf, uart_env.uart_tx_length);
data_len += uart_env.uart_tx_length;
host_event_data.data_len += uart_env.uart_tx_length;
if (callback != NULL) {
uart_env.tx.callback = NULL;
uart_env.tx.dummy = NULL;
callback(data, RWIP_EIF_STATUS_OK);
} else {
}
}
if (host_event_data.data_len != 0) {
host_get_event();
}
data_len = 0;
if (host_cmd_data.data_len > 0) {
while (uart_env.uart_rx_enable == 1) {
callback = uart_env.rx.callback;
data = uart_env.rx.dummy;
uart_env.uart_rx_enable = 0;
memcpy((void *)uart_env.uart_rx_buf,
(void *)&host_cmd_data.data_buff[data_len],
uart_env.uart_rx_length);
data_len += uart_env.uart_rx_length;
// DEBUG("data_len:%d,uart_rx_length:%d\r\n",data_len,uart_env.uart_rx_length);
// DEBUG("callback:%x\r\n",callback);
if (callback != NULL) {
uart_env.rx.callback = NULL;
uart_env.rx.dummy = NULL;
callback(data, RWIP_EIF_STATUS_OK);
} else {
}
// DEBUG("data_len:%d,host_cmd_data.data_len:%d\r\n",data_len,host_cmd_data.data_len);
if (data_len >= host_cmd_data.data_len) {
// hci_data_init(HCI_DATA_TYPE_CMD);
break;
}
}
hci_data_init(HCI_DATA_TYPE_CMD);
}
}
#endif
// Creation of uart external interface api
const struct rwip_eif_api uart_api = {
uart_read,
uart_write,
uart_flow_on,
uart_flow_off,
};
// static bool test_mode = false;
static bool test_mode = true;
bool get_test_mode(void) { return test_mode; }
void enter_test_mode(void)
{
DEBUG("enter_test_mode \n");
/// rf_test_pin_init();
uart_init();
NVIC_SetPriority((IRQn_Type)UART1_IRQn, 2);
h4tl_init(0, rwip_eif_get(0));
while (1) {
// schedule all pending events
rwip_schedule();
#if (VIRTUAL_UART_H4TL == 1)
uart_h4tl_data_switch();
timeout_check();
#endif
}
}
const struct rwip_eif_api *rwip_eif_get(uint8_t idx)
{
const struct rwip_eif_api *ret = NULL;
switch (idx) {
case 0: {
ret = &uart_api;
} break;
default: {
ASSERT_INFO(0, idx, 0);
} break;
}
return ret;
}
#endif // (BLE_TEST_MODE_SUPPORT)
/// @} UART
@@ -0,0 +1,207 @@
/**
****************************************************************************************
*
* @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 <stdbool.h> // standard boolean definitions
#include <stdint.h> // 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_ */