PRIVATE IX_STATUS timerInit (void) { IxOsalThread taskId; IX_STATUS ixStatus; IxOsalThreadAttr timerThreadAttr; ixStatus = ixOsalSemaphoreInit (&ixOsalCriticalSectSem, IX_OSAL_TIMER_SEM_AVAILABLE); if (ixStatus != IX_SUCCESS) { ixOsalLog (IX_OSAL_LOG_LVL_ERROR, IX_OSAL_LOG_DEV_STDOUT, "Error creating critical section semaphore\n", 0, 0, 0, 0, 0, 0); return IX_FAIL; } ixStatus = ixOsalSemaphoreInit (&ixOsalTimerRecalcSem, IX_OSAL_TIMER_SEM_AVAILABLE); if (ixStatus != IX_SUCCESS) { ixOsalLog (IX_OSAL_LOG_LVL_ERROR, IX_OSAL_LOG_DEV_STDOUT, "Error creating timer recalc semaphore\n", 0, 0, 0, 0, 0, 0); return IX_FAIL; } timerThreadAttr.stackSize = 10 * 1024; timerThreadAttr.priority = 90; timerThreadAttr.name = ixOsalTimerThreadName; ixStatus = ixOsalThreadCreate (&taskId, &timerThreadAttr, (IxOsalVoidFnVoidPtr) timerLoop, NULL); if (ixStatus != IX_SUCCESS) { ixOsalLog (IX_OSAL_LOG_LVL_ERROR, IX_OSAL_LOG_DEV_STDOUT, "timerInit: fail to create timer thread. \n", 0, 0, 0, 0, 0, 0); return IX_FAIL; } ixStatus = ixOsalThreadStart (&taskId); if (ixStatus != IX_SUCCESS) { ixOsalLog (IX_OSAL_LOG_LVL_ERROR, IX_OSAL_LOG_DEV_STDOUT, "Error creating timerLoop task\n", 0, 0, 0, 0, 0, 0); return IX_FAIL; } return IX_SUCCESS; }
/** * @brief initializes the event queue and the event processor * * This function is called by the component initialization * function, ixEthDBInit(). * * @warning do not call directly * * @return IX_ETH_DB_SUCCESS if the operation completed * successfully or IX_ETH_DB_FAIL otherwise * * @internal */ IX_ETH_DB_PUBLIC IxEthDBStatus ixEthDBStartLearningFunction(void) { IxOsalThread eventProcessorThread; IxOsalThreadAttr threadAttr; threadAttr.name = "EthDB event thread"; threadAttr.stackSize = 32 * 1024; /* 32kbytes */ threadAttr.priority = 128; /* reset event queue */ ixOsalMutexLock(&eventQueueLock, IX_OSAL_WAIT_FOREVER); RESET_QUEUE(&eventQueue); ixOsalMutexUnlock(&eventQueueLock); /* init event queue semaphore */ if (ixOsalSemaphoreInit(&eventQueueSemaphore, 0) != IX_SUCCESS) { return IX_ETH_DB_FAIL; } ixEthDBLearningShutdown = FALSE; /* create processor loop thread */ if (ixOsalThreadCreate(&eventProcessorThread, &threadAttr, ixEthDBEventProcessorLoop, NULL) != IX_SUCCESS) { return IX_ETH_DB_FAIL; } /* start event processor */ ixOsalThreadStart(&eventProcessorThread); return IX_ETH_DB_SUCCESS; }
void ixHssAccCodeletChannelisedServiceConfigure ( IxHssAccHssPort hssPortId) { IX_STATUS status; unsigned bytesPerTSTrigger; UINT8 *rxCircular; unsigned numRxBytesPerTS; UINT32 *txPtrList; unsigned numTxPtrLists; unsigned numTxBytesPerBlk; IxHssAccChanRxCallback rxCallback; unsigned channelIndex; unsigned i; ClientInfo *pClientInfo = &clientInfo[hssPortId]; ChannelInfo *pChannelInfo; IxOsalThreadAttr ixHssAccCodeletChanThreadAttr; /* initialise client infor structure for this client */ pClientInfo->hssPortId = hssPortId; pClientInfo->lastTxOffset = -1; pClientInfo->nextRxOffset = 0; /* 1st rxOffset we receive to */ pClientInfo->lastRxOffset = -1; /* initially invalid */ pClientInfo->readyToLoopback = FALSE; /* no samples Rx'ed yet */ for (channelIndex = 0; channelIndex < IX_HSSACC_CODELET_CHAN_NUM_CHANS; channelIndex++) { pChannelInfo = &pClientInfo->channelInfo[channelIndex]; /* not receiving non-idle data yet */ pChannelInfo->receivingNonIdleData = FALSE; /* initialise the tx/rx sample data values (to channel number) */ pChannelInfo->txSampleData = channelIndex + 1; pChannelInfo->rxSampleData = channelIndex + 1; } /****************/ /* START THREAD */ /****************/ /* initialise message queue to empty */ pClientInfo->qHead = 0; pClientInfo->qTail = 0; /* initialise the rx semaphore */ (void) ixOsalSemaphoreInit ( &pClientInfo->messageSem, IX_HSSACC_CODELET_SEM_UNAVAILABLE); /* create the thread for processing callbacks */ /* when running both packetised and channelised services, the */ /* channelised service needs to be serviced in a higher priority */ /* thread (high) than the packetised service (low) */ ixHssAccCodeletChanThreadAttr.name = "HSS Codelet Chan CB"; ixHssAccCodeletChanThreadAttr.stackSize = 10240; ixHssAccCodeletChanThreadAttr.priority = IX_HSSACC_CODELET_THREAD_PRI_HIGH; (void) ixOsalThreadCreate ( &pClientInfo->threadId, /* threadId */ &ixHssAccCodeletChanThreadAttr, /* threadAttr */ (IxOsalVoidFnVoidPtr)ixHssAccCodeletChanThreadMain, /* startRoutine */ pClientInfo); /* arg */ /* start the thread for processing callbacks */ (void) ixOsalThreadStart ( &pClientInfo->threadId); /* threadId */ /********************/ /* ALLOCATE BUFFERS */ /********************/ /* allocate channelised RX buffers */ if (pClientInfo->rxBuffers == 0) { pClientInfo->rxBuffers = IX_OSAL_CACHE_DMA_MALLOC( sizeof (*pClientInfo->rxBuffers)); if (pClientInfo->rxBuffers == 0) { printf("Failed to allocated Rx buffers\n"); return; } } /* to allow for caching, we request a cache flush after memset */ MEMSET_AND_FLUSH (pClientInfo->rxBuffers, 0x00, sizeof (*pClientInfo->rxBuffers)); /* allocate channelised TX buffers */ if (pClientInfo->txBuffers == 0) { pClientInfo->txBuffers = IX_OSAL_CACHE_DMA_MALLOC( sizeof (*pClientInfo->txBuffers)); if (pClientInfo->txBuffers == 0) { printf("Failed to allocated Tx buffers\n"); return; } } /* to allow for caching, we request a cache flush after memset */ MEMSET_AND_FLUSH (pClientInfo->txBuffers, 0x00, sizeof (*pClientInfo->txBuffers)); /* allocate channelised TX pointer lists */ if (pClientInfo->txPointers == 0) { pClientInfo->txPointers = IX_OSAL_CACHE_DMA_MALLOC( sizeof (*pClientInfo->txPointers)); if (pClientInfo->txPointers == 0) { printf("Failed to allocated Tx pointers\n"); return; } } /* to allow for caching, we request a cache flush after memset */ MEMSET_AND_FLUSH (pClientInfo->txPointers, 0x00, sizeof (*pClientInfo->txPointers)); /**********************/ /* CONNECT TO SERVICE */ /**********************/ /* Bytes per timeslot trigger = 8 */ bytesPerTSTrigger = IX_HSSACC_CODELET_CHAN_BYTES_PER_TS_TRIG; /* RX circular buffer = RX buffer */ rxCircular = (UINT8 *)(*pClientInfo->rxBuffers); /* Number of RX bytes per timeslot = 176 (RX buf size per channel) */ numRxBytesPerTS = IX_HSSACC_CODELET_CHAN_RX_BUFSIZE_PERCHAN; /* TX pointer list = TX pointer array */ txPtrList = (UINT32 *)(*pClientInfo->txPointers); /* Number of TX pointer lists = 8 (latency factor) */ numTxPtrLists = IX_HSSACC_CODELET_CHAN_TX_LATENCY_FACTOR; /* Number of TX bytes per block = 44 (bytes per sample) */ numTxBytesPerBlk = IX_HSSACC_CODELET_CHAN_BYTES_PER_SAMPLE; /* Receive callback */ rxCallback = ixHssAccCodeletChanRxCallback; /* connect this client to the Channelised Service */ status = ixHssAccChanConnect ( hssPortId, /* hssPortId */ bytesPerTSTrigger, /* bytesPerTSTrigger */ rxCircular, /* rxCircular */ numRxBytesPerTS, /* numRxBytesPerTS */ txPtrList, /* txPtrList */ numTxPtrLists, /* numTxPtrLists */ numTxBytesPerBlk, /* numTxBytesPerBlk */ rxCallback); /* rxCallback */ /* if there was any problem then update stats */ if (status != IX_SUCCESS) { stats[hssPortId].chan.connectFails++; return; } /*******************/ /* PREPARE TX DATA */ /*******************/ /* prepare data for transmit */ for (i = 1; i <= IX_HSSACC_CODELET_CHAN_TX_LATENCY_FACTOR; i++) { /* by passing in txOffsets from 1 to the tx latency factor, we */ /* can reuse our transmit function to initially fill up the tx */ /* buffer with data */ ixHssAccCodeletChannelisedDataTransmit (hssPortId, i); } }
/** * @ingroup IxTimeSyncAccCodelet * * @fn ixTimeSyncAccCodeletPTPMsgTransmit () * * @brief Transmit Sync message from master port and Delay_Req message * from slave port every 2 seconds. * * @return void */ PRIVATE void ixTimeSyncAccCodeletPTPMsgTransmit () { IX_OSAL_MBUF *mBufPtr; IxEthAccPortId portId = 0; IxTimeSyncAcc1588PTPPort tsChannel; IxTimeSyncAcc1588PTPMsgType txMsgType; IxTimeSyncAcc1588PTPPortMode tsChannelMode; /* clear PTP message transmission halt flag */ ixTimeSyncAccCodeletTxHalt = FALSE; for (tsChannel = IX_TIMESYNCACC_NPE_A_1588PTP_PORT; tsChannel < IX_TIMESYNCACC_CODELET_MAX_TS_CHANNELS; tsChannel++) { portId = ixTimeSyncAccCodeletPortIdList[tsChannel]; tsChannelMode = ixTimeSyncAccCodeletConfigPtr->tsChannelMode[tsChannel]; txMsgType = ixTimeSyncAccCodeletPTPMsgTypeList[tsChannelMode]; /* build PTP message */ ixTimeSyncAccCodeletPTPMsgBuild (txMsgType); if (IX_SUCCESS != ixTimeSyncAccCodeletPortConfigure (portId)) { ixOsalLog (IX_OSAL_LOG_LVL_ERROR, IX_OSAL_LOG_DEV_STDERR, "ixTimeSyncAccCodeletPTPMsgTransmit: failed to configure port %d\n", portId, 0, 0, 0, 0, 0); /* terminate time sync codelet execution */ ixTimeSyncAccCodeletUninit (); return; } if (IX_ETH_ACC_SUCCESS != ixEthAccPortEnable (portId)) { ixOsalLog (IX_OSAL_LOG_LVL_ERROR, IX_OSAL_LOG_DEV_STDERR, "ixTimeSyncAccCodeletPTPMsgTransmit: failed to enable port %d\n", portId, 0, 0, 0, 0, 0); /* terminate time sync codelet execution */ ixTimeSyncAccCodeletUninit (); return; } mBufPtr = ixTimeSyncAccCodeletGlobalMBuf[portId]; if (NULL == mBufPtr) { ixOsalLog (IX_OSAL_LOG_LVL_ERROR, IX_OSAL_LOG_DEV_STDERR, "ixTimeSyncAccCodeletPTPMsgTransmit: NULL mBuf pointer, port Id %d\n", portId, 0, 0, 0, 0, 0); /* terminate time sync codelet execution */ ixTimeSyncAccCodeletUninit (); return; } /* copy PTP message data to mBuf's data buffer */ ixOsalMemCopy (IX_OSAL_MBUF_MDATA(mBufPtr), ixTimeSyncAccCodeletPtpMsgData, IX_TIMESYNCACC_CODELET_UDP_FRAME_LEN); } /* end of for loop */ if (IX_SUCCESS != ixOsalSemaphoreInit (&ixTimeSyncAccCodeletSemId, IX_TIMESYNCACC_CODELET_MAX_TS_CHANNELS)) { ixOsalLog (IX_OSAL_LOG_LVL_ERROR, IX_OSAL_LOG_DEV_STDERR, "ixTimeSyncAccCodeletPTPMsgTransmit: failed to create semaphore\n", 0, 0, 0, 0, 0, 0); /* terminate time sync codelet execution */ ixTimeSyncAccCodeletUninit (); return; } do { /* halt PTP message transmission */ if (TRUE == ixTimeSyncAccCodeletTxHalt) { ixOsalLog (IX_OSAL_LOG_LVL_USER, IX_OSAL_LOG_DEV_STDOUT, "ixTimeSyncAccCodeletPTPMsgTransmit: PTP message transmission was halted\n", 0, 0, 0, 0, 0, 0); return; } /* sleep and wait for interval time to elapse before transmitting next PTP message */ ixOsalSleep (IX_TIMESYNCACC_CODELET_PTP_MSG_XMIT_INTERVAL); for (portId = IX_ETH_PORT_1; portId <= IX_ETH_PORT_3; portId++) { if (IX_SUCCESS != ixOsalSemaphoreWait (&ixTimeSyncAccCodeletSemId, IX_TIMESYNCACC_CODELET_PTP_MSG_XMIT_INTERVAL)) { ixOsalLog (IX_OSAL_LOG_LVL_ERROR, IX_OSAL_LOG_DEV_STDERR, "ixTimeSyncAccCodeletPTPMsgTransmit: PTP message transmission error at port %d\n", portId, 0, 0, 0, 0, 0); /* terminate time sync codelet execution */ ixTimeSyncAccCodeletUninit (); return; } if (IX_ETH_ACC_SUCCESS != ixEthAccPortTxFrameSubmit (portId, ixTimeSyncAccCodeletGlobalMBuf[portId], IX_ETH_ACC_TX_DEFAULT_PRIORITY)) { ixOsalLog (IX_OSAL_LOG_LVL_ERROR, IX_OSAL_LOG_DEV_STDERR, "ixTimeSyncAccCodeletPTPMsgTransmit: failed to transmit PTP message from port %d\n", portId, 0, 0, 0, 0, 0); /* terminate time sync codelet execution */ ixTimeSyncAccCodeletUninit (); return; } } /* end of for loop */ } while (TRUE); } /* end of ixTimeSyncAccCodeletPTPMsgTransmit function */
PUBLIC IX_STATUS ixOsalMutexInit (IxOsalMutex *mutexP) { return ixOsalSemaphoreInit((IxOsalSemaphore *) mutexP, 1); }