Skip to content
Open
Show file tree
Hide file tree
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Loading
Jump to
The table of contents is too big for display.
Diff view
Diff view
  •  
  •  
  •  
Empty file added EVT/EXAM/ADC/.template
Empty file.
606 changes: 606 additions & 0 deletions EVT/EXAM/ADC/obj/ADC.hex

Large diffs are not rendered by default.

Empty file added EVT/EXAM/BLE/BLE_UART/.template
Empty file.
233 changes: 233 additions & 0 deletions EVT/EXAM/BLE/BLE_UART/APP/app_uart.c
Original file line number Diff line number Diff line change
@@ -0,0 +1,233 @@
/********************************** (C) COPYRIGHT *******************************
* File Name : peripheral.C
* Author : zhangxiyi @WCH
* Version : v0.1
* Date : 2020/11/26
* Description :
*********************************************************************************
* Copyright (c) 2021 Nanjing Qinheng Microelectronics Co., Ltd.
* Attention: This software (modified or not) and binary are used for
* microcontroller manufactured by Nanjing Qinheng Microelectronics.
*******************************************************************************/

/*********************************************************************
* INCLUDES
*/
#include "CONFIG.h"
#include "devinfoservice.h"
#include "gattprofile.h"
#include "peripheral.h"
#include "app_uart.h"

/*********************************************************************
* MACROS
*/
//The buffer length should be a power of 2
#define APP_UART_TX_BUFFER_LENGTH 512U
#define APP_UART_RX_BUFFER_LENGTH 2048U

/*********************************************************************
* CONSTANTS
*/

/*********************************************************************
* TYPEDEFS
*/

/*********************************************************************
* GLOBAL VARIABLES
*/
uint8_t to_test_buffer[BLE_BUFF_MAX_LEN - 4 - 3];

app_drv_fifo_t app_uart_tx_fifo;
app_drv_fifo_t app_uart_rx_fifo;

//interupt uart rx flag ,clear at main loop
bool uart_rx_flag = false;

//for interrupt rx blcak hole ,when uart rx fifo full
uint8_t for_uart_rx_black_hole = 0;

//fifo length less that MTU-3, retry times
uint32_t uart_to_ble_send_evt_cnt = 0;

/*********************************************************************
* EXTERNAL VARIABLES
*/

/*********************************************************************
* EXTERNAL FUNCTIONS
*/

/*********************************************************************
* LOCAL VARIABLES
*/
//

//The tx buffer and rx buffer for app_drv_fifo
//length should be a power of 2
static uint8_t app_uart_tx_buffer[APP_UART_TX_BUFFER_LENGTH] = {0};
static uint8_t app_uart_rx_buffer[APP_UART_RX_BUFFER_LENGTH] = {0};


/*********************************************************************
* LOCAL FUNCTIONS
*/

/*********************************************************************
* PROFILE CALLBACKS
*/

/*********************************************************************
* PUBLIC FUNCTIONS
*/

/*********************************************************************
* @fn app_uart_process
*
* @brief process uart data
*
* @return NULL
*/
void app_uart_process(void)
{
UINT32 irq_status;
SYS_DisableAllIrq(&irq_status);
if(uart_rx_flag)
{
tmos_start_task(Peripheral_TaskID, UART_TO_BLE_SEND_EVT, 2);
uart_rx_flag = false;
}
SYS_RecoverIrq(irq_status);

//tx process
if(R8_UART3_TFC < UART_FIFO_SIZE)
{
app_drv_fifo_read_to_same_addr(&app_uart_tx_fifo, (uint8_t *)&R8_UART3_THR, UART_FIFO_SIZE - R8_UART3_TFC);
}
}

/*********************************************************************
* @fn app_uart_init
*
* @brief init uart
*
* @return NULL
*/
void app_uart_init()
{
//tx fifo and tx fifo
//The buffer length should be a power of 2
app_drv_fifo_init(&app_uart_tx_fifo, app_uart_tx_buffer, APP_UART_TX_BUFFER_LENGTH);
app_drv_fifo_init(&app_uart_rx_fifo, app_uart_rx_buffer, APP_UART_RX_BUFFER_LENGTH);

//uart tx io
GPIOA_SetBits(bTXD3);
GPIOA_ModeCfg(bTXD3, GPIO_ModeOut_PP_5mA);

//uart rx io
GPIOA_SetBits(bRXD3);
GPIOA_ModeCfg(bRXD3, GPIO_ModeIN_PU);

//uart3 init
UART3_DefInit();

//enable interupt
UART3_INTCfg(ENABLE, RB_IER_RECV_RDY | RB_IER_LINE_STAT);
PFIC_EnableIRQ(UART3_IRQn);
}

/*********************************************************************
* @fn app_uart_tx_data
*
* @brief app_uart_tx_data
*
* @return NULL
*/
void app_uart_tx_data(uint8_t *data, uint16_t length)
{
uint16_t write_length = length;
app_drv_fifo_write(&app_uart_tx_fifo, data, &write_length);
}

