micropython: add micropython component

This commit is contained in:
KY-zhang-X
2022-09-29 12:10:37 +08:00
parent 1514f1cb9b
commit dd76146324
2679 changed files with 354110 additions and 0 deletions

View File

@@ -0,0 +1,557 @@
/*
* device.c - CC31xx/CC32xx Host Driver Implementation
*
* Copyright (C) 2014 Texas Instruments Incorporated - http://www.ti.com/
*
*
* Redistribution and use in source and binary forms, with or without
* modification, are permitted provided that the following conditions
* are met:
*
* Redistributions of source code must retain the above copyright
* notice, this list of conditions and the following disclaimer.
*
* Redistributions in binary form must reproduce the above copyright
* notice, this list of conditions and the following disclaimer in the
* documentation and/or other materials provided with the
* distribution.
*
* Neither the name of Texas Instruments Incorporated nor the names of
* its contributors may be used to endorse or promote products derived
* from this software without specific prior written permission.
*
* THIS SOFTWARE IS PROVIDED BY THE COPYRIGHT HOLDERS AND CONTRIBUTORS
* "AS IS" AND ANY EXPRESS OR IMPLIED WARRANTIES, INCLUDING, BUT NOT
* LIMITED TO, THE IMPLIED WARRANTIES OF MERCHANTABILITY AND FITNESS FOR
* A PARTICULAR PURPOSE ARE DISCLAIMED. IN NO EVENT SHALL THE COPYRIGHT
* OWNER OR CONTRIBUTORS BE LIABLE FOR ANY DIRECT, INDIRECT, INCIDENTAL,
* SPECIAL, EXEMPLARY, OR CONSEQUENTIAL DAMAGES (INCLUDING, BUT NOT
* LIMITED TO, PROCUREMENT OF SUBSTITUTE GOODS OR SERVICES; LOSS OF USE,
* DATA, OR PROFITS; OR BUSINESS INTERRUPTION) HOWEVER CAUSED AND ON ANY
* THEORY OF LIABILITY, WHETHER IN CONTRACT, STRICT LIABILITY, OR TORT
* (INCLUDING NEGLIGENCE OR OTHERWISE) ARISING IN ANY WAY OUT OF THE USE
* OF THIS SOFTWARE, EVEN IF ADVISED OF THE POSSIBILITY OF SUCH DAMAGE.
*
*/
/*****************************************************************************/
/* Include files */
/*****************************************************************************/
#include "simplelink.h"
#include "protocol.h"
#include "flowcont.h"
#include "driver.h"
/*****************************************************************************/
/* Internal functions */
/*****************************************************************************/
const _i8 StartResponseLUT[8] =
{
ROLE_UNKNOWN_ERR,
ROLE_STA,
ROLE_STA_ERR,
ROLE_AP,
ROLE_AP_ERR,
ROLE_P2P,
ROLE_P2P_ERR,
ROLE_UNKNOWN_ERR
};
_i16 _sl_GetStartResponseConvert(_u32 Status)
{
return (_i16)StartResponseLUT[Status & 0x7];
}
/*****************************************************************************/
/* API Functions */
/*****************************************************************************/
/*****************************************************************************/
/* sl_Task */
/*****************************************************************************/
#if _SL_INCLUDE_FUNC(sl_Task)
void sl_Task(void)
{
#ifdef _SlTaskEntry
_SlTaskEntry();
#endif
}
#endif
/*****************************************************************************/
/* sl_Start */
/*****************************************************************************/
#if _SL_INCLUDE_FUNC(sl_Start)
_i16 sl_Start(const void* pIfHdl, _i8* pDevName, const P_INIT_CALLBACK pInitCallBack)
{
_i16 ObjIdx = MAX_CONCURRENT_ACTIONS;
InitComplete_t AsyncRsp;
/* Perform any preprocessing before enable networking services */
sl_DeviceEnablePreamble();
/* ControlBlock init */
_SlDrvDriverCBInit();
/* open the interface: usually SPI or UART */
if (NULL == pIfHdl)
{
g_pCB->FD = sl_IfOpen((void *)pDevName, 0);
}
else
{
g_pCB->FD = (_SlFd_t)pIfHdl;
}
ObjIdx = _SlDrvProtectAsyncRespSetting((_u8 *)&AsyncRsp, START_STOP_ID, SL_MAX_SOCKETS);
if (MAX_CONCURRENT_ACTIONS == ObjIdx)
{
return SL_POOL_IS_EMPTY;
}
if( g_pCB->FD >= (_SlFd_t)0)
{
sl_DeviceDisable();
sl_IfRegIntHdlr((SL_P_EVENT_HANDLER)_SlDrvRxIrqHandler, NULL);
g_pCB->pInitCallback = pInitCallBack;
sl_DeviceEnable();
if (NULL == pInitCallBack)
{
_SlDrvSyncObjWaitForever(&g_pCB->ObjPool[ObjIdx].SyncObj);
/* release Pool Object */
_SlDrvReleasePoolObj(g_pCB->FunctionParams.AsyncExt.ActionIndex);
return _sl_GetStartResponseConvert(AsyncRsp.Status);
}
else
{
return SL_RET_CODE_OK;
}
}
return SL_BAD_INTERFACE;
}
#endif
/***************************************************************************
_sl_HandleAsync_InitComplete - handles init complete signalling to
a waiting object
****************************************************************************/
void _sl_HandleAsync_InitComplete(void *pVoidBuf)
{
InitComplete_t *pMsgArgs = (InitComplete_t *)_SL_RESP_ARGS_START(pVoidBuf);
_SlDrvProtectionObjLockWaitForever();
if(g_pCB->pInitCallback)
{
g_pCB->pInitCallback(_sl_GetStartResponseConvert(pMsgArgs->Status));
}
else
{
sl_Memcpy(g_pCB->ObjPool[g_pCB->FunctionParams.AsyncExt.ActionIndex].pRespArgs, pMsgArgs, sizeof(InitComplete_t));
_SlDrvSyncObjSignal(&g_pCB->ObjPool[g_pCB->FunctionParams.AsyncExt.ActionIndex].SyncObj);
}
_SlDrvProtectionObjUnLock();
if(g_pCB->pInitCallback)
{
_SlDrvReleasePoolObj(g_pCB->FunctionParams.AsyncExt.ActionIndex);
}
}
/***************************************************************************
_sl_HandleAsync_Stop - handles stop signalling to
a waiting object
****************************************************************************/
void _sl_HandleAsync_Stop(void *pVoidBuf)
{
_BasicResponse_t *pMsgArgs = (_BasicResponse_t *)_SL_RESP_ARGS_START(pVoidBuf);
VERIFY_SOCKET_CB(NULL != g_pCB->StopCB.pAsyncRsp);
_SlDrvProtectionObjLockWaitForever();
sl_Memcpy(g_pCB->ObjPool[g_pCB->FunctionParams.AsyncExt.ActionIndex].pRespArgs, pMsgArgs, sizeof(_BasicResponse_t));
_SlDrvSyncObjSignal(&g_pCB->ObjPool[g_pCB->FunctionParams.AsyncExt.ActionIndex].SyncObj);
_SlDrvProtectionObjUnLock();
return;
}
/*****************************************************************************
sl_stop
******************************************************************************/
typedef union
{
_DevStopCommand_t Cmd;
_BasicResponse_t Rsp;
}_SlStopMsg_u;
const _SlCmdCtrl_t _SlStopCmdCtrl =
{
SL_OPCODE_DEVICE_STOP_COMMAND,
sizeof(_DevStopCommand_t),
sizeof(_BasicResponse_t)
};
#if _SL_INCLUDE_FUNC(sl_Stop)
_i16 sl_Stop(const _u16 timeout)
{
_i16 RetVal=0;
_SlStopMsg_u Msg;
_BasicResponse_t AsyncRsp;
_i8 ObjIdx = MAX_CONCURRENT_ACTIONS;
/* if timeout is 0 the shutdown is forced immediately */
if( 0 == timeout )
{
sl_IfRegIntHdlr(NULL, NULL);
sl_DeviceDisable();
RetVal = sl_IfClose(g_pCB->FD);
}
else
{
/* let the device make the shutdown using the defined timeout */
Msg.Cmd.Timeout = timeout;
ObjIdx = _SlDrvProtectAsyncRespSetting((_u8 *)&AsyncRsp, START_STOP_ID, SL_MAX_SOCKETS);
if (MAX_CONCURRENT_ACTIONS == ObjIdx)
{
return SL_POOL_IS_EMPTY;
}
VERIFY_RET_OK(_SlDrvCmdOp((_SlCmdCtrl_t *)&_SlStopCmdCtrl, &Msg, NULL));
if(SL_OS_RET_CODE_OK == (_i16)Msg.Rsp.status)
{
_SlDrvSyncObjWaitForever(&g_pCB->ObjPool[ObjIdx].SyncObj);
Msg.Rsp.status = AsyncRsp.status;
RetVal = Msg.Rsp.status;
}
_SlDrvReleasePoolObj(ObjIdx);
sl_IfRegIntHdlr(NULL, NULL);
sl_DeviceDisable();
sl_IfClose(g_pCB->FD);
}
_SlDrvDriverCBDeinit();
return RetVal;
}
#endif
/*****************************************************************************
sl_EventMaskSet
*****************************************************************************/
typedef union
{
_DevMaskEventSetCommand_t Cmd;
_BasicResponse_t Rsp;
}_SlEventMaskSetMsg_u;
#if _SL_INCLUDE_FUNC(sl_EventMaskSet)
const _SlCmdCtrl_t _SlEventMaskSetCmdCtrl =
{
SL_OPCODE_DEVICE_EVENTMASKSET,
sizeof(_DevMaskEventSetCommand_t),
sizeof(_BasicResponse_t)
};
_i16 sl_EventMaskSet(const _u8 EventClass ,const _u32 Mask)
{
_SlEventMaskSetMsg_u Msg;
Msg.Cmd.group = EventClass;
Msg.Cmd.mask = Mask;
VERIFY_RET_OK(_SlDrvCmdOp((_SlCmdCtrl_t *)&_SlEventMaskSetCmdCtrl, &Msg, NULL));
return (_i16)Msg.Rsp.status;
}
#endif
/******************************************************************************
sl_EventMaskGet
******************************************************************************/
typedef union
{
_DevMaskEventGetCommand_t Cmd;
_DevMaskEventGetResponse_t Rsp;
}_SlEventMaskGetMsg_u;
#if _SL_INCLUDE_FUNC(sl_EventMaskGet)
const _SlCmdCtrl_t _SlEventMaskGetCmdCtrl =
{
SL_OPCODE_DEVICE_EVENTMASKGET,
sizeof(_DevMaskEventGetCommand_t),
sizeof(_DevMaskEventGetResponse_t)
};
_i16 sl_EventMaskGet(const _u8 EventClass,_u32 *pMask)
{
_SlEventMaskGetMsg_u Msg;
Msg.Cmd.group = EventClass;
VERIFY_RET_OK(_SlDrvCmdOp((_SlCmdCtrl_t *)&_SlEventMaskGetCmdCtrl, &Msg, NULL));
*pMask = Msg.Rsp.mask;
return SL_RET_CODE_OK;
}
#endif
/******************************************************************************
sl_DevGet
******************************************************************************/
typedef union
{
_DeviceSetGet_t Cmd;
_DeviceSetGet_t Rsp;
}_SlDeviceMsgGet_u;
#if _SL_INCLUDE_FUNC(sl_DevGet)
const _SlCmdCtrl_t _SlDeviceGetCmdCtrl =
{
SL_OPCODE_DEVICE_DEVICEGET,
sizeof(_DeviceSetGet_t),
sizeof(_DeviceSetGet_t)
};
_i32 sl_DevGet(const _u8 DeviceGetId,_u8 *pOption,_u8 *pConfigLen, _u8 *pValues)
{
_SlDeviceMsgGet_u Msg;
_SlCmdExt_t CmdExt;
if (*pConfigLen == 0)
{
return SL_EZEROLEN;
}
if( pOption )
{
_SlDrvResetCmdExt(&CmdExt);
CmdExt.RxPayloadLen = *pConfigLen;
CmdExt.pRxPayload = (_u8 *)pValues;
Msg.Cmd.DeviceSetId = DeviceGetId;
Msg.Cmd.Option = (_u16)*pOption;
VERIFY_RET_OK(_SlDrvCmdOp((_SlCmdCtrl_t *)&_SlDeviceGetCmdCtrl, &Msg, &CmdExt));
if( pOption )
{
*pOption = (_u8)Msg.Rsp.Option;
}
if (CmdExt.RxPayloadLen < CmdExt.ActualRxPayloadLen)
{
*pConfigLen = (_u8)CmdExt.RxPayloadLen;
return SL_ESMALLBUF;
}
else
{
*pConfigLen = (_u8)CmdExt.ActualRxPayloadLen;
}
return (_i16)Msg.Rsp.Status;
}
else
{
return -1;
}
}
#endif
/******************************************************************************
sl_DevSet
******************************************************************************/
typedef union
{
_DeviceSetGet_t Cmd;
_BasicResponse_t Rsp;
}_SlDeviceMsgSet_u;
#if _SL_INCLUDE_FUNC(sl_DevSet)
const _SlCmdCtrl_t _SlDeviceSetCmdCtrl =
{
SL_OPCODE_DEVICE_DEVICESET,
sizeof(_DeviceSetGet_t),
sizeof(_BasicResponse_t)
};
_i32 sl_DevSet(const _u8 DeviceSetId ,const _u8 Option,const _u8 ConfigLen,const _u8 *pValues)
{
_SlDeviceMsgSet_u Msg;
_SlCmdExt_t CmdExt;
_SlDrvResetCmdExt(&CmdExt);
CmdExt.TxPayloadLen = (ConfigLen+3) & (~3);
CmdExt.pTxPayload = (_u8 *)pValues;
Msg.Cmd.DeviceSetId = DeviceSetId;
Msg.Cmd.ConfigLen = ConfigLen;
Msg.Cmd.Option = Option;
VERIFY_RET_OK(_SlDrvCmdOp((_SlCmdCtrl_t *)&_SlDeviceSetCmdCtrl, &Msg, &CmdExt));
return (_i16)Msg.Rsp.status;
}
#endif
/******************************************************************************
_SlDrvDeviceEventHandler - handles internally device async events
******************************************************************************/
void _SlDrvDeviceEventHandler(void* pArgs)
{
_SlResponseHeader_t *pHdr = (_SlResponseHeader_t *)pArgs;
switch(pHdr->GenHeader.Opcode)
{
case SL_OPCODE_DEVICE_INITCOMPLETE:
_sl_HandleAsync_InitComplete(pHdr);
break;
case SL_OPCODE_DEVICE_STOP_ASYNC_RESPONSE:
_sl_HandleAsync_Stop(pHdr);
break;
case SL_OPCODE_DEVICE_ABORT:
{
#if defined (sl_GeneralEvtHdlr) || defined(EXT_LIB_REGISTERED_GENERAL_EVENTS)
SlDeviceEvent_t devHandler;
devHandler.Event = SL_DEVICE_ABORT_ERROR_EVENT;
devHandler.EventData.deviceReport.AbortType = *((_u32*)pArgs + 2);
devHandler.EventData.deviceReport.AbortData = *((_u32*)pArgs + 3);
_SlDrvHandleGeneralEvents(&devHandler);
#endif
}
break;
case SL_OPCODE_DEVICE_DEVICEASYNCFATALERROR:
#if defined (sl_GeneralEvtHdlr) || defined(EXT_LIB_REGISTERED_GENERAL_EVENTS)
{
_BasicResponse_t *pMsgArgs = (_BasicResponse_t *)_SL_RESP_ARGS_START(pHdr);
SlDeviceEvent_t devHandler;
devHandler.Event = SL_DEVICE_FATAL_ERROR_EVENT;
devHandler.EventData.deviceEvent.status = pMsgArgs->status & 0xFF;
devHandler.EventData.deviceEvent.sender = (SlErrorSender_e)((pMsgArgs->status >> 8) & 0xFF);
_SlDrvHandleGeneralEvents(&devHandler);
}
#endif
break;
default:
SL_ERROR_TRACE2(MSG_306, "ASSERT: _SlDrvDeviceEventHandler : invalid opcode = 0x%x = %1", pHdr->GenHeader.Opcode, pHdr->GenHeader.Opcode);
}
}
/******************************************************************************
sl_UartSetMode
******************************************************************************/
#ifdef SL_IF_TYPE_UART
typedef union
{
_DevUartSetModeCommand_t Cmd;
_DevUartSetModeResponse_t Rsp;
}_SlUartSetModeMsg_u;
#if _SL_INCLUDE_FUNC(sl_UartSetMode)
const _SlCmdCtrl_t _SlUartSetModeCmdCtrl =
{
SL_OPCODE_DEVICE_SETUARTMODECOMMAND,
sizeof(_DevUartSetModeCommand_t),
sizeof(_DevUartSetModeResponse_t)
};
_i16 sl_UartSetMode(const SlUartIfParams_t* pUartParams)
{
_SlUartSetModeMsg_u Msg;
_u32 magicCode = 0xFFFFFFFF;
Msg.Cmd.BaudRate = pUartParams->BaudRate;
Msg.Cmd.FlowControlEnable = pUartParams->FlowControlEnable;
VERIFY_RET_OK(_SlDrvCmdOp((_SlCmdCtrl_t *)&_SlUartSetModeCmdCtrl, &Msg, NULL));
/* cmd response OK, we can continue with the handshake */
if (SL_RET_CODE_OK == Msg.Rsp.status)
{
sl_IfMaskIntHdlr();
/* Close the comm port */
sl_IfClose(g_pCB->FD);
/* Re-open the comm port */
sl_IfOpen((void * )pUartParams, UART_IF_OPEN_FLAG_RE_OPEN);
sl_IfUnMaskIntHdlr();
/* send the magic code and wait for the response */
sl_IfWrite(g_pCB->FD, (_u8* )&magicCode, 4);
magicCode = UART_SET_MODE_MAGIC_CODE;
sl_IfWrite(g_pCB->FD, (_u8* )&magicCode, 4);
/* clear magic code */
magicCode = 0;
/* wait (blocking) till the magic code to be returned from device */
sl_IfRead(g_pCB->FD, (_u8* )&magicCode, 4);
/* check for the received magic code matching */
if (UART_SET_MODE_MAGIC_CODE != magicCode)
{
_SL_ASSERT(0);
}
}
return (_i16)Msg.Rsp.status;
}
#endif
#endif

