Skip to content

SDK Software Structure


1. SDK Software Structure Diagram

SDK软件结构

Figure 1-1 SDK Software Structure

2. SDK directory structure

--Components//Function components
----Asr//Speech recognition
----Alg//Speech preprocessing algorithm library
------Denoise//Noise reduction
----Assist//Auxiliary functions, such as timing functions for testing algorithms
----audio_ in_ Manage//Audio collection real-time task
----audio_ pre_ rslt_ iis_ out//Speech preprocessing result output component
----ci_ Nvdm//User data management
----cmd_ Info//Firmware information analysis
----codec_ Manage//Codec Manager
----Fft//fft manager
----flash_ control//flash manager
----flash_ Encrypt//Flash encryption policy
----freertos//Operating system
----Led//Three color light control manager
----Log//Log printing
----msg_ Com//Serial port protocol
----Ota//OTA upgrade
----Player//player
----RISCV//RISCV related
----sys_ Monitor//System monitor
--Projects//Application example code
----offline_ asr_ Sample//ci130x template project
--Driver//driver
----Boards//Board level support, such as 1302/1306
----ci130x_ chip_ Driver//Internal driver of the chip, such as IIC driver
----third_ device_ Driver//External driver, such as external codec driver ES8388
--Startup//Start code
--system//Unified header definitions
--tools//Firmware building tool
--Utils//Debugging tool set

3. SDK User Code Description

The SDK user code area is shown in Figure 3-1 below:

SDK用户代码区域

Figure 3-1 SDK User Code Area

Directory of the following files: CI130X_ SDK\projects\offline_ asr_ sample\src\

File name Description
sample_ main. C File of main function: including task creation, platform initialization and system startup code
system_ hook. C Event hook interface c file: system startup, wake-up, exit wake-up, voice recognition event hook function
system_ hook. H Event hook interface h file
system_ msg_ deal. C System message processing task c file
system_ msg_ deal. H System message processing task h file
user_ config. H User configuration macro definition H File
user_ msg_ deal. C User code C File: serial port protocol, IIC protocol, key message and other user processing
user_ msg_ deal. H User code H File

4. Add code examples

(1) Add protocol and other processing codes for wake-up words, and find CI130X_ SDK\projects\offline_ asr_ sample\src,

  • First on the user_ msg_ Add processing interface declaration in deal. h, for example:
void wake_ up_ xxx_ deal(void);
  • Then, in the user_ msg_ Add processing interface definitions in deal.c, for example:
void wake_ up_ xxx_ deal(void)
{
/*Processing interface logic code*/
}
  • Finally, in the system_ Call the interface in hook. c, for example:
__ WEAK void sys_ weakup_ hook(void)
{
#if MSG_ COM_ USE_ UART_ EN
vmup_ send_ notify(VMUP_MSG_DATA_NOTIFY_WAKEUPENTER);
#endif

/*Add processing interface call here*/
wake_ up_ xxx_ deal();
}

Note

Other states of the system (system startup, system exit wake-up, voice recognition) can also refer to the above methods to add codes, but they need to be called in the corresponding event hook function.

(2) Add processing code according to the command word ID, and find CI130X_ SDK\projects\offline_ asr_ sample\src\user_ msg_ deal. c_ asr_ msg_ by_ cmd_ Id function.

The corresponding command word of the command word ID is determined by CI130X_ SDK\projects\offline_ asr_ sample\firmware\user_ file\cmd_ info[60000]{xxx}cmd_ Info.xls specifies

uint32_ t deal_ asr_ msg_ by_ cmd_ id(sys_msg_asr_data_t *asr_msg, cmd_handle_t cmd_handle, uint16_t cmd_id)
{
uint32_ t ret = 1;
int select_ index = -1;
switch(cmd_id)
{
Case 2://"Turn on the air conditioner"
{
/*Add processing code according to command word ID here*/
break;
}
/*Add case processing command word ID by yourself*/
/*Omit some codes*/
default:
ret = 0;
break;
}
/*Omit some codes*/
}

(3) Add processing code according to semantic ID, and find CI130X_ SDK\projects\offline_ asr_ sample\src\user_ msg_ deal. c_ asr_ msg_ by_ semantic_ Id function.

For more semantic ID information, you can visit ☞CI130X Semantic ID Description Document page

uint32_ t deal_ asr_ msg_ by_ semantic_ id(sys_msg_asr_data_t *asr_msg, cmd_handle_t cmd_handle, uint32_t semantic_id)
{
uint32_ t ret = 1;
if (PRODUCT_GENERAL == get_product_id_from_semantic_id(semantic_id))
{
uint8_ t vol;
int select_ index = -1;
switch(get_function_id_from_semantic_id(semantic_id))
{
case VOLUME_ UP://Increase the volume
vol = vol_ set(vol_get() + 1);
select_ index = (vol == VOLUME_MAX) ?  1:0;
break;
case XXX_ XXX:
/*Add processing code according to semantic ID here*/
break;
/*Add case processing semantic ID by yourself*/
/*Omit some codes*/
default:
ret = 0;
break;
}
/*Omit some codes*/
}
/*Omit some codes*/
}

5. SDK Code Logic Analysis

Due to the specific needs of the speech recognition system, the SDK has included a lot of initialization work. In order to help users become more familiar with the code structure process, the program startup process and working status are briefly described.

SDK程序启动流程和工作状态

Figure 5-1 SDK Program Startup Process and Working Status

As shown in the figure above, after the system is powered on and started, enter the main function to initialize relevant hardware, and then create a vTaskCreate thread to start the FreeRTOS system. The vTaskCreate thread will create relevant threads for recognition and broadcast, and then the system will enter the sleep state and collect voice input.

When the correct voice is input to the recognition thread, the recognition thread will send the message to the user thread through the message queue mechanism for processing. In the user thread of the SDK, some operations have been completed, such as playing the corresponding broadcast voice, switching the system state, sending the serial port protocol, etc. The user generally only needs to add the code in the user thread when adding the code, Therefore, understanding the message processing mechanism in the user thread can easily extend the function.

When the external communication serial port sends the serial port protocol control voice board, the serial port protocol will be parsed in the communication serial port interrupt, and vmup will be called in the interrupt after successful parsing_ port_ send_ packet_ rev_ The msg function sends a serial port message to the user thread. After receiving the message, the user thread will call deal in turn_ userdef_ msg>>userapp_ deal_ com_ msg>>userapp_ deal_ The cmd finally executes the function synchronously or asynchronously here (most of them are synchronous, but the broadcast words are asynchronous requests), and sends back ACK to the communication serial port after completion.