Merge branch 'master' into LwIP_software

This commit is contained in:
yudongdong 2021-05-29 13:46:29 +08:00
commit bee2741235
25 changed files with 287 additions and 94 deletions

View File

@ -7,4 +7,12 @@ menuconfig USER_TEST
bool "Config test lora adhoc" bool "Config test lora adhoc"
default n default n
config USER_TEST_SPI_LORA
bool "Config test spi lora"
default n
config USER_TEST_SPI_FLASH
bool "Config test spi flash"
default n
endif endif

View File

@ -4,4 +4,12 @@ ifeq ($(CONFIG_USER_TEST_LORA_ADHOC),y)
SRC_FILES += test_adhoc_lora.c SRC_FILES += test_adhoc_lora.c
endif endif
ifeq ($(CONFIG_USER_TEST_SPI_LORA),y)
SRC_FILES += test_spi_lora.c
endif
ifeq ($(CONFIG_USER_TEST_SPI_FLASH),y)
SRC_FILES += test_spi_flash.c
endif
include $(KERNEL_ROOT)/compiler.mk include $(KERNEL_ROOT)/compiler.mk

View File

@ -0,0 +1,175 @@
/*
* File : spi_flash_sfud.c
* This file is part of RT-Thread RTOS
* COPYRIGHT (C) 2006 - 2016, RT-Thread Development Team
*
* This program is free software; you can redistribute it and/or modify
* it under the terms of the GNU General Public License as published by
* the Free Software Foundation; either version 2 of the License, or
* (at your option) any later version.
*
* This program is distributed in the hope that it will be useful,
* but WITHOUT ANY WARRANTY; without even the implied warranty of
* MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the
* GNU General Public License for more details.
*
* You should have received a copy of the GNU General Public License along
* with this program; if not, write to the Free Software Foundation, Inc.,
* 51 Franklin Street, Fifth Floor, Boston, MA 02110-1301 USA.
*
* Change Logs:
* Date Author Notes
* 2016-09-28 armink first version.
*/
/**
* @file test_spi_flash.c
* @brief support to test spi flash function
* @version 1.0
* @author AIIT XUOS Lab
* @date 2021-05-17
*/
/*************************************************
File name: test_spi_flash.c
Description: support spi flash function test
Others: add spi flash test cmd from SFUD/blob/master/demo/stm32f2xx_rtt/RT-Thread-2.1.0/components/drivers/spi/spi_flash_sfud.c
https://github.com/armink/SFUD/
History:
1. Date: 2021-05-17
Author: AIIT XUOS Lab
Modification:
1. support spi flash open, read and write function
*************************************************/
#include <xiuos.h>
#include <device.h>
#include <flash_spi.h>
#include <user_api.h>
#define SPI_FLASH_PATH "/dev/spi1_W25Q64"
#define FlashDataPrint(ch) ((unsigned int)((ch) - ' ') < 127u - ' ')
static int spi_flash_fd;
void FlashOpen(void)
{
x_err_t ret = EOK;
spi_flash_fd = open(SPI_FLASH_PATH, O_RDWR);
if (spi_flash_fd < 0) {
KPrintf("open spi flash fd error %d\n", spi_flash_fd);
}
KPrintf("Spi Flash init succeed\n");
return;
}
SHELL_EXPORT_CMD(SHELL_CMD_PERMISSION(0)|SHELL_CMD_TYPE(SHELL_TYPE_CMD_MAIN),
FlashOpen, FlashOpen, open spi flash device);
void FlashRead(int argc, char *argv[])
{
x_size_t i, j = 0;
uint32 addr;
uint32 size;
uint8 data[16];
struct BusBlockReadParam read_param;
memset(&read_param, 0, sizeof(struct BusBlockReadParam));
memset(data, 0, 16);
if (3 != argc) {
KPrintf("FlashRead cmd format: FlashRead addr size.\n");
return;
} else {
addr = strtol(argv[1], NULL, 0);
size = strtol(argv[2], NULL, 0);
read_param.buffer = data;
read_param.pos = addr;
read_param.size = size;
if (read_param.buffer) {
read(spi_flash_fd, &read_param, size);
if (size == read_param.read_length) {
KPrintf("Read the %s flash data success. Start from 0x%08X, size is %ld. The data is:\n",
SPI_FLASH_PATH, addr, size);
KPrintf("Offset (h) 00 01 02 03 04 05 06 07 08 09 0A 0B 0C 0D 0E 0F\n");
for (i = 0; i < size; i += 16) {
KPrintf("[%08X] ", addr + i);
/* dump hex */
for (j = 0; j < 16; j++) {
if (i + j < size) {
KPrintf("%02X ", data[i + j]);
} else {
KPrintf(" ");
}
}
/* dump char for hex */
for (j = 0; j < 16; j++) {
if (i + j < size) {
KPrintf("%c", FlashDataPrint(data[i + j]) ? data[i + j] : '.');
}
}
KPrintf("\n");
}
KPrintf("\n");
}
} else {
KPrintf("SpiFlashRead alloc read buffer failed!\n");
}
}
return;
}
SHELL_EXPORT_CMD(SHELL_CMD_PERMISSION(0)|SHELL_CMD_TYPE(SHELL_TYPE_CMD_MAIN),
FlashRead, FlashRead, read data from spi flash device);
void FlashWrite(int argc, char *argv[])
{
x_err_t ret = EOK;
x_size_t i, j = 0;
uint32 addr;
uint32 size;
uint8 data[16];
struct BusBlockWriteParam write_param;
memset(&write_param, 0, sizeof(struct BusBlockWriteParam));
memset(data, 0, 16);
if (argc < 3) {
KPrintf("FlashWrite cmd format: FlashWrite addr data.\n");
return;
} else {
addr = strtol(argv[1], NULL, 0);
size = argc - 2;
write_param.buffer = data;
write_param.pos = addr;
write_param.size = size;
if (data) {
for (i = 0; i < size; i++) {
data[i] = strtol(argv[2 + i], NULL, 0);
}
ret = write(spi_flash_fd, &write_param, size);
if (EOK == ret) {
KPrintf("Write the %s flash data success. Start from 0x%08X, size is %ld.\n",
SPI_FLASH_PATH, addr, size);
KPrintf("Write data: ");
for (i = 0; i < size; i++) {
KPrintf("%d ", data[i]);
}
KPrintf(".\n");
}
} else {
KPrintf("SpiFlashWrite alloc write buffer failed!\n");
}
}
}
SHELL_EXPORT_CMD(SHELL_CMD_PERMISSION(0)|SHELL_CMD_TYPE(SHELL_TYPE_CMD_MAIN),
FlashWrite, FlashWrite, write data to spi flash device);