File diff suppressed because it is too large Load Diff

View File

@@ -0,0 +1,71 @@
/*
* flowcont.c - CC31xx/CC32xx Host Driver Implementation
*
* Copyright (C) 2014 Texas Instruments Incorporated - http://www.ti.com/
*
*
* Redistribution and use in source and binary forms, with or without
* modification, are permitted provided that the following conditions
* are met:
*
* Redistributions of source code must retain the above copyright
* notice, this list of conditions and the following disclaimer.
*
* Redistributions in binary form must reproduce the above copyright
* notice, this list of conditions and the following disclaimer in the
* documentation and/or other materials provided with the
* distribution.
*
* Neither the name of Texas Instruments Incorporated nor the names of
* its contributors may be used to endorse or promote products derived
* from this software without specific prior written permission.
*
* THIS SOFTWARE IS PROVIDED BY THE COPYRIGHT HOLDERS AND CONTRIBUTORS
* "AS IS" AND ANY EXPRESS OR IMPLIED WARRANTIES, INCLUDING, BUT NOT
* LIMITED TO, THE IMPLIED WARRANTIES OF MERCHANTABILITY AND FITNESS FOR
* A PARTICULAR PURPOSE ARE DISCLAIMED. IN NO EVENT SHALL THE COPYRIGHT
* OWNER OR CONTRIBUTORS BE LIABLE FOR ANY DIRECT, INDIRECT, INCIDENTAL,
* SPECIAL, EXEMPLARY, OR CONSEQUENTIAL DAMAGES (INCLUDING, BUT NOT
* LIMITED TO, PROCUREMENT OF SUBSTITUTE GOODS OR SERVICES; LOSS OF USE,
* DATA, OR PROFITS; OR BUSINESS INTERRUPTION) HOWEVER CAUSED AND ON ANY
* THEORY OF LIABILITY, WHETHER IN CONTRACT, STRICT LIABILITY, OR TORT
* (INCLUDING NEGLIGENCE OR OTHERWISE) ARISING IN ANY WAY OUT OF THE USE
* OF THIS SOFTWARE, EVEN IF ADVISED OF THE POSSIBILITY OF SUCH DAMAGE.
*
*/
/*****************************************************************************/
/* Include files */
/*****************************************************************************/
#include "simplelink.h"
#include "protocol.h"
#include "driver.h"
#include "flowcont.h"
/*****************************************************************************/
/* _SlDrvFlowContInit */
/*****************************************************************************/
void _SlDrvFlowContInit(void)
{
g_pCB->FlowContCB.TxPoolCnt = FLOW_CONT_MIN;
OSI_RET_OK_CHECK(sl_LockObjCreate(&g_pCB->FlowContCB.TxLockObj, "TxLockObj"));
OSI_RET_OK_CHECK(sl_SyncObjCreate(&g_pCB->FlowContCB.TxSyncObj, "TxSyncObj"));
}
/*****************************************************************************/
/* _SlDrvFlowContDeinit */
/*****************************************************************************/
void _SlDrvFlowContDeinit(void)
{
g_pCB->FlowContCB.TxPoolCnt = 0;
OSI_RET_OK_CHECK(sl_LockObjDelete(&g_pCB->FlowContCB.TxLockObj));
OSI_RET_OK_CHECK(sl_SyncObjDelete(&g_pCB->FlowContCB.TxSyncObj));
}

