Code structure
Applicable items
usage method
1. Add file
BabyOS//can be used as a git submodule ├── bos │Γ - algorithm//Common algorithm, no need to add files │ -- core//core files, all included in the project │Γ -- drivers//Driver file, select the splash driver to add to the project │☆ -- modules//functional modules, all of which are added to the project and configured by the configuration file b_config. h │Γ - thirdparty//Third party code, select SFUD third party code to add to the project │ L -- utils//Utility code, select delay part of the code to add to the project ▄ - doc//related documents ☆ - LICENSE//Open source protocol └── README.md BabyOS_Config//After cloning, place them in the project directory and add them all to the project BabyOS_Hal//After cloning, place it in the project directory, and add hal, gpio, uart, and spi parts
//Enter the user project directory to execute git submodule add https://gitee.com/notrynohigh/BabyOS.git git clone https://gitee.com/notrynohigh/BabyOS_Config.git //Clone configuration file and device registration file git clone https://gitee.com/notrynohigh/BabyOS_Hal.git //After cloning, switch to the branch of the corresponding platform. If not, use the master branch as the template
2. Add system timer
//For example, using the tick timer, the interrupt service function calls: void bHalIncSysTick (void); //Note: The cycle of the timer should match the _TICK_FRQ_HZ in b_config. h
3. Select function module
4. Register equipment
//B_device_list. h, add used peripherals. For example, if the project only needs to use SPIFlash, add the following code: //Device Driver Description B_DEVICE_REG(SPIFLASH, bSPIFLASH_Driver[0], "flash") //If no device is registered, uncomment B_DEVICE_REG (null, bNullDriver, "null") //B_DEVICE_REG(null, bNullDriver, "null")
5. Modify hardware interface
#define HAL_SPIFLASH_QSPI_EN 0 #define HAL_SPIFLASH_TOTAL_NUMBER 1 #define HAL_SPIFLASH_IF {{B_HAL_QSPI_INVALID, B_HAL_SPI_1, {B_HAL_GPIOB, B_HAL_PIN12}},}
6. Modify SPI part of hardware abstraction layer
//b_hal_spi.c int bHalSPI_Send(bHalSPINumber_t spi, uint8_t *pbuf, uint16_t len) { if(pbuf == NULL) { return -1; } switch(spi) { case B_HAL_SPI_1: HAL_SPI_Transmit(&hspi1, pbuf, len, 0xfff); break; default: break; } return 0; } int bHalSPI_Receive(bHalSPINumber_t spi, uint8_t *pbuf, uint16_t len) { if(pbuf == NULL) { return -1; } switch(spi) { case B_HAL_SPI_1: HAL_SPI_Receive(&hspi1, pbuf, len, 0xfff); break; default: break; } return 0; }
7. Modify the GPIO part of the hardware abstraction layer
void bHalGPIO_WritePin(uint8_t port, uint8_t pin, uint8_t s) { GPIO_PinState sta = (s) ? GPIO_PIN_SET : GPIO_PIN_RESET; HAL_GPIO_WritePin(GPIO_PortTable[port], GPIO_PinTable[pin], sta); }
8. Using KV function based on SPIFLASH
#Include "b_os. h"//Header file //Enable KV storage in b_config. h configuration file int main() { uint8_t buf[128]; bInit(); // Initialization. Initialization of peripherals will be called here If (0==bKV_Init (SPIFLASH, 0xA000, 4096 * 4, 4096))//Initialize the KV storage and specify the storage device SPIFLASH { b_log("bKV_Init ok...\r\n"); } //Storage key value pair (available for storage system configuration information) bKV_Set("name", (uint8_t *)"BabyOS", 7); bKV_Get("name", buf); b_log("name:%s\r\n", buf); //...... while(1) { //..... bExec(); // Loop this function //..... } }
//For example, use SPIFLASH to read data, and read 128 bytes of data from the 0 address to buf { int fd = -1; fd = bOpen(SPIFLASH, BCORE_FLAG_RW); if(fd == -1) { return; } bLseek(fd, 0); bRead(fd, buf, 128); bClose(fd); }