/*********************************************************************
* @fn UART3_IRQHandler
*
* @brief Not every uart reception will end with a UART_II_RECV_TOUT
* UART_II_RECV_TOUT can only be triggered when R8_UARTx_RFC is not 0
* Here we cannot rely UART_II_RECV_TOUT as the end of a uart reception
*
* @return NULL
*/
__INTERRUPT
__HIGH_CODE
void UART3_IRQHandler(void)
{
uint16_t error;
switch(UART3_GetITFlag())
{
case UART_II_LINE_STAT:
UART3_GetLinSTA();
break;

case UART_II_RECV_RDY:
case UART_II_RECV_TOUT:
error = app_drv_fifo_write_from_same_addr(&app_uart_rx_fifo, (uint8_t *)&R8_UART3_RBR, R8_UART3_RFC);
if(error != APP_DRV_FIFO_RESULT_SUCCESS)
{
for(uint8_t i = 0; i < R8_UART3_RFC; i++)
{
//fifo full,put to fifo black hole
for_uart_rx_black_hole = R8_UART3_RBR;
}
}
uart_rx_flag = true;
break;

case UART_II_THR_EMPTY:
break;
case UART_II_MODEM_CHG:
break;
default:
break;
}
}

/*********************************************************************
* @fn on_bleuartServiceEvt
*
* @brief ble uart service callback handler
*
* @return NULL
*/
void on_bleuartServiceEvt(uint16_t connection_handle, ble_uart_evt_t *p_evt)
{
switch(p_evt->type)
{
case BLE_UART_EVT_TX_NOTI_DISABLED:
PRINT("%02x:bleuart_EVT_TX_NOTI_DISABLED\r\n", connection_handle);
break;
case BLE_UART_EVT_TX_NOTI_ENABLED:
PRINT("%02x:bleuart_EVT_TX_NOTI_ENABLED\r\n", connection_handle);
break;
case BLE_UART_EVT_BLE_DATA_RECIEVED:
PRINT("BLE RX DATA len:%d\r\n", p_evt->data.length);

//for notify back test
//to ble
uint16_t to_write_length = p_evt->data.length;
app_drv_fifo_write(&app_uart_rx_fifo, (uint8_t *)p_evt->data.p_data, &to_write_length);
tmos_start_task(Peripheral_TaskID, UART_TO_BLE_SEND_EVT, 2);
//end of nofify back test

//ble to uart
app_uart_tx_data((uint8_t *)p_evt->data.p_data, p_evt->data.length);

break;
default:
break;
}
}

/*********************************************************************
*********************************************************************/
66 changes: 66 additions & 0 deletions EVT/EXAM/BLE/BLE_UART/APP/include/app_uart.h
Original file line number Diff line number Diff line change
@@ -0,0 +1,66 @@
/********************************** (C) COPYRIGHT *******************************
* File Name : app_uart.h
* Author : WCH
* Version : V1.0
* Date : 2018/12/11
* Description :
*********************************************************************************
* Copyright (c) 2021 Nanjing Qinheng Microelectronics Co., Ltd.
* Attention: This software (modified or not) and binary are used for
* microcontroller manufactured by Nanjing Qinheng Microelectronics.
*******************************************************************************/

#ifndef app_uart_H
#define app_uart_H

#ifdef __cplusplus
extern "C" {
#endif

/*********************************************************************
* INCLUDES
*/

#include "app_drv_fifo.h"
#include "ble_uart_service.h"

/*********************************************************************
* CONSTANTS
*/

extern uint8_t to_test_buffer[BLE_BUFF_MAX_LEN - 4 - 3];

extern app_drv_fifo_t app_uart_tx_fifo;
extern app_drv_fifo_t app_uart_rx_fifo;

//interupt uart rx flag ,clear at main loop
extern bool uart_rx_flag;

//for interrupt rx blcak hole ,when uart rx fifo full
extern uint8_t for_uart_rx_black_hole;

//fifo length less that MTU-3, retry times
extern uint32_t uart_to_ble_send_evt_cnt;

/*********************************************************************
* MACROS
*/

/*********************************************************************
* FUNCTIONS
*/

extern void app_uart_process(void);

extern void app_uart_init(void);

extern void on_bleuartServiceEvt(uint16_t connection_handle, ble_uart_evt_t *p_evt);

/*********************************************************************
*********************************************************************/

#ifdef __cplusplus
}
#endif

#endif
1 change: 1 addition & 0 deletions EVT/EXAM/BLE/BLE_UART/APP/include/peripheral.h
Original file line number Diff line number Diff line change
Expand Up @@ -43,6 +43,7 @@ typedef struct
uint16 connTimeout;
} peripheralConnItem_t;

extern uint8_t Peripheral_TaskID;
/*********************************************************************
* FUNCTIONS
*/
Expand Down
Loading