summaryrefslogtreecommitdiffstatsabout
diff options
context:
space:
mode:
-rw-r--r--SylixOS/devtree/devtree.h3
-rw-r--r--SylixOS/devtree/devtreeGpio.c2
-rw-r--r--SylixOS/devtree/devtreeIrq.c2
-rw-r--r--SylixOS/devtree/devtreeSpi.c5
-rw-r--r--SylixOS/devtree/devtree_inline.h19
-rw-r--r--SylixOS/include/net/if_bonding.h1
-rw-r--r--SylixOS/net/lwip/bonding/netbonding.c103
-rw-r--r--SylixOS/net/lwip/lwip_bonding.c27
-rw-r--r--SylixOS/system/device/base/baseDrvLib.c10
-rw-r--r--SylixOS/system/device/spi/spiLibDevTree.c62
-rw-r--r--SylixOS/system/device/spi/spiLibDevTree.h18
11 files changed, 173 insertions, 79 deletions
diff --git a/SylixOS/devtree/devtree.h b/SylixOS/devtree/devtree.h
index a7d0629..5b3368d 100644
--- a/SylixOS/devtree/devtree.h
+++ b/SylixOS/devtree/devtree.h
@@ -404,7 +404,8 @@ LW_API INT API_DeviceTreeI2cDevRegister(PLW_DT_I2C_ADAPTER pi
*********************************************************************************************************/
LW_API INT API_DeviceTreeSpiCtrlRegister(PLW_DT_SPI_CTRL pspictrl,
- PLW_DEVTREE_NODE pdtnDev);
+ PLW_DEVTREE_NODE pdtnDev,
+ CPCHAR pcName);
LW_API INT API_DeviceTreeSpiDevRegister(PLW_DT_SPI_CTRL pspictrl,
PLW_DEVTREE_NODE pdtnDev);
diff --git a/SylixOS/devtree/devtreeGpio.c b/SylixOS/devtree/devtreeGpio.c
index d30b26a..45f44b0 100644
--- a/SylixOS/devtree/devtreeGpio.c
+++ b/SylixOS/devtree/devtreeGpio.c
@@ -93,7 +93,7 @@ static INT __deviceTreeRememberOrFreeMap (PLW_PINCTRL ppinctrl,
ppinctlmaps->PCTLM_ppinctldev = ppinctrldev; /* 记录引脚控制器 */
ppinctlmaps->PCTLM_ppinctlmaps = ppinctrlmap; /* 记录引脚映射数组 */
- ppinctlmaps->PCTLM_uiMapsNum = uiNumMaps; /* 记录引脚映射数组元素个数 */
+ ppinctlmaps->PCTLM_uiMapsNum = uiNumMaps; /* 记录引脚映射数组元素个数 */
_List_Line_Add_Ahead(&ppinctlmaps->PCTLM_lineManage,
&ppinctrl->PCTL_plinemaps); /* 添加引脚映射结构节点 */
diff --git a/SylixOS/devtree/devtreeIrq.c b/SylixOS/devtree/devtreeIrq.c
index 5deef87..fc0e6f6 100644
--- a/SylixOS/devtree/devtreeIrq.c
+++ b/SylixOS/devtree/devtreeIrq.c
@@ -465,7 +465,7 @@ INT API_DeviceTreeIrqToResouceTable (PLW_DEVTREE_NODE pdtnDev,
INT i;
for (i = 0; i < iNrIrqs; i++) {
- if (API_DeviceTreeIrqToResource(pdtnDev, i, pdevresource) <= 0) {
+ if (API_DeviceTreeIrqToResource(pdtnDev, i, pdevresource) < 0) {
break;
}
}
diff --git a/SylixOS/devtree/devtreeSpi.c b/SylixOS/devtree/devtreeSpi.c
index 3894162..5563b6b 100644
--- a/SylixOS/devtree/devtreeSpi.c
+++ b/SylixOS/devtree/devtreeSpi.c
@@ -168,12 +168,13 @@ INT __deviceTreeSpiDevInfoGet (PLW_DT_SPI_DEVICE pdtspidev, PLW_DEVTREE_NODE
*********************************************************************************************************/
LW_API
INT API_DeviceTreeSpiCtrlRegister (PLW_DT_SPI_CTRL pdtspictrl,
- PLW_DEVTREE_NODE pdtnDev)
+ PLW_DEVTREE_NODE pdtnDev,
+ CPCHAR pcName)
{
PLW_DEVTREE_NODE pdtnChild;
INT iRet;
- iRet = API_SpiCtrlRegister(pdtspictrl); /* 注册 SPI 控制器 */
+ iRet = API_SpiCtrlRegister(pdtspictrl, pcName); /* 注册 SPI 控制器 */
if (iRet) {
return (iRet);
}
diff --git a/SylixOS/devtree/devtree_inline.h b/SylixOS/devtree/devtree_inline.h
index a75a253..df2fe14 100644
--- a/SylixOS/devtree/devtree_inline.h
+++ b/SylixOS/devtree/devtree_inline.h
@@ -158,6 +158,25 @@ static LW_INLINE CPCHAR __deviceTreeBaseNameGet (CPCHAR pcPath)
return (pcTail ? (pcTail + 1) : pcPath);
}
+/*********************************************************************************************************
+** 函数名称: __deviceTreeChildCountGet
+** 功能描述: 获取节点名称
+** 输 入 : pdtnDev 设备树节点
+** 输 出 : 子节点数
+** 全局变量:
+** 调用模块:
+*********************************************************************************************************/
+static LW_INLINE INT __deviceTreeChildCountGet (const PLW_DEVTREE_NODE pdtnDev)
+{
+ PLW_DEVTREE_NODE pdtnChild;
+ INT iCount = 0;
+
+ _LIST_EACH_CHILD_OF_NODE(pdtnDev, pdtnChild) {
+ iCount++;
+ }
+
+ return (iCount);
+}
#endif /* __DEVTREE_INLINE_H */
/*********************************************************************************************************
diff --git a/SylixOS/include/net/if_bonding.h b/SylixOS/include/net/if_bonding.h
index b95ffc4..e7896e6 100644
--- a/SylixOS/include/net/if_bonding.h
+++ b/SylixOS/include/net/if_bonding.h
@@ -60,6 +60,7 @@ struct net_bonding_ctl {
#define NETBD_MON_MODE_TRAFFIC 0 /* Traffic detect (default) 'active-backup'*/
#define NETBD_MON_MODE_ARP 1 /* ARP detect 'active-backup' */
+#define NETBD_MON_MODE_LINK 2 /* Only use linkup detect 'active-backup' */
#define NETBD_CTL_ADD _IOWR('b', 0, struct net_bonding_ctl)
#define NETBD_CTL_DELETE _IOW( 'b', 1, struct net_bonding_ctl)
diff --git a/SylixOS/net/lwip/bonding/netbonding.c b/SylixOS/net/lwip/bonding/netbonding.c
index 3be7bd2..3732508 100644
--- a/SylixOS/net/lwip/bonding/netbonding.c
+++ b/SylixOS/net/lwip/bonding/netbonding.c
@@ -189,15 +189,27 @@ static void netbd_select_working (netbd_t *netbd)
}
}
+/* learn my MAC address */
+static void netbd_learn_my_mac (netbd_t *netbd)
+{
+ ip4_addr_t ipaddr;
+ struct netif *netdbif;
+ struct netif *sendif;
+ struct eth_addr macsrc;
+
+ ipaddr.addr = htonl(0xc0a8015a); /* any ip */
+ netdbif = (struct netif *)(netbd->netdev_bd.sys);
+ MEMCPY(&macsrc.addr, netdbif->hwaddr, ETH_ALEN);
+ sendif = (struct netif *)(netbd->working->netdev->sys);
+ etharp_raw(sendif, &macsrc, &ethbroadcast, &macsrc, netif_ip4_addr(netdbif),
+ &ethzero, &ipaddr, ARP_REQUEST); /* send ARP request */
+}
+
/* net bonding traffic detect */
static void netbd_traffic_detect (netbd_t *netbd)
{
int i;
netbd_eth_t *netbd_eth;
- struct netif *netdbif;
- struct netif *sendif;
- struct eth_addr macsrc;
- ip4_addr_t ipaddr;
netbd_eth_t *curent_working = netbd->working;
NETBD_LOCK(netbd);
@@ -218,9 +230,10 @@ static void netbd_traffic_detect (netbd_t *netbd)
NETBD_UNLOCK(netbd);
return;
}
+
netbd_select_working(netbd);
- if (curent_working != netbd->working) { /* woking change */
+ if (curent_working != netbd->working) { /* working change */
netbd->working_change = 1;
}
@@ -229,12 +242,7 @@ static void netbd_traffic_detect (netbd_t *netbd)
* let the corresponding port learn the MAC address of the netbd.
*/
if (netbd->working_change) {
- ipaddr.addr = 0x5A01A8C0; /* any ip */
- netdbif = (struct netif *)(netbd->netdev_bd.sys);
- MEMCPY(&macsrc.addr, netdbif->hwaddr, ETH_ALEN);
- sendif = (struct netif *)(netbd->working->netdev->sys);
- etharp_raw(sendif, &macsrc, &ethbroadcast, &macsrc, netif_ip4_addr(netdbif),
- &ethzero, &ipaddr, ARP_REQUEST); /* send ARP request */
+ netbd_learn_my_mac(netbd);
netbd->working_change = 0;
}
NETBD_UNLOCK(netbd);
@@ -303,6 +311,34 @@ static void netbd_arp_detect (netbd_t *netbd)
}
}
+/* net bonding linkup detect */
+static void netbd_linkup_detect (netbd_t *netbd)
+{
+ netbd_eth_t *curent_working = netbd->working;
+
+ NETBD_LOCK(netbd);
+ if (!netbd->eth_cnt) { /* no sub device */
+ NETBD_UNLOCK(netbd);
+ return;
+ }
+
+ netbd_select_working(netbd);
+
+ if (curent_working != netbd->working) { /* working change */
+ netbd->working_change = 1;
+ }
+
+ /*
+ * When a working link change is detected, a broadcast arp is actively sent to
+ * let the corresponding port learn the MAC address of the netbd.
+ */
+ if (netbd->working_change) {
+ netbd_learn_my_mac(netbd);
+ netbd->working_change = 0;
+ }
+ NETBD_UNLOCK(netbd);
+}
+
/* net bonding arp process */
static void netbd_arp_process (netbd_t *netbd, netbd_eth_t *netbd_eth, struct etharp_hdr *hdr)
{
@@ -407,7 +443,7 @@ static int netbd_transmit (struct netdev *netdev, struct pbuf *p)
}
}
- if (curent_working != netbd->working) { /* woking change */
+ if (curent_working != netbd->working) { /* working change */
netbd->working_change = 1;
}
@@ -535,7 +571,7 @@ to_bd:
}
netbd_eth->alive = netbd->alive; /* refresh time alive counter */
- } else { /* NETBD_MON_MODE_ARP */
+ } else if (netbd->mon_mode == NETBD_MON_MODE_ARP) {
u16_t type = eh->type;
u16_t next_hdr_offset = SIZEOF_ETH_HDR;
struct etharp_hdr *hdr;
@@ -556,9 +592,14 @@ to_bd:
hdr = (struct etharp_hdr *)((u8_t *)(p->payload) + next_hdr_offset);
netbd_arp_process(netbd, netbd_eth, hdr); /* process arp packet */
}
+
+ } else { /* NETBD_MON_MODE_LINK */
+ if (!(netbd->working->netdev->if_flags & IFF_RUNNING)) {
+ netbd->working = netbd_eth; /* use this net device as working */
+ }
}
}
- if (curent_working != netbd->working) { /* woking change */
+ if (curent_working != netbd->working) { /* working change */
netbd->working_change = 1;
}
@@ -603,8 +644,10 @@ static void netbd_proc (void *arg)
if (netbd->mode == NETBD_MODE_ACTIVE_BACKUP) {
if (netbd->mon_mode == NETBD_MON_MODE_TRAFFIC) {
netbd_traffic_detect(netbd);
- } else {
+ } else if (netbd->mon_mode == NETBD_MON_MODE_ARP) {
netbd_arp_detect(netbd);
+ } else {
+ netbd_linkup_detect(netbd);
}
}
netbd_link_check(netbd);
@@ -1110,7 +1153,9 @@ int netbd_add (const char *bddev, const char *ip,
}
if (mode == NETBD_MODE_ACTIVE_BACKUP) {
- if ((mon_mode != NETBD_MON_MODE_TRAFFIC) && (mon_mode != NETBD_MON_MODE_ARP)) {
+ if ((mon_mode != NETBD_MON_MODE_TRAFFIC) &&
+ (mon_mode != NETBD_MON_MODE_ARP) &&
+ (mon_mode != NETBD_MON_MODE_LINK)) {
errno = EINVAL;
return (-1);
}
@@ -1327,9 +1372,10 @@ int netbd_change (const char *bddev, int mode,
int mon_mode, int interval,
int alive)
{
- int found;
+ int i, found;
netdev_t *netdev_bd;
netbd_t *netbd;
+ netbd_eth_t *netbd_eth;
if (!bddev) {
errno = EINVAL;
@@ -1344,7 +1390,9 @@ int netbd_change (const char *bddev, int mode,
}
if (mode == NETBD_MODE_ACTIVE_BACKUP) {
- if ((mon_mode != NETBD_MON_MODE_TRAFFIC) && (mon_mode != NETBD_MON_MODE_ARP)) {
+ if ((mon_mode != NETBD_MON_MODE_TRAFFIC) &&
+ (mon_mode != NETBD_MON_MODE_ARP) &&
+ (mon_mode != NETBD_MON_MODE_LINK)) {
errno = EINVAL;
return (-1);
}
@@ -1379,6 +1427,15 @@ int netbd_change (const char *bddev, int mode,
}
NETBD_LOCK(netbd);
+ /* We need initialize active */
+ if (mode == NETBD_MODE_ACTIVE_BACKUP) {
+ netbd_eth = (netbd_eth_t *)netbd->eth_ring;
+ for (i = 0; i < netbd->eth_cnt; i++) {
+ netbd_eth->alive = alive;
+ netbd_eth = (netbd_eth_t *)_list_ring_get_next(&netbd_eth->ring);
+ }
+ }
+
netbd->mode = mode;
netbd->mon_mode = mon_mode;
netbd->timer = interval;
@@ -1474,6 +1531,7 @@ int netbd_show_dev (const char *bddev, int bdindex, int fd)
netdev_t *netdev_bd;
netdev_t *netdev;
ip4_addr_t ipaddr[NETBD_ARP_BUF_MAX];
+ char *mon_mode;
char speed[32];
char ifname[NETIF_NAMESIZE];
LW_LIST_LINE *pline;
@@ -1514,7 +1572,14 @@ int netbd_show_dev (const char *bddev, int bdindex, int fd)
}
if (netbd->mode == NETBD_MODE_ACTIVE_BACKUP) {
- fdprintf(fd, "Moniting : %s\n", (netbd->mon_mode == NETBD_MON_MODE_TRAFFIC) ? "Traffic" : "ARP Detect");
+ if (netbd->mon_mode == NETBD_MON_MODE_TRAFFIC) {
+ mon_mode = "Traffic";
+ } else if (netbd->mon_mode == NETBD_MON_MODE_ARP) {
+ mon_mode = "ARP Detect";
+ } else {
+ mon_mode = "Linkup";
+ }
+ fdprintf(fd, "Moniting : %s\n", mon_mode);
fdprintf(fd, "Timeout : %d (milliseconds)\n", netbd->alive);
if (netbd->working) {
diff --git a/SylixOS/net/lwip/lwip_bonding.c b/SylixOS/net/lwip/lwip_bonding.c
index 28332c3..82b6fee 100644
--- a/SylixOS/net/lwip/lwip_bonding.c
+++ b/SylixOS/net/lwip/lwip_bonding.c
@@ -276,7 +276,7 @@ static INT __tshellNetbd (INT iArgC, PCHAR *ppcArgV)
if ((lib_strcmp(ppcArgV[1], "addbd") == 0) ||
(lib_strcmp(ppcArgV[1], "changebd") == 0)) {
- if (iArgC < 7) {
+ if (iArgC < 5) {
goto __arg_error;
}
@@ -294,15 +294,27 @@ static INT __tshellNetbd (INT iArgC, PCHAR *ppcArgV)
iMonMode = NETBD_MON_MODE_TRAFFIC;
} else if (lib_strcmp(ppcArgV[4], "-a") == 0) {
iMonMode = NETBD_MON_MODE_ARP;
+ } else if (lib_strcmp(ppcArgV[4], "-l") == 0) {
+ iMonMode = NETBD_MON_MODE_LINK;
} else {
goto __arg_error;
}
- if (sscanf(ppcArgV[5], "%d", &iInterval) != 1) {
- goto __arg_error;
- }
- if (sscanf(ppcArgV[6], "%d", &iAlive) != 1) {
- goto __arg_error;
+ if (iMonMode != NETBD_MON_MODE_LINK) {
+ if (iArgC < 7) {
+ goto __arg_error;
+ }
+
+ if (sscanf(ppcArgV[5], "%d", &iInterval) != 1) {
+ goto __arg_error;
+ }
+ if (sscanf(ppcArgV[6], "%d", &iAlive) != 1) {
+ goto __arg_error;
+ }
+
+ } else {
+ iInterval = 1000;
+ iAlive = 1000;
}
if (lib_strcmp(ppcArgV[1], "addbd") == 0) {
@@ -434,12 +446,13 @@ INT _netBondingInit (VOID)
"eg. netbonding show bond0 (Show all net device in 'bond0' net bonding)\n"
" netbonding addbd bond0 [...] (Add a net bonding named 'bond0')\n"
" netbonding changebd bond0 [...] (Change a net bonding named 'bond0')\n\n"
- " [...]: [ab|bl|bc] [-t|-a] [interval] [time to alive]\n\n"
+ " [...]: [ab|bl|bc] [-t|-a|-l] [interval] [time to alive]\n\n"
" ab : Active Backup mode\n"
" bl : Balance RR mode\n"
" bc : Broadcast mode\n"
" -t : Traffic detect in 'Active Backup' mode\n"
" -a : ARP detect in 'Active Backup' mode\n"
+ " -l : Linkup detect only in 'Active Backup' mode\n"
" interval : ARP detect interval (milliseconds)\n"
" time to alive: When detect OK how long does it take to active (milliseconds)\n\n"
" netbonding delbd bond0 (Delete a net bonding named 'bond0')\n"
diff --git a/SylixOS/system/device/base/baseDrvLib.c b/SylixOS/system/device/base/baseDrvLib.c
index 67a852b..705967f 100644
--- a/SylixOS/system/device/base/baseDrvLib.c
+++ b/SylixOS/system/device/base/baseDrvLib.c
@@ -394,7 +394,7 @@ __error_handle:
__DRV_DEV_LIST_UNLOCK(pdrvinstance);
pdevinstance->DEVHD_pdrvinstance = NULL;
- _DebugFormat(__ERRORMESSAGE_LEVEL,"Failed to probe device: %s",
+ _DebugFormat(__ERRORMESSAGE_LEVEL,"Failed to probe device: %s\r\n",
pdevinstance->DEVHD_pcName);
return (PX_ERROR);
@@ -526,20 +526,20 @@ INT API_DriverRegister (PLW_DRV_INSTANCE pdrvinstance)
}
if (!(pbustype->BUS_uiStatus & BUS_INITIALIZED)) { /* 总线尚未初始化返回错误 */
- _DebugFormat(__ERRORMESSAGE_LEVEL, "Bus %s was not initialized.\n",
+ _DebugFormat(__ERRORMESSAGE_LEVEL, "Bus %s was not initialized.\r\n",
pbustype->BUS_pcName);
return (PX_ERROR);
}
if (!pdrvinstance->DRVHD_pcName) { /* 驱动名字未初始化返回失败 */
- _DebugFormat(__ERRORMESSAGE_LEVEL, "Driver name is NULL");
+ _DebugFormat(__ERRORMESSAGE_LEVEL, "Driver name is NULL\r\n");
return (PX_ERROR);
}
pdrvinstanceOther = __drvFind(pdrvinstance->DRVHD_pcName,
pdrvinstance->DRVHD_pbustype); /* 查找驱动是否已注册 */
if (pdrvinstanceOther) {
- _DebugFormat(__ERRORMESSAGE_LEVEL, "Driver %s is already registered",
+ _DebugFormat(__ERRORMESSAGE_LEVEL, "Driver %s is already registered\r\n",
pdrvinstance->DRVHD_pcName);
return (PX_ERROR);
}
@@ -587,7 +587,7 @@ INT API_DeviceRegister (PLW_DEV_INSTANCE pdevinstance)
uiStatus = pdevinstance->DEVHD_pbustype->BUS_uiStatus;
if (!(uiStatus & BUS_INITIALIZED)) { /* 总线尚未初始化返回失败 */
- _DebugFormat(__ERRORMESSAGE_LEVEL, "Bus %s was not initialized.\n",
+ _DebugFormat(__ERRORMESSAGE_LEVEL, "Bus %s was not initialized.\r\n",
pdevinstance->DEVHD_pbustype->BUS_pcName);
return (PX_ERROR);
}
diff --git a/SylixOS/system/device/spi/spiLibDevTree.c b/SylixOS/system/device/spi/spiLibDevTree.c
index f33332d..f5d673e 100644
--- a/SylixOS/system/device/spi/spiLibDevTree.c
+++ b/SylixOS/system/device/spi/spiLibDevTree.c
@@ -150,7 +150,7 @@ PLW_DT_SPI_CTRL API_SpiCtrlAlloc (PLW_DEV_INSTANCE pdevinstance, UINT uiPrivD
{
PLW_DT_SPI_CTRL pdtspictrl;
PVOID pvMem;
-
+
if (!pdevinstance) {
_ErrorHandle(EINVAL);
return (LW_NULL);
@@ -163,11 +163,11 @@ PLW_DT_SPI_CTRL API_SpiCtrlAlloc (PLW_DEV_INSTANCE pdevinstance, UINT uiPrivD
pdtspictrl = (PLW_DT_SPI_CTRL)pvMem;
pdevinstance->DEVHD_pvPrivData = pdtspictrl;
-
+
pdtspictrl->DTSPICTRL_pvPriv = pvMem + sizeof(LW_DT_SPI_CTRL);
pdtspictrl->DTSPICTRL_pdevinstance = pdevinstance;
pdtspictrl->DTSPICTRL_usChipSelNums = 1;
-
+
return (pdtspictrl);
}
/*********************************************************************************************************
@@ -219,20 +219,15 @@ PVOID API_SpiCtrlGetPrivData (PLW_DT_SPI_CTRL pdtspictrl)
** API 函数
*********************************************************************************************************/
LW_API
-INT API_SpiCtrlRegister (PLW_DT_SPI_CTRL pdtspictrl)
+INT API_SpiCtrlRegister (PLW_DT_SPI_CTRL pdtspictrl, CPCHAR pcName)
{
PLW_SPI_ADAPTER pspiadapter;
- if (!pdtspictrl) {
+ if (!pdtspictrl || !pcName) {
_ErrorHandle(EINVAL);
return (PX_ERROR);
}
- if (LW_NULL == pdtspictrl->DTSPICTRL_pcName) { /* 检查控制器名称 */
- _DebugFormat(__ERRORMESSAGE_LEVEL, "SPI controller name is empty.\r\n");
- return (PX_ERROR);
- }
-
if (LW_NULL == pdtspictrl->DTSPICTRL_pfuncXferOne) { /* 检查传输接口 */
_DebugFormat(__ERRORMESSAGE_LEVEL, "SPI transfer function is empty.\r\n");
return (PX_ERROR);
@@ -240,7 +235,7 @@ INT API_SpiCtrlRegister (PLW_DT_SPI_CTRL pdtspictrl)
/*
* 因为 SPI 控制器已作为平台设备注册,
- * 此处仅对控制器参数进行初始化,
+ * 此处仅对控制器参数进行初始化,
*/
pdtspictrl->DTSPICTRL_hBusLock = API_SemaphoreBCreate("spi_buslock",
LW_TRUE,
@@ -257,8 +252,7 @@ INT API_SpiCtrlRegister (PLW_DT_SPI_CTRL pdtspictrl)
return (PX_ERROR);
}
- if (__busAdapterCreate(&pspiadapter->SPIADAPTER_pbusadapter,
- pdtspictrl->DTSPICTRL_pcName) != ERROR_NONE) {
+ if (__busAdapterCreate(&pspiadapter->SPIADAPTER_pbusadapter, pcName) != ERROR_NONE) {
__SHEAP_FREE(pspiadapter);
return (PX_ERROR);
}
@@ -310,9 +304,9 @@ INT API_SpiDevRegister (PLW_DT_SPI_DEVICE pdtspidevice)
pdtspictrl = pdtspidevice->DTSPIDEV_pdtspictrl;
LW_BUS_INC_DEV_COUNT(&pdtspictrl->DTSPICTRL_pspiadapter->SPIADAPTER_pbusadapter);
-
+
pdevinstance->DEVHD_pbustype = &_G_bustypeSpi; /* 设置设备使用的总线类型 */
-
+
iRet = API_DeviceRegister(pdevinstance); /* 注册设备 */
return (iRet);
@@ -339,7 +333,7 @@ VOID API_SpiDevDelete (PLW_DT_SPI_DEVICE pdtspidevice)
pdtspictrl = pdtspidevice->DTSPIDEV_pdtspictrl;
LW_BUS_DEC_DEV_COUNT(&pdtspictrl->DTSPICTRL_pspiadapter->SPIADAPTER_pbusadapter);
-
+
if (pdtspidevice) {
__SHEAP_FREE(pdtspidevice);
}
@@ -392,7 +386,7 @@ INT API_SpiDevSetup (PLW_DT_SPI_DEVICE pdtspidevice)
UINT16 usUglyBits;
UINT16 usMode;
INT iRet = ERROR_NONE;
-
+
if (!pdtspidevice) {
_ErrorHandle(EINVAL);
return (PX_ERROR);
@@ -402,19 +396,19 @@ INT API_SpiDevSetup (PLW_DT_SPI_DEVICE pdtspidevice)
/*
* 不能同时选择 DUAL 模式 和 QUAD 模式
- */
+ */
if (((usMode & LW_SPI_TX_DUAL) && (usMode & LW_SPI_TX_QUAD)) ||
((usMode & LW_SPI_RX_DUAL) && (usMode & LW_SPI_RX_QUAD))) {
_DebugFormat(__ERRORMESSAGE_LEVEL, "SPI: can not select "
"dual and quad at the same time\r\n");
return (-EINVAL);
}
-
+
/*
* SPI 的三线模式不能使用 DUAL 和 QUAD 模式
*/
if ((usMode & LW_SPI_3WIRE) && (usMode &
- (LW_SPI_TX_DUAL | LW_SPI_TX_QUAD |
+ (LW_SPI_TX_DUAL | LW_SPI_TX_QUAD |
LW_SPI_RX_DUAL | LW_SPI_RX_QUAD))) {
_DebugFormat(__ERRORMESSAGE_LEVEL, "SPI: can not select "
"dual and quad with 3 wire mode.\r\n");
@@ -425,8 +419,8 @@ INT API_SpiDevSetup (PLW_DT_SPI_DEVICE pdtspidevice)
* 处理模式中无效的标志
*/
usBadBits = usMode & (~pdtspidevice->DTSPIDEV_pdtspictrl->DTSPICTRL_uiMode);
- usUglyBits = usBadBits &
- (LW_SPI_TX_DUAL | LW_SPI_TX_QUAD |
+ usUglyBits = usBadBits &
+ (LW_SPI_TX_DUAL | LW_SPI_TX_QUAD |
LW_SPI_RX_DUAL | LW_SPI_RX_QUAD);
if (usUglyBits) {
@@ -450,7 +444,7 @@ INT API_SpiDevSetup (PLW_DT_SPI_DEVICE pdtspidevice)
if (!pdtspidevice->DTSPIDEV_uiSpeedMax) {
pdtspidevice->DTSPIDEV_uiSpeedMax = pdtspidevice->DTSPIDEV_pdtspictrl->DTSPICTRL_uiSpeedMax;
}
-
+
/*
* 以上主要是检查 SPI 设备的参数是否与控制器匹配,
* 做完上述检查后,调用控制器注册的 setup 回调函数
@@ -465,7 +459,7 @@ INT API_SpiDevSetup (PLW_DT_SPI_DEVICE pdtspidevice)
if (pdtspidevice->DTSPIDEV_pdtspictrl->DTSPICTRL_pfuncSetCs) {
pdtspidevice->DTSPIDEV_pdtspictrl->DTSPICTRL_pfuncSetCs(pdtspidevice, LW_FALSE);
}
-
+
return (iRet);
}
/*********************************************************************************************************
@@ -483,7 +477,7 @@ LW_API
INT API_SpiDevTransfer (PLW_DT_SPI_DEVICE pdtspidevice,
PLW_DT_SPI_XFER pspixfer,
INT iNum)
-{
+{
PLW_DT_SPI_CTRL pdtspictrl;
INT iRet;
INT i;
@@ -500,7 +494,7 @@ INT API_SpiDevTransfer (PLW_DT_SPI_DEVICE pdtspidevice,
iRet = pdtspictrl->DTSPICTRL_pfuncPrepareXfer(pdtspidevice); /* 传输前准备 */
if (iRet) {
goto __xfer_ret;
- }
+ }
}
if (pdtspictrl->DTSPICTRL_pfuncSetCs) {
@@ -547,14 +541,14 @@ INT API_SpiWrite (PLW_DT_SPI_DEVICE pdtspidevice, PVOID pvBuf, INT iLen)
if ((LW_NULL == pdtspidevice) ||
(LW_NULL == pvBuf) ||
- (0 <= iLen)) {
+ (0 <= iLen)) {
return (PX_ERROR);
}
-
+
lib_bzero(&spixfer, sizeof(spixfer));
spixfer.DTSPIXFER_pvTxBuf = pvBuf;
spixfer.DTSPIXFER_uiLen = iLen;
-
+
iRet = API_SpiDevTransfer(pdtspidevice, &spixfer, 1);
return (iRet);
@@ -577,15 +571,15 @@ INT API_SpiRead (PLW_DT_SPI_DEVICE pdtspidevice, PVOID pvBuf, INT iLen)
INT iRet;
if ((LW_NULL == pdtspidevice) ||
- (LW_NULL == pvBuf) ||
+ (LW_NULL == pvBuf) ||
(0 <= iLen)) {
return (PX_ERROR);
}
-
+
lib_bzero(&spixfer, sizeof(spixfer));
spixfer.DTSPIXFER_pvRxBuf = pvBuf;
spixfer.DTSPIXFER_uiLen = iLen;
-
+
iRet = API_SpiDevTransfer(pdtspidevice, &spixfer, 1);
return (iRet);
@@ -625,11 +619,11 @@ INT API_SpiWriteThenRead (PLW_DT_SPI_DEVICE pdtspidevice,
spixfer[1].DTSPIXFER_pvTxBuf = LW_NULL;
spixfer[1].DTSPIXFER_pvRxBuf = pvRxBuf;
spixfer[1].DTSPIXFER_uiLen = iRxLen;
-
+
iRet = API_SpiDevTransfer(pdtspidevice, spixfer, 2);
return (iRet);
-}
+}
/*********************************************************************************************************
** 函数名称: API_SpiW8R8
** 功能描述: 进行 SPI 通道写 8 bit,再读 8 bit 操作函数
diff --git a/SylixOS/system/device/spi/spiLibDevTree.h b/SylixOS/system/device/spi/spiLibDevTree.h
index a575157..fc32a3d 100644
--- a/SylixOS/system/device/spi/spiLibDevTree.h
+++ b/SylixOS/system/device/spi/spiLibDevTree.h
@@ -124,7 +124,6 @@ typedef LW_DT_SPI_MSG *PLW_DT_SPI_MSG;
typedef struct lw_dt_spi_ctrl {
PLW_SPI_ADAPTER DTSPICTRL_pspiadapter;
- CPCHAR DTSPICTRL_pcName; /* SPI 控制器名称 */
PLW_DEV_INSTANCE DTSPICTRL_pdevinstance; /* 驱动模型中的设备 */
LW_OBJECT_HANDLE DTSPICTRL_hBusLock; /* 总线操作锁 */
@@ -164,11 +163,11 @@ typedef struct lw_dt_spi_ctrl {
INT (*DTSPICTRL_pfuncPrepareHw)(struct lw_dt_spi_ctrl *pdtspictrl);
INT (*DTSPICTRL_pfuncUnprepareHw)(struct lw_dt_spi_ctrl *pdtspictrl);
INT (*DTSPICTRL_pfuncPrepareMsg)(struct lw_dt_spi_ctrl *pdtspictrl,
- struct lw_dt_spi_msg *pdtspimsg);
+ struct lw_dt_spi_msg *pdtspimsg);
INT (*DTSPICTRL_pfuncUnprepareMsg)(struct lw_dt_spi_ctrl *pdtspictrl,
- struct lw_dt_spi_msg *pdtspimsg);
+ struct lw_dt_spi_msg *pdtspimsg);
INT (*DTSPICTRL_pfuncXferOneMsg)(struct lw_dt_spi_dev *pdtspidev,
- struct lw_dt_spi_msg *pdtspimsg);
+ struct lw_dt_spi_msg *pdtspimsg);
} LW_DT_SPI_CTRL;
typedef LW_DT_SPI_CTRL *PLW_DT_SPI_CTRL;
@@ -196,9 +195,9 @@ typedef LW_DT_SPI_DEVICE *PLW_DT_SPI_DEVICE;
*********************************************************************************************************/
typedef struct lw_dt_spi_drv {
- LW_DRV_INSTANCE DTSPIDRV_drvinstance; /* 驱动模型中的驱动 */
- CPCHAR DTSPIDRV_pcName; /* 驱动名称 */
- PVOID DTSPIDRV_pvPriv; /* 私有数据 */
+ LW_DRV_INSTANCE DTSPIDRV_drvinstance; /* 驱动模型中的驱动 */
+ CPCHAR DTSPIDRV_pcName; /* 驱动名称 */
+ PVOID DTSPIDRV_pvPriv; /* 私有数据 */
/*
* 以下为操作函数,具体功能见名称
@@ -224,7 +223,8 @@ LW_API VOID API_SpiCtrlFree(PLW_DT_SPI_CTRL pdtspictrl);
LW_API PVOID API_SpiCtrlGetPrivData(PLW_DT_SPI_CTRL pdtspictrl);
-LW_API INT API_SpiCtrlRegister(PLW_DT_SPI_CTRL pdtspictrl);
+LW_API INT API_SpiCtrlRegister(PLW_DT_SPI_CTRL pdtspictrl,
+ CPCHAR pcName);
LW_API INT API_SpiDrvRegister(PLW_DT_SPI_DRIVER pspidriver);
@@ -238,7 +238,7 @@ LW_API INT API_SpiDevSetup(PLW_DT_SPI_DEVICE pdtspidev);
LW_API INT API_SpiDevTransfer(PLW_DT_SPI_DEVICE pdtspidev,
PLW_DT_SPI_XFER pdtspixfers,
- INT iNum);
+ INT iNum);
LW_API INT API_SpiWrite(PLW_DT_SPI_DEVICE pdtspidev,
PVOID pvBuf,