Skip to content

Commit

Permalink
1.初始化后打印设备信息 2.调整默认设备B_REG_DEV_NULL的设备号为0
Browse files Browse the repository at this point in the history
  • Loading branch information
yyds committed Dec 12, 2022
1 parent e94bf07 commit 8b5fefb
Show file tree
Hide file tree
Showing 6 changed files with 48 additions and 40 deletions.
2 changes: 1 addition & 1 deletion _config/b_config.h
Original file line number Diff line number Diff line change
Expand Up @@ -37,7 +37,7 @@
//<o> Hardware version
#define HW_VERSION 211212
//<o> Firmware version
#define FW_VERSION 80000
#define FW_VERSION 80100
//<s> Firware Name
#define FW_NAME "BabyOS"
//</h>
Expand Down
22 changes: 11 additions & 11 deletions bos/core/b_core.c
Original file line number Diff line number Diff line change
Expand Up @@ -84,7 +84,7 @@
* \{
*/

static bCoreFd_t bCoreFdTable[B_REG_DRV_NUMBER];
static bCoreFd_t bCoreFdTable[B_REG_DEV_NUMBER];

bSECTION_DEF_FLASH(bos_polling, pbPoling_t);
/**
Expand Down Expand Up @@ -118,14 +118,14 @@ static int _bCoreCreateFd(uint32_t dev_no, uint8_t flag)
static uint8_t init = 0;
if (init == 0)
{
for (i = 0; i < B_REG_DRV_NUMBER; i++)
for (i = 0; i < B_REG_DEV_NUMBER; i++)
{
bCoreFdTable[i].status = BCORE_STA_NULL;
}
init = 1;
}

for (i = 0; i < B_REG_DRV_NUMBER; i++)
for (i = 0; i < B_REG_DEV_NUMBER; i++)
{
if (bCoreFdTable[i].status == BCORE_STA_OPEN)
{
Expand All @@ -136,7 +136,7 @@ static int _bCoreCreateFd(uint32_t dev_no, uint8_t flag)
}
}

for (i = 0; i < B_REG_DRV_NUMBER; i++)
for (i = 0; i < B_REG_DEV_NUMBER; i++)
{
if (bCoreFdTable[i].status == BCORE_STA_NULL)
{
Expand Down Expand Up @@ -210,7 +210,7 @@ int bOpen(uint32_t dev_no, uint8_t flag)
int bRead(int fd, uint8_t *pdata, uint32_t len)
{
int retval;
if (fd < 0 || fd >= B_REG_DRV_NUMBER || pdata == NULL)
if (fd < 0 || fd >= B_REG_DEV_NUMBER || pdata == NULL)
{
return -1;
}
Expand All @@ -231,7 +231,7 @@ int bRead(int fd, uint8_t *pdata, uint32_t len)
int bWrite(int fd, uint8_t *pdata, uint32_t len)
{
int retval;
if (fd < 0 || fd >= B_REG_DRV_NUMBER || pdata == NULL)
if (fd < 0 || fd >= B_REG_DEV_NUMBER || pdata == NULL)
{
return -1;
}
Expand All @@ -251,7 +251,7 @@ int bWrite(int fd, uint8_t *pdata, uint32_t len)

int bLseek(int fd, uint32_t off)
{
if (fd < 0 || fd >= B_REG_DRV_NUMBER)
if (fd < 0 || fd >= B_REG_DEV_NUMBER)
{
return -1;
}
Expand All @@ -266,7 +266,7 @@ int bLseek(int fd, uint32_t off)

int bCtl(int fd, uint8_t cmd, void *param)
{
if (fd < 0 || fd >= B_REG_DRV_NUMBER)
if (fd < 0 || fd >= B_REG_DEV_NUMBER)
{
return -1;
}
Expand All @@ -275,7 +275,7 @@ int bCtl(int fd, uint8_t cmd, void *param)

int bClose(int fd)
{
if (fd < 0 || fd >= B_REG_DRV_NUMBER)
if (fd < 0 || fd >= B_REG_DEV_NUMBER)
{
return -1;
}
Expand All @@ -291,7 +291,7 @@ int bClose(int fd)
int bCoreIsIdle()
{
int i;
for (i = 0; i < B_REG_DRV_NUMBER; i++)
for (i = 0; i < B_REG_DEV_NUMBER; i++)
{
if (bCoreFdTable[i].status == BCORE_STA_OPEN)
{
Expand Down Expand Up @@ -321,7 +321,7 @@ int bInit()
b_log("HW:%d.%d.%d FW:%d.%d.%d COMPILE:%s-%s\r\n", (HW_VERSION / 10000),
(HW_VERSION % 10000) / 100, HW_VERSION % 100, (FW_VERSION / 10000),
(FW_VERSION % 10000) / 100, FW_VERSION % 100, __DATE__, __TIME__);
b_log("device number:%d\r\n", B_REG_DRV_NUMBER);
b_log("device number:%d\r\n", B_REG_DEV_NUMBER);
return bDeviceInit();
}

Expand Down
44 changes: 26 additions & 18 deletions bos/core/b_device.c
Original file line number Diff line number Diff line change
Expand Up @@ -80,19 +80,19 @@
* \defgroup DEVICE_Private_Variables
* \{
*/
static bDriverNumber_t bDriverNumberTable[B_REG_DRV_NUMBER] = {
static bDriverNumber_t bDriverNumberTable[B_REG_DEV_NUMBER] = {
B_DRIVER_NULL,
#define B_DEVICE_REG(dev, driver, desc) driver,
#include "b_device_list.h"
B_DRIVER_NULL,
};

static const char *bDeviceDescTable[B_REG_DRV_NUMBER] = {
static const char *bDeviceDescTable[B_REG_DEV_NUMBER] = {
"null",
#define B_DEVICE_REG(dev, driver, desc) desc,
#include "b_device_list.h"
"null",
};

static bDriverInterface_t bDriverInterfaceTable[B_REG_DRV_NUMBER];
static bDriverInterface_t bDriverInterfaceTable[B_REG_DEV_NUMBER];

bSECTION_DEF_FLASH(driver_init_0, bDriverRegInit_t);
bSECTION_DEF_FLASH(driver_init, bDriverRegInit_t);
Expand All @@ -117,7 +117,7 @@ bSECTION_DEF_FLASH(driver_init, bDriverRegInit_t);
static int _bDriverNullInit(bDriverInterface_t *pdrv)
{
(void)pdrv; // prevent unused warning
if (strcmp(bDeviceDescTable[0], "null") == 0)
if (B_REG_DEV_NUMBER == 1)
{
b_log_i("No device is registered\r\n");
}
Expand Down Expand Up @@ -146,7 +146,7 @@ int bDeviceInit()
bSECTION_FOR_EACH(driver_init_0, bDriverRegInit_t, pdriver_init_0)
{
j = 0;
for (i = 0; i < B_REG_DRV_NUMBER; i++)
for (i = 0; i < B_REG_DEV_NUMBER; i++)
{
if (bDriverNumberTable[i] == pdriver_init_0->drv_number)
{
Expand All @@ -159,7 +159,7 @@ int bDeviceInit()
bSECTION_FOR_EACH(driver_init, bDriverRegInit_t, pdriver_init)
{
j = 0;
for (i = 0; i < B_REG_DRV_NUMBER; i++)
for (i = 0; i < B_REG_DEV_NUMBER; i++)
{
if (bDriverNumberTable[i] == pdriver_init->drv_number)
{
Expand All @@ -169,12 +169,20 @@ int bDeviceInit()
}
}
}

b_log("dev_no\t\t%16s\tstate\n", "des");
for (i = 0; i < B_REG_DEV_NUMBER; i++)
{
b_log("%d\t\t%16s\t%d\n", i, bDriverInterfaceTable[i].pdes,
bDriverInterfaceTable[i].status);
}
b_log("\r\n");
return 0;
}

int bDeviceReinit(uint32_t dev_no)
{
if (dev_no >= B_REG_DRV_NUMBER)
if (dev_no >= B_REG_DEV_NUMBER)
{
return -1;
}
Expand All @@ -190,7 +198,7 @@ int bDeviceReinit(uint32_t dev_no)
int bDeviceOpen(uint32_t dev_no)
{
int retval = B_DEVICE_FUNC_NULL;
if (dev_no >= B_REG_DRV_NUMBER)
if (dev_no >= B_REG_DEV_NUMBER)
{
return -1;
}
Expand All @@ -212,7 +220,7 @@ int bDeviceOpen(uint32_t dev_no)
int bDeviceRead(uint32_t dev_no, uint32_t offset, uint8_t *pdata, uint32_t len)
{
int retval = B_DEVICE_FUNC_NULL;
if (dev_no >= B_REG_DRV_NUMBER || pdata == NULL)
if (dev_no >= B_REG_DEV_NUMBER || pdata == NULL)
{
return -1;
}
Expand All @@ -235,7 +243,7 @@ int bDeviceRead(uint32_t dev_no, uint32_t offset, uint8_t *pdata, uint32_t len)
int bDeviceWrite(uint32_t dev_no, uint32_t address, uint8_t *pdata, uint32_t len)
{
int retval = B_DEVICE_FUNC_NULL;
if (dev_no >= B_REG_DRV_NUMBER || pdata == NULL)
if (dev_no >= B_REG_DEV_NUMBER || pdata == NULL)
{
return -1;
}
Expand All @@ -258,7 +266,7 @@ int bDeviceWrite(uint32_t dev_no, uint32_t address, uint8_t *pdata, uint32_t len
int bDeviceClose(uint32_t dev_no)
{
int retval = B_DEVICE_FUNC_NULL;
if (dev_no >= B_REG_DRV_NUMBER)
if (dev_no >= B_REG_DEV_NUMBER)
{
return -1;
}
Expand All @@ -280,7 +288,7 @@ int bDeviceClose(uint32_t dev_no)
int bDeviceCtl(uint32_t dev_no, uint8_t cmd, void *param)
{
int retval = B_DEVICE_FUNC_NULL;
if (dev_no >= B_REG_DRV_NUMBER)
if (dev_no >= B_REG_DEV_NUMBER)
{
return -1;
}
Expand All @@ -302,7 +310,7 @@ int bDeviceCtl(uint32_t dev_no, uint8_t cmd, void *param)
int bDeviceModifyHalIf(uint32_t dev_no, uint32_t offset, const uint8_t *pVal, uint8_t size)
{
uint32_t halif_addr = 0;
if (dev_no >= B_REG_DRV_NUMBER || pVal == NULL || size == 0)
if (dev_no >= B_REG_DEV_NUMBER || pVal == NULL || size == 0)
{
return -1;
}
Expand All @@ -322,7 +330,7 @@ int bDeviceModifyHalIf(uint32_t dev_no, uint32_t offset, const uint8_t *pVal, ui

int bDeviceISNormal(uint32_t dev_no)
{
if (dev_no >= B_REG_DRV_NUMBER)
if (dev_no >= B_REG_DEV_NUMBER)
{
return -1;
}
Expand All @@ -338,7 +346,7 @@ int bDeviceISNormal(uint32_t dev_no)
*/
int bDeviceReadMessage(uint32_t dev_no, bDeviceMsg_t *pmsg)
{
if (pmsg == NULL || dev_no >= B_REG_DRV_NUMBER)
if (pmsg == NULL || dev_no >= B_REG_DEV_NUMBER)
{
return -1;
}
Expand All @@ -354,7 +362,7 @@ int bDeviceReadMessage(uint32_t dev_no, bDeviceMsg_t *pmsg)
*/
int bDeviceWriteMessage(uint32_t dev_no, bDeviceMsg_t *pmsg)
{
if (pmsg == NULL || dev_no >= B_REG_DRV_NUMBER)
if (pmsg == NULL || dev_no >= B_REG_DEV_NUMBER)
{
return -1;
}
Expand Down
4 changes: 2 additions & 2 deletions bos/core/inc/b_device.h
Original file line number Diff line number Diff line change
Expand Up @@ -62,10 +62,10 @@ extern "C" {

typedef enum
{
B_REG_DEV_NULL,
#define B_DEVICE_REG(dev, driver, desc) dev,
#include "b_device_list.h"
B_REG_DRV_NULL,
B_REG_DRV_NUMBER
B_REG_DEV_NUMBER
} bDeviceName_t;

typedef union
Expand Down
14 changes: 7 additions & 7 deletions doc/BabyOS设计和使用手册.md
Original file line number Diff line number Diff line change
Expand Up @@ -615,24 +615,24 @@ typedef enum
{
#define B_DEVICE_REG(dev, driver, desc) dev,
#include "b_device_list.h"
B_REG_DRV_NULL,
B_REG_DRV_NUMBER
B_REG_DEV_NULL,
B_REG_DEV_NUMBER
} bDeviceName_t;
//b_device.c
//驱动号数组
static bDriverNumber_t bDriverNumberTable[B_REG_DRV_NUMBER] = {
static bDriverNumber_t bDriverNumberTable[B_REG_DEV_NUMBER] = {
#define B_DEVICE_REG(dev, driver, desc) driver,
#include "b_device_list.h"
B_DRIVER_NULL,
};
//设备描述信息数组
static const char *bDeviceDescTable[B_REG_DRV_NUMBER] = {
static const char *bDeviceDescTable[B_REG_DEV_NUMBER] = {
#define B_DEVICE_REG(dev, driver, desc) desc,
#include "b_device_list.h"
"null",
};
//驱动实例数组
static bDriverInterface_t bDriverInterfaceTable[B_REG_DRV_NUMBER];
static bDriverInterface_t bDriverInterfaceTable[B_REG_DEV_NUMBER];
```
根据注册的设备,定义相应数量的驱动实例。以宏的形式来实现,避免对动态内存的依赖。
Expand Down Expand Up @@ -722,7 +722,7 @@ int bDeviceInit()
bSECTION_FOR_EACH(driver_init_0, bDriverRegInit_t, pdriver_init_0)
{
j = 0;
for (i = 0; i < B_REG_DRV_NUMBER; i++)
for (i = 0; i < B_REG_DEV_NUMBER; i++)
{
if (bDriverNumberTable[i] == pdriver_init_0->drv_number)
{
Expand All @@ -735,7 +735,7 @@ int bDeviceInit()
bSECTION_FOR_EACH(driver_init, bDriverRegInit_t, pdriver_init)
{
j = 0;
for (i = 0; i < B_REG_DRV_NUMBER; i++)
for (i = 0; i < B_REG_DEV_NUMBER; i++)
{
if (bDriverNumberTable[i] == pdriver_init->drv_number)
{
Expand Down
2 changes: 1 addition & 1 deletion test/kv/config/b_config.h
Original file line number Diff line number Diff line change
Expand Up @@ -37,7 +37,7 @@
//<o> Hardware version
#define HW_VERSION 211212
//<o> Firmware version
#define FW_VERSION 80000
#define FW_VERSION 80100
//<s> Firware Name
#define FW_NAME "BabyOS"
//</h>
Expand Down

0 comments on commit 8b5fefb

Please sign in to comment.