View File

@@ -0,0 +1,424 @@
/*
* fs.c - CC31xx/CC32xx Host Driver Implementation
*
* Copyright (C) 2014 Texas Instruments Incorporated - http://www.ti.com/
*
*
* Redistribution and use in source and binary forms, with or without
* modification, are permitted provided that the following conditions
* are met:
*
* Redistributions of source code must retain the above copyright
* notice, this list of conditions and the following disclaimer.
*
* Redistributions in binary form must reproduce the above copyright
* notice, this list of conditions and the following disclaimer in the
* documentation and/or other materials provided with the
* distribution.
*
* Neither the name of Texas Instruments Incorporated nor the names of
* its contributors may be used to endorse or promote products derived
* from this software without specific prior written permission.
*
* THIS SOFTWARE IS PROVIDED BY THE COPYRIGHT HOLDERS AND CONTRIBUTORS
* "AS IS" AND ANY EXPRESS OR IMPLIED WARRANTIES, INCLUDING, BUT NOT
* LIMITED TO, THE IMPLIED WARRANTIES OF MERCHANTABILITY AND FITNESS FOR
* A PARTICULAR PURPOSE ARE DISCLAIMED. IN NO EVENT SHALL THE COPYRIGHT
* OWNER OR CONTRIBUTORS BE LIABLE FOR ANY DIRECT, INDIRECT, INCIDENTAL,
* SPECIAL, EXEMPLARY, OR CONSEQUENTIAL DAMAGES (INCLUDING, BUT NOT
* LIMITED TO, PROCUREMENT OF SUBSTITUTE GOODS OR SERVICES; LOSS OF USE,
* DATA, OR PROFITS; OR BUSINESS INTERRUPTION) HOWEVER CAUSED AND ON ANY
* THEORY OF LIABILITY, WHETHER IN CONTRACT, STRICT LIABILITY, OR TORT
* (INCLUDING NEGLIGENCE OR OTHERWISE) ARISING IN ANY WAY OUT OF THE USE
* OF THIS SOFTWARE, EVEN IF ADVISED OF THE POSSIBILITY OF SUCH DAMAGE.
*
*/
/*****************************************************************************/
/* Include files */
/*****************************************************************************/
#include "simplelink.h"
#include "protocol.h"
#include "driver.h"
/*****************************************************************************/
/* Macro declarations */
/*****************************************************************************/
#define sl_min(a,b) (((a) < (b)) ? (a) : (b))
#define MAX_NVMEM_CHUNK_SIZE 1460
/*****************************************************************************/
/* Internal functions */
/*****************************************************************************/
/*****************************************************************************/
/* _sl_Strlen */
/*****************************************************************************/
_u16 _sl_Strlen(const _u8 *buffer)
{
_u16 len = 0;
if( buffer != NULL )
{
while(*buffer++) len++;
}
return len;
}
/*****************************************************************************/
/* _sl_GetCreateFsMode */
/*****************************************************************************/
_u32 _sl_GetCreateFsMode(_u32 maxSizeInBytes,_u32 accessFlags)
{
_u32 granIdx = 0;
_u32 granNum = 0;
_u32 granTable[_FS_MAX_MODE_SIZE_GRAN] = {256,1024,4096,16384,65536};
for(granIdx= _FS_MODE_SIZE_GRAN_256B ;granIdx< _FS_MAX_MODE_SIZE_GRAN;granIdx++)
{
if( granTable[granIdx]*255 >= maxSizeInBytes )
break;
}
granNum = maxSizeInBytes/granTable[granIdx];
if( maxSizeInBytes % granTable[granIdx] != 0 )
granNum++;
return _FS_MODE(_FS_MODE_OPEN_WRITE_CREATE_IF_NOT_EXIST, granIdx, granNum, accessFlags);
}
/*****************************************************************************/
/* API functions */
/*****************************************************************************/
/*****************************************************************************/
/* sl_FsOpen */
/*****************************************************************************/
typedef union
{
_FsOpenCommand_t Cmd;
_FsOpenResponse_t Rsp;
}_SlFsOpenMsg_u;
#if _SL_INCLUDE_FUNC(sl_FsOpen)
const _SlCmdCtrl_t _SlFsOpenCmdCtrl =
{
SL_OPCODE_NVMEM_FILEOPEN,
sizeof(_FsOpenCommand_t),
sizeof(_FsOpenResponse_t)
};
_i32 sl_FsOpen(const _u8 *pFileName,const _u32 AccessModeAndMaxSize, _u32 *pToken,_i32 *pFileHandle)
{
_SlReturnVal_t RetVal;
_SlFsOpenMsg_u Msg;
_SlCmdExt_t CmdExt;
CmdExt.TxPayloadLen = (_sl_Strlen(pFileName)+4) & (~3); /* add 4: 1 for NULL and the 3 for align */
CmdExt.RxPayloadLen = 0;
CmdExt.pTxPayload = (_u8*)pFileName;
CmdExt.pRxPayload = NULL;
Msg.Cmd.Mode = AccessModeAndMaxSize;
if(pToken != NULL)
{
Msg.Cmd.Token = *pToken;
}
else
{
Msg.Cmd.Token = 0;
}
RetVal = _SlDrvCmdOp((_SlCmdCtrl_t *)&_SlFsOpenCmdCtrl, &Msg, &CmdExt);
*pFileHandle = Msg.Rsp.FileHandle;
if (pToken != NULL)
{
*pToken = Msg.Rsp.Token;
}
/* in case of an error, return the erros file handler as an error code */
if( *pFileHandle < 0 )
{
return *pFileHandle;
}
return (_i32)RetVal;
}
#endif
/*****************************************************************************/
/* sl_FsClose */
/*****************************************************************************/
typedef union
{
_FsCloseCommand_t Cmd;
_BasicResponse_t Rsp;
}_SlFsCloseMsg_u;
#if _SL_INCLUDE_FUNC(sl_FsClose)
const _SlCmdCtrl_t _SlFsCloseCmdCtrl =
{
SL_OPCODE_NVMEM_FILECLOSE,
sizeof(_FsCloseCommand_t),
sizeof(_FsCloseResponse_t)
};
_i16 sl_FsClose(const _i32 FileHdl, const _u8* pCeritificateFileName,const _u8* pSignature ,const _u32 SignatureLen)
{
_SlFsCloseMsg_u Msg = {{0, 0}};
_SlCmdExt_t ExtCtrl;
Msg.Cmd.FileHandle = FileHdl;
if( pCeritificateFileName != NULL )
{
Msg.Cmd.CertificFileNameLength = (_sl_Strlen(pCeritificateFileName)+4) & (~3); /* add 4: 1 for NULL and the 3 for align */
}
Msg.Cmd.SignatureLen = SignatureLen;
ExtCtrl.TxPayloadLen = ((SignatureLen+3) & (~3)); /* align */
ExtCtrl.pTxPayload = (_u8*)pSignature;
ExtCtrl.RxPayloadLen = (_i16)Msg.Cmd.CertificFileNameLength;
ExtCtrl.pRxPayload = (_u8*)pCeritificateFileName; /* Add signature */
if(ExtCtrl.pRxPayload != NULL && ExtCtrl.RxPayloadLen != 0)
{
ExtCtrl.RxPayloadLen = ExtCtrl.RxPayloadLen * (-1);
}
VERIFY_RET_OK(_SlDrvCmdOp((_SlCmdCtrl_t *)&_SlFsCloseCmdCtrl, &Msg, &ExtCtrl));
return (_i16)((_i16)Msg.Rsp.status);
}
#endif
/*****************************************************************************/
/* sl_FsRead */
/*****************************************************************************/
typedef union
{
_FsReadCommand_t Cmd;
_FsReadResponse_t Rsp;
}_SlFsReadMsg_u;
#if _SL_INCLUDE_FUNC(sl_FsRead)
const _SlCmdCtrl_t _SlFsReadCmdCtrl =
{
SL_OPCODE_NVMEM_FILEREADCOMMAND,
sizeof(_FsReadCommand_t),
sizeof(_FsReadResponse_t)
};
_i32 sl_FsRead(const _i32 FileHdl,_u32 Offset, _u8* pData,_u32 Len)
{
_SlFsReadMsg_u Msg;
_SlCmdExt_t ExtCtrl;
_u16 ChunkLen;
_SlReturnVal_t RetVal =0;
_i32 RetCount = 0;
ExtCtrl.TxPayloadLen = 0;
ExtCtrl.pTxPayload = NULL;
ChunkLen = (_u16)sl_min(MAX_NVMEM_CHUNK_SIZE,Len);
ExtCtrl.RxPayloadLen = ChunkLen;
ExtCtrl.pRxPayload = (_u8 *)(pData);
Msg.Cmd.Offset = Offset;
Msg.Cmd.Len = ChunkLen;
Msg.Cmd.FileHandle = FileHdl;
do
{
RetVal = _SlDrvCmdOp((_SlCmdCtrl_t *)&_SlFsReadCmdCtrl, &Msg, &ExtCtrl);
if(SL_OS_RET_CODE_OK == RetVal)
{
if( Msg.Rsp.status < 0)
{
if( RetCount > 0)
{
return RetCount;
}
else
{
return Msg.Rsp.status;
}
}
RetCount += (_i32)Msg.Rsp.status;
Len -= ChunkLen;
Offset += ChunkLen;
Msg.Cmd.Offset = Offset;
ExtCtrl.pRxPayload += ChunkLen;
ChunkLen = (_u16)sl_min(MAX_NVMEM_CHUNK_SIZE,Len);
ExtCtrl.RxPayloadLen = ChunkLen;
Msg.Cmd.Len = ChunkLen;
Msg.Cmd.FileHandle = FileHdl;
}
else
{
return RetVal;
}
}while(ChunkLen > 0);
return (_i32)RetCount;
}
#endif
/*****************************************************************************/
/* sl_FsWrite */
/*****************************************************************************/
typedef union
{
_FsWriteCommand_t Cmd;
_FsWriteResponse_t Rsp;
}_SlFsWriteMsg_u;
#if _SL_INCLUDE_FUNC(sl_FsWrite)
const _SlCmdCtrl_t _SlFsWriteCmdCtrl =
{
SL_OPCODE_NVMEM_FILEWRITECOMMAND,
sizeof(_FsWriteCommand_t),
sizeof(_FsWriteResponse_t)
};
_i32 sl_FsWrite(const _i32 FileHdl,_u32 Offset, _u8* pData,_u32 Len)
{
_SlFsWriteMsg_u Msg;
_SlCmdExt_t ExtCtrl;
_u16 ChunkLen;
_SlReturnVal_t RetVal;
_i32 RetCount = 0;
ExtCtrl.RxPayloadLen = 0;
ExtCtrl.pRxPayload = NULL;
ChunkLen = (_u16)sl_min(MAX_NVMEM_CHUNK_SIZE,Len);
ExtCtrl.TxPayloadLen = ChunkLen;
ExtCtrl.pTxPayload = (_u8 *)(pData);
Msg.Cmd.Offset = Offset;
Msg.Cmd.Len = ChunkLen;
Msg.Cmd.FileHandle = FileHdl;
do
{
RetVal = _SlDrvCmdOp((_SlCmdCtrl_t *)&_SlFsWriteCmdCtrl, &Msg, &ExtCtrl);
if(SL_OS_RET_CODE_OK == RetVal)
{
if( Msg.Rsp.status < 0)
{
if( RetCount > 0)
{
return RetCount;
}
else
{
return Msg.Rsp.status;
}
}
RetCount += (_i32)Msg.Rsp.status;
Len -= ChunkLen;
Offset += ChunkLen;
Msg.Cmd.Offset = Offset;
ExtCtrl.pTxPayload += ChunkLen;
ChunkLen = (_u16)sl_min(MAX_NVMEM_CHUNK_SIZE,Len);
ExtCtrl.TxPayloadLen = ChunkLen;
Msg.Cmd.Len = ChunkLen;
Msg.Cmd.FileHandle = FileHdl;
}
else
{
return RetVal;
}
}while(ChunkLen > 0);
return (_i32)RetCount;
}
#endif
/*****************************************************************************/
/* sl_FsGetInfo */
/*****************************************************************************/
typedef union
{
_FsGetInfoCommand_t Cmd;
_FsGetInfoResponse_t Rsp;
}_SlFsGetInfoMsg_u;
#if _SL_INCLUDE_FUNC(sl_FsGetInfo)
const _SlCmdCtrl_t _SlFsGetInfoCmdCtrl =
{
SL_OPCODE_NVMEM_FILEGETINFOCOMMAND,
sizeof(_FsGetInfoCommand_t),
sizeof(_FsGetInfoResponse_t)
};
_i16 sl_FsGetInfo(const _u8 *pFileName,const _u32 Token,SlFsFileInfo_t* pFsFileInfo)
{
_SlFsGetInfoMsg_u Msg;
_SlCmdExt_t CmdExt;
CmdExt.TxPayloadLen = (_sl_Strlen(pFileName)+4) & (~3); /* add 4: 1 for NULL and the 3 for align */
CmdExt.RxPayloadLen = 0;
CmdExt.pTxPayload = (_u8*)pFileName;
CmdExt.pRxPayload = NULL;
Msg.Cmd.Token = Token;
VERIFY_RET_OK(_SlDrvCmdOp((_SlCmdCtrl_t *)&_SlFsGetInfoCmdCtrl, &Msg, &CmdExt));
pFsFileInfo->flags = Msg.Rsp.flags;
pFsFileInfo->FileLen = Msg.Rsp.FileLen;
pFsFileInfo->AllocatedLen = Msg.Rsp.AllocatedLen;
pFsFileInfo->Token[0] = Msg.Rsp.Token[0];
pFsFileInfo->Token[1] = Msg.Rsp.Token[1];
pFsFileInfo->Token[2] = Msg.Rsp.Token[2];
pFsFileInfo->Token[3] = Msg.Rsp.Token[3];
return (_i16)((_i16)Msg.Rsp.Status);
}
#endif
/*****************************************************************************/
/* sl_FsDel */
/*****************************************************************************/
typedef union
{
_FsDeleteCommand_t Cmd;
_FsDeleteResponse_t Rsp;
}_SlFsDeleteMsg_u;
#if _SL_INCLUDE_FUNC(sl_FsDel)
const _SlCmdCtrl_t _SlFsDeleteCmdCtrl =
{
SL_OPCODE_NVMEM_FILEDELCOMMAND,
sizeof(_FsDeleteCommand_t),
sizeof(_FsDeleteResponse_t)
};
_i16 sl_FsDel(const _u8 *pFileName,const _u32 Token)
{
_SlFsDeleteMsg_u Msg;
_SlCmdExt_t CmdExt;
CmdExt.TxPayloadLen = (_sl_Strlen(pFileName)+4) & (~3); /* add 4: 1 for NULL and the 3 for align */
CmdExt.RxPayloadLen = 0;
CmdExt.pTxPayload = (_u8*)pFileName;
CmdExt.pRxPayload = NULL;
Msg.Cmd.Token = Token;
VERIFY_RET_OK(_SlDrvCmdOp((_SlCmdCtrl_t *)&_SlFsDeleteCmdCtrl, &Msg, &CmdExt));
return (_i16)((_i16)Msg.Rsp.status);
}
#endif

