board_perf:add support for kv and vfs on ch32v307 board
This commit is contained in:
@@ -70,10 +70,12 @@
|
||||
<listOptionValue builtIn="false" value=""${workspace_loc:/${ProjName}/arch/common/include}""/>
|
||||
<listOptionValue builtIn="false" value=""${workspace_loc:/${ProjName}/arch/rv32i/gcc}""/>
|
||||
<listOptionValue builtIn="false" value=""${workspace_loc:/${ProjName}/kernel/core/include}""/>
|
||||
<listOptionValue builtIn="false" value=""${workspace_loc:/${ProjName}/kernel/hal/include}""/>
|
||||
<listOptionValue builtIn="false" value=""${workspace_loc:/${ProjName}/Core}""/>
|
||||
<listOptionValue builtIn="false" value=""${workspace_loc:/${ProjName}/User}""/>
|
||||
<listOptionValue builtIn="false" value=""${workspace_loc:/${ProjName}/Peripheral/inc}""/>
|
||||
<listOptionValue builtIn="false" value=""${workspace_loc:/${ProjName}/fs/kv/include}""/>
|
||||
<listOptionValue builtIn="false" value=""${workspace_loc:/${ProjName}/fs/fatfs/include}""/>
|
||||
<listOptionValue builtIn="false" value=""${workspace_loc:/${ProjName}/fs/vfs/include}""/>
|
||||
</option>
|
||||
<option id="ilg.gnumcueclipse.managedbuild.cross.riscv.option.c.compiler.std.2020844713" name="Language standard" superClass="ilg.gnumcueclipse.managedbuild.cross.riscv.option.c.compiler.std" useByScannerDiscovery="true" value="ilg.gnumcueclipse.managedbuild.cross.riscv.option.c.compiler.std.gnu99" valueType="enumerated"/>
|
||||
<option IS_BUILTIN_EMPTY="false" IS_VALUE_EMPTY="true" id="ilg.gnumcueclipse.managedbuild.cross.riscv.option.c.compiler.defs.177116515" name="Defined symbols (-D)" superClass="ilg.gnumcueclipse.managedbuild.cross.riscv.option.c.compiler.defs" useByScannerDiscovery="true" valueType="definedSymbols"/>
|
||||
@@ -124,7 +126,7 @@
|
||||
</toolChain>
|
||||
</folderInfo>
|
||||
<sourceEntries>
|
||||
<entry excluding="platform/hal/wch/ch32v30xx|kernel/hal|devices/esp8266_tencent_firmware|net/tencent_firmware_module_wrapper|kernel/core|net/at|kernel|arch|TencentOS-Tiny|Startup|Peripheral|Ld|Debug|Core" flags="VALUE_WORKSPACE_PATH|RESOLVED" kind="sourcePath" name=""/>
|
||||
<entry excluding="examples/fatfs_through_vfs_sample.c|User/mqtt_iot_explorer.c|examples/kv_sample.c|fs/fatfs|fs/vfs|fs/kv|components/kv|platform/hal/wch/ch32v30xx|kernel/hal|devices/esp8266_tencent_firmware|net/tencent_firmware_module_wrapper|kernel/core|net/at|kernel|arch|TencentOS-Tiny|Startup|Peripheral|Ld|Debug|Core" flags="VALUE_WORKSPACE_PATH|RESOLVED" kind="sourcePath" name=""/>
|
||||
<entry flags="VALUE_WORKSPACE_PATH|RESOLVED" kind="sourcePath" name="Core"/>
|
||||
<entry flags="VALUE_WORKSPACE_PATH|RESOLVED" kind="sourcePath" name="Debug"/>
|
||||
<entry flags="VALUE_WORKSPACE_PATH|RESOLVED" kind="sourcePath" name="Ld"/>
|
||||
@@ -132,6 +134,9 @@
|
||||
<entry flags="VALUE_WORKSPACE_PATH|RESOLVED" kind="sourcePath" name="Startup"/>
|
||||
<entry flags="VALUE_WORKSPACE_PATH|RESOLVED" kind="sourcePath" name="arch"/>
|
||||
<entry flags="VALUE_WORKSPACE_PATH|RESOLVED" kind="sourcePath" name="devices/esp8266_tencent_firmware"/>
|
||||
<entry flags="VALUE_WORKSPACE_PATH|RESOLVED" kind="sourcePath" name="fs/fatfs"/>
|
||||
<entry flags="VALUE_WORKSPACE_PATH|RESOLVED" kind="sourcePath" name="fs/kv"/>
|
||||
<entry flags="VALUE_WORKSPACE_PATH|RESOLVED" kind="sourcePath" name="fs/vfs"/>
|
||||
<entry flags="VALUE_WORKSPACE_PATH|RESOLVED" kind="sourcePath" name="kernel/core"/>
|
||||
<entry flags="VALUE_WORKSPACE_PATH|RESOLVED" kind="sourcePath" name="kernel/hal"/>
|
||||
<entry flags="VALUE_WORKSPACE_PATH|RESOLVED" kind="sourcePath" name="net/at"/>
|
||||
|
@@ -1,18 +1,18 @@
|
||||
<?xml version="1.0" encoding="UTF-8" standalone="no"?>
|
||||
<?xml version="1.0" encoding="UTF-8" ?>
|
||||
<projectDescription>
|
||||
<name>TencentOS-Tiny</name>
|
||||
<comment/>
|
||||
<projects/>
|
||||
<comment />
|
||||
<projects />
|
||||
<buildSpec>
|
||||
<buildCommand>
|
||||
<name>org.eclipse.cdt.managedbuilder.core.genmakebuilder</name>
|
||||
<triggers>clean,full,incremental,</triggers>
|
||||
<arguments/>
|
||||
<arguments />
|
||||
</buildCommand>
|
||||
<buildCommand>
|
||||
<name>org.eclipse.cdt.managedbuilder.core.ScannerConfigBuilder</name>
|
||||
<triggers>full,incremental,</triggers>
|
||||
<arguments/>
|
||||
<arguments />
|
||||
</buildCommand>
|
||||
</buildSpec>
|
||||
<natures>
|
||||
@@ -24,43 +24,58 @@
|
||||
<link>
|
||||
<name>arch</name>
|
||||
<type>2</type>
|
||||
<location>PARENT-2-PROJECT_LOC/arch/risc-v/risc-v3a</location>
|
||||
</link>
|
||||
<link>
|
||||
<name>kernel/core</name>
|
||||
<type>2</type>
|
||||
<location>PARENT-2-PROJECT_LOC/kernel/core</location>
|
||||
</link>
|
||||
<link>
|
||||
<name>net/at</name>
|
||||
<type>2</type>
|
||||
<location>PARENT-2-PROJECT_LOC/net/at</location>
|
||||
</link>
|
||||
<link>
|
||||
<name>net/tencent_firmware_module_wrapper</name>
|
||||
<type>2</type>
|
||||
<location>PARENT-2-PROJECT_LOC/net/tencent_firmware_module_wrapper</location>
|
||||
<locationURI>PARENT-2-PROJECT_LOC/arch/risc-v/risc-v3a</locationURI>
|
||||
</link>
|
||||
<link>
|
||||
<name>devices/esp8266_tencent_firmware</name>
|
||||
<type>2</type>
|
||||
<location>PARENT-2-PROJECT_LOC/devices/esp8266_tencent_firmware</location>
|
||||
<locationURI>PARENT-2-PROJECT_LOC/devices/esp8266_tencent_firmware</locationURI>
|
||||
</link>
|
||||
<link>
|
||||
<name>kernel/core</name>
|
||||
<type>2</type>
|
||||
<locationURI>PARENT-2-PROJECT_LOC/kernel/core</locationURI>
|
||||
</link>
|
||||
<link>
|
||||
<name>kernel/hal</name>
|
||||
<type>2</type>
|
||||
<location>PARENT-2-PROJECT_LOC/kernel/hal</location>
|
||||
<locationURI>PARENT-2-PROJECT_LOC/kernel/hal</locationURI>
|
||||
</link>
|
||||
<link>
|
||||
<name>net/at</name>
|
||||
<type>2</type>
|
||||
<locationURI>PARENT-2-PROJECT_LOC/net/at</locationURI>
|
||||
</link>
|
||||
<link>
|
||||
<name>net/tencent_firmware_module_wrapper</name>
|
||||
<type>2</type>
|
||||
<locationURI>PARENT-2-PROJECT_LOC/net/tencent_firmware_module_wrapper</locationURI>
|
||||
</link>
|
||||
<link>
|
||||
<name>platform/hal/wch/ch32v30xx</name>
|
||||
<type>2</type>
|
||||
<location>PARENT-2-PROJECT_LOC/platform/hal/wch/ch32v30xx/src</location>
|
||||
<locationURI>PARENT-2-PROJECT_LOC/platform/hal/wch/ch32v30xx/src</locationURI>
|
||||
</link>
|
||||
<link>
|
||||
<name>fs/kv</name>
|
||||
<type>2</type>
|
||||
<location>PARENT-2-PROJECT_LOC/components/fs/kv</location>
|
||||
</link>
|
||||
<link>
|
||||
<name>fs/vfs</name>
|
||||
<type>2</type>
|
||||
<location>PARENT-2-PROJECT_LOC/components/fs/vfs</location>
|
||||
</link>
|
||||
<link>
|
||||
<name>fs/fatfs</name>
|
||||
<type>2</type>
|
||||
<location>PARENT-2-PROJECT_LOC/components/fs/fatfs/wrapper</location>
|
||||
</link>
|
||||
</linkedResources>
|
||||
<filteredResources>
|
||||
<filter>
|
||||
<id>1595986042669</id>
|
||||
<name/>
|
||||
<name />
|
||||
<type>22</type>
|
||||
<matcher>
|
||||
<id>org.eclipse.ui.ide.multiFilter</id>
|
||||
|
@@ -53,6 +53,30 @@ uint8_t get_key(void)
|
||||
return 0;
|
||||
}
|
||||
|
||||
void lcd_test()
|
||||
{
|
||||
u8 i,j;
|
||||
float t=0;
|
||||
|
||||
LCD_ShowString(0,0,"Welcome TencentOS",WHITE,BLACK,32,0);
|
||||
LCD_ShowString(0,40,"LCD_W:",WHITE,BLACK,16,0);
|
||||
LCD_ShowIntNum(48,40,LCD_W,3,WHITE,BLACK,16);
|
||||
LCD_ShowString(80,40,"LCD_H:",WHITE,BLACK,16,0);
|
||||
LCD_ShowIntNum(128,40,LCD_H,3,WHITE,BLACK,16);
|
||||
LCD_ShowString(80,40,"LCD_H:",WHITE,BLACK,16,0);
|
||||
LCD_ShowString(0,70,"Increaseing Nun:",WHITE,BLACK,16,0);
|
||||
LCD_ShowFloatNum1(128,70,t,4,WHITE,BLACK,16);
|
||||
t+=0.11;
|
||||
for(j=0;j<3;j++)
|
||||
{
|
||||
for(i=0;i<6;i++)
|
||||
{
|
||||
LCD_ShowPicture(40*i,120+j*40,40,40,gImage_1);
|
||||
}
|
||||
}
|
||||
printf("lcd test finish\r\n");
|
||||
}
|
||||
|
||||
/*********************************************************************
|
||||
* @fn show_sdcard_info
|
||||
*
|
||||
@@ -109,33 +133,46 @@ void spi_flash_test(void)
|
||||
default:
|
||||
printf("Fail!\r\n");
|
||||
break;
|
||||
}
|
||||
}
|
||||
printf("Start Read W25Qxx before erase....\r\n");
|
||||
SPI_Flash_Read(datap,0x0,SIZE);
|
||||
for(int16_t i=0;i<SIZE;i++)
|
||||
{
|
||||
printf("%x ", datap[i] );
|
||||
}
|
||||
printf("\r\n" );
|
||||
|
||||
printf("Start Erase W25Qxx....\r\n");
|
||||
SPI_Flash_Erase_Sector(0);
|
||||
Delay_Ms(500);
|
||||
printf("Start Read W25Qxx....\r\n");
|
||||
SPI_Flash_Read(datap,0x0,SIZE);
|
||||
for(int16_t i=0;i<SIZE;i++)
|
||||
{
|
||||
printf("%x ", datap[i] );
|
||||
}
|
||||
printf("\r\n" );
|
||||
Delay_Ms(500);
|
||||
printf("Start Write W25Qxx....\r\n");
|
||||
SPI_Flash_Write((u8*)TEXT_Buf,0,SIZE);
|
||||
Delay_Ms(500);
|
||||
SPI_Flash_Read(datap,0x0,SIZE);
|
||||
printf("%s\r\n", datap );
|
||||
printf("Start Erase W25Qxx....\r\n");
|
||||
SPI_Flash_Erase_Sector(0);
|
||||
|
||||
if(memcmp(TEXT_Buf, datap, SIZE))
|
||||
{
|
||||
LCD_ShowString(16,16+16+16,"SPI Flash: Fail",WHITE,BLACK,16,0);
|
||||
}
|
||||
else
|
||||
{
|
||||
LCD_ShowString(16,16+16+16,"SPI Flash: OK",WHITE,BLACK,16,0);
|
||||
}
|
||||
Delay_Ms(500);
|
||||
|
||||
printf("Start Read W25Qxx....\r\n");
|
||||
SPI_Flash_Read(datap,0x0,SIZE);
|
||||
for(int16_t i=0;i<SIZE;i++)
|
||||
{
|
||||
printf("%x ", datap[i] );
|
||||
}
|
||||
printf("\r\n" );
|
||||
|
||||
Delay_Ms(500);
|
||||
|
||||
printf("Start Write W25Qxx....\r\n");
|
||||
SPI_Flash_Write((u8*)TEXT_Buf,0,SIZE);
|
||||
|
||||
Delay_Ms(500);
|
||||
|
||||
SPI_Flash_Read(datap,0x0,SIZE);
|
||||
printf("%s\r\n", datap );
|
||||
|
||||
if(memcmp(TEXT_Buf, datap, SIZE))
|
||||
{
|
||||
LCD_ShowString(16,16+16+16,"SPI Flash: Fail",WHITE,BLACK,16,0);
|
||||
}
|
||||
else
|
||||
{
|
||||
LCD_ShowString(16,16+16+16,"SPI Flash: OK",WHITE,BLACK,16,0);
|
||||
}
|
||||
}
|
||||
|
||||
u8 buf[512];
|
||||
@@ -184,7 +221,6 @@ void SD_Card_test(void)
|
||||
{
|
||||
LCD_ShowString(16,16+16+16+16+16,"SD ALL: FAIL",WHITE,BLACK,16,0);
|
||||
}
|
||||
|
||||
}
|
||||
|
||||
#define TASK1_STK_SIZE 1024
|
||||
@@ -201,7 +237,7 @@ __aligned(4) uint8_t task2_stk[TASK2_STK_SIZE];
|
||||
k_task_t application_task;
|
||||
__aligned(4) uint8_t application_task_stk[APPLICATION_TASK_STK_SIZE];
|
||||
|
||||
extern void application_entry1(void *arg);
|
||||
extern void application_entry(void *arg);
|
||||
|
||||
void task1_entry(void *arg)
|
||||
{
|
||||
@@ -230,8 +266,6 @@ volatile uint8_t key=0;
|
||||
*******************************************************************************/
|
||||
int main(void)
|
||||
{
|
||||
u8 i,j;
|
||||
float t=0;
|
||||
Delay_Init();
|
||||
USART_Printf_Init(115200);
|
||||
printf("SystemClk:%d\r\n",SystemCoreClock);
|
||||
@@ -244,7 +278,7 @@ int main(void)
|
||||
|
||||
|
||||
tos_knl_init();
|
||||
tos_task_create(&application_task, "application_task", application_entry1, NULL, 4, application_task_stk, APPLICATION_TASK_STK_SIZE, 0);
|
||||
tos_task_create(&application_task, "application_task", application_entry, NULL, 4, application_task_stk, APPLICATION_TASK_STK_SIZE, 0);
|
||||
//tos_task_create(&task1, "task1", task1_entry, NULL, 3, task1_stk, TASK1_STK_SIZE, 0); // Create task1
|
||||
//tos_task_create(&task2, "task2", task2_entry, NULL, 3, task2_stk, TASK2_STK_SIZE, 0);// Create task2
|
||||
tos_knl_start();
|
||||
@@ -258,7 +292,7 @@ int main(void)
|
||||
switch(key)
|
||||
{
|
||||
case 1:
|
||||
//lcd_test();
|
||||
lcd_test();
|
||||
break;
|
||||
case 2:
|
||||
LCD_Fill(0,0,LCD_W,LCD_H,BLACK);
|
||||
@@ -271,32 +305,5 @@ int main(void)
|
||||
default:
|
||||
break;
|
||||
}
|
||||
while(1)
|
||||
{
|
||||
LCD_ShowString(0,0,"Welcome TencentOS",WHITE,BLACK,32,0);
|
||||
LCD_ShowString(0,40,"LCD_W:",WHITE,BLACK,16,0);
|
||||
LCD_ShowIntNum(48,40,LCD_W,3,WHITE,BLACK,16);
|
||||
LCD_ShowString(80,40,"LCD_H:",WHITE,BLACK,16,0);
|
||||
LCD_ShowIntNum(128,40,LCD_H,3,WHITE,BLACK,16);
|
||||
LCD_ShowString(80,40,"LCD_H:",WHITE,BLACK,16,0);
|
||||
LCD_ShowString(0,70,"Increaseing Nun:",WHITE,BLACK,16,0);
|
||||
LCD_ShowFloatNum1(128,70,t,4,WHITE,BLACK,16);
|
||||
t+=0.11;
|
||||
for(j=0;j<3;j++)
|
||||
{
|
||||
for(i=0;i<6;i++)
|
||||
{
|
||||
LCD_ShowPicture(40*i,120+j*40,40,40,gImage_1);
|
||||
printf("pic test\r\n");
|
||||
}
|
||||
}
|
||||
printf("lcd test\r\n");
|
||||
}
|
||||
while(1);
|
||||
}
|
||||
|
||||
|
||||
|
||||
|
||||
|
||||
|
||||
|
||||
|
@@ -6,7 +6,7 @@
|
||||
* Description : This file contains the headers of the SDIO.
|
||||
*******************************************************************************/
|
||||
#ifndef __SDIO_H
|
||||
#define __SDIO_H
|
||||
#define __SDIO_H
|
||||
|
||||
#include"debug.h"
|
||||
|
||||
@@ -346,12 +346,3 @@ u8 SD_ReadDisk(u8*buf,u32 sector,u8 cnt);
|
||||
u8 SD_WriteDisk(u8*buf,u32 sector,u8 cnt);
|
||||
|
||||
#endif
|
||||
|
||||
|
||||
|
||||
|
||||
|
||||
|
||||
|
||||
|
||||
|
||||
|
@@ -211,6 +211,40 @@ void SPI_Flash_Erase_Sector(u32 Dst_Addr)
|
||||
SPI_Flash_Wait_Busy();
|
||||
}
|
||||
|
||||
/*********************************************************************
|
||||
* @fn SPI_Flash_Erase_Sector
|
||||
*
|
||||
* @brief Erase amount sector(4Kbyte).
|
||||
*
|
||||
* @param addr - Initial address(24bit).
|
||||
* size - Data length.
|
||||
*
|
||||
* @return errcode
|
||||
*/
|
||||
int SPI_Flash_Erase(u32 Addr, int size)
|
||||
{
|
||||
uint32_t begin;
|
||||
uint32_t end;
|
||||
int i;
|
||||
|
||||
if (size < 0
|
||||
|| Addr > SPI_FLASH_TOTAL_SIZE
|
||||
|| Addr + size > SPI_FLASH_TOTAL_SIZE)
|
||||
{
|
||||
return -1;
|
||||
}
|
||||
|
||||
begin = Addr / SPI_FLASH_SECTOR * SPI_FLASH_SECTOR;
|
||||
end = (Addr + size - 1) / SPI_FLASH_SECTOR * SPI_FLASH_SECTOR;
|
||||
|
||||
for (i = begin; i <= end; i += SPI_FLASH_SECTOR)
|
||||
{
|
||||
SPI_Flash_Erase_Sector(i);
|
||||
}
|
||||
|
||||
return 0;
|
||||
}
|
||||
|
||||
/*********************************************************************
|
||||
* @fn SPI_Flash_Read
|
||||
*
|
||||
|
@@ -1,5 +1,5 @@
|
||||
#ifndef __SPI_FLASH_H
|
||||
#define __SPI_FLASH_H
|
||||
#define __SPI_FLASH_H
|
||||
#include "debug.h"
|
||||
#include "string.h"
|
||||
|
||||
@@ -10,6 +10,11 @@
|
||||
#define W25Q64 0XEF16
|
||||
#define W25Q128 0XEF17
|
||||
|
||||
/* Winbond W25Q64 */
|
||||
#define SPI_FLASH_PAGESIZE 256
|
||||
#define SPI_FLASH_SECTOR 4096
|
||||
#define SPI_FLASH_TOTAL_SIZE 0x7FFFFF
|
||||
|
||||
/* Winbond SPIFalsh Instruction List */
|
||||
#define W25X_WriteEnable 0x06
|
||||
#define W25X_WriteDisable 0x04
|
||||
@@ -45,6 +50,7 @@ void SPI_FLASH_Write_Enable(void);
|
||||
void SPI_FLASH_Write_Disable(void);
|
||||
u16 SPI_Flash_ReadID(void);
|
||||
void SPI_Flash_Erase_Sector(u32 Dst_Addr);
|
||||
int SPI_Flash_Erase(u32 Addr, int size);
|
||||
void SPI_Flash_Read(u8* pBuffer,u32 ReadAddr,u16 size);
|
||||
void SPI_Flash_Write_Page(u8* pBuffer,u32 WriteAddr,u16 size);
|
||||
void SPI_Flash_Write_NoCheck(u8* pBuffer,u32 WriteAddr,u16 size);
|
||||
|
35
board/TencentOS_Tiny_CH32V307_EVB/User/spi_flash_kv.c
Normal file
35
board/TencentOS_Tiny_CH32V307_EVB/User/spi_flash_kv.c
Normal file
@@ -0,0 +1,35 @@
|
||||
#include "tos_kv.h"
|
||||
#include "spi_flash.h"
|
||||
|
||||
#define SECTOR_SIZE 4096 // sector size for spiflash
|
||||
#define SECTOR_SIZE_LOG2 12 // 2 ^ 12 = 4096
|
||||
|
||||
int ch32v30x_spiflash_read(uint32_t addr, void *buf, size_t len)
|
||||
{
|
||||
SPI_Flash_Read(buf, addr, len);
|
||||
|
||||
return 0;
|
||||
}
|
||||
|
||||
int ch32v30x_spiflash_write(uint32_t addr, const void *buf, size_t len)
|
||||
{
|
||||
SPI_Flash_Write((void*)buf, addr, len);
|
||||
|
||||
return 0;
|
||||
}
|
||||
|
||||
int ch32v30x_spiflash_erase(uint32_t addr, size_t size)
|
||||
{
|
||||
return SPI_Flash_Erase(addr, size);
|
||||
}
|
||||
|
||||
kv_flash_drv_t ch32v30x_spiflash_drv = {
|
||||
.write = ch32v30x_spiflash_write,
|
||||
.read = ch32v30x_spiflash_read,
|
||||
.erase = ch32v30x_spiflash_erase,
|
||||
};
|
||||
|
||||
kv_flash_prop_t ch32v30x_spiflash_prop = {
|
||||
.sector_size_log2 = SECTOR_SIZE_LOG2,
|
||||
.pgm_type = KV_FLASH_PROGRAM_TYPE_BYTE,
|
||||
};
|
@@ -0,0 +1,84 @@
|
||||
#include "tos_k.h"
|
||||
#include "tos_hal.h"
|
||||
#include "ff.h"
|
||||
#include "tos_vfs.h"
|
||||
#include "tos_fatfs_drv.h"
|
||||
#include "tos_fatfs_vfs.h"
|
||||
|
||||
char buf[512];
|
||||
|
||||
void application_entry(void *arg)
|
||||
{
|
||||
int fd, ret;
|
||||
vfs_err_t err;
|
||||
extern vfs_blkdev_ops_t sd_dev;
|
||||
extern vfs_fs_ops_t fatfs_ops;
|
||||
|
||||
err = tos_vfs_block_device_register("/dev/sd", &sd_dev);
|
||||
if (err != VFS_ERR_NONE) {
|
||||
printf("/dev/sd block device register failed!\n");
|
||||
}
|
||||
|
||||
err = tos_vfs_fs_register("fatfs_sd", &fatfs_ops);
|
||||
if (err != VFS_ERR_NONE) {
|
||||
printf("fatfs_sd fs register failed!\n");
|
||||
}
|
||||
|
||||
if (tos_vfs_fs_mkfs("/dev/sd", "fatfs_sd", FM_FAT32, 0) != 0) {
|
||||
printf("mkfs failed!\n");
|
||||
}
|
||||
|
||||
if (tos_vfs_fs_mount("/dev/sd", "/fs/fatfs_sd", "fatfs_sd") != 0) {
|
||||
printf("mount failed!\n");
|
||||
}
|
||||
|
||||
fd = tos_vfs_open("/fs/fatfs_sd/test_file.txt", VFS_OFLAG_CREATE_ALWAYS | VFS_OFLAG_WRITE);
|
||||
if (fd < 0) {
|
||||
printf("open failed!\n");
|
||||
}
|
||||
|
||||
ret = tos_vfs_write(fd, "fatfs sample content", strlen("fatfs sample content"));
|
||||
if (ret >= 0) {
|
||||
printf("write ok\n");
|
||||
printf("write data:\n%s\n", "fatfs sample content");
|
||||
} else {
|
||||
printf("write error: %d\n", ret);
|
||||
}
|
||||
ret = tos_vfs_close(fd);
|
||||
if (ret < 0) {
|
||||
printf("close failed!\n");
|
||||
}
|
||||
|
||||
fd = tos_vfs_open("/fs/fatfs_sd/test_file.txt", VFS_OFLAG_EXISTING | VFS_OFLAG_READ);
|
||||
if (fd < 0) {
|
||||
printf("open file error!\n");
|
||||
}
|
||||
|
||||
memset(buf, 0, sizeof(buf));
|
||||
ret = tos_vfs_read(fd, buf, sizeof(buf));
|
||||
if (ret >= 0) {
|
||||
printf("read ok: %d\n", ret);
|
||||
printf("read data:\n%s\n", buf);
|
||||
} else {
|
||||
printf("read error: %d\n", ret);
|
||||
}
|
||||
|
||||
////////////////////////////////////////////////
|
||||
ret = tos_vfs_lseek(fd, 2, VFS_SEEK_CUR);
|
||||
if (ret < 0) {
|
||||
printf("lseek error\n");
|
||||
}
|
||||
|
||||
memset(buf, 0, sizeof(buf));
|
||||
ret = tos_vfs_read(fd, buf, sizeof(buf));
|
||||
if (ret >= 0) {
|
||||
printf("read ok: %d\n", ret);
|
||||
printf("read data:\n%s\n", buf);
|
||||
} else {
|
||||
printf("read error: %d\n", ret);
|
||||
}
|
||||
/////////////////////////////////////////////////
|
||||
|
||||
tos_vfs_close(fd);
|
||||
}
|
||||
|
84
board/TencentOS_Tiny_CH32V307_EVB/examples/kv_sample.c
Normal file
84
board/TencentOS_Tiny_CH32V307_EVB/examples/kv_sample.c
Normal file
@@ -0,0 +1,84 @@
|
||||
#include "tos_kv.h"
|
||||
|
||||
extern kv_flash_drv_t ch32v30x_spiflash_drv;
|
||||
extern kv_flash_prop_t ch32v30x_spiflash_prop;
|
||||
|
||||
//#define KV_SAMPLE_DEBUG
|
||||
|
||||
void disp_value(uint8_t *value, uint32_t value_len)
|
||||
{
|
||||
int i = 0;
|
||||
|
||||
printf("value_len: %d\r\n", value_len);
|
||||
|
||||
printf("\"");
|
||||
for (i = 0; i < value_len; ++i) {
|
||||
printf("%c", value[i]);
|
||||
}
|
||||
printf("\"\r\n\n");
|
||||
}
|
||||
|
||||
void kv_test(void)
|
||||
{
|
||||
int has_key;
|
||||
kv_err_t err;
|
||||
uint8_t value_buf[40];
|
||||
uint32_t value_len;
|
||||
|
||||
err = tos_kv_init(0, 2 * 4096, &ch32v30x_spiflash_drv, &ch32v30x_spiflash_prop);
|
||||
printf("kv init, rc: %d\r\n", err);
|
||||
|
||||
has_key = tos_kv_has_key("key00");
|
||||
printf("has key[%s] ? %s\r\n\n", "key00", has_key ? "True" : "False");
|
||||
|
||||
err = tos_kv_set("key00", "value_00", strlen("value_00"));
|
||||
printf("kv set(%s), rc: %d\r\n\n", "key00", err);
|
||||
|
||||
has_key = tos_kv_has_key("key00");
|
||||
printf("has key[%s] ? %s\r\n\n", "key00", has_key ? "True" : "False");
|
||||
|
||||
if (err == KV_ERR_NONE) {
|
||||
err = tos_kv_get("key00", value_buf, sizeof(value_buf), &value_len);
|
||||
printf("kv get(%s), rc: %d\r\n\n", "key00", err);
|
||||
|
||||
if (err == KV_ERR_NONE) {
|
||||
disp_value(value_buf, value_len);
|
||||
}
|
||||
|
||||
#ifdef KV_SAMPLE_DEBUG
|
||||
tos_kv_walkthru();
|
||||
#endif
|
||||
}
|
||||
|
||||
err = tos_kv_set("key00", "value_xx", strlen("value_xx"));
|
||||
printf("kv set(%s), rc: %d\r\n\n", "key00", err);
|
||||
|
||||
if (err == KV_ERR_NONE) {
|
||||
err = tos_kv_get("key00", value_buf, sizeof(value_buf), &value_len);
|
||||
printf("kv get(%s), rc: %d\r\n\n", "key00", err);
|
||||
|
||||
if (err == KV_ERR_NONE) {
|
||||
disp_value(value_buf, value_len);
|
||||
}
|
||||
}
|
||||
|
||||
#ifdef KV_SAMPLE_DEBUG
|
||||
tos_kv_walkthru();
|
||||
#endif
|
||||
|
||||
err = tos_kv_del("key00");
|
||||
printf("kv del(%s), rc: %d\r\n\n", "key00", err);
|
||||
|
||||
has_key = tos_kv_has_key("key00");
|
||||
printf("has key[%s] ? %s\r\n\n", "key00", has_key ? "True" : "False");
|
||||
|
||||
#ifdef KV_SAMPLE_DEBUG
|
||||
tos_kv_walkthru();
|
||||
#endif
|
||||
}
|
||||
|
||||
void application_entry(void *arg)
|
||||
{
|
||||
kv_test();
|
||||
}
|
||||
|
@@ -31,7 +31,7 @@ void mqtt_demo_task(void)
|
||||
char *product_id = PRODUCT_ID;
|
||||
char *device_name = DEVICE_NAME;
|
||||
char *key = DEVICE_KEY;
|
||||
|
||||
|
||||
device_info_t dev_info;
|
||||
memset(&dev_info, 0, sizeof(device_info_t));
|
||||
|
||||
@@ -39,11 +39,11 @@ void mqtt_demo_task(void)
|
||||
* Please Choose your AT Port first, default is HAL_UART_2(USART2)
|
||||
*/
|
||||
ret = esp8266_tencent_firmware_sal_init(HAL_UART_PORT_2);
|
||||
|
||||
|
||||
if (ret < 0) {
|
||||
printf("esp8266 tencent firmware sal init fail, ret is %d\r\n", ret);
|
||||
}
|
||||
|
||||
|
||||
esp8266_tencent_firmware_join_ap("TencentOS", "tencentos");
|
||||
|
||||
strncpy(dev_info.product_id, product_id, PRODUCT_ID_MAX_SIZE);
|
||||
@@ -72,25 +72,25 @@ void mqtt_demo_task(void)
|
||||
} else {
|
||||
printf("module mqtt sub success\n");
|
||||
}
|
||||
|
||||
|
||||
memset(report_topic_name, 0, sizeof(report_topic_name));
|
||||
size = snprintf(report_topic_name, TOPIC_NAME_MAX_SIZE, "$thing/up/property/%s/%s", product_id, device_name);
|
||||
|
||||
if (size < 0 || size > sizeof(report_topic_name) - 1) {
|
||||
printf("pub topic content length not enough! content size:%d buf size:%d", size, (int)sizeof(report_topic_name));
|
||||
}
|
||||
|
||||
|
||||
while (1) {
|
||||
tos_sleep_ms(5000);
|
||||
|
||||
/* use AT+PUB AT command */
|
||||
memset(payload, 0, sizeof(payload));
|
||||
snprintf(payload, sizeof(payload), REPORT_DATA_TEMPLATE, lightness++);
|
||||
|
||||
|
||||
if (lightness > 100) {
|
||||
lightness = 0;
|
||||
}
|
||||
|
||||
|
||||
if (tos_tf_module_mqtt_pub(report_topic_name, QOS0, payload) != 0) {
|
||||
printf("module mqtt pub fail\n");
|
||||
break;
|
||||
@@ -100,7 +100,7 @@ void mqtt_demo_task(void)
|
||||
}
|
||||
}
|
||||
|
||||
void application_entry1(void *arg)
|
||||
void application_entry(void *arg)
|
||||
{
|
||||
mqtt_demo_task();
|
||||
while (1) {
|
Reference in New Issue
Block a user