summaryrefslogtreecommitdiffstatsabout
diff options
context:
space:
mode:
authorGavin.Bai <gavin_8724@163.com>2019-08-27 06:31:41 (GMT)
committer Gavin.Bai <gavin_8724@163.com>2019-08-27 06:31:41 (GMT)
commit80e35685b59d74edf66e3a6fe4072f84b843fdd3 (patch)
tree48436d2c597584d44fd3f0d77573a6bb86bac51b
parent679ac04af33953f2715790b8d2ea90cdb60ba444 (diff)
parent59b423ac9e9bfef465d14731ccecd1cbd6002b35 (diff)
downloadAIC-OS-80e35685b59d74edf66e3a6fe4072f84b843fdd3.zip
Merge branch 'AIC-OS'
-rw-r--r--SylixOS/arch/ppc/common/e500/ppcExcE500.c16
-rw-r--r--SylixOS/arch/ppc/common/ppcExc.c16
-rw-r--r--SylixOS/config/gjb/gjb_cfg.h2
-rw-r--r--SylixOS/config/kernel/kernel_cfg.h2
-rw-r--r--SylixOS/config/system/system_cfg.h2
-rw-r--r--SylixOS/driver/bu61580/bu61580.c621
-rw-r--r--SylixOS/driver/bu61580/bu61580.h67
-rw-r--r--SylixOS/kernel/core/_KernelHighLevelInit.c4
-rw-r--r--SylixOS/kernel/core/_ThreadAffinity.c14
-rw-r--r--SylixOS/kernel/include/k_api.h3
-rw-r--r--SylixOS/kernel/include/k_globalvar.h1
-rw-r--r--SylixOS/kernel/include/k_kernel.h2
-rw-r--r--SylixOS/kernel/interface/ThreadAffinity.c40
-rw-r--r--SylixOS/kernel/vmm/vmmAbort.c19
-rw-r--r--SylixOS/loader/src/loader_vpdebug.c14
-rw-r--r--SylixOS/loader/src/loader_vpthread.c25
-rw-r--r--SylixOS/net/lwip/bonding/netbonding.c158
-rw-r--r--SylixOS/net/lwip/bridge/netbridge.c6
-rw-r--r--SylixOS/posix/gjbext/gjb_interrupt.c18
-rw-r--r--SylixOS/posix/gjbext/gjb_timerel.c15
-rw-r--r--SylixOS/posix/mqueue/mqueue.c4
-rw-r--r--SylixOS/posix/semaphore/semaphore.c4
-rw-r--r--SylixOS/system/device/1553B/bus1553.c1050
-rw-r--r--SylixOS/system/device/1553B/bus1553.h175
-rw-r--r--SylixOS/system/device/ahci/ahciCfg.h2
-rw-r--r--SylixOS/system/device/nvme/nvmeCfg.h2
-rw-r--r--SylixOS/system/include/s_system.h1
-rw-r--r--SylixOS/system/ioLib/ioLockF.c6
-rw-r--r--libsylixos.mk2
29 files changed, 2188 insertions, 103 deletions
diff --git a/SylixOS/arch/ppc/common/e500/ppcExcE500.c b/SylixOS/arch/ppc/common/e500/ppcExcE500.c
index fb20088..7f5ee4c 100644
--- a/SylixOS/arch/ppc/common/e500/ppcExcE500.c
+++ b/SylixOS/arch/ppc/common/e500/ppcExcE500.c
@@ -204,14 +204,22 @@ VOID archE500AlignmentExceptionHandle (addr_t ulRetAddr)
{
PLW_CLASS_TCB ptcbCur;
LW_VMM_ABORT abtInfo;
+ addr_t ulAbortAddr;
+ PPC_PARAM *param = archKernelParamGet();
LW_TCB_GET_CUR(ptcbCur);
- ptcbCur->TCB_archRegCtx.REG_uiDar = ppcE500GetDEAR();
+ ulAbortAddr = ppcE500GetDEAR();
+ ptcbCur->TCB_archRegCtx.REG_uiDar = ulAbortAddr;
- abtInfo = ppcUnalignedHandle(&ptcbCur->TCB_archRegCtx);
- if (abtInfo.VMABT_uiType) {
- API_VmmAbortIsr(ulRetAddr, ptcbCur->TCB_archRegCtx.REG_uiDar, &abtInfo, ptcbCur);
+ abtInfo.VMABT_uiType = LW_VMM_ABORT_TYPE_BUS;
+ abtInfo.VMABT_uiMethod = BUS_ADRALN;
+
+ if (param->PP_bUnalign) {
+ API_VmmAbortIsrEx(ulRetAddr, ulAbortAddr, &abtInfo, ptcbCur, archE500UnalignedHandle);
+
+ } else {
+ API_VmmAbortIsr(ulRetAddr, ulAbortAddr, &abtInfo, ptcbCur);
}
}
/*********************************************************************************************************
diff --git a/SylixOS/arch/ppc/common/ppcExc.c b/SylixOS/arch/ppc/common/ppcExc.c
index 736280c..cba1022 100644
--- a/SylixOS/arch/ppc/common/ppcExc.c
+++ b/SylixOS/arch/ppc/common/ppcExc.c
@@ -250,14 +250,22 @@ VOID archAlignmentExceptionHandle (addr_t ulRetAddr)
{
PLW_CLASS_TCB ptcbCur;
LW_VMM_ABORT abtInfo;
+ addr_t ulAbortAddr;
+ PPC_PARAM *param = archKernelParamGet();
LW_TCB_GET_CUR(ptcbCur);
- ptcbCur->TCB_archRegCtx.REG_uiDar = ppcGetDAR();
+ ulAbortAddr = ppcGetDAR();
+ ptcbCur->TCB_archRegCtx.REG_uiDar = ulAbortAddr;
- abtInfo = ppcUnalignedHandle(&ptcbCur->TCB_archRegCtx);
- if (abtInfo.VMABT_uiType) {
- API_VmmAbortIsr(ulRetAddr, ptcbCur->TCB_archRegCtx.REG_uiDar, &abtInfo, ptcbCur);
+ abtInfo.VMABT_uiType = LW_VMM_ABORT_TYPE_BUS;
+ abtInfo.VMABT_uiMethod = BUS_ADRALN;
+
+ if (param->PP_bUnalign) {
+ API_VmmAbortIsrEx(ulRetAddr, ulAbortAddr, &abtInfo, ptcbCur, archUnalignedHandle);
+
+ } else {
+ API_VmmAbortIsr(ulRetAddr, ulAbortAddr, &abtInfo, ptcbCur);
}
}
/*********************************************************************************************************
diff --git a/SylixOS/config/gjb/gjb_cfg.h b/SylixOS/config/gjb/gjb_cfg.h
index 2736bc2..045c11a 100644
--- a/SylixOS/config/gjb/gjb_cfg.h
+++ b/SylixOS/config/gjb/gjb_cfg.h
@@ -28,7 +28,7 @@
*********************************************************************************************************/
#define LW_CFG_GJB7714_EN 1 /* 是否提供 GJB7714 支持 */
-#define LW_CFG_GJB7714_INT_EN 0 /* 是否提供 GJB7714 中断接口 */
+#define LW_CFG_GJB7714_INT_EN 1 /* 是否提供 GJB7714 中断接口 */
#endif /* __GJB_CFG_H */
/*********************************************************************************************************
diff --git a/SylixOS/config/kernel/kernel_cfg.h b/SylixOS/config/kernel/kernel_cfg.h
index 39525bb..8174b1f 100644
--- a/SylixOS/config/kernel/kernel_cfg.h
+++ b/SylixOS/config/kernel/kernel_cfg.h
@@ -72,7 +72,7 @@
* 依存关系: 无
*********************************************************************************************************/
-#define LW_CFG_INTER_MEASURE_HOOK_EN 0 /* 是否允许系统中断测量接口 (不需要请关闭) */
+#define LW_CFG_INTER_MEASURE_HOOK_EN 1 /* 是否允许系统中断测量接口 (不需要请关闭) */
/*********************************************************************************************************
* 系统跟踪与监控管理
diff --git a/SylixOS/config/system/system_cfg.h b/SylixOS/config/system/system_cfg.h
index 677472f..ef546b9 100644
--- a/SylixOS/config/system/system_cfg.h
+++ b/SylixOS/config/system/system_cfg.h
@@ -288,6 +288,7 @@
*********************************************************************************************************/
#define LW_CFG_AHCI_EN 1 /* 是否允许系统提供 AHCI 主控设备管理 */
+#define LW_CFG_AHCI_TRIM_EN 1 /* 是否允许系统使用 TRIM 命令 */
#define LW_CFG_AHCI_CACHE_SIZE_MB 1 /* SATA 盘文件系统 CACHE 大小, 单位: MB */
/*********************************************************************************************************
@@ -301,6 +302,7 @@
*********************************************************************************************************/
#define LW_CFG_NVME_EN 1 /* 是否允许系统提供 NVMe 主控设备管理 */
+#define LW_CFG_NVME_TRIM_EN 1 /* 是否允许系统使用 TRIM 命令 */
#define LW_CFG_NVME_CACHE_SIZE_MB 1 /* NVMe 盘文件系统 CACHE 大小, 单位: MB */
/*********************************************************************************************************
diff --git a/SylixOS/driver/bu61580/bu61580.c b/SylixOS/driver/bu61580/bu61580.c
new file mode 100644
index 0000000..178173a
--- /dev/null
+++ b/SylixOS/driver/bu61580/bu61580.c
@@ -0,0 +1,621 @@
+/*********************************************************************************************************
+**
+** 中国软件开源组织
+**
+** 嵌入式实时操作系统
+**
+** SylixOS(TM) LW : long wing
+**
+** Copyright All Rights Reserved
+**
+**--------------文件信息--------------------------------------------------------------------------------
+**
+** 文 件 名: bu61580.c
+**
+** 创 建 人: Zhu.Jianhui (朱剑辉)
+**
+** 文件创建日期: 2019 年 08 月 05 日
+**
+** 描 述: 1553B 总线驱动支持.
+*********************************************************************************************************/
+#define __SYLIXOS_KERNEL
+#include "SylixOS.h"
+#include "../SylixOS/config/driver/drv_cfg.h"
+#include "bu61580.h"
+
+
+/*********************************************************************************************************
+ internal function declare
+*********************************************************************************************************/
+static INT Bu61580Ioctl(BU61580_CHAN *pbu61580chan, INT cmd, LONG arg);
+static INT Bu61580TxStartup(BU61580_CHAN *pbu61580chan);
+static INT Bu61580CallbackInstall(BU61580_CHAN *pbu61580chan,
+ INT callbackType,
+ INT (*callback)(),
+ VOID *callbackArg);
+/*********************************************************************************************************
+ bu61580 driver functions
+*********************************************************************************************************/
+static DRV_FUNCS_1553 bu61580_drv_funcs = {
+ (INT (*)())Bu61580Ioctl,
+ (INT (*)())Bu61580TxStartup,
+ (INT (*)())Bu61580CallbackInstall
+};
+/*********************************************************************************************************
+** 函数名称: Bu61580Init
+** 功能描述: 初始化 bu61580 驱动程序
+** 输 入 : pbu61580chan bu61580 CHAN
+** 输 出 : ERROR or OK
+** 全局变量:
+** 调用模块:
+*********************************************************************************************************/
+INT Bu61580Init (BU61580_CHAN *pbu61580chan)
+{
+ if(!pbu61580chan) {
+ return -1;
+ }
+
+ if (pbu61580chan->channel == 0) {
+ _ErrorHandle(ENOSYS);
+ return (PX_ERROR);
+ }
+
+ LW_SPIN_INIT(&pbu61580chan->bu61580_splock);
+
+ pbu61580chan->pDrvFuncs = &bu61580_drv_funcs;
+ pbu61580chan->channel = 0;
+ pbu61580chan->busMode = INIT_MOD; //初始化模式,可以通过IOCtrl更改
+
+ return (ERROR_NONE);
+}
+
+/*********************************************************************************************************
+** 函数名称: Bu61580Send
+** 功能描述: bu61580 发送
+** 输 入 : pbu61580chan bu61580 CHAN
+** dataFrame bu61580 消息帧
+** 输 出 : ERROR or OK
+*********************************************************************************************************/
+static INT Bu61580Send (BU61580_CHAN *pbu61580chan, FRAME_1553DATA *dataFrame)
+{
+ INTREG intreg;
+ UINT8 wordCnt = 0;
+ UINT16 ctrlWord = 0;
+ UINT8 index = 0;
+ UINT32 msgBlkPtr = 0;
+ UINT32 msgStackPtr = 0;
+ UINT8 subAddr = 0;
+
+ if(!pbu61580chan || !dataFrame) {
+ return -1;
+ }
+
+ LW_SPIN_LOCK_QUICK(&pbu61580chan->bu61580_splock, &intreg);
+
+ //从数据帧获取信息,组成消息帧发送
+ //注意需要区分BC 和RT 模式,BC还需区分发送和接收
+ if (dataFrame->frameInfo1.CMDWORD1.WCOUNT > 0) {
+ wordCnt = dataFrame->frameInfo1.CMDWORD1.WCOUNT;
+ } else {
+ wordCnt = 32;
+ }
+
+ if(pbu61580chan->busMode == BC_MOD) {
+ msgBlkPtr = 0x108;
+ for(index=0;index<38;index++) { //数据清零
+ pbu61580chan->WriteMem(pbu61580chan,msgBlkPtr+index, 0);
+ }
+ pbu61580chan->WriteMem(pbu61580chan,msgBlkPtr, dataFrame->msgCtrlWord); //控制字
+ pbu61580chan->WriteMem(pbu61580chan,msgBlkPtr+1, dataFrame->frameInfo1.cmdWord1); //命令字
+ switch(dataFrame->msgType) {
+ case BC_RT:
+ case BCST:
+ for(index=0;index<wordCnt;index++) {
+ pbu61580chan->WriteMem(pbu61580chan,msgBlkPtr+2+index, dataFrame->msgData[index]);
+ }
+ break;
+ case RT_BC:
+ case MC_ND:
+ case TX_MC_WD:
+ case MCND_BCST:
+
+ break;
+ case RT_RT:
+ case RT_RTS:
+ pbu61580chan->WriteMem(pbu61580chan,msgBlkPtr+2, dataFrame->frameInfo2.cmdWord2);
+ break;
+ case RX_MC_WD:
+ case MCWD_BCST:
+ pbu61580chan->WriteMem(pbu61580chan,msgBlkPtr+2, dataFrame->msgData[0]);
+ break;
+ default:
+ break;
+ }
+ //填写4个字的消息堆栈信息
+ pbu61580chan->WriteMem(pbu61580chan, msgStackPtr, 0);
+ pbu61580chan->WriteMem(pbu61580chan, msgStackPtr+1, 0);
+ pbu61580chan->WriteMem(pbu61580chan, msgStackPtr+2, dataFrame->msgGapTime);
+ pbu61580chan->WriteMem(pbu61580chan, msgStackPtr+3, msgBlkPtr);
+
+ pbu61580chan->WriteMem(pbu61580chan,0x0101, 0xfffeU); //此处设置只发一条消息
+ pbu61580chan->WriteMem(pbu61580chan,0x0100, 0); //设置堆栈
+ pbu61580chan->WriteReg(pbu61580chan,STR_RST, 0x0022); //启动
+ } else if(pbu61580chan->busMode == RT_MOD) {
+ switch(dataFrame->msgType) {
+ case RT_TO_BC:
+ subAddr = dataFrame->frameInfo1.CMDWORD1.SADDR;
+ //msgBlkPtr = pbu61580chan->rtTxSubAddrInfo[subAddr].rtTxSubAddrStartAddr;
+ msgBlkPtr = 0x0660 + subAddr*32;
+ for(index=0;index<wordCnt;index++) {
+ pbu61580chan->WriteMem(pbu61580chan,msgBlkPtr+index, dataFrame->msgData[index]);
+ }
+ break;
+ case MODE_CODE:
+ //
+ break;
+ default:
+ break;
+ }
+ } else {
+ return -1;
+ }
+
+ LW_SPIN_UNLOCK_QUICK(&pbu61580chan->bu61580_splock, intreg);
+
+
+ return (ERROR_NONE);
+}
+
+/*********************************************************************************************************
+** 函数名称: Bu61580Recv
+** 功能描述: bu61580 接收
+** 输 入 : pbu61580chan bu61580 CHAN
+** dataFrame bu61580 消息帧
+** 输 出 : ERROR or OK
+** 全局变量:
+** 调用模块:
+*********************************************************************************************************/
+static INT Bu61580Recv (BU61580_CHAN *pbu61580chan, FRAME_1553DATA *dataFrame)
+{
+ INTREG intreg =0;
+ UINT32 msgBlkPtr = 0;
+ UINT8 wordCnt = 0;
+ UINT8 rtSubAddr = 0;
+ int i = 0;
+ char buf[40];
+
+ if(!pbu61580chan || !dataFrame) {
+ return -1;
+ }
+
+ LW_SPIN_LOCK_QUICK(&pbu61580chan->bu61580_splock, &intreg);
+
+ if (dataFrame->frameInfo1.CMDWORD1.WCOUNT > 0) {
+ wordCnt = dataFrame->frameInfo1.CMDWORD1.WCOUNT;
+ } else {
+ wordCnt = 32;
+ }
+
+ if(pbu61580chan->busMode == BC_MOD) {
+ msgBlkPtr = 0x0108U;
+ switch (dataFrame->msgType) {
+ case BC_RT:
+ dataFrame->loopBack = pbu61580chan->ReadMem(pbu61580chan,msgBlkPtr + wordCnt + 2) & 0xFFFF;
+ dataFrame->msgStatus1 = pbu61580chan->ReadMem(pbu61580chan,msgBlkPtr + wordCnt + 3) & 0xFFFF;
+ break;
+ case RT_BC:
+ for (i=0; i<wordCnt; i++) {
+ dataFrame->msgData[i] = pbu61580chan->ReadMem(pbu61580chan,msgBlkPtr + i + 4) & 0xFFFF;
+ }
+ dataFrame->loopBack = pbu61580chan->ReadMem(pbu61580chan,msgBlkPtr + 2) & 0xFFFF;
+ dataFrame->msgStatus1 = pbu61580chan->ReadMem(pbu61580chan,msgBlkPtr + 3) & 0xFFFF;
+ break;
+ case RT_RT:
+ dataFrame->loopBack = pbu61580chan->ReadMem(pbu61580chan,msgBlkPtr + 3) & 0xFFFF;
+ dataFrame->msgStatus1 = pbu61580chan->ReadMem(pbu61580chan,msgBlkPtr + 4) & 0xFFFF;
+ for (i=0; i<wordCnt; i++) {
+ dataFrame->msgData[i] = pbu61580chan->ReadMem(pbu61580chan,msgBlkPtr + i + 5) & 0xFFFF;
+ }
+ dataFrame->msgStatus2 = pbu61580chan->ReadMem(pbu61580chan,msgBlkPtr + wordCnt + 5) & 0xFFFF;
+ break;
+ case BCST:
+ dataFrame->loopBack = pbu61580chan->ReadMem(pbu61580chan,msgBlkPtr + wordCnt + 2) & 0xFFFF;
+ break;
+ case RT_RTS:
+ dataFrame->loopBack = pbu61580chan->ReadMem(pbu61580chan,msgBlkPtr + 3) & 0xFFFF;
+ dataFrame->msgStatus1 = pbu61580chan->ReadMem(pbu61580chan,msgBlkPtr + 4) & 0xFFFF;
+ for (i=0; i<wordCnt; i++) {
+ dataFrame->msgData[i] = pbu61580chan->ReadMem(pbu61580chan,msgBlkPtr + i + 5) & 0xFFFF;
+ }
+ break;
+ case MC_ND:
+ dataFrame->loopBack = pbu61580chan->ReadMem(pbu61580chan,msgBlkPtr + 2) & 0xFFFF;
+ dataFrame->msgStatus1 = pbu61580chan->ReadMem(pbu61580chan,msgBlkPtr + 3) & 0xFFFF;
+ break;
+ case TX_MC_WD:
+ dataFrame->loopBack = pbu61580chan->ReadMem(pbu61580chan,msgBlkPtr + 2) & 0xFFFF;
+ dataFrame->msgStatus1 = pbu61580chan->ReadMem(pbu61580chan,msgBlkPtr + 3) & 0xFFFF;
+ dataFrame->msgData[0] = pbu61580chan->ReadMem(pbu61580chan,msgBlkPtr + 4) & 0xFFFF;
+ break;
+ case RX_MC_WD:
+ dataFrame->loopBack = pbu61580chan->ReadMem(pbu61580chan,msgBlkPtr + 3) & 0xFFFF;
+ dataFrame->msgStatus1 = pbu61580chan->ReadMem(pbu61580chan,msgBlkPtr + 4) & 0xFFFF;
+ break;
+ case MCND_BCST:
+ dataFrame->loopBack = pbu61580chan->ReadMem(pbu61580chan,msgBlkPtr + 2) & 0xFFFF;
+ break;
+ case MCWD_BCST:
+ dataFrame->msgStatus1 = pbu61580chan->ReadMem(pbu61580chan,msgBlkPtr + 3) & 0xFFFF;
+ break;
+ default:
+ break;
+ }
+ } else if(pbu61580chan->busMode == RT_MOD) {
+ rtSubAddr = dataFrame->frameInfo1.CMDWORD1.SADDR;
+ if(dataFrame->frameInfo1.CMDWORD1.RTADDR == 31) { //broadcast
+ //msgBlkPtr = pbu61580chan->broadcastSubAddrInfo[rtSubAddr].broadcastSubAddrStartAddr;
+ msgBlkPtr = 0x0a60 + rtSubAddr*32;
+ for (i = 0; i < wordCnt; i++) {
+ dataFrame->msgData[i] = pbu61580chan->ReadMem(pbu61580chan,msgBlkPtr + i) & 0xFFFF;
+ }
+ pbu61580chan->WriteMem(pbu61580chan,0x0180 + rtSubAddr, msgBlkPtr); // 查找表指针复位
+ dataFrame->msgType = BROADCAST;
+ } else if((rtSubAddr==0) || (rtSubAddr==31)) { //mode code
+ //只有0x00、0x14、0x15三种命令有数接收,此处不处理
+ dataFrame->msgType = MODE_CODE;
+ } else { //BC_RT
+ //msgBlkPtr = pbu61580chan->rtRxSubAddrInfo[rtSubAddr].rtRxSubAddrStartAddr;
+ msgBlkPtr = 0x0260 + rtSubAddr*32;
+ for (i = 0; i < wordCnt; i++)
+ {
+ dataFrame->msgData[i] = pbu61580chan->ReadMem(pbu61580chan,msgBlkPtr + i) & 0xFFFF;
+ }
+ pbu61580chan->WriteMem(pbu61580chan,0x0140 + rtSubAddr, msgBlkPtr); // 查找表指针复位
+ dataFrame->msgType = BC_TO_RT;
+ }
+ } else {
+ return -1;
+ }
+
+ LW_SPIN_UNLOCK_QUICK(&pbu61580chan->bu61580_splock, intreg);
+
+ return (ERROR_NONE);
+}
+
+static void Bu61580MemClear(BU61580_CHAN *pbu61580chan)
+{
+ UINT index = 0;
+
+ for(index=0;index<0x1000;index++) {
+ pbu61580chan->WriteMem(pbu61580chan, index, 0);
+ }
+}
+
+static void Bu61580RegInit(BU61580_CHAN *pbu61580chan, UINT rtAddr)
+{
+ if(pbu61580chan->busMode == BC_MOD) {
+ pbu61580chan->WriteReg(pbu61580chan, STR_RST, 0x0001);
+ pbu61580chan->WriteReg(pbu61580chan, CONFIG3, 0x8000);
+ pbu61580chan->WriteReg(pbu61580chan, INTRMASK, 0x0001);//end of message interrupt
+ pbu61580chan->WriteReg(pbu61580chan, CONFIG1, 0x1838);
+ pbu61580chan->WriteReg(pbu61580chan, CONFIG2, 0x8418);
+ pbu61580chan->WriteReg(pbu61580chan, CONFIG4, 0x1080);
+ pbu61580chan->WriteReg(pbu61580chan, CONFIG5, 0x0e00);
+ pbu61580chan->WriteReg(pbu61580chan, TIMETAG, 0x0000);
+ } else if(pbu61580chan->busMode == RT_MOD) {
+ pbu61580chan->WriteReg(pbu61580chan, STR_RST, 0x0001);
+ pbu61580chan->WriteReg(pbu61580chan, CONFIG3, 0x8000);
+ pbu61580chan->WriteReg(pbu61580chan, INTRMASK, 0x0003);//end of message & mode code interrupt
+ pbu61580chan->WriteReg(pbu61580chan, CONFIG3, 0x8081);
+ pbu61580chan->WriteReg(pbu61580chan, CONFIG2, 0x8a9f);
+ pbu61580chan->WriteReg(pbu61580chan, CONFIG4, 0x0008);//enable RT address conf
+ pbu61580chan->WriteReg(pbu61580chan, TIMETAG, 0x0000);
+ if((rtAddr >= 0) && (rtAddr< 32)) {
+ pbu61580chan->WriteReg(pbu61580chan,CONFIG5, 0x0600 | (rtAddr<<1));//校验位可不配
+ } else {
+ pbu61580chan->WriteReg(pbu61580chan, CONFIG5, 0x0600);//default
+ }
+ }
+}
+
+static void Bu61580MemInit(BU61580_CHAN *pbu61580chan)
+{
+ UINT16 index = 0;
+
+ if(pbu61580chan->busMode == BC_MOD) {
+ pbu61580chan->WriteMem(pbu61580chan, 0x0100, 0); //stack pointer A
+ pbu61580chan->WriteMem(pbu61580chan, 0x0104, 0); //stack pointer B
+ } else if(pbu61580chan->busMode == RT_MOD) {
+ pbu61580chan->WriteMem(pbu61580chan, 0x0100, 0); //stack pointer
+ pbu61580chan->WriteMem(pbu61580chan, 0x0104, 0x0f00);//stack pointer B
+
+ for (index=0;index<32;index++) {
+ pbu61580chan->WriteMem(pbu61580chan, 0x0140+index, 0x0260 + index*32);//每条消息32个字
+ pbu61580chan->WriteMem(pbu61580chan, 0x0160+index, 0x0660 + index*32);
+ pbu61580chan->WriteMem(pbu61580chan, 0x0180+index, 0x0a60 + index*32);
+
+ pbu61580chan->WriteMem(pbu61580chan, 0x01c0+index, 0x0260 + index*32);//area B
+ pbu61580chan->WriteMem(pbu61580chan, 0x01e0+index, 0x0660 + index*32);
+ pbu61580chan->WriteMem(pbu61580chan, 0x0200+index, 0x0a60 + index*32);
+
+ pbu61580chan->WriteMem(pbu61580chan, 0x01a0+index, 0x4210); //控制字
+ pbu61580chan->WriteMem(pbu61580chan, 0x0220+index, 0x4210);
+ }
+ } else {
+ //do nothing?
+ }
+}
+
+/*********************************************************************************************************
+** 函数名称: Bu61580InitChip
+** 功能描述: bu61580 芯片初始化
+** 输 入 : pbu61580chan bu61580 CHAN
+** 输 出 : 无
+** 全局变量:
+** 调用模块:
+*********************************************************************************************************/
+static VOID Bu61580InitChip (BU61580_CHAN *pbu61580chan, UINT rtAddr)
+{
+ Bu61580MemClear(pbu61580chan); //数据清零
+ Bu61580RegInit(pbu61580chan,rtAddr); //初始化配置寄存器
+ Bu61580MemInit(pbu61580chan); //初始化配置存储
+
+ if(pbu61580chan->busMode == RT_MOD) {
+ pbu61580chan->WriteReg(pbu61580chan, CONFIG1, 0x8f80); //启动RT
+ }
+ pbu61580chan->ReadReg(pbu61580chan, INTR_STATUS); //读中断状态寄存器,清除中断状态
+}
+
+/*********************************************************************************************************
+** 函数名称: Bu61580TxStartup
+** 功能描述: SJA1000 芯片启动发送
+** 输 入 : pbu61580chan bu16580 CHAN
+** 输 出 : ERROR or OK
+** 全局变量:
+** 调用模块:
+*********************************************************************************************************/
+static INT Bu61580TxStartup (BU61580_CHAN *pbu61580chan)
+{
+ FRAME_1553DATA dataFrame;
+
+ if(!pbu61580chan) {
+ return -1;
+ }
+
+ if (pbu61580chan->GetTxFrame(pbu61580chan->GetTxFrameArg, &dataFrame) == ERROR_NONE) {
+ Bu61580Send(pbu61580chan, &dataFrame);
+ }
+
+ return (ERROR_NONE);
+}
+/*********************************************************************************************************
+** 函数名称: bu61580CallbackInstall
+** 功能描述: bu61580安装回调
+** 输 入 : pbu61580chan bu61580 CHAN
+** callbackType 回调类型
+** callback 回调函数
+** callbackArg 回调参数
+** 输 出 : ERROR or OK
+** 全局变量:
+** 调用模块:
+*********************************************************************************************************/
+static INT Bu61580CallbackInstall (BU61580_CHAN *pbu61580chan,
+ INT callbackType,
+ INT (*callback)(),
+ VOID *callbackArg)
+{
+ if(!pbu61580chan) {
+ return -1;
+ }
+ switch (callbackType) {
+
+ case _1553_CB_GET_TX_FRAME:
+ pbu61580chan->GetTxFrame = callback;
+ pbu61580chan->GetTxFrameArg = callbackArg;
+ return (ERROR_NONE);
+
+ case _1553_CB_PUT_RX_FRAME:
+ pbu61580chan->PutRxFrame = callback;
+ pbu61580chan->PutRxFrameArg = callbackArg;
+ return (ERROR_NONE);
+
+ case _1553_CB_PUT_BUS_STATE:
+ pbu61580chan->SetBusState = callback;
+ pbu61580chan->SetBusStateArg = callbackArg;
+ return (ERROR_NONE);
+
+ default:
+ _ErrorHandle(ENOSYS);
+ return (PX_ERROR);
+ }
+}
+/*********************************************************************************************************
+** 函数名称: Bu61580Ioctl
+** 功能描述: Bu61580 控制
+** 输 入 : pbu61580chan bu61580 CHAN
+** cmd 控制命令
+** arg 控制参数
+** 输 出 : ERROR or OK
+** 全局变量:
+** 调用模块:
+*********************************************************************************************************/
+static INT Bu61580Ioctl (BU61580_CHAN *pbu61580chan, INT cmd, LONG arg)
+{
+ INTREG intreg;
+ INT tmp;
+
+ if(!pbu61580chan) {
+ return -1;
+ }
+
+ switch (cmd) {
+ case _1553_DEV_OPEN: /* 打开 1553 设备 */
+ pbu61580chan->open(pbu61580chan);
+ break;
+
+ case _1553_DEV_CLOSE: /* 关闭 1553 设备 */
+ pbu61580chan->close(pbu61580chan);
+ break;
+
+ case _1553_DEV_SET_MODE:
+ if(pbu61580chan->busMode != INIT_MOD) //只有且必须在尚未启动运行前设置
+ break;
+ switch(arg) {
+ case BC_MOD:
+ pbu61580chan->busMode = BC_MOD;
+ break;
+ case RT_MOD:
+ pbu61580chan->busMode = RT_MOD;
+ break;
+ case MT_MOD:
+ pbu61580chan->busMode = MT_MOD;
+ break;
+ default:
+ break;
+ }
+ break;
+
+ case _1553_DEV_REST_BUS:
+ case _1553_DEV_STARTUP:
+ pbu61580chan->reset(pbu61580chan);
+ pbu61580chan->SetBusState(pbu61580chan->SetBusStateArg, _1553_DEV_BUS_OK);
+
+ intreg = KN_INT_DISABLE();
+
+ Bu61580InitChip(pbu61580chan,arg);
+
+ KN_INT_ENABLE(intreg);
+
+ Bu61580TxStartup(pbu61580chan);
+
+ break;
+
+ default:
+ errno = ENOSYS;
+ return (PX_ERROR);
+ }
+
+ return (ERROR_NONE);
+}
+/*********************************************************************************************************
+** 函数名称: Bu61580BcIsr
+** 功能描述: bu61580 BC模式中断处理
+** 输 入 : pbu61580chan bu61580 CHAN
+** cmd 控制命令
+** arg 控制参数
+** 输 出 : ERROR or OK
+** 全局变量:
+** 调用模块:
+*********************************************************************************************************/
+VOID Bu61580BcIsr (BU61580_CHAN *pbu61580chan)
+{
+ FRAME_1553DATA dataFrame;
+ UINT32 msgCmdWord = 0;
+ UINT16 msgCtrlWord = 0;
+ UINT8 msgFormat = 0;
+ UINT8 trRxBit = 0;
+
+ if(!pbu61580chan) {
+ return;
+ }
+
+ pbu61580chan->ReadReg(pbu61580chan, INTR_STATUS); //读中断状态寄存器,清除1553中断
+
+ /*
+ *读消息发送数据区获取消息命令字、控制字
+ * 此处需注意:必须保证当前消息处理完才能处理后续消息
+ * 即产生中断的消息数据没有被后续消息刷新
+ * 但是如果这样的话,到底是由用户保证还是驱动保证??? 如何加锁???
+ * 是否可以考虑用全局或静态变量暂存产生当前中断的消息信息???
+ */
+ msgCmdWord = pbu61580chan->ReadMem(pbu61580chan, 0x109);
+ dataFrame.frameInfo1.cmdWord1 = msgCmdWord;
+ trRxBit = (msgCmdWord & CMD_TXRX_BIT_MASK) >> CMD_TXRX_BIT;
+
+ msgCtrlWord = (pbu61580chan->ReadMem(pbu61580chan,0x0108U)) & 0xFFFF;
+ msgFormat = msgCtrlWord & 0x07;
+ dataFrame.msgChannel = msgCtrlWord & (0x01<<7);
+
+ //根据消息控制字的低3位和消息收发标志确定消息类型
+ switch(msgFormat) {
+ case 0:
+ if(trRxBit == 1) {
+ dataFrame.msgType = RT_BC;
+ } else {
+ dataFrame.msgType = BC_RT;
+ }
+ break;
+ case 1:
+ dataFrame.msgType = RT_RT;
+ break;
+ case 2:
+ dataFrame.msgType = BCST;
+ break;
+ case 3:
+ dataFrame.msgType = RT_RTS;
+ break;
+ case 4:
+ if(trRxBit == 1) {
+ dataFrame.msgType = TX_MC_WD;
+ } else {
+ dataFrame.msgType = RX_MC_WD;
+ }
+ break;
+ case 6:
+ break;
+ default:
+ break;
+ }
+
+ //不论发送还是接收,均返回用户消息数据或状态信息
+ //但是注意:对于BC发送数据,只有返回的状态信息有效,数据已不在
+ Bu61580Recv(pbu61580chan, &dataFrame);
+ if (pbu61580chan->PutRxFrame(pbu61580chan->PutRxFrameArg, &dataFrame)) {
+ pbu61580chan->SetBusState(pbu61580chan->SetBusStateArg,_1553_DEV_BUS_ERROR);
+ }
+
+ //继续尝试从发送队列取消息帧发送
+ if (pbu61580chan->GetTxFrame(pbu61580chan->GetTxFrameArg, &dataFrame) == ERROR_NONE) {
+ Bu61580Send(pbu61580chan, &dataFrame);
+ }
+}
+
+/*********************************************************************************************************
+** 函数名称: Bu61580RtIsr
+** 功能描述: bu61580 RT模式中断处理
+** 输 入 : pbu61580chan bu61580 CHAN
+** cmd 控制命令
+** arg 控制参数
+** 输 出 : ERROR or OK
+** 全局变量:
+** 调用模块:
+*********************************************************************************************************/
+VOID Bu61580RtIsr (BU61580_CHAN *pbu61580chan)
+{
+ FRAME_1553DATA dataFrame;
+ union
+ {
+ COMMANDWORD CMDWORD;
+ UINT32 cmdWord;
+ } msgCmdWord;
+
+ if(!pbu61580chan)
+ {
+ return;
+ }
+
+ pbu61580chan->ReadReg(pbu61580chan, INTR_STATUS); //读中断状态寄存器,清除1553中断
+ msgCmdWord.cmdWord = pbu61580chan->ReadReg(pbu61580chan, RT_LAST_CMD_WORD);//获取消息命令字
+
+ dataFrame.frameInfo1.cmdWord1 = msgCmdWord.cmdWord;
+ if(msgCmdWord.CMDWORD.TR == 0) { //接收消息中断
+ Bu61580Recv(pbu61580chan, &dataFrame);
+ if (pbu61580chan->PutRxFrame(pbu61580chan->PutRxFrameArg, &dataFrame)) {
+ pbu61580chan->SetBusState(pbu61580chan->SetBusStateArg,_1553_DEV_BUS_ERROR);
+ }
+ } else { //发送消息中断
+ if (pbu61580chan->GetTxFrame(pbu61580chan->GetTxFrameArg, &dataFrame) == ERROR_NONE) {
+ Bu61580Send(pbu61580chan, &dataFrame);
+ }
+ }
+}
diff --git a/SylixOS/driver/bu61580/bu61580.h b/SylixOS/driver/bu61580/bu61580.h
new file mode 100644
index 0000000..3ab5b2d
--- /dev/null
+++ b/SylixOS/driver/bu61580/bu61580.h
@@ -0,0 +1,67 @@
+/*********************************************************************************************************
+**
+** 中国软件开源组织
+**
+** 嵌入式实时操作系统
+**
+** SylixOS(TM) LW : long wing
+**
+** Copyright All Rights Reserved
+**
+**--------------文件信息--------------------------------------------------------------------------------
+**
+** 文 件 名: bu61580.h
+**
+** 创 建 人: Zhu.Jianhui (朱剑辉)
+**
+** 文件创建日期: 2019 年 08 月 05 日
+**
+** 描 述: 1553B 总线驱动支持.
+*********************************************************************************************************/
+#ifndef __bu61580__
+#define __bu61580__
+
+#include "SylixOS.h"
+
+#define CMD_TXRX_BIT 10
+#define CMD_TXRX_BIT_MASK (1<<10)
+
+typedef struct bu61580_chan BU61580_CHAN;
+
+struct bu61580_chan {
+ DRV_FUNCS_1553 *pDrvFuncs;
+
+ INT channel; //用作启动识别?????????初始化前为1/2,初始化后为0
+ INT busMode; /* BC or RT or MT */
+
+ LW_SPINLOCK_DEFINE (bu61580_splock);
+
+ INT (*SetBusState)();
+ INT (*GetTxFrame)();
+ INT (*PutRxFrame)();
+
+ PVOID SetBusStateArg;
+ PVOID GetTxFrameArg;
+ PVOID PutRxFrameArg;
+
+ void (*WriteMem)(BU61580_CHAN *, UINT memAddr, UINT val); /* write memmory value */
+ UINT (*ReadMem)(BU61580_CHAN *, UINT memAddr); /* read memmory value */
+ void (*WriteReg)(BU61580_CHAN *, UINT regAddr, UINT val); /* write register value */
+ UINT (*ReadReg)(BU61580_CHAN *, UINT regAddr); /* read register value */
+
+ void (*reset)(BU61580_CHAN *);
+ void (*open)(BU61580_CHAN *);
+ void (*close)(BU61580_CHAN *);
+
+ void *priv; /* user can use this save some thing */
+};
+
+/*********************************************************************************************************
+ bu61580 driver functions
+*********************************************************************************************************/
+
+INT Bu61580Init(BU61580_CHAN *pcanchan);
+VOID Bu61580BcIsr(BU61580_CHAN *pcanchan);
+VOID Bu61580RtIsr (BU61580_CHAN *pbu61580chan);
+
+#endif /* __bu61580__ */
diff --git a/SylixOS/kernel/core/_KernelHighLevelInit.c b/SylixOS/kernel/core/_KernelHighLevelInit.c
index 656af00..f11c378 100644
--- a/SylixOS/kernel/core/_KernelHighLevelInit.c
+++ b/SylixOS/kernel/core/_KernelHighLevelInit.c
@@ -83,8 +83,8 @@ static VOID _CreateIdleThread (VOID)
LW_CPU_SET(i, &cpuset); /* 锁定到指定 CPU */
_ThreadSetAffinity(_K_ptcbIdle[i], sizeof(LW_CLASS_CPUSET), &cpuset);
- LW_CPU_CLR(i, &cpuset);
-
+ LW_CPU_CLR(i, &cpuset); /* 绑核操作确保目标线程未就绪 */
+ /* 不需要使用 stop 操作 */
API_ThreadStart(_K_ulIdleId[i]);
}
diff --git a/SylixOS/kernel/core/_ThreadAffinity.c b/SylixOS/kernel/core/_ThreadAffinity.c
index 4b80fbb..7015535 100644
--- a/SylixOS/kernel/core/_ThreadAffinity.c
+++ b/SylixOS/kernel/core/_ThreadAffinity.c
@@ -36,13 +36,13 @@
** 全局变量:
** 调用模块:
** 注 意 : LW_CPU_ZERO(pcpuset) 可以解除 CPU 锁定.
+** 如果是设置其他 ptcb 则外层必须保证目标线程没有就绪或运行.
*********************************************************************************************************/
ULONG _ThreadSetAffinity (PLW_CLASS_TCB ptcb, size_t stSize, const PLW_CLASS_CPUSET pcpuset)
{
INTREG iregInterLevel;
ULONG i;
ULONG ulNumChk;
- ULONG ulError;
PLW_CLASS_TCB ptcbCur;
PLW_CLASS_PCB ppcb;
@@ -85,11 +85,6 @@ ULONG _ThreadSetAffinity (PLW_CLASS_TCB ptcb, size_t stSize, const PLW_CLASS_
}
} else {
- ulError = _ThreadStop(ptcb);
- if (ulError) {
- return (ulError);
- }
-
if (i >= ulNumChk) {
ptcb->TCB_bCPULock = LW_FALSE; /* 关闭 CPU 锁定 */
@@ -97,8 +92,6 @@ ULONG _ThreadSetAffinity (PLW_CLASS_TCB ptcb, size_t stSize, const PLW_CLASS_
ptcb->TCB_ulCPULock = i;
ptcb->TCB_bCPULock = LW_TRUE; /* 锁定执行 CPU */
}
-
- _ThreadContinue(ptcb, LW_FALSE); /* 唤醒目标 */
}
return (ERROR_NONE);
@@ -115,11 +108,10 @@ ULONG _ThreadSetAffinity (PLW_CLASS_TCB ptcb, size_t stSize, const PLW_CLASS_
*********************************************************************************************************/
VOID _ThreadGetAffinity (PLW_CLASS_TCB ptcb, size_t stSize, PLW_CLASS_CPUSET pcpuset)
{
+ lib_bzero(pcpuset, stSize); /* 没有亲和度设置 */
+
if (ptcb->TCB_bCPULock) {
LW_CPU_SET(ptcb->TCB_ulCPULock, pcpuset);
-
- } else {
- lib_bzero(pcpuset, stSize); /* 没有亲和度设置 */
}
}
/*********************************************************************************************************
diff --git a/SylixOS/kernel/include/k_api.h b/SylixOS/kernel/include/k_api.h
index b7074e8..7d5d993 100644
--- a/SylixOS/kernel/include/k_api.h
+++ b/SylixOS/kernel/include/k_api.h
@@ -288,11 +288,10 @@ LW_API PLW_CLASS_TCB API_ThreadTcbSelf(VOID); /* 获得
LW_API LW_OBJECT_HANDLE API_ThreadIdInter(VOID); /* 获得被中断线程 ID */
LW_API PLW_CLASS_TCB API_ThreadTcbInter(VOID); /* 获得被中断线程 TCB */
- /* 只在内核模块中使用 */
LW_API ULONG API_ThreadTcbById(LW_OBJECT_HANDLE ulId,
PLW_CLASS_TCB pctcb);
-#endif
+#endif /* 只在内核模块中使用 */
LW_API ULONG API_ThreadDesc(LW_OBJECT_HANDLE ulId,
PLW_CLASS_TCB_DESC ptcbdesc); /* 获得线程概要信息 */
diff --git a/SylixOS/kernel/include/k_globalvar.h b/SylixOS/kernel/include/k_globalvar.h
index 9b05fc3..740a091 100644
--- a/SylixOS/kernel/include/k_globalvar.h
+++ b/SylixOS/kernel/include/k_globalvar.h
@@ -50,6 +50,7 @@
*********************************************************************************************************/
__KERNEL_EXT VOIDFUNCPTR _K_pfuncKernelDebugLog; /* 内核调试信息 */
__KERNEL_EXT VOIDFUNCPTR _K_pfuncKernelDebugError; /* 内核错误信息 */
+__KERNEL_EXT VOIDFUNCPTR _K_pfuncKernelExc;
/*********************************************************************************************************
HOOK TABLE
*********************************************************************************************************/
diff --git a/SylixOS/kernel/include/k_kernel.h b/SylixOS/kernel/include/k_kernel.h
index 846c71f..b16a6f6 100644
--- a/SylixOS/kernel/include/k_kernel.h
+++ b/SylixOS/kernel/include/k_kernel.h
@@ -51,7 +51,7 @@
#define __SYLIXOS_MAJOR_VER 1
#define __SYLIXOS_MINOR_VER 10
-#define __SYLIXOS_PATCH_VER 6
+#define __SYLIXOS_PATCH_VER 7
#define __SYLIXOS_PATCH_PAD 0
/*********************************************************************************************************
diff --git a/SylixOS/kernel/interface/ThreadAffinity.c b/SylixOS/kernel/interface/ThreadAffinity.c
index 4088f9b..f985818 100644
--- a/SylixOS/kernel/interface/ThreadAffinity.c
+++ b/SylixOS/kernel/interface/ThreadAffinity.c
@@ -43,7 +43,7 @@ ULONG API_ThreadSetAffinity (LW_OBJECT_HANDLE ulId, size_t stSize, const PLW_
REGISTER UINT16 usIndex;
REGISTER PLW_CLASS_TCB ptcb;
PLW_CLASS_TCB ptcbCur;
- ULONG ulMaxLock;
+ ULONG ulError;
usIndex = _ObjectGetIndex(ulId);
@@ -82,14 +82,40 @@ ULONG API_ThreadSetAffinity (LW_OBJECT_HANDLE ulId, size_t stSize, const PLW_
}
LW_TCB_GET_CUR(ptcbCur);
- ulMaxLock = (ptcb == ptcbCur) ? 1 : 0;
- if (__THREAD_LOCK_GET(ptcb) > ulMaxLock) { /* 任务被锁定 */
+ if (ptcb == ptcbCur) {
+ if (__THREAD_LOCK_GET(ptcb) > 1) { /* 任务被锁定 */
+ __KERNEL_EXIT(); /* 退出内核 */
+ _ErrorHandle(EBUSY);
+ return (EBUSY);
+ }
+ _ThreadSetAffinity(ptcb, stSize, pcpuset); /* 设置 */
+
+ } else {
+ if (__THREAD_LOCK_GET(ptcb)) { /* 任务被锁定 */
+ __KERNEL_EXIT(); /* 退出内核 */
+ _ErrorHandle(EBUSY);
+ return (EBUSY);
+ }
+
+ ulError = _ThreadStop(ptcb);
__KERNEL_EXIT(); /* 退出内核 */
- _ErrorHandle(EBUSY);
- return (EBUSY);
+ if (ulError) {
+ return (ulError);
+ }
+
+#if LW_CFG_SMP_EN > 0
+ if (ptcbCur->TCB_uiStatusChangeReq) {
+ ptcbCur->TCB_uiStatusChangeReq = 0;
+ _ErrorHandle(ERROR_THREAD_NULL);
+ return (ERROR_THREAD_NULL);
+ }
+#endif /* LW_CFG_SMP_EN */
+
+ __KERNEL_ENTER(); /* 进入内核 */
+ _ThreadSetAffinity(ptcb, stSize, pcpuset); /* 设置 */
+ _ThreadContinue(ptcb, LW_FALSE); /* 唤醒目标 */
}
-
- _ThreadSetAffinity(ptcb, stSize, pcpuset); /* 设置 */
+
__KERNEL_EXIT(); /* 退出内核 */
return (ERROR_NONE);
diff --git a/SylixOS/kernel/vmm/vmmAbort.c b/SylixOS/kernel/vmm/vmmAbort.c
index 042daa2..aba7d93 100644
--- a/SylixOS/kernel/vmm/vmmAbort.c
+++ b/SylixOS/kernel/vmm/vmmAbort.c
@@ -972,13 +972,18 @@ static VOID __vmmAbortAccess (PLW_VMM_PAGE_FAIL_CTX pvmpagefailctx)
break;
default:
- printk(KERN_EMERG "ACCESS ERROR: abort in thread %lx[%s]. "
- "ret_addr: 0x%08lx abt_addr: 0x%08lx, abt_type: %s.\n",
- pvmpagefailctx->PAGEFCTX_ptcb->TCB_ulId,
- pvmpagefailctx->PAGEFCTX_ptcb->TCB_cThreadName,
- pvmpagefailctx->PAGEFCTX_ulRetAddr,
- pvmpagefailctx->PAGEFCTX_ulAbortAddr,
- __vmmAbortTypeStr(&pvmpagefailctx->PAGEFCTX_abtInfo)); /* 操作异常 */
+ if (_K_pfuncKernelExc) {
+ ((VOID(*)(INT))_K_pfuncKernelExc)(pabtctx->ABTCTX_abtInfo.VMABT_uiType);
+
+ } else {
+ printk(KERN_EMERG "ACCESS ERROR: abort in thread %lx[%s]. "
+ "ret_addr: 0x%08lx abt_addr: 0x%08lx, abt_type: %s.\n",
+ pabtctx->ABTCTX_ptcb->TCB_ulId,
+ pabtctx->ABTCTX_ptcb->TCB_cThreadName,
+ pabtctx->ABTCTX_ulRetAddr,
+ pabtctx->ABTCTX_ulAbortAddr,
+ __vmmAbortTypeStr(&pabtctx->ABTCTX_abtInfo)); /* 操作异常 */
+ }
break;
}
#endif /* LW_CFG_ABORT_BASIC_INFO_EN */
diff --git a/SylixOS/loader/src/loader_vpdebug.c b/SylixOS/loader/src/loader_vpdebug.c
index 12489a3..443cf3a 100644
--- a/SylixOS/loader/src/loader_vpdebug.c
+++ b/SylixOS/loader/src/loader_vpdebug.c
@@ -92,9 +92,6 @@ VOID vprocDebugStop (PVOID pvVProc, PLW_CLASS_TCB ptcbExcp)
plineTemp = _list_line_get_next(plineTemp)) {
ptcb = _LIST_ENTRY(plineTemp, LW_CLASS_TCB, TCB_lineProcess);
- if (ptcb->TCB_iDeleteProcStatus) {
- continue; /* 已经在删除过程中 */
- }
if (ptcb == ptcbExcp) {
continue; /* 不停止此任务 */
}
@@ -132,15 +129,14 @@ VOID vprocDebugContinue (PVOID pvVProc, PLW_CLASS_TCB ptcbExcp)
plineTemp = _list_line_get_next(plineTemp)) {
ptcb = _LIST_ENTRY(plineTemp, LW_CLASS_TCB, TCB_lineProcess);
- if (ptcb->TCB_iDeleteProcStatus) {
- continue; /* 已经在删除过程中 */
- }
if (ptcb == ptcbExcp) {
continue; /* 不启动此任务 */
}
- __KERNEL_ENTER(); /* 进入内核 */
- _ThreadContinue(ptcb, LW_FALSE);
- __KERNEL_EXIT(); /* 退出内核 */
+ if (ptcb->TCB_iDeleteProcStatus == LW_TCB_DELETE_PROC_NONE) {
+ __KERNEL_ENTER(); /* 进入内核 */
+ _ThreadContinue(ptcb, LW_FALSE);
+ __KERNEL_EXIT(); /* 退出内核 */
+ }
}
LW_VP_UNLOCK(pvproc); /* 解锁当前进程 */
}
diff --git a/SylixOS/loader/src/loader_vpthread.c b/SylixOS/loader/src/loader_vpthread.c
index 4ae0b61..0d49f51 100644
--- a/SylixOS/loader/src/loader_vpthread.c
+++ b/SylixOS/loader/src/loader_vpthread.c
@@ -248,29 +248,40 @@ INT vprocThreadAffinity (PVOID pvVProc, size_t stSize, const PLW_CLASS_CPUSET
{
LW_LD_VPROC *pvproc = (LW_LD_VPROC *)pvVProc;
PLW_LIST_LINE plineTemp;
- PLW_CLASS_TCB ptcb;
+ PLW_CLASS_TCB ptcb, ptcbCur;
if (!pvproc) {
_ErrorHandle(ESRCH);
return (PX_ERROR);
}
+ LW_TCB_GET_CUR_SAFE(ptcbCur);
+
LW_VP_LOCK(pvproc); /* 锁定当前进程 */
for (plineTemp = pvproc->VP_plineThread;
plineTemp != LW_NULL;
plineTemp = _list_line_get_next(plineTemp)) {
ptcb = _LIST_ENTRY(plineTemp, LW_CLASS_TCB, TCB_lineProcess);
- if (ptcb->TCB_iDeleteProcStatus) {
- continue; /* 已经在删除过程中 */
- }
if (__THREAD_LOCK_GET(ptcb)) { /* 外部没有锁定此任务 */
continue; /* 线程被锁定 */
}
- __KERNEL_ENTER(); /* 进入内核 */
- _ThreadSetAffinity(ptcb, stSize, pcpuset);
- __KERNEL_EXIT(); /* 退出内核 */
+ if (ptcb == ptcbCur) {
+ __KERNEL_ENTER(); /* 进入内核 */
+ _ThreadSetAffinity(ptcb, stSize, pcpuset);
+ __KERNEL_EXIT(); /* 退出内核 */
+
+ } else if (ptcb->TCB_iDeleteProcStatus == LW_TCB_DELETE_PROC_NONE) {
+ __KERNEL_ENTER(); /* 进入内核 */
+ _ThreadStop(ptcb);
+ __KERNEL_EXIT(); /* 退出内核 (可能产生调度) */
+
+ __KERNEL_ENTER(); /* 进入内核 */
+ _ThreadSetAffinity(ptcb, stSize, pcpuset);
+ _ThreadContinue(ptcb, LW_FALSE);
+ __KERNEL_EXIT(); /* 退出内核 */
+ }
}
LW_VP_UNLOCK(pvproc); /* 解锁当前进程 */
diff --git a/SylixOS/net/lwip/bonding/netbonding.c b/SylixOS/net/lwip/bonding/netbonding.c
index 84175cd..6903f12 100644
--- a/SylixOS/net/lwip/bonding/netbonding.c
+++ b/SylixOS/net/lwip/bonding/netbonding.c
@@ -106,6 +106,7 @@ typedef struct netbd {
sys_mutex_t lock; /* net bonding lock */
netdev_t netdev_bd; /* net bonding net device */
netbd_eth_t *master; /* master device */
+ netbd_eth_t *working; /* current device */
LW_LIST_RING_HEADER eth_ring; /* sub ethernet device ring */
LW_LIST_LINE_HEADER arp_list; /* arp detect list */
@@ -124,6 +125,34 @@ static sys_mutex_t netdb_list_lock;
#define NETBD_LIST_LOCK() sys_mutex_lock(&netdb_list_lock)
#define NETBD_LIST_UNLOCK() sys_mutex_unlock(&netdb_list_lock)
+/* net bonding select device */
+static void netbd_select_working (netbd_t *netbd)
+{
+ int i, ok = 0;
+ netbd_eth_t *netbd_eth;
+
+ if (netbd->master) {
+ netbd_eth = netbd->master; /* first check master device */
+ if (netbd_eth->alive && (netbd_eth->netdev->if_flags & IFF_RUNNING)) { /* is alive and linkup ? */
+ netbd->working = netbd_eth;
+ ok = 1;
+ }
+ }
+
+ if (!ok) {
+ for (i = 0; i < netbd->eth_cnt; i++) {
+ netbd_eth = (netbd_eth_t *)netbd->eth_ring;
+ if (netbd->master != netbd_eth) { /* not master */
+ if (netbd_eth->alive && (netbd_eth->netdev->if_flags & IFF_RUNNING)) { /* is alive and linkup ? */
+ netbd->working = netbd_eth;
+ break;
+ }
+ }
+ netbd->eth_ring = _list_ring_get_next(&netbd_eth->ring); /* next sub net device (Rotation) */
+ }
+ }
+}
+
/* net bonding traffic detect */
static void netbd_traffic_detect (netbd_t *netbd)
{
@@ -135,8 +164,12 @@ static void netbd_traffic_detect (netbd_t *netbd)
for (i = 0; i < netbd->eth_cnt; i++) {
if (netbd_eth->alive > NETBONDING_POLL_INTERVAL) {
netbd_eth->alive -= NETBONDING_POLL_INTERVAL;
- } else {
+
+ } else if (netbd_eth->alive) {
netbd_eth->alive = 0; /* dead! not use this device transmit */
+ if (netbd->working == netbd_eth) {
+ netbd_select_working(netbd);
+ }
}
netbd_eth = (netbd_eth_t *)_list_ring_get_next(&netbd_eth->ring);
}
@@ -158,8 +191,27 @@ static void netbd_arp_detect (netbd_t *netbd)
return;
}
- netbd_traffic_detect(netbd); /* process time alive */
-
+ NETBD_LOCK(netbd);
+ netbd_eth = (netbd_eth_t *)netbd->eth_ring;
+ for (i = 0; i < netbd->eth_cnt; i++) {
+ if (netbd->working == netbd_eth) {
+ if (netbd_eth->alive > NETBONDING_POLL_INTERVAL) {
+ netbd_eth->alive -= NETBONDING_POLL_INTERVAL;
+ } else {
+ netbd_eth->alive = 0; /* dead! not use this device transmit */
+ }
+
+ } else {
+ if (netbd_eth->netdev->if_flags & IFF_RUNNING) {
+ netbd_eth->alive = netbd->alive; /* not current, if linkup we think it is a valid */
+ } else {
+ netbd_eth->alive = 0;
+ }
+ }
+ netbd_eth = (netbd_eth_t *)_list_ring_get_next(&netbd_eth->ring);
+ }
+ NETBD_UNLOCK(netbd);
+
if (netbd->timer > NETBONDING_POLL_INTERVAL) {
netbd->timer -= NETBONDING_POLL_INTERVAL;
@@ -172,17 +224,17 @@ static void netbd_arp_detect (netbd_t *netbd)
NETBD_LOCK(netbd);
netdbif = (struct netif *)(netbd->netdev_bd.sys);
MEMCPY(&macsrc.addr, netdbif->hwaddr, ETH_ALEN);
+
+ if (!netbd->working->alive || !(netbd->working->netdev->if_flags & IFF_RUNNING)) {
+ netbd_select_working(netbd);
+ }
- for (pline = netbd->arp_list; pline != NULL; pline = _list_line_get_next(pline)) {
- netbd_arp = (netbd_arp_t *)pline;
- netbd_eth = (netbd_eth_t *)netbd->eth_ring;
- for (i = 0; i < netbd->eth_cnt; i++) {
- if (netbd_eth->netdev->if_flags & IFF_RUNNING) { /* is linkup ? */
- sendif = (struct netif *)(netbd_eth->netdev->sys);
- etharp_raw(sendif, &macsrc, &ethbroadcast, &macsrc, netif_ip4_addr(netdbif),
- &ethzero, &netbd_arp->ipaddr, ARP_REQUEST); /* send ARP request */
- }
- netbd_eth = (netbd_eth_t *)_list_ring_get_next(&netbd_eth->ring);
+ if (netbd->working->netdev->if_flags & IFF_RUNNING) {
+ for (pline = netbd->arp_list; pline != NULL; pline = _list_line_get_next(pline)) {
+ netbd_arp = (netbd_arp_t *)pline;
+ sendif = (struct netif *)(netbd->working->netdev->sys);
+ etharp_raw(sendif, &macsrc, &ethbroadcast, &macsrc, netif_ip4_addr(netdbif),
+ &ethzero, &netbd_arp->ipaddr, ARP_REQUEST); /* send ARP request */
}
}
NETBD_UNLOCK(netbd);
@@ -214,6 +266,9 @@ static void netbd_arp_process (netbd_t *netbd, netbd_eth_t *netbd_eth, struct et
for (pline = netbd->arp_list; pline != NULL; pline = _list_line_get_next(pline)) {
netbd_arp = (netbd_arp_t *)pline;
if (ip4_addr_cmp(&netbd_arp->ipaddr, &srcip)) {
+ if (!netbd->working->alive) {
+ netbd->working = netbd_eth; /* use this net device as working */
+ }
netbd_eth->alive = netbd->alive; /* refresh time alive counter */
break;
}
@@ -230,6 +285,12 @@ static int netbd_transmit (struct netdev *netdev, struct pbuf *p)
netbd_eth_t *netbd_eth;
struct ethhdr *eh = (struct ethhdr *)p->payload;
+ if (!netbd->eth_cnt) { /* no sub device */
+ netdev_linkinfo_err_inc(netdev);
+ netdev_statinfo_errors_inc(netdev, LINK_OUTPUT);
+ return (-1);
+ }
+
NETBD_LOCK(netbd);
if (netbd->mode == NETBD_MODE_BALANCE_RR) { /* 'balance-rr' */
for (i = 0; i < netbd->eth_cnt; i++) {
@@ -243,26 +304,34 @@ static int netbd_transmit (struct netdev *netdev, struct pbuf *p)
}
} else if (netbd->mode == NETBD_MODE_ACTIVE_BACKUP) { /* 'active-backup' */
- if (netbd->master) {
- netbd_eth = netbd->master; /* first check master device */
- if (netbd_eth->alive && (netbd_eth->netdev->if_flags & IFF_RUNNING)) { /* is alive and linkup ? */
- netbd_eth->netdev->drv->transmit(netbd_eth->netdev, p); /* transmit */
- ok = 1;
+ if (!netbd->working->alive || !(netbd->working->netdev->if_flags & IFF_RUNNING)) { /* working dead ? */
+ if (netbd->master) {
+ netbd_eth = netbd->master; /* first check master device */
+ if (netbd_eth->alive && (netbd_eth->netdev->if_flags & IFF_RUNNING)) { /* is alive and linkup ? */
+ netbd->working = netbd_eth;
+ netbd_eth->netdev->drv->transmit(netbd_eth->netdev, p); /* transmit */
+ ok = 1;
+ }
}
- }
-
- if (!ok) {
- for (i = 0; i < netbd->eth_cnt; i++) {
- netbd_eth = (netbd_eth_t *)netbd->eth_ring;
- if (netbd->master != netbd_eth) { /* not master */
- if (netbd_eth->alive && (netbd_eth->netdev->if_flags & IFF_RUNNING)) { /* is alive and linkup ? */
- netbd_eth->netdev->drv->transmit(netbd_eth->netdev, p); /* transmit */
- ok = 1;
- break;
+
+ if (!ok) {
+ for (i = 0; i < netbd->eth_cnt; i++) {
+ netbd_eth = (netbd_eth_t *)netbd->eth_ring;
+ if (netbd->master != netbd_eth) { /* not master */
+ if (netbd_eth->alive && (netbd_eth->netdev->if_flags & IFF_RUNNING)) { /* is alive and linkup ? */
+ netbd->working = netbd_eth;
+ netbd_eth->netdev->drv->transmit(netbd_eth->netdev, p); /* transmit */
+ ok = 1;
+ break;
+ }
}
+ netbd->eth_ring = _list_ring_get_next(&netbd_eth->ring); /* next sub net device (Rotation) */
}
- netbd->eth_ring = _list_ring_get_next(&netbd_eth->ring); /* next sub net device (Rotation) */
}
+
+ } else { /* use working transmit */
+ netbd->working->netdev->drv->transmit(netbd->working->netdev, p); /* transmit */
+ ok = 1;
}
} else { /* broadcast */
@@ -389,6 +458,9 @@ to_bd:
if (netbd->mode == NETBD_MODE_ACTIVE_BACKUP) { /* active backup */
if (netbd->mon_mode == NETBD_MON_MODE_TRAFFIC) {
+ if (!netbd->working->alive) {
+ netbd->working = netbd_eth; /* use this net device as working */
+ }
netbd_eth->alive = netbd->alive; /* refresh time alive counter */
} else { /* NETBD_MON_MODE_ARP */
@@ -416,6 +488,13 @@ to_bd:
}
input: /* TODO: this function may be parallelization, and statistical variables should be locked */
+ if (netbd->mode == NETBD_MODE_ACTIVE_BACKUP) {
+ if (netbd->working != netbd_eth) {
+ pbuf_free(p);
+ return (ERR_OK); /* not working net device */
+ }
+ }
+
if (netif_bd->input(p, netif_bd)) { /* send to our tcpip stack */
netdev_linkinfo_drop_inc(netdev_bd);
netdev_statinfo_discards_inc(netdev_bd, LINK_INPUT);
@@ -547,6 +626,8 @@ int netbd_add_dev (const char *bddev, int bdindex, const char *sub, int sub_is_
MEMCPY(netdev_bd->hwaddr, netdev->hwaddr, ETH_ALEN); /* use first port mac address */
MEMCPY(netif_bd->hwaddr, netdev->hwaddr, ETH_ALEN);
+
+ netbd->working = netbd_eth; /* first working net device */
}
MEMCPY(netbd_eth->old_hwaddr, netdev->hwaddr, ETH_ALEN); /* save old hwaddr */
@@ -705,6 +786,9 @@ int netbd_delete_dev (const char *bddev, int bdindex, const char *sub, int sub_
}
}
+ netif->input = netbd_eth->input; /* restore old input function */
+ netif->ext_ctl = netif->ext_eth = NULL;
+
NETBD_LOCK(netbd);
if (netbd->master == netbd_eth) {
netbd->master = NULL;
@@ -712,11 +796,15 @@ int netbd_delete_dev (const char *bddev, int bdindex, const char *sub, int sub_
netif->vlanid = netbd_eth->old_vlanid;
_List_Ring_Del(&netbd_eth->ring, &netbd->eth_ring);
netbd->eth_cnt--;
+ if (netbd->working == netbd_eth) {
+ if (netbd->eth_cnt) {
+ netbd_select_working(netbd);
+ } else {
+ netbd->working = NULL;
+ }
+ }
NETBD_UNLOCK(netbd);
- netif->input = netbd_eth->input; /* restore old input function */
- netif->ext_ctl = netif->ext_eth = NULL;
-
mem_free(netbd_eth);
if (!(netdev->init_flags & NETDEV_INIT_TIGHT)) {
@@ -1280,6 +1368,12 @@ int netbd_show_dev (const char *bddev, int bdindex, int fd)
fdprintf(fd, "Moniting : %s\n", (netbd->mon_mode == NETBD_MON_MODE_TRAFFIC) ? "Traffic" : "ARP Detect");
fdprintf(fd, "Timeout : %d (milliseconds)\n", netbd->alive);
+ if (netbd->working) {
+ netdev = netbd->working->netdev;
+ netif = (struct netif *)netdev->sys;
+ fdprintf(fd, "Working : Dev: %s Prev-Ifname: %s\n", netdev->dev_name, netif_get_name(netif, ifname));
+ }
+
if (netbd->mon_mode == NETBD_MON_MODE_ARP) {
fdprintf(fd, "ARP Interval: %d (milliseconds)\n", netbd->interval);
fdprintf(fd, "\nNet bonding ARP target list >>\n\n");
diff --git a/SylixOS/net/lwip/bridge/netbridge.c b/SylixOS/net/lwip/bridge/netbridge.c
index 5420675..3bbc1db 100644
--- a/SylixOS/net/lwip/bridge/netbridge.c
+++ b/SylixOS/net/lwip/bridge/netbridge.c
@@ -555,13 +555,13 @@ int netbr_delete_dev (const char *brdev, int brindex, const char *sub, int sub_
}
}
+ netif->input = netbr_eth->input; /* restore old input function */
+ netif->ext_ctl = netif->ext_eth = NULL;
+
NETBR_LOCK(netbr);
_List_Line_Del(&netbr_eth->list, &netbr->eth_list);
NETBR_UNLOCK(netbr);
- netif->input = netbr_eth->input; /* restore old input function */
- netif->ext_ctl = netif->ext_eth = NULL;
-
mem_free(netbr_eth);
if (!(netdev->init_flags & NETDEV_INIT_TIGHT)) {
diff --git a/SylixOS/posix/gjbext/gjb_interrupt.c b/SylixOS/posix/gjbext/gjb_interrupt.c
index 8237893..a292dbf 100644
--- a/SylixOS/posix/gjbext/gjb_interrupt.c
+++ b/SylixOS/posix/gjbext/gjb_interrupt.c
@@ -189,10 +189,20 @@ int int_uninstall_handler (int vecnum)
LW_API
EXC_HANDLER exception_handler_set (EXC_HANDLER exc_handler)
{
- (VOID)exc_handler;
-
- errno = ENOSYS;
- return (LW_NULL);
+ EXC_HANDLER old_exc_handler;
+ INTREG iregInterLevel;
+
+ if (getpid() > 0) {
+ errno = EACCES;
+ return (LW_NULL);
+ }
+
+ LW_SPIN_KERN_LOCK_QUICK(&iregInterLevel);
+ old_exc_handler = (EXC_HANDLER)_K_pfuncKernelExc;
+ _K_pfuncKernelExc = (VOIDFUNCPTR)exc_handler;
+ LW_SPIN_KERN_UNLOCK_QUICK(iregInterLevel);
+
+ return (old_exc_handler);
}
/*********************************************************************************************************
** 函数名称: shared_int_install
diff --git a/SylixOS/posix/gjbext/gjb_timerel.c b/SylixOS/posix/gjbext/gjb_timerel.c
index 9155288..f78e42c 100644
--- a/SylixOS/posix/gjbext/gjb_timerel.c
+++ b/SylixOS/posix/gjbext/gjb_timerel.c
@@ -51,7 +51,11 @@ uint64_t tick_get (void)
LW_API
void tick_set (uint64_t ticks)
{
- errno = ENOTSUP;
+ INTREG iregInterLevel;
+
+ LW_SPIN_KERN_LOCK_QUICK(&iregInterLevel);
+ _K_atomic64KernelTime.counter = ticks;
+ LW_SPIN_KERN_UNLOCK_QUICK(iregInterLevel);
}
/*********************************************************************************************************
** 函数名称: sys_clk_rate_get
@@ -79,8 +83,13 @@ uint32_t sys_clk_rate_get (void)
LW_API
int sys_clk_rate_set (int ticks_per_second)
{
- errno = ENOTSUP;
- return (PX_ERROR);
+ INTREG iregInterLevel;
+
+ LW_SPIN_KERN_LOCK_QUICK(&iregInterLevel);
+ LW_TICK_HZ = ticks_per_second;
+ LW_SPIN_KERN_UNLOCK_QUICK(iregInterLevel);
+
+ return (ERROR_NONE);
}
/*********************************************************************************************************
** 函数名称: wdg_create
diff --git a/SylixOS/posix/mqueue/mqueue.c b/SylixOS/posix/mqueue/mqueue.c
index ccbf4fc..a28188b 100644
--- a/SylixOS/posix/mqueue/mqueue.c
+++ b/SylixOS/posix/mqueue/mqueue.c
@@ -753,6 +753,10 @@ mqd_t mq_open (const char *name, int flag, ...)
return (MQ_FAILED);
}
+#if LW_CFG_GJB7714_EN > 0
+ mq_open_method(MQ_OPEN_METHOD_GJB, NULL);
+#endif
+
__PX_LOCK(); /* 锁住 posix */
pxnode = __pxnameSeach(name, -1);
if (pxnode) { /* 找到 */
diff --git a/SylixOS/posix/semaphore/semaphore.c b/SylixOS/posix/semaphore/semaphore.c
index 39d6a2f..6786557 100644
--- a/SylixOS/posix/semaphore/semaphore.c
+++ b/SylixOS/posix/semaphore/semaphore.c
@@ -278,6 +278,10 @@ sem_t *sem_open (const char *name, int flag, ...)
return (SEM_FAILED);
}
+#if LW_CFG_GJB7714_EN > 0
+ sem_open_method(SEM_OPEN_METHOD_GJB, NULL);
+#endif
+
__PX_LOCK(); /* 锁住 posix */
pxnode = __pxnameSeach(name, -1);
if (pxnode) { /* 找到 */
diff --git a/SylixOS/system/device/1553B/bus1553.c b/SylixOS/system/device/1553B/bus1553.c
new file mode 100644
index 0000000..caa24be
--- /dev/null
+++ b/SylixOS/system/device/1553B/bus1553.c
@@ -0,0 +1,1050 @@
+/*********************************************************************************************************
+**
+** 中国软件开源组织
+**
+** 嵌入式实时操作系统
+**
+** SylixOS(TM) LW : long wing
+**
+** Copyright All Rights Reserved
+**
+**--------------文件信息--------------------------------------------------------------------------------
+**
+** 文 件 名: bus1553.c
+**
+** 创 建 人: Zhu.Jianhui (朱剑辉)
+**
+** 文件创建日期: 2019 年 08 月 05 日
+**
+** 描 述: 1553B 总线驱动支持.
+*********************************************************************************************************/
+#define __SYLIXOS_KERNEL
+#include "../SylixOS/kernel/include/k_kernel.h"
+#include "../SylixOS/system/include/s_system.h"
+#include "../SylixOS/fs/include/fs_fs.h" /* 需要根文件系统时间 */
+#include "bus1553.h"
+
+
+/*********************************************************************************************************
+ 定义全局变量, 用于保存1553驱动号
+*********************************************************************************************************/
+static INT _G_1553DrvNum = PX_ERROR;
+
+/*********************************************************************************************************
+ 定义 1553 缓冲队列结构体
+*********************************************************************************************************/
+typedef struct {
+ UINT Q_counter; /* 当前缓冲区数据帧个数 */
+ UINT Q_maxFrame; /* 最大数据帧个数 */
+ P1553DATA_FRAME Q_p1553frameIn; /* 入队指针*/
+ P1553DATA_FRAME Q_p1553frameOut; /* 出队指针*/
+ P1553DATA_FRAME Q_p1553frameEnd; /* 队尾 */
+ P1553DATA_FRAME Q_p1553frameBuffer; /* 队头,缓冲区的首地址*/
+} _1553_QUEUE, *P1553_QUEUE;
+
+/*********************************************************************************************************
+ _1553_DEV_WR_STATE
+*********************************************************************************************************/
+typedef struct {
+ BOOL STAT1553_bBufEmpty; /* FIFO 空标志*/
+} _1553_DEV_STATE;
+
+/*********************************************************************************************************
+ 1553 设备结构
+*********************************************************************************************************/
+typedef struct {
+ LW_DEV_HDR _1553_devhdr; /* 设备头*/
+ UINT _1553_channel; /* 1553 通道号 */
+
+ P1553_QUEUE _1553_pRecvQueue; /* 接收队列*/
+ P1553_QUEUE _1553_pSendQueue; /* 发送队列 */
+
+ LW_HANDLE _1553_recvSemB; /* 1553 接收信号*/
+ LW_HANDLE _1553_sendSemB; /* 1553 发送信号*/
+ LW_HANDLE _1553_mutexSemM; /* 互斥信号*/
+
+ _1553_DEV_STATE _1553_readState; /* 读状态 */
+ _1553_DEV_STATE _1553_writeState; /* 写状态 */
+ UINT _1553_busState; /* 总线状态*/
+
+ ULONG _1553_sendTimeout; /* 发送超时时间*/
+ ULONG _1553_recvTimeout; /* 接收超时时间 */
+
+ LW_SEL_WAKEUPLIST _1553_selwulList; /* select() 等待链 */
+
+ LW_SPINLOCK_DEFINE (_1553_spLock); /* 自旋锁 */
+} _1553_DEV;
+
+typedef struct {
+ _1553_DEV PORT_1553Dev; /* 1553 设备 */
+ CHAN_1553 *PORT_1553Chan; /* 1553 设备通道*/
+} _1553_PORT, *P1553_PORT;
+
+/*********************************************************************************************************
+ 1553 LOCK
+*********************************************************************************************************/
+#define PORT1553_LOCK(p1553port) \
+ API_SemaphoreMPend(p1553port->PORT_1553Dev._1553_mutexSemM, LW_OPTION_WAIT_INFINITE)
+#define PORT1553_UNLOCK(p1553port) \
+ API_SemaphoreMPost(p1553port->PORT_1553Dev._1553_mutexSemM)
+
+#define DEV1553_LOCK(p1553dev) \
+ API_SemaphoreMPend(p1553dev->_1553_mutexSemM, LW_OPTION_WAIT_INFINITE)
+#define DEV1553_UNLOCK(p1553dev) \
+ API_SemaphoreMPost(p1553dev->_1553_mutexSemM)
+
+/*********************************************************************************************************
+** 函数名称: __1553InitQueue
+** 功能描述: 缓冲初始化
+** 输 入 : uiMaxFrame 缓冲区 1553帧个数
+** 输 出 : 缓冲区指针
+** 全局变量:
+** 调用模块:
+*********************************************************************************************************/
+static P1553_QUEUE __1553InitQueue (UINT uiMaxFrame)
+{
+ size_t stAllocSize;
+ _1553_QUEUE *p1553queue = NULL;
+
+ stAllocSize = (size_t)(sizeof(_1553_QUEUE) + (uiMaxFrame * sizeof(FRAME_1553DATA)));
+ p1553queue = (_1553_QUEUE *)__SHEAP_ALLOC(stAllocSize);
+ if (p1553queue == LW_NULL) {
+ return (LW_NULL);
+ }
+
+ p1553queue->Q_counter = 0;
+ p1553queue->Q_maxFrame = uiMaxFrame;
+ p1553queue->Q_p1553frameBuffer = (P1553DATA_FRAME)(p1553queue + 1);
+ p1553queue->Q_p1553frameIn = p1553queue->Q_p1553frameBuffer;
+ p1553queue->Q_p1553frameOut = p1553queue->Q_p1553frameBuffer;
+ p1553queue->Q_p1553frameEnd = p1553queue->Q_p1553frameBuffer + p1553queue->Q_maxFrame;
+
+ return (p1553queue);
+}
+/*********************************************************************************************************
+** 函数名称: __1553WriteQueue
+** 功能描述: 向队列中写入数据
+** 输 入 :
+** p1553dev 指向设备结构
+** p1553queue 队列指针
+** p1553frame 指向要写入数据的指针
+** iNumber 要写入的个数
+** 输 出 : 实际写入的个数
+** 全局变量:
+** 调用模块:
+*********************************************************************************************************/
+static INT __1553WriteQueue (_1553_DEV *p1553dev,
+ P1553_QUEUE p1553queue,
+ P1553DATA_FRAME p1553frame,
+ INT iNumber)
+{
+ INT i = 0;
+ INTREG iregInterLevel;
+
+ while (iNumber) {
+ /*
+ * 关中断,将关中断放在这里是为了关中断时间可预测
+ */
+ LW_SPIN_LOCK_QUICK(&p1553dev->_1553_spLock, &iregInterLevel);
+ if (p1553queue->Q_counter < p1553queue->Q_maxFrame) { /* 更新接收队列*/
+ p1553queue->Q_counter++;
+ p1553queue->Q_p1553frameIn[0] = *p1553frame;
+ p1553queue->Q_p1553frameIn++;
+ if (p1553queue->Q_p1553frameIn >= p1553queue->Q_p1553frameEnd) {
+ p1553queue->Q_p1553frameIn = p1553queue->Q_p1553frameBuffer;
+ }
+ iNumber--;
+ p1553frame++;
+ i++;
+ } else {
+ LW_SPIN_UNLOCK_QUICK(&p1553dev->_1553_spLock, iregInterLevel);
+ break;
+ }
+ LW_SPIN_UNLOCK_QUICK(&p1553dev->_1553_spLock, iregInterLevel);
+ }
+
+ return (i);
+}
+/*********************************************************************************************************
+** 函数名称: __1553ReadQueue
+** 功能描述: 向队列中写入数据
+** 输 入 :
+** p1553dev 指向设备结构
+** p1553queue 队列指针
+** p1553frame 指向要读出数据的指针
+** iNumber 要读出的个数
+** 输 出 : 实际读出的个数
+** 全局变量:
+** 调用模块:
+*********************************************************************************************************/
+static INT __1553ReadQueue (_1553_DEV *p1553dev,
+ P1553_QUEUE p1553queue,
+ P1553DATA_FRAME p1553frame,
+ INT iNumber)
+{
+ INT i = 0;
+ INTREG iregInterLevel;
+
+ while (iNumber) {
+ /*
+ * 关中断,将关中断放在这里是为了关中断时间可预测
+ */
+ LW_SPIN_LOCK_QUICK(&p1553dev->_1553_spLock, &iregInterLevel);
+ if (p1553queue->Q_counter > 0) {
+ p1553queue->Q_counter--;
+ *p1553frame = p1553queue->Q_p1553frameOut[0];
+ p1553queue->Q_p1553frameOut++;
+ if (p1553queue->Q_p1553frameOut == p1553queue->Q_p1553frameEnd) {
+ p1553queue->Q_p1553frameOut = p1553queue->Q_p1553frameBuffer;
+ }
+ iNumber--;
+ p1553frame++;
+ i++;
+ } else {
+ LW_SPIN_UNLOCK_QUICK(&p1553dev->_1553_spLock, iregInterLevel);
+ break;
+ }
+ LW_SPIN_UNLOCK_QUICK(&p1553dev->_1553_spLock, iregInterLevel);
+ }
+
+ return (i);
+}
+/*********************************************************************************************************
+** 函数名称: __1553QFreeNum
+** 功能描述: 获取队列中空闲数量
+** 输 入 : p1553queue 队列指针
+** 输 出 : 空闲数量
+** 全局变量:
+** 调用模块:
+*********************************************************************************************************/
+static INT __1553QFreeNum (P1553_QUEUE p1553queue)
+{
+
+ REGISTER INT iNum;
+
+ iNum = p1553queue->Q_maxFrame - p1553queue->Q_counter;
+
+ return (iNum);
+}
+/*********************************************************************************************************
+** 函数名称: __1553QCount
+** 功能描述: 队列中消息的数量
+** 输 入 :
+** p1553queue 队列指针
+** 输 出 : 队列中有用数据的个数
+** 全局变量:
+** 调用模块:
+*********************************************************************************************************/
+static INT __1553QCount (P1553_QUEUE p1553queue)
+{
+ return (p1553queue->Q_counter);
+}
+/*********************************************************************************************************
+** 函数名称: __1553FlushQueue
+** 功能描述: 清空队列
+** 输 入 :
+** p1553Queue 队列指针
+** 输 出 : NONE
+** 全局变量:
+** 调用模块:
+*********************************************************************************************************/
+static VOID __1553FlushQueue (P1553_QUEUE p1553queue)
+{
+ p1553queue->Q_counter = 0;
+ p1553queue->Q_p1553frameIn = p1553queue->Q_p1553frameBuffer;
+ p1553queue->Q_p1553frameOut = p1553queue->Q_p1553frameBuffer;
+}
+/*********************************************************************************************************
+** 函数名称: __1553DeleteQueue
+** 功能描述: 删除队列
+** 输 入 :
+** p1553queue 队列指针
+** 输 出 : NONE
+** 全局变量:
+** 调用模块:
+*********************************************************************************************************/
+static VOID __1553DeleteQueue (P1553_QUEUE p1553queue)
+{
+ __SHEAP_FREE((PVOID)p1553queue);
+}
+
+/*********************************************************************************************************
+** 函数名称: __1553FlushRd
+** 功能描述: 清除1553设备读缓冲区
+** 输 入 : p1553port 1553设备
+** 输 出 : NONE
+** 全局变量:
+** 调用模块:
+*********************************************************************************************************/
+static VOID __1553FlushRd (_1553_PORT *p1553port)
+{
+ INTREG iregInterLevel;
+
+ PORT1553_LOCK(p1553port); /* 等待设备使用权*/
+
+ LW_SPIN_LOCK_QUICK(&p1553port->PORT_1553Dev._1553_spLock, &iregInterLevel);
+ __1553FlushQueue(p1553port->PORT_1553Dev._1553_pRecvQueue); /* 清除缓冲区*/
+ LW_SPIN_UNLOCK_QUICK(&p1553port->PORT_1553Dev._1553_spLock, iregInterLevel);
+
+ API_SemaphoreBClear(p1553port->PORT_1553Dev._1553_recvSemB); /* 清除读同步*/
+
+ PORT1553_UNLOCK(p1553port); /* 释放设备使用权*/
+}
+
+/*********************************************************************************************************
+** 函数名称: __1553FlushWrt
+** 功能描述: 清除1553 设备写缓冲区
+** 输 入 : p1553port 1553 设备
+** 输 出 : NONE
+** 全局变量:
+** 调用模块:
+*********************************************************************************************************/
+static VOID __1553FlushWrt (_1553_PORT *p1553port)
+{
+ INTREG iregInterLevel;
+
+ PORT1553_LOCK(p1553port); /* 等待设备使用权*/
+
+ LW_SPIN_LOCK_QUICK(&p1553port->PORT_1553Dev._1553_spLock, &iregInterLevel);
+ __1553FlushQueue(p1553port->PORT_1553Dev._1553_pSendQueue); /* 清除缓冲区*/
+ p1553port->PORT_1553Dev._1553_writeState.STAT1553_bBufEmpty = LW_TRUE; /* 发送队列空*/
+ LW_SPIN_UNLOCK_QUICK(&p1553port->PORT_1553Dev._1553_spLock, iregInterLevel);
+
+ API_SemaphoreBPost(p1553port->PORT_1553Dev._1553_sendSemB); /* 通知线程可写*/
+
+ PORT1553_UNLOCK(p1553port); /* 释放设备使用权*/
+
+ SEL_WAKE_UP_ALL(&p1553port->PORT_1553Dev._1553_selwulList, SELWRITE); /* 通知 select 线程可写*/
+}
+
+/*********************************************************************************************************
+** 函数名称: __1553GetFrameFromTxQueue
+** 功能描述: 从发送缓冲区中读出一帧数据
+** 输 入 :
+** p1553dev 1553 设备
+** p1553frame 指向待读出的数据
+** 输 出 : ERROR_NONE or PX_ERROR
+** 全局变量:
+** 调用模块:
+*********************************************************************************************************/
+static INT __1553GetFrameFromTxQueue (_1553_DEV *p1553dev, P1553DATA_FRAME p1553frame)
+{
+ INTREG iregInterLevel;
+ INT iTemp = 0;
+
+ if (!p1553dev || !p1553frame) {
+ return (PX_ERROR);
+ }
+
+ iTemp = __1553ReadQueue(p1553dev,
+ p1553dev->_1553_pSendQueue,
+ p1553frame, 1); /* 从发送队列中读取一帧数据*/
+
+ LW_SPIN_LOCK_QUICK(&p1553dev->_1553_spLock, &iregInterLevel);
+ if (iTemp <= 0) {
+ p1553dev->_1553_writeState.STAT1553_bBufEmpty = LW_TRUE; /* 发送队列空*/
+ }
+ LW_SPIN_UNLOCK_QUICK(&p1553dev->_1553_spLock, iregInterLevel);
+
+ API_SemaphoreBPost(p1553dev->_1553_sendSemB); /* 释放信号量*/
+ SEL_WAKE_UP_ALL(&p1553dev->_1553_selwulList, SELWRITE); /* 释放所有等待写的线程*/
+
+ return ((iTemp) ? (ERROR_NONE) : (PX_ERROR));
+}
+/*********************************************************************************************************
+** 函数名称: __1553PutFrameToRxQueue
+** 功能描述: 向接收缓冲区中写入一帧数据
+** 输 入 :
+** p1553dev 1553 设备
+** p1553frame 指向待写入的数据
+** 输 出 : ERROR_NONE or PX_ERROR
+** 全局变量:
+** 调用模块:
+*********************************************************************************************************/
+static INT __1553PutFrameToRxQueue (_1553_DEV *p1553dev, P1553DATA_FRAME p1553frame)
+{
+ INT iTemp = 0;
+
+ if (!p1553dev || !p1553frame) {
+ return (PX_ERROR);
+ }
+
+ iTemp = __1553WriteQueue(p1553dev,
+ p1553dev->_1553_pRecvQueue,
+ p1553frame, 1); /* 往接收队列中写入一帧数据 */
+
+ API_SemaphoreBPost(p1553dev->_1553_recvSemB); /* 释放信号量*/
+ SEL_WAKE_UP_ALL(&p1553dev->_1553_selwulList, SELREAD); /* select() 激活*/
+
+ return ((iTemp) ? (ERROR_NONE) : (PX_ERROR));
+}
+/*********************************************************************************************************
+** 函数名称: __1553TxStartup
+** 功能描述: 启动发送函数
+** 输 入 : p1553port 1553 通道
+** 输 出 : NONE
+** 全局变量:
+** 调用模块:
+*********************************************************************************************************/
+static VOID __1553TxStartup (_1553_PORT *p1553port)
+{
+ INTREG iregInterLevel;
+
+ if (p1553port->PORT_1553Dev._1553_writeState.STAT1553_bBufEmpty == LW_TRUE) {
+ LW_SPIN_LOCK_QUICK(&p1553port->PORT_1553Dev._1553_spLock, &iregInterLevel); /* 关闭中断*/
+ if (p1553port->PORT_1553Dev._1553_writeState.STAT1553_bBufEmpty == LW_TRUE) {
+ p1553port->PORT_1553Dev._1553_writeState.STAT1553_bBufEmpty = LW_FALSE;
+ LW_SPIN_UNLOCK_QUICK(&p1553port->PORT_1553Dev._1553_spLock, iregInterLevel); /* 打开中断*/
+ p1553port->PORT_1553Chan->pDrvFuncs->txStartup(p1553port->PORT_1553Chan);/* 启动发送*/
+ return;
+ }
+ LW_SPIN_UNLOCK_QUICK(&p1553port->PORT_1553Dev._1553_spLock, iregInterLevel);/* 打开中断*/
+ }
+}
+/*********************************************************************************************************
+** 函数名称: __1553SetBusState
+** 功能描述: 设置 1553 设备的总线状态
+** 输 入 :
+** p1553dev 1553 设备
+** iState 总线状态
+** 输 出 : ERROR_NONE or PX_ERROR
+** 全局变量:
+** 调用模块:
+*********************************************************************************************************/
+static VOID __1553SetBusState (_1553_DEV *p1553dev, INT iState)
+{
+ INTREG iregInterLevel;
+ _1553_PORT *p1553port = (_1553_PORT *)p1553dev;////////有这个必要吗????下面全是对dev操作
+
+ LW_SPIN_LOCK_QUICK(&p1553port->PORT_1553Dev._1553_spLock, &iregInterLevel);
+ if (iState) {
+ p1553dev->_1553_busState |= iState;
+ } else {
+ p1553dev->_1553_busState = _1553_DEV_BUS_OK;
+ }
+ LW_SPIN_UNLOCK_QUICK(&p1553port->PORT_1553Dev._1553_spLock, iregInterLevel);
+
+ if (p1553dev->_1553_busState != _1553_DEV_BUS_OK) { /* 总线异常*/
+ API_SemaphoreBFlush(p1553dev->_1553_sendSemB, LW_NULL); /* 激活写等待任务*/
+ API_SemaphoreBFlush(p1553dev->_1553_recvSemB, LW_NULL); /* 激活读等待任务*/
+ SEL_WAKE_UP_ALL(&p1553dev->_1553_selwulList, SELEXCEPT); /* select() 激活*/
+
+ //////////总线异常需要复位吗?///////////////
+ }
+}
+
+/*********************************************************************************************************
+** 函数名称: __1553DevInit
+** 功能描述: 创建1553 设备
+** 输 入 :
+** p1553dev 1553设备
+** uiRdFrameSize 接收缓冲区大小
+** uiWrtFrameSize 发送缓冲区大小
+** 输 出 : ERROR_NONE or PX_ERROR
+** 全局变量:
+** 调用模块:
+*********************************************************************************************************/
+static INT __1553DevInit (_1553_DEV *p1553dev,
+ UINT uiRdFrameSize,
+ UINT uiWrtFrameSize)
+{
+ REGISTER INT iErrLevel = 0;
+
+ p1553dev->_1553_sendTimeout = LW_OPTION_WAIT_INFINITE; /* 初始化为永久等待 */
+ p1553dev->_1553_recvTimeout = LW_OPTION_WAIT_INFINITE; /* 初始化为永久等待*/
+
+ p1553dev->_1553_pRecvQueue = __1553InitQueue(uiRdFrameSize); /* 创建读缓冲区*/
+ if (p1553dev->_1553_pRecvQueue == LW_NULL) { /* 创建失败*/
+ _DebugHandle(__ERRORMESSAGE_LEVEL, "system low memory.\r\n");
+ _ErrorHandle(ERROR_SYSTEM_LOW_MEMORY);
+ return (PX_ERROR);
+ }
+
+ p1553dev->_1553_pSendQueue = __1553InitQueue(uiWrtFrameSize); /* 创建写缓冲区*/
+ if (p1553dev->_1553_pSendQueue == LW_NULL) { /* 创建失败*/
+ _DebugHandle(__ERRORMESSAGE_LEVEL, "system low memory.\r\n");
+ _ErrorHandle(ERROR_SYSTEM_LOW_MEMORY);
+ iErrLevel = 1;
+ goto __error_handle;
+ }
+ p1553dev->_1553_writeState.STAT1553_bBufEmpty = LW_TRUE; /* 发送队列空*/
+ p1553dev->_1553_busState = _1553_DEV_BUS_OK; /* 发送队列空*/
+ p1553dev->_1553_recvSemB = API_SemaphoreBCreate("1553_rsync",
+ LW_FALSE,
+ LW_OPTION_WAIT_PRIORITY | LW_OPTION_OBJECT_GLOBAL,
+ LW_NULL); /* 读同步*/
+ if (!p1553dev->_1553_recvSemB) {
+ iErrLevel = 2;
+ goto __error_handle;
+ }
+
+ p1553dev->_1553_sendSemB = API_SemaphoreBCreate("1553_wsync",
+ LW_TRUE,
+ LW_OPTION_WAIT_PRIORITY | LW_OPTION_OBJECT_GLOBAL,
+ LW_NULL); /* 写同步*/
+ if (!p1553dev->_1553_sendSemB) {
+ iErrLevel = 3;
+ goto __error_handle;
+ }
+
+ p1553dev->_1553_mutexSemM = API_SemaphoreMCreate("1553_lock",
+ LW_PRIO_DEF_CEILING,
+ LW_OPTION_WAIT_PRIORITY |
+ LW_OPTION_DELETE_SAFE |
+ LW_OPTION_INHERIT_PRIORITY |
+ LW_OPTION_OBJECT_GLOBAL,
+ LW_NULL); /* 互斥访问控制信号量*/
+ if (!p1553dev->_1553_mutexSemM) {
+ iErrLevel = 4;
+ goto __error_handle;
+ }
+
+ SEL_WAKE_UP_LIST_INIT(&p1553dev->_1553_selwulList); /* 初始化 select 等待链*/
+
+ LW_SPIN_INIT(&p1553dev->_1553_spLock); /* 初始化自旋锁*/
+
+ return (ERROR_NONE);
+
+__error_handle:
+ if (iErrLevel > 3) {
+ API_SemaphoreBDelete(&p1553dev->_1553_sendSemB); /* 删除写同步 */
+ }
+ if (iErrLevel > 2) {
+ API_SemaphoreBDelete(&p1553dev->_1553_recvSemB); /* 删除读同步*/
+ }
+ if (iErrLevel > 1) {
+ __1553DeleteQueue(p1553dev->_1553_pSendQueue); /* 删除读缓冲区*/
+ }
+ if (iErrLevel > 0) {
+ __1553DeleteQueue(p1553dev->_1553_pRecvQueue); /* 删除写缓冲区*/
+ }
+ return (PX_ERROR);
+}
+
+/*********************************************************************************************************
+** 函数名称: _1553DevDelete
+** 功能描述: 删除1553 设备资源
+** 输 入 : p1553Dev 1553 设备
+** 输 出 : NONE
+** 全局变量:
+** 调用模块:
+*********************************************************************************************************/
+static VOID __1553DevDelete (_1553_DEV *p1553Dev)
+{
+ __1553DeleteQueue(p1553Dev->_1553_pRecvQueue);
+ __1553DeleteQueue(p1553Dev->_1553_pSendQueue);
+
+ API_SemaphoreBDelete(&p1553Dev->_1553_recvSemB);
+ API_SemaphoreBDelete(&p1553Dev->_1553_sendSemB);
+ API_SemaphoreMDelete(&p1553Dev->_1553_mutexSemM);
+}
+
+/*********************************************************************************************************
+** 函数名称: __1553Ioctl
+** 功能描述: 1553 设备控制
+** 输 入 :
+** p1553dev 1553 设备
+** iCmd 控制命令
+** lArg 参数
+** 输 出 : ERROR_NONE or PX_ERROR
+** 全局变量:
+** 调用模块:
+*********************************************************************************************************/
+static INT __1553Ioctl (_1553_DEV *p1553dev, INT iCmd, LONG lArg)
+{
+ INTREG iregInterLevel;
+ INT iStatus = ERROR_NONE;
+ struct stat *pstat;
+ PLW_SEL_WAKEUPNODE pselwunNode;
+
+ struct timeval *timevalTemp;
+
+ _1553_PORT *p1553port = (_1553_PORT *)p1553dev;
+ DRV_FUNCS_1553 *p1553DevFuncs = p1553port->PORT_1553Chan->pDrvFuncs;
+
+ DEV1553_LOCK(p1553dev); /* 等待设备使用权*/
+
+ if (p1553DevFuncs->ioctl) {
+ iStatus = p1553DevFuncs->ioctl(p1553port->PORT_1553Chan, iCmd, (PVOID)lArg);
+
+ } else {
+ iStatus = ENOSYS;
+ }
+
+ if ((iStatus == ENOSYS) ||
+ ((iStatus == PX_ERROR) && (errno == ENOSYS))) { /* 驱动程序无法识别的命令*/
+
+ iStatus = ERROR_NONE; /* 清除驱动程序错误*/
+
+ switch (iCmd) {
+
+ case FIONREAD: /* 读缓冲区有效数据数量 */
+ {
+ LONG lNFrame = __1553QCount(p1553dev->_1553_pRecvQueue);
+ *((INT *)lArg) = (INT)(lNFrame * sizeof(FRAME_1553DATA));
+ }
+ break;
+
+ case FIONWRITE:
+ {
+ LONG lNFrame = __1553QCount(p1553dev->_1553_pSendQueue);
+ *((INT *)lArg) = (INT)(lNFrame * sizeof(FRAME_1553DATA));
+ }
+ break;
+
+ case FIOFLUSH: /* 清空设备缓冲区*/
+ __1553FlushRd(p1553port);
+ __1553FlushWrt(p1553port);
+ break;
+
+ case FIOWFLUSH:
+ __1553FlushRd(p1553port); /* 清空写缓冲区*/
+ break;
+
+ case FIORFLUSH:
+ __1553FlushWrt(p1553port); /* 清空读缓冲区*/
+ break;
+
+ case FIOFSTATGET: /* 获得文件属性*/
+ pstat = (struct stat *)lArg;
+ pstat->st_dev = (dev_t)p1553dev;
+ pstat->st_ino = (ino_t)0; /* 相当于唯一节点*/
+ pstat->st_mode = 0666 | S_IFCHR; /* 默认属性*/
+ pstat->st_nlink = 1;
+ pstat->st_uid = 0;
+ pstat->st_gid = 0;
+ pstat->st_rdev = 1;
+ pstat->st_size = 0;
+ pstat->st_blksize = 0;
+ pstat->st_blocks = 0;
+ pstat->st_atime = API_RootFsTime(LW_NULL); /* 默认使用 root fs 基准时间*/
+ pstat->st_mtime = API_RootFsTime(LW_NULL);
+ pstat->st_ctime = API_RootFsTime(LW_NULL);
+ break;
+
+ case FIOSELECT:
+ pselwunNode = (PLW_SEL_WAKEUPNODE)lArg;
+ SEL_WAKE_NODE_ADD(&p1553dev->_1553_selwulList, pselwunNode);
+
+ switch (pselwunNode->SELWUN_seltypType) {
+
+ case SELREAD: /* 等待数据可读*/
+ if (__1553QCount(p1553dev->_1553_pRecvQueue) > 0) {
+ SEL_WAKE_UP(pselwunNode); /* 唤醒节点*/
+ }
+ break;
+
+ case SELWRITE:
+ if (__1553QFreeNum(p1553dev->_1553_pSendQueue) > 0) {
+ SEL_WAKE_UP(pselwunNode); /* 唤醒节点*/
+ }
+ break;
+
+ case SELEXCEPT: /* 总线是否异常*/
+ LW_SPIN_LOCK_QUICK(&p1553port->PORT_1553Dev._1553_spLock, &iregInterLevel);
+ if (p1553dev->_1553_busState != _1553_DEV_BUS_OK) {
+ LW_SPIN_UNLOCK_QUICK(&p1553port->PORT_1553Dev._1553_spLock, iregInterLevel);
+ SEL_WAKE_UP(pselwunNode); /* 唤醒节点*/
+ } else {
+ LW_SPIN_UNLOCK_QUICK(&p1553port->PORT_1553Dev._1553_spLock, iregInterLevel);
+ }
+ break;
+ }
+ break;
+
+ case FIOUNSELECT:
+ SEL_WAKE_NODE_DELETE(&p1553dev->_1553_selwulList, (PLW_SEL_WAKEUPNODE)lArg);
+ break;
+
+ case _1553_DEV_GET_BUS_STATE: /* 获取 1553 控制器状态*/
+ LW_SPIN_LOCK_QUICK(&p1553port->PORT_1553Dev._1553_spLock, &iregInterLevel);
+ *((LONG *)lArg) = p1553dev->_1553_busState;
+ p1553dev->_1553_busState = _1553_DEV_BUS_OK; /* 读取后清除状态*/
+ LW_SPIN_UNLOCK_QUICK(&p1553port->PORT_1553Dev._1553_spLock, iregInterLevel);
+ break;
+
+ case FIOWTIMEOUT:
+ if (lArg) {
+ timevalTemp = (struct timeval *)lArg;
+ p1553dev->_1553_sendTimeout = __timevalToTick(timevalTemp); /* 转换为系统时钟*/
+ } else {
+ p1553dev->_1553_sendTimeout = LW_OPTION_WAIT_INFINITE;
+ }
+ break;
+
+ case FIORTIMEOUT:
+ if (lArg) {
+ timevalTemp = (struct timeval *)lArg;
+ p1553dev->_1553_recvTimeout = __timevalToTick(timevalTemp); /* 转换为系统时钟*/
+ } else {
+ p1553dev->_1553_recvTimeout = LW_OPTION_WAIT_INFINITE;
+ }
+ break;
+
+ default:
+ _ErrorHandle(ERROR_IO_UNKNOWN_REQUEST);
+ iStatus = PX_ERROR;
+ break;
+ }
+ }
+
+ DEV1553_UNLOCK(p1553dev); /* 释放设备使用权*/
+
+ return (iStatus);
+}
+/*********************************************************************************************************
+** 函数名称: __1553Open
+** 功能描述: 1553 设备打开
+** 输 入 :
+** p1553dev 1553设备
+** pcName 设备名称
+** iFlags 打开设备时使用的标志
+** iMode 打开的方式,保留
+** 输 出 : 1553 设备指针
+** 全局变量:
+** 调用模块:
+*********************************************************************************************************/
+static LONG __1553Open (_1553_DEV *p1553dev,
+ PCHAR pcName,
+ INT iFlags,
+ INT iMode)
+{
+ _1553_PORT *p1553port = (_1553_PORT *)p1553dev;
+
+ if (LW_DEV_INC_USE_COUNT(&p1553dev->_1553_devhdr) == 1) {
+ if (p1553port->PORT_1553Chan->pDrvFuncs->ioctl) { /* 打开端口*/
+ p1553port->PORT_1553Chan->pDrvFuncs->ioctl(p1553port->PORT_1553Chan, _1553_DEV_OPEN, LW_NULL);
+ }
+ }
+
+ return ((LONG)p1553dev);
+}
+/*********************************************************************************************************
+** 函数名称: __1553Close
+** 功能描述: 1553 设备关闭
+** 输 入 : p1553dev 1553设备
+** 输 出 : ERROR_NONE or PX_ERROR
+** 全局变量:
+** 调用模块:
+*********************************************************************************************************/
+static INT __1553Close (_1553_DEV *p1553dev)
+{
+ _1553_PORT *p1553port = (_1553_PORT *)p1553dev;
+
+ if (LW_DEV_GET_USE_COUNT(&p1553dev->_1553_devhdr)) {
+ if (!LW_DEV_DEC_USE_COUNT(&p1553dev->_1553_devhdr)) {
+ if (p1553port->PORT_1553Chan->pDrvFuncs->ioctl) { /* 挂起端口*/
+ p1553port->PORT_1553Chan->pDrvFuncs->ioctl(p1553port->PORT_1553Chan, _1553_DEV_CLOSE, LW_NULL);
+ }
+ SEL_WAKE_UP_ALL(&p1553dev->_1553_selwulList, SELEXCEPT); /* 激活异常等待*/
+ }
+ }
+
+ return (ERROR_NONE);
+}
+/*********************************************************************************************************
+** 函数名称: __1553Write
+** 功能描述: 写 1553设备
+** 输 入 :
+** p1553dev 1553 设备
+** p1553frame 写缓冲区指针
+** stNBytes 发送缓冲区字节数
+** 输 出 : 返回实际写入的个数
+** 全局变量:
+** 调用模块:
+*********************************************************************************************************/
+static ssize_t __1553Write (_1553_DEV *p1553dev,
+ P1553DATA_FRAME p1553frame,
+ size_t stNBytes)
+{
+
+ INTREG iregInterLevel;
+ INT iFrameput;
+ INT i = 0;
+ ULONG ulError;
+ _1553_PORT *p1553port = (_1553_PORT *)p1553dev;
+ size_t stNumber = stNBytes / sizeof(FRAME_1553DATA); /* 转换为数据包个数*/
+
+ while (stNumber > 0) {
+ ulError = API_SemaphoreBPend(p1553dev->_1553_sendSemB,
+ p1553dev->_1553_sendTimeout);
+ if (ulError) {
+ _ErrorHandle(ERROR_IO_DEVICE_TIMEOUT); /* 超时*/
+ return ((ssize_t)(i * sizeof(FRAME_1553DATA)));
+ }
+
+ DEV1553_LOCK(p1553dev); /* 等待设备使用权*/
+
+ LW_SPIN_LOCK_QUICK(&p1553dev->_1553_spLock, &iregInterLevel);
+ if (p1553dev->_1553_busState != _1553_DEV_BUS_OK) { /* 总线错误*/
+ LW_SPIN_UNLOCK_QUICK(&p1553dev->_1553_spLock, iregInterLevel);
+ DEV1553_UNLOCK(p1553dev);
+ _ErrorHandle(EIO);
+ return ((ssize_t)(i * sizeof(FRAME_1553DATA)));
+ }
+ LW_SPIN_UNLOCK_QUICK(&p1553dev->_1553_spLock, iregInterLevel);
+
+ iFrameput = __1553WriteQueue(p1553dev,
+ p1553dev->_1553_pSendQueue,
+ p1553frame,
+ (INT)stNumber);
+
+ __1553TxStartup(p1553port); /* 启动一次发送 */
+
+ stNumber -= (size_t)iFrameput; /* 剩余需要发送的数据*/
+ p1553frame += iFrameput; /* 新的缓冲区起始地址*/
+ i += iFrameput;
+
+ LW_SPIN_LOCK_QUICK(&p1553dev->_1553_spLock, &iregInterLevel); /* 关闭中断*/
+ if (__1553QFreeNum(p1553dev->_1553_pSendQueue) > 0) {
+ LW_SPIN_UNLOCK_QUICK(&p1553dev->_1553_spLock, iregInterLevel); /* 打开中断*/
+ API_SemaphoreBPost(p1553dev->_1553_sendSemB); /* 缓冲区还有空间*/
+ } else {
+ LW_SPIN_UNLOCK_QUICK(&p1553dev->_1553_spLock, iregInterLevel); /* 打开中断*/
+ }
+
+ DEV1553_UNLOCK(p1553dev); /* 释放设备使用权*/
+ }
+
+ return ((ssize_t)(i * sizeof(FRAME_1553DATA)));
+}
+/*********************************************************************************************************
+** 函数名称: __1553Read
+** 功能描述: 读 1553 设备
+** 输 入 :
+** p1553dev 1553设备
+** p1553frame 1553发送缓冲区指针
+** stNBytes 读取缓冲区的字节数
+** 输 出 : 返回实际读取的个数
+** 全局变量:
+** 调用模块:
+*********************************************************************************************************/
+static ssize_t __1553Read (_1553_DEV *p1553dev,
+ P1553DATA_FRAME p1553frame,
+ size_t stNBytes)
+{
+ INTREG iregInterLevel;
+ REGISTER ssize_t sstNRead;
+ size_t stNumber = stNBytes / sizeof(FRAME_1553DATA); /* 转换为数据包个数*/
+ ULONG ulError;
+
+ for (;;) {
+ ulError = API_SemaphoreBPend(p1553dev->_1553_recvSemB, p1553dev->_1553_recvTimeout);
+ if (ulError) {
+ _ErrorHandle(ERROR_IO_DEVICE_TIMEOUT); /* 超时*/
+ return (0);
+ }
+
+ DEV1553_LOCK(p1553dev); /* 等待设备使用权*/
+
+ LW_SPIN_LOCK_QUICK(&p1553dev->_1553_spLock, &iregInterLevel); /* 关闭中断*/
+ if (__1553QCount(p1553dev->_1553_pRecvQueue)) { /* 检查是否有数据*/
+ break;
+ } else {
+ if (p1553dev->_1553_busState != _1553_DEV_BUS_OK) { /* 总线错误*/
+ LW_SPIN_UNLOCK_QUICK(&p1553dev->_1553_spLock, iregInterLevel);
+ DEV1553_UNLOCK(p1553dev);
+ _ErrorHandle(EIO);
+ return (0);
+ }
+ }
+ LW_SPIN_UNLOCK_QUICK(&p1553dev->_1553_spLock, iregInterLevel); /* 打开中断*/
+ DEV1553_UNLOCK(p1553dev); /* 释放设备使用权*/
+ }
+
+ LW_SPIN_UNLOCK_QUICK(&p1553dev->_1553_spLock, iregInterLevel);
+ sstNRead = __1553ReadQueue(p1553dev,
+ p1553dev->_1553_pRecvQueue,
+ p1553frame,
+ (INT)stNumber);
+ LW_SPIN_LOCK_QUICK(&p1553dev->_1553_spLock, &iregInterLevel);
+
+ if (__1553QCount(p1553dev->_1553_pRecvQueue)) { /* 是否还有数据*/
+ LW_SPIN_UNLOCK_QUICK(&p1553dev->_1553_spLock, iregInterLevel);
+ API_SemaphoreBPost(p1553dev->_1553_recvSemB); /* 通知其他等待读的线程*/
+ } else {
+ LW_SPIN_UNLOCK_QUICK(&p1553dev->_1553_spLock, iregInterLevel);
+ }
+
+ DEV1553_UNLOCK(p1553dev);/* 释放设备使用权*/
+
+ return (sstNRead * sizeof(FRAME_1553DATA));
+}
+
+/*********************************************************************************************************
+** 函数名称: API_1553DrvInstall
+** 功能描述: 安装1553驱动程序
+** 输 入 : NONE
+** 输 出 : NONE
+** 全局变量:
+** 调用模块:
+** API 函数
+*********************************************************************************************************/
+LW_API
+INT API_1553DrvInstall (void)
+{
+ if (_G_1553DrvNum > 0) {
+ return (ERROR_NONE);
+ }
+
+ _G_1553DrvNum = iosDrvInstall(__1553Open, LW_NULL, __1553Open, __1553Close,
+ __1553Read, __1553Write, __1553Ioctl);
+
+ DRIVER_LICENSE(_G_1553DrvNum, "GPL->Ver 2.0");
+ DRIVER_AUTHOR(_G_1553DrvNum, "Jianhui.Zhu");
+ DRIVER_DESCRIPTION(_G_1553DrvNum, "1553 Bus driver.");
+
+ return (_G_1553DrvNum > 0) ? (ERROR_NONE) : (PX_ERROR);
+}
+/*********************************************************************************************************
+** 函数名称: API_1553DevCreate
+** 功能描述: 创建 1553设备
+** 输 入 : pcName 设备名
+** pc1553chan 通道
+** uiRdFrameSize 接收缓冲区大小
+** uiWrtFrameSize 发送缓冲区大小
+** 输 出 : 是否成功
+** 全局变量:
+** 调用模块:
+** API 函数
+*********************************************************************************************************/
+LW_API
+INT API_1553DevCreate (PCHAR pcName,
+ CHAN_1553 *p1553chan,
+ UINT uiRdFrameSize,
+ UINT uiWrtFrameSize)
+{
+ P1553_PORT p1553port;
+ INT iTemp;
+
+ if ((!pcName) || (!p1553chan)) {
+ _DebugHandle(__ERRORMESSAGE_LEVEL, "parameter error.\r\n");
+ _ErrorHandle(EINVAL);
+ return (PX_ERROR);
+ }
+
+ if ((uiRdFrameSize < 1) || (uiWrtFrameSize < 1)) {
+ _DebugHandle(__ERRORMESSAGE_LEVEL, "parameter error.\r\n");
+ _ErrorHandle(EINVAL);
+ return (PX_ERROR);
+ }
+
+ if ((!p1553chan->pDrvFuncs->callbackInstall) ||
+ (!p1553chan->pDrvFuncs->txStartup)) {
+ _DebugHandle(__ERRORMESSAGE_LEVEL, "parameter error.\r\n");
+ _ErrorHandle(EINVAL);
+ return (PX_ERROR);
+ }
+
+ if (_G_1553DrvNum <= 0) {
+ _DebugHandle(__ERRORMESSAGE_LEVEL, "1553 Driver invalidate.\r\n");
+ _ErrorHandle(ERROR_IO_NO_DRIVER);
+ return (PX_ERROR);
+ }
+
+ p1553port = (P1553_PORT)__SHEAP_ALLOC(sizeof(_1553_PORT));
+ if (!p1553port) {
+ _DebugHandle(__ERRORMESSAGE_LEVEL, "system low memory.\r\n");
+ _ErrorHandle(ERROR_SYSTEM_LOW_MEMORY);
+ return (PX_ERROR);
+ }
+ lib_bzero(p1553port, sizeof(_1553_PORT));
+
+ iTemp = __1553DevInit(&p1553port->PORT_1553Dev,
+ uiRdFrameSize,
+ uiWrtFrameSize); /* 初始化设备控制块 */
+
+ if (iTemp != ERROR_NONE) {
+ __SHEAP_FREE(p1553port);
+ _DebugHandle(__ERRORMESSAGE_LEVEL, "system low memory.\r\n");
+ _ErrorHandle(ERROR_SYSTEM_LOW_MEMORY);
+ return (PX_ERROR);
+ }
+
+ __1553FlushRd(p1553port);
+ __1553FlushWrt(p1553port);
+
+ p1553port->PORT_1553Chan = p1553chan;
+
+ p1553chan->pDrvFuncs->callbackInstall(p1553chan, _1553_CB_GET_TX_FRAME,
+ (CALLBACK_1553)__1553GetFrameFromTxQueue, (PVOID)p1553port);
+ p1553chan->pDrvFuncs->callbackInstall(p1553chan, _1553_CB_PUT_RX_FRAME,
+ (CALLBACK_1553)__1553PutFrameToRxQueue, (PVOID)p1553port);
+ p1553chan->pDrvFuncs->callbackInstall(p1553chan, _1553_CB_PUT_BUS_STATE,
+ (CALLBACK_1553)__1553SetBusState, (PVOID)p1553port);
+
+ iTemp = (INT)iosDevAddEx(&p1553port->PORT_1553Dev._1553_devhdr,
+ pcName,
+ _G_1553DrvNum,
+ DT_CHR);
+ if (iTemp) {
+ __1553DevDelete(&p1553port->PORT_1553Dev);
+ __SHEAP_FREE(p1553port);
+ _DebugHandle(__ERRORMESSAGE_LEVEL, "add device error.\r\n");
+ _ErrorHandle(ERROR_SYSTEM_LOW_MEMORY);
+ return (PX_ERROR);
+
+ } else {
+ return (ERROR_NONE);
+ }
+}
+/*********************************************************************************************************
+** 函数名称: API_1553DevRemove
+** 功能描述: 移除一个 1553 设备
+** 输 入 :
+** pcName 需要移除的 1553 设备
+** bForce 模式选择
+** 输 出 : ERROR_NONE or PX_ERROR
+** 全局变量:
+** 调用模块:
+** API 函数
+*********************************************************************************************************/
+LW_API
+INT API_1553DevRemove (PCHAR pcName, BOOL bForce)
+{
+ P1553_PORT pDevHdr;
+ PCHAR pcTail = LW_NULL;
+
+ if (LW_CPU_GET_CUR_NESTING()) {
+ _DebugHandle(__ERRORMESSAGE_LEVEL, "called from ISR.\r\n");
+ _ErrorHandle(ERROR_KERNEL_IN_ISR);
+ return (PX_ERROR);
+ }
+
+ if (_G_1553DrvNum <= 0) {
+ _DebugHandle(__ERRORMESSAGE_LEVEL, "no driver.\r\n");
+ _ErrorHandle(ERROR_IO_NO_DRIVER);
+ return (PX_ERROR);
+ }
+
+ pDevHdr = (P1553_PORT)iosDevFind(pcName, &pcTail);
+ if ((pDevHdr == LW_NULL) || (pcName == pcTail)) {
+ _DebugHandle(__ERRORMESSAGE_LEVEL, "device not found.\r\n");
+ _ErrorHandle(ERROR_IOS_DEVICE_NOT_FOUND);
+ return (PX_ERROR);
+ }
+
+ if (bForce == LW_FALSE) {
+ if (LW_DEV_GET_USE_COUNT(&pDevHdr->PORT_1553Dev._1553_devhdr)) {
+ _DebugHandle(__ERRORMESSAGE_LEVEL, "too many open files.\r\n");
+ _ErrorHandle(EBUSY);
+ return (PX_ERROR);
+ }
+ if (SEL_WAKE_UP_LIST_LEN(&pDevHdr->PORT_1553Dev._1553_selwulList) > 0) {
+ errno = EBUSY;
+ return (PX_ERROR);
+ }
+ }
+
+ iosDevFileAbnormal(&pDevHdr->PORT_1553Dev._1553_devhdr);
+ iosDevDelete(&pDevHdr->PORT_1553Dev._1553_devhdr);
+
+ SEL_WAKE_UP_LIST_TERM(&pDevHdr->PORT_1553Dev._1553_selwulList);
+
+ __1553DevDelete(&pDevHdr->PORT_1553Dev);
+
+ __SHEAP_FREE((PVOID)pDevHdr);
+
+ return (ERROR_NONE);
+}
+
diff --git a/SylixOS/system/device/1553B/bus1553.h b/SylixOS/system/device/1553B/bus1553.h
new file mode 100644
index 0000000..c1199f2
--- /dev/null
+++ b/SylixOS/system/device/1553B/bus1553.h
@@ -0,0 +1,175 @@
+/*********************************************************************************************************
+**
+** 中国软件开源组织
+**
+** 嵌入式实时操作系统
+**
+** SylixOS(TM) LW : long wing
+**
+** Copyright All Rights Reserved
+**
+**--------------文件信息--------------------------------------------------------------------------------
+**
+** 文 件 名: bus1553.h
+**
+** 创 建 人: Zhu.Jianhui (朱剑辉)
+**
+** 文件创建日期: 2019 年 08 月 05 日
+**
+** 描 述: 1553B 总线驱动支持.
+*********************************************************************************************************/
+#ifndef __bus1553__
+#define __bus1553__
+
+/*********************************************************************************************************
+ 定义驱动安装回调函数时的命令
+*********************************************************************************************************/
+#ifdef __SYLIXOS_KERNEL
+#define _1553_CB_GET_TX_FRAME 1 /* 安装发送数据时的回调 */
+#define _1553_CB_PUT_RX_FRAME 2 /* 安装接收数据时的回调 */
+#define _1553_CB_PUT_BUS_STATE 3 /* 安装总线状态改变时的回调 */
+#endif /* __SYLIXOS_KERNEL */
+
+/*********************************************************************************************************
+ 总线状态宏定义
+*********************************************************************************************************/
+#define _1553_DEV_BUS_OK 0x0000 /* 正常状态*/
+#define _1553_DEV_BUS_ERROR 0x0001 /* 错误状态*/
+
+#ifdef __SYLIXOS_KERNEL
+#define _1553_DEV_OPEN LW_OSIO('c', 201) /* 1553 设备打开命令*/
+#define _1553_DEV_CLOSE LW_OSIO('c', 202) /* 1553 设备关闭命令 */
+#endif /* __SYLIXOS_KERNEL */
+
+#define _1553_DEV_GET_BUS_STATE LW_OSIOR('c', 203, LONG) /* 获取1553总线状态*/
+#define _1553_DEV_REST_BUS LW_OSIO( 'c', 204) /* 复位 1553总线 控制器*/
+#define _1553_DEV_STARTUP LW_OSIO( 'c', 205) /* 启动 1553总线 控制器 */
+#define _1553_DEV_SET_MODE LW_OSIOD('c', 206, INT) /* 设置15553总线模式*/
+
+//msg type ,仅限于BC 模式用
+#define BC_RT 0 // 0
+#define RT_BC 1 // 0
+#define RT_RT 2 // 1
+#define BCST 3 // 2 broadcast
+#define RT_RTS 4 // 3
+#define MC_ND 5 // 4 mode code no data
+#define TX_MC_WD 6 // 4 mode code with data
+#define RX_MC_WD 7 // 4 mode code with data
+#define MCND_BCST 8 // 6 mode code broadcast
+#define MCWD_BCST 9 // 6 mode code broadcast
+
+//msg type ,仅限于RT 模式用
+#define BC_TO_RT 0
+#define RT_TO_BC 1
+#define BROADCAST 2
+#define MODE_CODE 3
+
+#define TX 1
+#define RX 0
+
+typedef enum {BC_MOD, RT_MOD, MT_MOD,INIT_MOD} BUSMOD;
+
+#define CHANNEL_A 1
+#define CHANNEL_B 0
+
+//1553B寄存器片内偏移地址
+#define INTRMASK 0x0000
+#define CONFIG1 0x0001
+#define CONFIG2 0x0002
+#define STR_RST 0x0003 //WR
+#define CMD_STK_POINT 0x0003 //RD
+#define RT_SA_CTRL_WORD 0x0004
+#define BC_CTRL_WORD 0x0004
+#define TIMETAG 0x0005
+#define INTR_STATUS 0x0006
+#define CONFIG3 0x0007
+#define CONFIG4 0x0008
+#define CONFIG5 0x0009
+#define RT_DATA_STACK_ADDR 0x000a
+#define BC_FRM_TIME_REMAIN 0x000b
+#define BC_MSG_TIME 0x000c
+#define RT_LAST_CMD_WORD 0x000d
+#define BC_FRM_TIME 0x000d
+#define RT_STATUS 0x000e
+#define RT_BIT_WORD 0x000f
+
+
+typedef struct CmdWord
+{
+ UINT32 Reserve:16; //16位与32位对齐
+ UINT32 RTADDR:5;
+ UINT32 TR:1;
+ UINT32 SADDR:5;
+ UINT32 WCOUNT:5;
+} COMMANDWORD;
+
+/*********************************************************************************************************
+ 1553数据帧结构定义
+*********************************************************************************************************/
+typedef struct _1553DataFrame{
+ UINT16 msgType;
+ UINT16 msgChannel;
+ union{
+ COMMANDWORD CMDWORD1;
+ UINT32 cmdWord1;
+ }frameInfo1;
+ union{
+ COMMANDWORD CMDWORD2;
+ UINT32 cmdWord2;
+ }frameInfo2;
+ UINT16 msgCtrlWord;
+ UINT16 msgStatus1; /* RT 接收消息状态字,仅用于RT模式读*/
+ UINT16 msgStatus2; /* 仅RT-RT 模式使用*/
+ UINT16 loopBack; //仅限于BC模式使用
+ UINT32 msgGapTime;
+ UINT16 msgData[32];
+}FRAME_1553DATA, *P1553DATA_FRAME; /* 1553数据帧类型*/
+
+#ifdef __cplusplus
+typedef INT (*CALLBACK_1553)(...);
+#else
+typedef INT (*CALLBACK_1553)();
+#endif
+
+typedef struct _1553_drv_funcs DRV_FUNCS_1553;
+
+typedef struct _1553_chan {
+ DRV_FUNCS_1553 *pDrvFuncs;
+} CHAN_1553;
+
+struct _1553_drv_funcs {
+ INT (*ioctl)
+ (
+ CHAN_1553 *p1553chan,
+ INT cmd,
+ PVOID arg
+ );
+
+ INT (*txStartup)
+ (
+ CHAN_1553 *p1553chan
+ );
+
+ INT (*callbackInstall)
+ (
+ CHAN_1553 *p1553chan,
+ INT callbackType,
+ CALLBACK_1553 callback,
+ PVOID callbackArg
+ );
+};
+
+LW_API INT API_1553DrvInstall(VOID);
+LW_API INT API_1553DevCreate (PCHAR pcName,
+ CHAN_1553 *p1553chan,
+ UINT uiRdFrameSize,
+ UINT uiWrtFrameSize);
+LW_API INT API_1553DevRemove(PCHAR pcName, BOOL bForce);
+
+
+#define bus1553Drv API_1553DrvInstall
+#define bus1553DevCreate API_1553DevCreate
+#define bus1553DevRemove API_1553DevRemove
+
+
+#endif /* __bus1553__ */
diff --git a/SylixOS/system/device/ahci/ahciCfg.h b/SylixOS/system/device/ahci/ahciCfg.h
index 6a56e09..60834f9 100644
--- a/SylixOS/system/device/ahci/ahciCfg.h
+++ b/SylixOS/system/device/ahci/ahciCfg.h
@@ -57,7 +57,7 @@
/*********************************************************************************************************
TRIM 操作
*********************************************************************************************************/
-#define AHCI_TRIM_EN 1 /* 是否使能 TRIM 操作 */
+#define AHCI_TRIM_EN LW_CFG_AHCI_TRIM_EN /* 是否使能 TRIM 操作 */
#define AHCI_TRIM_TIMEOUT_MS 50 /* TRIM 单次超时时间 */
#define AHCI_TRIM_TIMEOUT_NUM 100 /* TRIM 单次超时时间次数 */
/*********************************************************************************************************
diff --git a/SylixOS/system/device/nvme/nvmeCfg.h b/SylixOS/system/device/nvme/nvmeCfg.h
index 0e4a1c6..ba42eb8 100644
--- a/SylixOS/system/device/nvme/nvmeCfg.h
+++ b/SylixOS/system/device/nvme/nvmeCfg.h
@@ -45,7 +45,7 @@
/*********************************************************************************************************
TRIM 操作
*********************************************************************************************************/
-#define NVME_TRIM_EN 1 /* 是否使能 TRIM 操作 */
+#define NVME_TRIM_EN LW_CFG_NVME_TRIM_EN /* 是否使能 TRIM 操作 */
/*********************************************************************************************************
FLUSH 操作
*********************************************************************************************************/
diff --git a/SylixOS/system/include/s_system.h b/SylixOS/system/include/s_system.h
index ec3adb7..54492e1 100644
--- a/SylixOS/system/include/s_system.h
+++ b/SylixOS/system/include/s_system.h
@@ -89,6 +89,7 @@
#include "../SylixOS/system/device/pty/pty.h" /* pseudo terminal */
#include "../SylixOS/system/device/block/blockIo.h" /* block device */
#include "../SylixOS/system/device/can/can.h" /* CAN bus device */
+#include "../SylixOS/system/device/1553B/bus1553.h"
#include "../SylixOS/system/device/buzzer/buzzer.h" /* buzzer device */
#include "../SylixOS/system/device/graph/gmemDev.h" /* graph memory device */
diff --git a/SylixOS/system/ioLib/ioLockF.c b/SylixOS/system/ioLib/ioLockF.c
index b434068..aeb8c53 100644
--- a/SylixOS/system/ioLib/ioLockF.c
+++ b/SylixOS/system/ioLib/ioLockF.c
@@ -1156,7 +1156,7 @@ INT _FdLockfIoctl (PLW_FD_ENTRY pfdentry, INT iCmd, struct flock *pfl)
}
pfdnode = (PLW_FD_NODE)pfdentry->FDENTRY_lValue;
- if (pfdnode == LW_NULL) {
+ if ((pfdnode == LW_NULL) || (pfdnode == (PLW_FD_NODE)PX_ERROR)) {
_ErrorHandle(ERROR_IOS_DRIVER_NOT_SUP);
return (PX_ERROR);
}
@@ -1216,7 +1216,7 @@ INT _FdLockfProc (PLW_FD_ENTRY pfdentry, INT iType, pid_t pid)
}
pfdnode = (PLW_FD_NODE)pfdentry->FDENTRY_lValue;
- if (pfdnode == LW_NULL) {
+ if ((pfdnode == LW_NULL) || (pfdnode == (PLW_FD_NODE)PX_ERROR)) {
_ErrorHandle(ERROR_IOS_DRIVER_NOT_SUP);
return (PX_ERROR);
}
@@ -1286,7 +1286,7 @@ INT _FdLockfClearFdEntry (PLW_FD_ENTRY pfdentry, pid_t pid)
}
pfdnode = (PLW_FD_NODE)pfdentry->FDENTRY_lValue;
- if (pfdnode == LW_NULL) {
+ if ((pfdnode == LW_NULL) || (pfdnode == (PLW_FD_NODE)PX_ERROR)) {
_ErrorHandle(ERROR_IOS_DRIVER_NOT_SUP);
return (PX_ERROR);
}
diff --git a/libsylixos.mk b/libsylixos.mk
index 026c5cf..df988fa 100644
--- a/libsylixos.mk
+++ b/libsylixos.mk
@@ -775,6 +775,7 @@ SylixOS/debug/hwdbg/openocd.c
#*********************************************************************************************************
DRV_SRCS = \
SylixOS/driver/can/sja1000.c \
+SylixOS/driver/bu61580/bu61580.c \
SylixOS/driver/dma/i8237a.c \
SylixOS/driver/int/i8259a.c \
SylixOS/driver/net/dm9000.c \
@@ -1804,6 +1805,7 @@ SylixOS/system/device/bmsg/bmsgDev.c \
SylixOS/system/device/bmsg/bmsgfd.c \
SylixOS/system/device/buzzer/buzzer.c \
SylixOS/system/device/can/can.c \
+SylixOS/system/device/1553B/bus1553.c \
SylixOS/system/device/dma/dma.c \
SylixOS/system/device/dma/dmaLib.c \
SylixOS/system/device/eventfd/eventfdDev.c \