View File

@ -607,10 +607,10 @@ out:
/*manage the i2c device operations*/ /*manage the i2c device operations*/
static const struct I2cDevDone i2c_dev_done = static const struct I2cDevDone i2c_dev_done =
{ {
.open = NONE, .dev_open = NONE,
.close = NONE, .dev_close = NONE,
.write = I2cWriteData, .dev_write = I2cWriteData,
.read = I2cReadData, .dev_read = I2cReadData,
}; };
/*Init i2c bus*/ /*Init i2c bus*/

View File

@ -46,7 +46,7 @@ int FlashW25qxxSpiDeviceInit(void)
return ERROR; return ERROR;
} }
if (NONE == SpiFlashInit(SPI_BUS_NAME_1, "spi1_dev0", SPI_1_DRV_NAME, "W25Q64")) { if (NONE == SpiFlashInit(SPI_BUS_NAME_1, "spi1_dev0", SPI_1_DRV_NAME, "spi1_W25Q64")) {
return ERROR; return ERROR;
} }

View File

@ -1347,10 +1347,10 @@ static uint32 Stm32SpiDrvConfigure(void *drv, struct BusConfigureInfo *configure
/*manage the spi device operations*/ /*manage the spi device operations*/
static const struct SpiDevDone spi_dev_done = static const struct SpiDevDone spi_dev_done =
{ {
.open = NONE, .dev_open = NONE,
.close = NONE, .dev_close = NONE,
.write = Stm32SpiWriteData, .dev_write = Stm32SpiWriteData,
.read = Stm32SpiReadData, .dev_read = Stm32SpiReadData,
}; };
#if defined(BSP_USING_SPI1) #if defined(BSP_USING_SPI1)

View File

@ -515,10 +515,10 @@ out:
/*manage the i2c device operations*/ /*manage the i2c device operations*/
static const struct I2cDevDone i2c_dev_done = static const struct I2cDevDone i2c_dev_done =
{ {
.open = NONE, .dev_open = NONE,
.close = NONE, .dev_close = NONE,
.write = I2cWriteData, .dev_write = I2cWriteData,
.read = I2cReadData, .dev_read = I2cReadData,
}; };
/*Init i2c bus*/ /*Init i2c bus*/

View File

@ -291,10 +291,10 @@ static uint32 SpiReadData(struct SpiHardwareDevice *spi_dev, struct SpiDataStand
/*manage the spi device operations*/ /*manage the spi device operations*/
static const struct SpiDevDone spi_dev_done = static const struct SpiDevDone spi_dev_done =
{ {
.open = NONE, .dev_open = NONE,
.close = NONE, .dev_close = NONE,
.write = SpiWriteData, .dev_write = SpiWriteData,
.read = SpiReadData, .dev_read = SpiReadData,
}; };
static int BoardSpiBusInit(struct SpiBus *spi_bus, struct SpiDriver *spi_driver) static int BoardSpiBusInit(struct SpiBus *spi_bus, struct SpiDriver *spi_driver)

View File

@ -54,7 +54,6 @@ Modification:
extern x_base cpu2_boot_flag; extern x_base cpu2_boot_flag;
extern void entry(void); extern void entry(void);
extern void SecondaryCpuCStart(void); extern void SecondaryCpuCStart(void);
extern void ShutdownCpu(void);
extern int IoConfigInit(void); extern int IoConfigInit(void);
extern int HwSpiInit(void); extern int HwSpiInit(void);
extern int HwI2cInit(void); extern int HwI2cInit(void);
@ -187,25 +186,3 @@ void HwCpuReset(void)
SHELL_EXPORT_CMD(SHELL_CMD_PERMISSION(0)|SHELL_CMD_TYPE(SHELL_TYPE_CMD_FUNC)|SHELL_CMD_PARAM_NUM(0), SHELL_EXPORT_CMD(SHELL_CMD_PERMISSION(0)|SHELL_CMD_TYPE(SHELL_TYPE_CMD_FUNC)|SHELL_CMD_PARAM_NUM(0),
reboot, HwCpuReset, reset machine ); reboot, HwCpuReset, reset machine );
static void (*pre_shutdown_action)(void *);
static void *pre_shutdown_action_arg;
void SetPreShutdownAction(void (*func)(void *), void *arg)
{
pre_shutdown_action = func;
pre_shutdown_action_arg = arg;
}
void CmdShutdown()
{
#ifdef FS_VFS
SyncOpenedFiles();
#endif
if (pre_shutdown_action != NULL)
pre_shutdown_action(pre_shutdown_action_arg);
ShutdownCpu();
}
SHELL_EXPORT_CMD(SHELL_CMD_PERMISSION(0)|SHELL_CMD_TYPE(SHELL_TYPE_CMD_FUNC)|SHELL_CMD_PARAM_NUM(0),
shutdown,CmdShutdown,shutdown machine);

View File

@ -503,10 +503,10 @@ out:
/*manage the i2c device operations*/ /*manage the i2c device operations*/
static const struct I2cDevDone i2c_dev_done = static const struct I2cDevDone i2c_dev_done =
{ {
.open = NONE, .dev_open = NONE,
.close = NONE, .dev_close = NONE,
.write = I2cWriteData, .dev_write = I2cWriteData,
.read = I2cReadData, .dev_read = I2cReadData,
}; };
/*Init i2c bus*/ /*Init i2c bus*/

View File

@ -290,10 +290,10 @@ static uint32 SpiReadData(struct SpiHardwareDevice *spi_dev, struct SpiDataStand
/*manage the spi device operations*/ /*manage the spi device operations*/
static const struct SpiDevDone spi_dev_done = static const struct SpiDevDone spi_dev_done =
{ {
.open = NONE, .dev_open = NONE,
.close = NONE, .dev_close = NONE,
.write = SpiWriteData, .dev_write = SpiWriteData,
.read = SpiReadData, .dev_read = SpiReadData,
}; };
static int BoardSpiBusInit(struct SpiBus *spi_bus, struct SpiDriver *spi_driver) static int BoardSpiBusInit(struct SpiBus *spi_bus, struct SpiDriver *spi_driver)

View File

@ -503,10 +503,10 @@ out:
/*manage the i2c device operations*/ /*manage the i2c device operations*/
static const struct I2cDevDone i2c_dev_done = static const struct I2cDevDone i2c_dev_done =
{ {
.open = NONE, .dev_open = NONE,
.close = NONE, .dev_close = NONE,
.write = I2cWriteData, .dev_write = I2cWriteData,
.read = I2cReadData, .dev_read = I2cReadData,
}; };
/*Init i2c bus*/ /*Init i2c bus*/

View File

@ -290,10 +290,10 @@ static uint32 SpiReadData(struct SpiHardwareDevice *spi_dev, struct SpiDataStand
/*manage the spi device operations*/ /*manage the spi device operations*/
static const struct SpiDevDone spi_dev_done = static const struct SpiDevDone spi_dev_done =
{ {
.open = NONE, .dev_open = NONE,
.close = NONE, .dev_close = NONE,
.write = SpiWriteData, .dev_write = SpiWriteData,
.read = SpiReadData, .dev_read = SpiReadData,
}; };
static int BoardSpiBusInit(struct SpiBus *spi_bus, struct SpiDriver *spi_driver) static int BoardSpiBusInit(struct SpiBus *spi_bus, struct SpiDriver *spi_driver)

View File

@ -603,10 +603,10 @@ out:
/*manage the i2c device operations*/ /*manage the i2c device operations*/
static const struct I2cDevDone i2c_dev_done = static const struct I2cDevDone i2c_dev_done =
{ {
.open = NONE, .dev_open = NONE,
.close = NONE, .dev_close = NONE,
.write = I2cWriteData, .dev_write = I2cWriteData,
.read = I2cReadData, .dev_read = I2cReadData,
}; };
/*Init i2c bus*/ /*Init i2c bus*/

View File

@ -46,7 +46,7 @@ int FlashW25qxxSpiDeviceInit(void)
return ERROR; return ERROR;
} }
if (NONE == SpiFlashInit(SPI_BUS_NAME_1, "spi1_dev0", SPI_1_DRV_NAME, "W25Q64")) { if (NONE == SpiFlashInit(SPI_BUS_NAME_1, "spi1_dev0", SPI_1_DRV_NAME, "spi1_W25Q64")) {
return ERROR; return ERROR;
} }

View File

@ -1251,10 +1251,10 @@ static uint32 Stm32SpiDrvConfigure(void *drv, struct BusConfigureInfo *configure
/*manage the spi device operations*/ /*manage the spi device operations*/
static const struct SpiDevDone spi_dev_done = static const struct SpiDevDone spi_dev_done =
{ {
.open = NONE, .dev_open = NONE,
.close = NONE, .dev_close = NONE,
.write = Stm32SpiWriteData, .dev_write = Stm32SpiWriteData,
.read = Stm32SpiReadData, .dev_read = Stm32SpiReadData,
}; };
#if defined(BSP_USING_SPI1) #if defined(BSP_USING_SPI1)

View File

@ -39,7 +39,7 @@ extern void ShowMemory(void);
extern long ShowSem(void); extern long ShowSem(void);
extern long ShowEvent(void); extern long ShowEvent(void);
extern long ShowMutex(void); extern long ShowMutex(void);
//extern long ShowMemPool(void); //extern long ShowGatherMem(void);
extern long ShowMsgQueue(void); extern long ShowMsgQueue(void);
//extern long showdevice(void); //extern long showdevice(void);
extern long ShowTimer(void); extern long ShowTimer(void);
@ -75,7 +75,7 @@ uintptr_t KsPrintInfo(uint32_t knum,uintptr_t *param, uint8_t num )
#endif #endif
break; break;
case 6: case 6:
//ShowMemPool(); //ShowGatherMem();
break; break;
case 7: case 7:
#ifdef KERNEL_MESSAGEQUEUE #ifdef KERNEL_MESSAGEQUEUE

View File

@ -21,7 +21,7 @@
#include <xiuos.h> #include <xiuos.h>
#include <string.h> #include <string.h>
extern long ShowMemPool(void); extern long ShowGatherMem(void);
extern void ShowMemory(void); extern void ShowMemory(void);
extern void ShowBuddy(void); extern void ShowBuddy(void);
/**************************single gatherblock test sample***********************************/ /**************************single gatherblock test sample***********************************/
@ -93,7 +93,7 @@ int SingleGatherblockTest(char * parameter)
if(0 == strncmp("static", parameter, strlen("static"))){ if(0 == strncmp("static", parameter, strlen("static"))){
KPrintf("test static create gatherblock.\n"); KPrintf("test static create gatherblock.\n");
InitMemGather(&gm, "mp_s", &mempool[0], sizeof(mempool), 80); InitMemGather(&gm, "mp_s", &mempool[0], sizeof(mempool), 80);
ShowMemPool(); ShowGatherMem();
} }
if(0 == strncmp("dynamic", parameter, strlen("dynamic"))){ if(0 == strncmp("dynamic", parameter, strlen("dynamic"))){
@ -105,7 +105,7 @@ int SingleGatherblockTest(char * parameter)
return -1; return -1;
} }
ShowMemPool(); ShowGatherMem();
} }
/* create task1, alloc memory blocks */ /* create task1, alloc memory blocks */
tid1 = KTaskCreate("task1", Task1GmAlloc, parameter, tid1 = KTaskCreate("task1", Task1GmAlloc, parameter,
@ -204,7 +204,7 @@ int MultipleGatherblockTest(void)
KPrintf("create m_gm_d2 failed."); KPrintf("create m_gm_d2 failed.");
CHECK(0); CHECK(0);
} }
ShowMemPool(); ShowGatherMem();
/* create task1, alloc memory blocks */ /* create task1, alloc memory blocks */
m_tid1 = KTaskCreate("task1_m", Task1AllocEntry, NONE, m_tid1 = KTaskCreate("task1_m", Task1AllocEntry, NONE,
@ -443,7 +443,7 @@ int RandomAllocFreeTest(void *parameter)
if(0 == strncmp("static", parameter, strlen("static"))){ if(0 == strncmp("static", parameter, strlen("static"))){
KPrintf("test static create gatherblock-%s.\n",parameter); KPrintf("test static create gatherblock-%s.\n",parameter);
InitMemGather(&random_static_gm, "ran_mp_s", &dynamic_mempool[0], sizeof(dynamic_mempool), 80); InitMemGather(&random_static_gm, "ran_mp_s", &dynamic_mempool[0], sizeof(dynamic_mempool), 80);
ShowMemPool(); ShowGatherMem();
}else{ }else{
KPrintf("test dynamic create gatherblock.\n"); KPrintf("test dynamic create gatherblock.\n");
random_dynamic_gm = CreateMemGather("ran_mp_d",40,80); random_dynamic_gm = CreateMemGather("ran_mp_d",40,80);
@ -451,7 +451,7 @@ int RandomAllocFreeTest(void *parameter)
KPrintf("%s: allocate failure.\n",__func__); KPrintf("%s: allocate failure.\n",__func__);
return -1; return -1;
} }
ShowMemPool(); ShowGatherMem();
} }
/* create task1, alloc memory blocks */ /* create task1, alloc memory blocks */
random_tid1 = KTaskCreate("r_task1", RandomTask1GmAlloc, parameter, random_tid1 = KTaskCreate("r_task1", RandomTask1GmAlloc, parameter,

View File

@ -88,21 +88,25 @@ int TestMain(int argc, char*argv[])
break; break;
case MEM: case MEM:
#ifdef KERNEL_TEST_MEM #ifdef KERNEL_TEST_MEM
if (argc > 2)
TestMem(argc-2,&argv[2]); TestMem(argc-2,&argv[2]);
#endif #endif
break; break;
case TIMER: case TIMER:
#ifdef KERNEL_TEST_TIMER #ifdef KERNEL_TEST_TIMER
if (argc > 2)
TestTmr(argc-2,&argv[2]); TestTmr(argc-2,&argv[2]);
#endif #endif
break; break;
case GATHERBLOCK: case GATHERBLOCK:
#ifdef KERNEL_TEST_MEM #ifdef KERNEL_TEST_MEM
if (argc > 2)
TestGatherblock(&argv[2]); TestGatherblock(&argv[2]);
#endif #endif
break; break;
case SCHED: case SCHED:
#ifdef KERNEL_TEST_SCHED #ifdef KERNEL_TEST_SCHED
if (argc > 2)
TestTaskReadyAndSched(argc-2, &argv[2]); TestTaskReadyAndSched(argc-2, &argv[2]);
#endif #endif
break; break;
@ -112,6 +116,7 @@ int TestMain(int argc, char*argv[])
#endif #endif
case REALTIME: case REALTIME:
#ifdef KERNEL_TEST_REALTIME #ifdef KERNEL_TEST_REALTIME
if (argc > 2)
TestRealtime(argc-2, &argv[2]); TestRealtime(argc-2, &argv[2]);
#endif #endif
default: default:

View File

@ -66,7 +66,7 @@ struct DynamicAllocNode
*/ */
struct DynamicFreeNode struct DynamicFreeNode
{ {
uint32 size; /* the size of dynamicAllocNode */ x_size_t size; /* the size of dynamicAllocNode */
uint32 prev_adj_size; /* the size of the previous adjacent node, (dynamic alloc node or dynamic free node */ uint32 prev_adj_size; /* the size of the previous adjacent node, (dynamic alloc node or dynamic free node */
struct DynamicFreeNode *next; struct DynamicFreeNode *next;
@ -341,7 +341,7 @@ static void* BigMemMalloc(struct DynamicBuddyMemory *dynamic_buddy, x_size_t siz
}; };
/* get the best-fit freeNode */ /* get the best-fit freeNode */
if (node) { if (node && (node->size > allocsize)) {
struct DynamicFreeNode *remainder; struct DynamicFreeNode *remainder;
struct DynamicFreeNode *next; struct DynamicFreeNode *next;
x_size_t remaining; x_size_t remaining;

View File

@ -44,7 +44,7 @@ static uint32 I2cDeviceWrite(void *dev, struct BusBlockWriteParam *write_param)
i2c_msg.retries = 1; i2c_msg.retries = 1;
i2c_msg.next = NONE; i2c_msg.next = NONE;
return i2c_dev->i2c_dev_done->write(i2c_dev, &i2c_msg); return i2c_dev->i2c_dev_done->dev_write(i2c_dev, &i2c_msg);
} }
static uint32 I2cDeviceRead(void *dev, struct BusBlockReadParam *read_param) static uint32 I2cDeviceRead(void *dev, struct BusBlockReadParam *read_param)
@ -62,7 +62,7 @@ static uint32 I2cDeviceRead(void *dev, struct BusBlockReadParam *read_param)
i2c_msg.retries = 1; i2c_msg.retries = 1;
i2c_msg.next = NONE; i2c_msg.next = NONE;
return i2c_dev->i2c_dev_done->read(i2c_dev, &i2c_msg); return i2c_dev->i2c_dev_done->dev_read(i2c_dev, &i2c_msg);
} }
static const struct HalDevDone dev_done = static const struct HalDevDone dev_done =

View File

@ -50,10 +50,10 @@ struct I2cHardwareDevice;
struct I2cDevDone struct I2cDevDone
{ {
uint32 (*open) (struct I2cHardwareDevice *i2c_device); uint32 (*dev_open) (struct I2cHardwareDevice *i2c_device);
uint32 (*close) (struct I2cHardwareDevice *i2c_device); uint32 (*dev_close) (struct I2cHardwareDevice *i2c_device);
uint32 (*write) (struct I2cHardwareDevice *i2c_device, struct I2cDataStandard *msg); uint32 (*dev_write) (struct I2cHardwareDevice *i2c_device, struct I2cDataStandard *msg);
uint32 (*read) (struct I2cHardwareDevice *i2c_device, struct I2cDataStandard *msg); uint32 (*dev_read) (struct I2cHardwareDevice *i2c_device, struct I2cDataStandard *msg);
}; };
struct I2cHardwareDevice struct I2cHardwareDevice

View File

@ -102,10 +102,10 @@ struct SpiHardwareDevice;
struct SpiDevDone struct SpiDevDone
{ {
uint32 (*open) (struct SpiHardwareDevice *dev); uint32 (*dev_open) (struct SpiHardwareDevice *dev);
uint32 (*close) (struct SpiHardwareDevice *dev); uint32 (*dev_close) (struct SpiHardwareDevice *dev);
uint32 (*write) (struct SpiHardwareDevice *dev, struct SpiDataStandard *msg); uint32 (*dev_write) (struct SpiHardwareDevice *dev, struct SpiDataStandard *msg);
uint32 (*read) (struct SpiHardwareDevice *dev, struct SpiDataStandard *msg); uint32 (*dev_read) (struct SpiHardwareDevice *dev, struct SpiDataStandard *msg);
}; };
struct SpiHardwareDevice struct SpiHardwareDevice

View File

@ -62,7 +62,7 @@ static uint32 SpiDeviceWrite(void *dev, struct BusBlockWriteParam *write_param)
spi_msg.spi_cs_release = 0; spi_msg.spi_cs_release = 0;
spi_msg.next = NONE; spi_msg.next = NONE;
return spi_dev->spi_dev_done->write(spi_dev, &spi_msg); return spi_dev->spi_dev_done->dev_write(spi_dev, &spi_msg);
} }
static uint32 SpiDeviceRead(void *dev, struct BusBlockReadParam *read_param) static uint32 SpiDeviceRead(void *dev, struct BusBlockReadParam *read_param)
@ -80,7 +80,7 @@ static uint32 SpiDeviceRead(void *dev, struct BusBlockReadParam *read_param)
spi_msg.spi_cs_release = 0; spi_msg.spi_cs_release = 0;
spi_msg.next = NONE; spi_msg.next = NONE;
return spi_dev->spi_dev_done->read(spi_dev, &spi_msg); return spi_dev->spi_dev_done->dev_read(spi_dev, &spi_msg);
} }
static const struct HalDevDone dev_done = static const struct HalDevDone dev_done =
@ -190,5 +190,5 @@ int SpiDevConfigureCs(struct HardwareDev *dev, uint8 spi_chip_select, uint8 spi_
msg.spi_chip_select = spi_chip_select; msg.spi_chip_select = spi_chip_select;
msg.spi_cs_release = spi_cs_release; msg.spi_cs_release = spi_cs_release;
return spi_dev->spi_dev_done->write(spi_dev, &msg); return spi_dev->spi_dev_done->dev_write(spi_dev, &msg);
} }

