Skip to content

Commit

Permalink
update evt to 1.9
Browse files Browse the repository at this point in the history
  • Loading branch information
qitas committed Sep 9, 2023
1 parent 702153e commit f7da0a0
Show file tree
Hide file tree
Showing 399 changed files with 6,329 additions and 52,011 deletions.
12 changes: 6 additions & 6 deletions README.md
Original file line number Diff line number Diff line change
Expand Up @@ -3,19 +3,18 @@
[![Build Status](https://github.com/SoCXin/CH583/workflows/build/badge.svg)](https://github.com/SoCXin/CH583/actions/workflows/build.yml)

* [WCH](http://www.wch.cn/)[RISC-V4A (RV32IMAC)](https://github.com/SoCXin/RISC-V)
* [L2R2](https://github.com/SoCXin/Level):80 MHz (1.56DMIPS) , [¥4.43 (QFN48)](https://item.szlcsc.com/3226374.html)
* [L1R1](https://github.com/SoCXin/Level)20/80 MHz (1.56DMIPS) , [¥4.43 (QFN48)](https://item.szlcsc.com/3226374.html)

## [简介](https://github.com/SoCXin/CH583/wiki)

[CH583](https://www.wch.cn/products/CH583.html) 集成BLE无线通讯的32位RISC微控制器。片上集成2Mbps低功耗蓝牙BLE 通讯模块、2个全速USB主机和设备控制器及收发器、2个SPI、4个串口、ADC、触摸按键检测模块、RTC等丰富的外设资源。

### 关键特性

* 20/80 MHz RISC-V4A Core (RV32IMAC)
* 32KB SRAM + 512KB/1MB Flash
* 2.4GHz RF收发器和基带及链路控制,支持BLE5.1
* BLE 接收灵敏度-98dBm,可编程+7dBm发送功率
* 2xUSB2.0
* 20/80 MHz RISC-V4A (RV32IMAC)
* 32KB SRAM + 448KB Flash
* BLE5.3 接收灵敏度-98dBm,可编程+7dBm发送功率
* 2x USB1.1 H/D
* 4xUART,SPI,12x PWM,IIC
* 14x TouchPad

Expand All @@ -37,6 +36,7 @@ CH581 则相对 CH582 再去掉了一组USB、触摸按键、I2C模块和两个

[CH583](https://github.com/SoCXin/CH583)最新升级型号[CH592](https://github.com/SoCXin/CH592)支持BLE 5.4,但是减少了外设配置,只保留一组USB

同品牌相似系列[CH32V208](https://www.wch.cn/products/CH32V208.html)

## [开源集锦](https://github.com/OS-Q)

Expand Down
178 changes: 89 additions & 89 deletions src/EVT/CH583_List.txt

Large diffs are not rendered by default.

233 changes: 233 additions & 0 deletions src/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 src/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 src/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

0 comments on commit f7da0a0

Please sign in to comment.