File diff suppressed because it is too large Load Diff

View File

@@ -0,0 +1,150 @@
/*
* netcfg.c - CC31xx/CC32xx Host Driver Implementation
*
* Copyright (C) 2014 Texas Instruments Incorporated - http://www.ti.com/
*
*
* Redistribution and use in source and binary forms, with or without
* modification, are permitted provided that the following conditions
* are met:
*
* Redistributions of source code must retain the above copyright
* notice, this list of conditions and the following disclaimer.
*
* Redistributions in binary form must reproduce the above copyright
* notice, this list of conditions and the following disclaimer in the
* documentation and/or other materials provided with the
* distribution.
*
* Neither the name of Texas Instruments Incorporated nor the names of
* its contributors may be used to endorse or promote products derived
* from this software without specific prior written permission.
*
* THIS SOFTWARE IS PROVIDED BY THE COPYRIGHT HOLDERS AND CONTRIBUTORS
* "AS IS" AND ANY EXPRESS OR IMPLIED WARRANTIES, INCLUDING, BUT NOT
* LIMITED TO, THE IMPLIED WARRANTIES OF MERCHANTABILITY AND FITNESS FOR
* A PARTICULAR PURPOSE ARE DISCLAIMED. IN NO EVENT SHALL THE COPYRIGHT
* OWNER OR CONTRIBUTORS BE LIABLE FOR ANY DIRECT, INDIRECT, INCIDENTAL,
* SPECIAL, EXEMPLARY, OR CONSEQUENTIAL DAMAGES (INCLUDING, BUT NOT
* LIMITED TO, PROCUREMENT OF SUBSTITUTE GOODS OR SERVICES; LOSS OF USE,
* DATA, OR PROFITS; OR BUSINESS INTERRUPTION) HOWEVER CAUSED AND ON ANY
* THEORY OF LIABILITY, WHETHER IN CONTRACT, STRICT LIABILITY, OR TORT
* (INCLUDING NEGLIGENCE OR OTHERWISE) ARISING IN ANY WAY OUT OF THE USE
* OF THIS SOFTWARE, EVEN IF ADVISED OF THE POSSIBILITY OF SUCH DAMAGE.
*
*/
/*****************************************************************************/
/* Include files */
/*****************************************************************************/
#include "simplelink.h"
#include "protocol.h"
#include "driver.h"
/*****************************************************************************/
/* sl_NetCfgSet */
/*****************************************************************************/
typedef union
{
_NetCfgSetGet_t Cmd;
_BasicResponse_t Rsp;
}_SlNetCfgMsgSet_u;
#if _SL_INCLUDE_FUNC(sl_NetCfgSet)
const _SlCmdCtrl_t _SlNetCfgSetCmdCtrl =
{
SL_OPCODE_DEVICE_NETCFG_SET_COMMAND,
sizeof(_NetCfgSetGet_t),
sizeof(_BasicResponse_t)
};
_i32 sl_NetCfgSet(const _u8 ConfigId ,const _u8 ConfigOpt,const _u8 ConfigLen,const _u8 *pValues)
{
_SlNetCfgMsgSet_u Msg;
_SlCmdExt_t CmdExt;
_SlDrvResetCmdExt(&CmdExt);
CmdExt.TxPayloadLen = (ConfigLen+3) & (~3);
CmdExt.pTxPayload = (_u8 *)pValues;
Msg.Cmd.ConfigId = ConfigId;
Msg.Cmd.ConfigLen = ConfigLen;
Msg.Cmd.ConfigOpt = ConfigOpt;
VERIFY_RET_OK(_SlDrvCmdOp((_SlCmdCtrl_t *)&_SlNetCfgSetCmdCtrl, &Msg, &CmdExt));
return (_i16)Msg.Rsp.status;
}
#endif
/*****************************************************************************/
/* sl_NetCfgGet */
/*****************************************************************************/
typedef union
{
_NetCfgSetGet_t Cmd;
_NetCfgSetGet_t Rsp;
}_SlNetCfgMsgGet_u;
#if _SL_INCLUDE_FUNC(sl_NetCfgGet)
const _SlCmdCtrl_t _SlNetCfgGetCmdCtrl =
{
SL_OPCODE_DEVICE_NETCFG_GET_COMMAND,
sizeof(_NetCfgSetGet_t),
sizeof(_NetCfgSetGet_t)
};
_i32 sl_NetCfgGet(const _u8 ConfigId, _u8 *pConfigOpt,_u8 *pConfigLen, _u8 *pValues)
{
_SlNetCfgMsgGet_u Msg;
_SlCmdExt_t CmdExt;
if (*pConfigLen == 0)
{
return SL_EZEROLEN;
}
_SlDrvResetCmdExt(&CmdExt);
CmdExt.RxPayloadLen = *pConfigLen;
CmdExt.pRxPayload = (_u8 *)pValues;
Msg.Cmd.ConfigLen = *pConfigLen;
Msg.Cmd.ConfigId = ConfigId;
if( pConfigOpt )
{
Msg.Cmd.ConfigOpt = (_u16)*pConfigOpt;
}
VERIFY_RET_OK(_SlDrvCmdOp((_SlCmdCtrl_t *)&_SlNetCfgGetCmdCtrl, &Msg, &CmdExt));
if( pConfigOpt )
{
*pConfigOpt = (_u8)Msg.Rsp.ConfigOpt;
}
if (CmdExt.RxPayloadLen < CmdExt.ActualRxPayloadLen)
{
*pConfigLen = (_u8)CmdExt.RxPayloadLen;
if( SL_MAC_ADDRESS_GET == ConfigId )
{
return SL_RET_CODE_OK; /* sp fix */
}
else
{
return SL_ESMALLBUF;
}
}
else
{
*pConfigLen = (_u8)CmdExt.ActualRxPayloadLen;
}
return (_i16)Msg.Rsp.Status;
}
#endif