View File

@ -18,6 +18,8 @@
* @date 2021-04-24 * @date 2021-04-24
*/ */
#include <bus_spi.h>
#include <dev_spi.h>
#include <flash_spi.h> #include <flash_spi.h>
/** /**
@ -43,13 +45,20 @@ static uint32 SpiFlashWrite(void *dev, struct BusBlockWriteParam *write_param)
HardwareDevType haldev = (struct HardwareDev *)dev; HardwareDevType haldev = (struct HardwareDev *)dev;
struct SpiHardwareDevice *flash_dev; struct SpiHardwareDevice *flash_dev;
struct BusBlockWriteParam *flash_write_param = (struct BusBlockWriteParam *)write_param->buffer;
flash_dev = CONTAINER_OF(haldev, struct SpiHardwareDevice, haldev); flash_dev = CONTAINER_OF(haldev, struct SpiHardwareDevice, haldev);
spi_flash_dev = CONTAINER_OF(flash_dev, struct SpiFlashDevice, flash_dev); spi_flash_dev = CONTAINER_OF(flash_dev, struct SpiFlashDevice, flash_dev);
sfud_flash_dev = (sfud_flash *)spi_flash_dev->flash_param.flash_private_data; sfud_flash_dev = (sfud_flash *)spi_flash_dev->flash_param.flash_private_data;
pos = write_param->pos * spi_flash_dev->flash_param.flash_block_param.sector_bytes; pos = flash_write_param->pos;// * spi_flash_dev->flash_param.flash_block_param.sector_bytes;
size = write_param->size * spi_flash_dev->flash_param.flash_block_param.sector_bytes; size = flash_write_param->size;// * spi_flash_dev->flash_param.flash_block_param.sector_bytes;
write_buffer = (uint8 *)write_param->buffer; write_buffer = (uint8 *)flash_write_param->buffer;
KPrintf("flash write pos %u sector_bytes %u size %u\n",
flash_write_param->pos,
spi_flash_dev->flash_param.flash_block_param.sector_bytes,
flash_write_param->size);
ret = sfud_erase_write(sfud_flash_dev, pos, size, write_buffer); ret = sfud_erase_write(sfud_flash_dev, pos, size, write_buffer);
if (SFUD_SUCCESS != ret) { if (SFUD_SUCCESS != ret) {
@ -57,6 +66,8 @@ static uint32 SpiFlashWrite(void *dev, struct BusBlockWriteParam *write_param)
return ERROR; return ERROR;
} }
haldev->owner_bus->owner_haldev = haldev;
return ret; return ret;
} }
@ -82,13 +93,15 @@ static uint32 SpiFlashRead(void *dev, struct BusBlockReadParam *read_param)
HardwareDevType haldev = (struct HardwareDev *)dev; HardwareDevType haldev = (struct HardwareDev *)dev;
struct SpiHardwareDevice *flash_dev; struct SpiHardwareDevice *flash_dev;
struct BusBlockReadParam *flash_read_param = (struct BusBlockReadParam *)read_param->buffer;
flash_dev = CONTAINER_OF(haldev, struct SpiHardwareDevice, haldev); flash_dev = CONTAINER_OF(haldev, struct SpiHardwareDevice, haldev);
spi_flash_dev = CONTAINER_OF(flash_dev, struct SpiFlashDevice, flash_dev); spi_flash_dev = CONTAINER_OF(flash_dev, struct SpiFlashDevice, flash_dev);
sfud_flash_dev = (sfud_flash *)spi_flash_dev->flash_param.flash_private_data; sfud_flash_dev = (sfud_flash *)spi_flash_dev->flash_param.flash_private_data;
pos = read_param->pos * spi_flash_dev->flash_param.flash_block_param.sector_bytes; pos = flash_read_param->pos;// * spi_flash_dev->flash_param.flash_block_param.sector_bytes;
size = read_param->size * spi_flash_dev->flash_param.flash_block_param.sector_bytes; size = flash_read_param->size;// * spi_flash_dev->flash_param.flash_block_param.sector_bytes;
read_buffer = (uint8 *)read_param->buffer; read_buffer = (uint8 *)flash_read_param->buffer;
ret = sfud_read(sfud_flash_dev, pos, size, read_buffer); ret = sfud_read(sfud_flash_dev, pos, size, read_buffer);
if (SFUD_SUCCESS != ret) { if (SFUD_SUCCESS != ret) {
@ -96,6 +109,13 @@ static uint32 SpiFlashRead(void *dev, struct BusBlockReadParam *read_param)
return ERROR; return ERROR;
} }
flash_read_param->read_length = flash_read_param->size;
read_param->read_length = flash_read_param->size;
haldev->owner_bus->owner_haldev = haldev;
KPrintf("SpiFlashRead read buffer done\n");
return ret; return ret;
} }