View File

@@ -0,0 +1,171 @@
/*
* nonos.c - CC31xx/CC32xx Host Driver Implementation
*
* Copyright (C) 2014 Texas Instruments Incorporated - http://www.ti.com/
*
*
* Redistribution and use in source and binary forms, with or without
* modification, are permitted provided that the following conditions
* are met:
*
* Redistributions of source code must retain the above copyright
* notice, this list of conditions and the following disclaimer.
*
* Redistributions in binary form must reproduce the above copyright
* notice, this list of conditions and the following disclaimer in the
* documentation and/or other materials provided with the
* distribution.
*
* Neither the name of Texas Instruments Incorporated nor the names of
* its contributors may be used to endorse or promote products derived
* from this software without specific prior written permission.
*
* THIS SOFTWARE IS PROVIDED BY THE COPYRIGHT HOLDERS AND CONTRIBUTORS
* "AS IS" AND ANY EXPRESS OR IMPLIED WARRANTIES, INCLUDING, BUT NOT
* LIMITED TO, THE IMPLIED WARRANTIES OF MERCHANTABILITY AND FITNESS FOR
* A PARTICULAR PURPOSE ARE DISCLAIMED. IN NO EVENT SHALL THE COPYRIGHT
* OWNER OR CONTRIBUTORS BE LIABLE FOR ANY DIRECT, INDIRECT, INCIDENTAL,
* SPECIAL, EXEMPLARY, OR CONSEQUENTIAL DAMAGES (INCLUDING, BUT NOT
* LIMITED TO, PROCUREMENT OF SUBSTITUTE GOODS OR SERVICES; LOSS OF USE,
* DATA, OR PROFITS; OR BUSINESS INTERRUPTION) HOWEVER CAUSED AND ON ANY
* THEORY OF LIABILITY, WHETHER IN CONTRACT, STRICT LIABILITY, OR TORT
* (INCLUDING NEGLIGENCE OR OTHERWISE) ARISING IN ANY WAY OUT OF THE USE
* OF THIS SOFTWARE, EVEN IF ADVISED OF THE POSSIBILITY OF SUCH DAMAGE.
*
*/
/*****************************************************************************/
/* Include files */
/*****************************************************************************/
#include "simplelink.h"
#include "protocol.h"
#include "driver.h"
#ifndef SL_PLATFORM_MULTI_THREADED
#include "nonos.h"
#ifndef SL_TINY_EXT
#define NONOS_MAX_SPAWN_ENTRIES 5
#else
#define NONOS_MAX_SPAWN_ENTRIES 1
#endif
typedef struct
{
_SlSpawnEntryFunc_t pEntry;
void* pValue;
}_SlNonOsSpawnEntry_t;
typedef struct
{
_SlNonOsSpawnEntry_t SpawnEntries[NONOS_MAX_SPAWN_ENTRIES];
}_SlNonOsCB_t;
_SlNonOsCB_t g__SlNonOsCB;
_SlNonOsRetVal_t _SlNonOsSemSet(_SlNonOsSemObj_t* pSemObj , _SlNonOsSemObj_t Value)
{
*pSemObj = Value;
return NONOS_RET_OK;
}
_SlNonOsRetVal_t _SlNonOsSemGet(_SlNonOsSemObj_t* pSyncObj, _SlNonOsSemObj_t WaitValue, _SlNonOsSemObj_t SetValue, _SlNonOsTime_t Timeout)
{
#ifdef _SlSyncWaitLoopCallback
_SlNonOsTime_t timeOutRequest = Timeout;
#endif
while (Timeout>0)
{
if (WaitValue == *pSyncObj)
{
*pSyncObj = SetValue;
break;
}
if (Timeout != NONOS_WAIT_FOREVER)
{
Timeout--;
}
_SlNonOsMainLoopTask();
#ifdef _SlSyncWaitLoopCallback
if( (__NON_OS_SYNC_OBJ_SIGNAL_VALUE == WaitValue) && (timeOutRequest != NONOS_NO_WAIT) )
{
if (WaitValue == *pSyncObj)
{
*pSyncObj = SetValue;
break;
}
_SlSyncWaitLoopCallback();
}
#endif
}
if (0 == Timeout)
{
return NONOS_RET_ERR;
}
else
{
return NONOS_RET_OK;
}
}
_SlNonOsRetVal_t _SlNonOsSpawn(_SlSpawnEntryFunc_t pEntry , void* pValue , _u32 flags)
{
_i8 i = 0;
#ifndef SL_TINY_EXT
for (i=0 ; i<NONOS_MAX_SPAWN_ENTRIES ; i++)
#endif
{
_SlNonOsSpawnEntry_t* pE = &g__SlNonOsCB.SpawnEntries[i];
if (NULL == pE->pEntry)
{
pE->pValue = pValue;
pE->pEntry = pEntry;
#ifndef SL_TINY_EXT
break;
#endif
}
}
return NONOS_RET_OK;
}
_SlNonOsRetVal_t _SlNonOsMainLoopTask(void)
{
_i8 i=0;
#ifndef SL_TINY_EXT
for (i=0 ; i<NONOS_MAX_SPAWN_ENTRIES ; i++)
#endif
{
_SlNonOsSpawnEntry_t* pE = &g__SlNonOsCB.SpawnEntries[i];
_SlSpawnEntryFunc_t pF = pE->pEntry;
if (NULL != pF)
{
if(RxIrqCnt != (g_pCB)->RxDoneCnt)
{
pF(0); /* (pValue) */
}
pE->pEntry = NULL;
pE->pValue = NULL;
}
}
return NONOS_RET_OK;
}
#endif /*(SL_PLATFORM != SL_PLATFORM_NON_OS)*/

File diff suppressed because it is too large Load Diff

View File

@@ -0,0 +1,197 @@
/*
* spawn.c - CC31xx/CC32xx Host Driver Implementation
*
* Copyright (C) 2014 Texas Instruments Incorporated - http://www.ti.com/
*
*
* Redistribution and use in source and binary forms, with or without
* modification, are permitted provided that the following conditions
* are met:
*
* Redistributions of source code must retain the above copyright
* notice, this list of conditions and the following disclaimer.
*
* Redistributions in binary form must reproduce the above copyright
* notice, this list of conditions and the following disclaimer in the
* documentation and/or other materials provided with the
* distribution.
*
* Neither the name of Texas Instruments Incorporated nor the names of
* its contributors may be used to endorse or promote products derived
* from this software without specific prior written permission.
*
* THIS SOFTWARE IS PROVIDED BY THE COPYRIGHT HOLDERS AND CONTRIBUTORS
* "AS IS" AND ANY EXPRESS OR IMPLIED WARRANTIES, INCLUDING, BUT NOT
* LIMITED TO, THE IMPLIED WARRANTIES OF MERCHANTABILITY AND FITNESS FOR
* A PARTICULAR PURPOSE ARE DISCLAIMED. IN NO EVENT SHALL THE COPYRIGHT
* OWNER OR CONTRIBUTORS BE LIABLE FOR ANY DIRECT, INDIRECT, INCIDENTAL,
* SPECIAL, EXEMPLARY, OR CONSEQUENTIAL DAMAGES (INCLUDING, BUT NOT
* LIMITED TO, PROCUREMENT OF SUBSTITUTE GOODS OR SERVICES; LOSS OF USE,
* DATA, OR PROFITS; OR BUSINESS INTERRUPTION) HOWEVER CAUSED AND ON ANY
* THEORY OF LIABILITY, WHETHER IN CONTRACT, STRICT LIABILITY, OR TORT
* (INCLUDING NEGLIGENCE OR OTHERWISE) ARISING IN ANY WAY OUT OF THE USE
* OF THIS SOFTWARE, EVEN IF ADVISED OF THE POSSIBILITY OF SUCH DAMAGE.
*
*/
/*****************************************************************************/
/* Include files */
/*****************************************************************************/
#include "simplelink.h"
#if (defined (SL_PLATFORM_MULTI_THREADED)) && (!defined (SL_PLATFORM_EXTERNAL_SPAWN))
#define _SL_MAX_INTERNAL_SPAWN_ENTRIES 10
typedef struct _SlInternalSpawnEntry_t
{
_SlSpawnEntryFunc_t pEntry;
void* pValue;
struct _SlInternalSpawnEntry_t* pNext;
}_SlInternalSpawnEntry_t;
typedef struct
{
_SlInternalSpawnEntry_t SpawnEntries[_SL_MAX_INTERNAL_SPAWN_ENTRIES];
_SlInternalSpawnEntry_t* pFree;
_SlInternalSpawnEntry_t* pWaitForExe;
_SlInternalSpawnEntry_t* pLastInWaitList;
_SlSyncObj_t SyncObj;
_SlLockObj_t LockObj;
}_SlInternalSpawnCB_t;
_SlInternalSpawnCB_t g_SlInternalSpawnCB;
void _SlInternalSpawnTaskEntry()
{
_i16 i;
_SlInternalSpawnEntry_t* pEntry;
_u8 LastEntry;
/* create and lock the locking object. lock in order to avoid race condition
on the first creation */
sl_LockObjCreate(&g_SlInternalSpawnCB.LockObj,"SlSpawnProtect");
sl_LockObjLock(&g_SlInternalSpawnCB.LockObj,SL_OS_NO_WAIT);
/* create and clear the sync object */
sl_SyncObjCreate(&g_SlInternalSpawnCB.SyncObj,"SlSpawnSync");
sl_SyncObjWait(&g_SlInternalSpawnCB.SyncObj,SL_OS_NO_WAIT);
g_SlInternalSpawnCB.pFree = &g_SlInternalSpawnCB.SpawnEntries[0];
g_SlInternalSpawnCB.pWaitForExe = NULL;
g_SlInternalSpawnCB.pLastInWaitList = NULL;
/* create the link list between the entries */
for (i=0 ; i<_SL_MAX_INTERNAL_SPAWN_ENTRIES - 1 ; i++)
{
g_SlInternalSpawnCB.SpawnEntries[i].pNext = &g_SlInternalSpawnCB.SpawnEntries[i+1];
g_SlInternalSpawnCB.SpawnEntries[i].pEntry = NULL;
}
g_SlInternalSpawnCB.SpawnEntries[i].pNext = NULL;
_SlDrvObjUnLock(&g_SlInternalSpawnCB.LockObj);
/* here we ready to execute entries */
while (TRUE)
{
sl_SyncObjWait(&g_SlInternalSpawnCB.SyncObj,SL_OS_WAIT_FOREVER);
/* go over all entries that already waiting for execution */
LastEntry = FALSE;
do
{
/* get entry to execute */
_SlDrvObjLockWaitForever(&g_SlInternalSpawnCB.LockObj);
pEntry = g_SlInternalSpawnCB.pWaitForExe;
if ( NULL == pEntry )
{
_SlDrvObjUnLock(&g_SlInternalSpawnCB.LockObj);
break;
}
g_SlInternalSpawnCB.pWaitForExe = pEntry->pNext;
if (pEntry == g_SlInternalSpawnCB.pLastInWaitList)
{
g_SlInternalSpawnCB.pLastInWaitList = NULL;
LastEntry = TRUE;
}
_SlDrvObjUnLock(&g_SlInternalSpawnCB.LockObj);
/* pEntry could be null in case that the sync was already set by some
of the entries during execution of earlier entry */
if (NULL != pEntry)
{
pEntry->pEntry(pEntry->pValue);
/* free the entry */
_SlDrvObjLockWaitForever(&g_SlInternalSpawnCB.LockObj);
pEntry->pNext = g_SlInternalSpawnCB.pFree;
g_SlInternalSpawnCB.pFree = pEntry;
if (NULL != g_SlInternalSpawnCB.pWaitForExe)
{
/* new entry received meanwhile */
LastEntry = FALSE;
}
_SlDrvObjUnLock(&g_SlInternalSpawnCB.LockObj);
}
}while (!LastEntry);
}
}
_i16 _SlInternalSpawn(_SlSpawnEntryFunc_t pEntry , void* pValue , _u32 flags)
{
_i16 Res = 0;
_SlInternalSpawnEntry_t* pSpawnEntry;
if (NULL == pEntry)
{
Res = -1;
}
else
{
_SlDrvObjLockWaitForever(&g_SlInternalSpawnCB.LockObj);
pSpawnEntry = g_SlInternalSpawnCB.pFree;
g_SlInternalSpawnCB.pFree = pSpawnEntry->pNext;
pSpawnEntry->pEntry = pEntry;
pSpawnEntry->pValue = pValue;
pSpawnEntry->pNext = NULL;
if (NULL == g_SlInternalSpawnCB.pWaitForExe)
{
g_SlInternalSpawnCB.pWaitForExe = pSpawnEntry;
g_SlInternalSpawnCB.pLastInWaitList = pSpawnEntry;
}
else
{
g_SlInternalSpawnCB.pLastInWaitList->pNext = pSpawnEntry;
g_SlInternalSpawnCB.pLastInWaitList = pSpawnEntry;
}
_SlDrvObjUnLock(&g_SlInternalSpawnCB.LockObj);
/* this sync is called after releasing the lock object to avoid unnecessary context switches */
_SlDrvSyncObjSignal(&g_SlInternalSpawnCB.SyncObj);
}
return Res;
}
#endif

File diff suppressed because it is too large Load Diff