本文整理汇总了C++中xSemaphoreGive函数的典型用法代码示例。如果您正苦于以下问题:C++ xSemaphoreGive函数的具体用法?C++ xSemaphoreGive怎么用?C++ xSemaphoreGive使用的例子?那么, 这里精选的函数代码示例或许可以为您提供帮助。
在下文中一共展示了xSemaphoreGive函数的15个代码示例,这些例子默认根据受欢迎程度排序。您可以为喜欢或者感觉有用的代码点赞,您的评价将有助于系统推荐出更棒的C++代码示例。
示例1: updateTask
//.........这里部分代码省略.........
ship2.vel.x = 0;
ship2.vel.y = 0;
ship2.accel = 0;
ship2.a_vel = 0;
}
if (ship2.pos.y - SHIP_OFFSET < WALL_EDGE) {
ship2.pos.y += WALL_BOUNCE;
ship2.vel.x = 0;
ship2.vel.y = 0;
ship2.accel = 0;
ship2.a_vel = 0;
} else if (ship2.pos.y + SHIP_OFFSET > SCREEN_H - (WALL_EDGE)) {
ship2.pos.y -= WALL_BOUNCE;
ship2.vel.x = 0;
ship2.vel.y = 0;
ship2.accel = 0;
ship2.a_vel = 0;
}
// move bullets_ship1
objPrev = NULL;
objIter = bullets_ship1;
while (objIter != NULL) {
// Kill bullet after a while
objIter->life += FRAME_DELAY_MS;
if (objIter->life >= BULLET_LIFE_MS) {
xSemaphoreTake(usartMutex, portMAX_DELAY);
vSpriteDelete(objIter->handle);
if (objPrev != NULL) {
objPrev->next = objIter->next;
vPortFree(objIter);
objIter = objPrev->next;
} else {
bullets_ship1 = objIter->next;
vPortFree(objIter);
objIter = bullets_ship1;
}
xSemaphoreGive(usartMutex);
} else {
objIter->pos.x += objIter->vel.x;
objIter->pos.y += objIter->vel.y;
if (objIter->pos.x < 0.0) {
objIter->pos.x += SCREEN_W;
} else if (objIter->pos.x > SCREEN_W) {
objIter->pos.x -= SCREEN_W;
}
if (objIter->pos.y < 0.0) {
objIter->pos.y += SCREEN_H;
} else if (objIter->pos.y > SCREEN_H) {
objIter->pos.y -= SCREEN_H;
}
objPrev = objIter;
objIter = objIter->next;
}
}
// move bullets_ship2
objPrev = NULL;
objIter = bullets_ship2;
while (objIter != NULL) {
// Kill bullet after a while
objIter->life += FRAME_DELAY_MS;
if (objIter->life >= BULLET_LIFE_MS) {
xSemaphoreTake(usartMutex, portMAX_DELAY);
vSpriteDelete(objIter->handle);
if (objPrev != NULL) {
objPrev->next = objIter->next;
vPortFree(objIter);
objIter = objPrev->next;
} else {
bullets_ship2 = objIter->next;
vPortFree(objIter);
objIter = bullets_ship2;
}
xSemaphoreGive(usartMutex);
} else {
objIter->pos.x += objIter->vel.x;
objIter->pos.y += objIter->vel.y;
if (objIter->pos.x < 0.0) {
objIter->pos.x += SCREEN_W;
} else if (objIter->pos.x > SCREEN_W) {
objIter->pos.x -= SCREEN_W;
}
if (objIter->pos.y < 0.0) {
objIter->pos.y += SCREEN_H;
} else if (objIter->pos.y > SCREEN_H) {
objIter->pos.y -= SCREEN_H;
}
objPrev = objIter;
objIter = objIter->next;
}
}
vTaskDelay(FRAME_DELAY_MS / portTICK_RATE_MS);
}
}
示例2: vStartSemaphoreTasks
void vStartSemaphoreTasks( UBaseType_t uxPriority )
{
xSemaphoreParameters *pxFirstSemaphoreParameters, *pxSecondSemaphoreParameters;
const TickType_t xBlockTime = ( TickType_t ) 100;
/* Create the structure used to pass parameters to the first two tasks. */
pxFirstSemaphoreParameters = ( xSemaphoreParameters * ) pvPortMalloc( sizeof( xSemaphoreParameters ) );
if( pxFirstSemaphoreParameters != NULL )
{
/* Create the semaphore used by the first two tasks. */
pxFirstSemaphoreParameters->xSemaphore = xSemaphoreCreateBinary();
if( pxFirstSemaphoreParameters->xSemaphore != NULL )
{
xSemaphoreGive( pxFirstSemaphoreParameters->xSemaphore );
/* Create the variable which is to be shared by the first two tasks. */
pxFirstSemaphoreParameters->pulSharedVariable = ( uint32_t * ) pvPortMalloc( sizeof( uint32_t ) );
/* Initialise the share variable to the value the tasks expect. */
*( pxFirstSemaphoreParameters->pulSharedVariable ) = semtstNON_BLOCKING_EXPECTED_VALUE;
/* The first two tasks do not block on semaphore calls. */
pxFirstSemaphoreParameters->xBlockTime = ( TickType_t ) 0;
/* Spawn the first two tasks. As they poll they operate at the idle priority. */
xTaskCreate( prvSemaphoreTest, "PolSEM1", semtstSTACK_SIZE, ( void * ) pxFirstSemaphoreParameters, tskIDLE_PRIORITY, ( TaskHandle_t * ) NULL );
xTaskCreate( prvSemaphoreTest, "PolSEM2", semtstSTACK_SIZE, ( void * ) pxFirstSemaphoreParameters, tskIDLE_PRIORITY, ( TaskHandle_t * ) NULL );
/* vQueueAddToRegistry() adds the semaphore to the registry, if one
is in use. The registry is provided as a means for kernel aware
debuggers to locate semaphores and has no purpose if a kernel aware
debugger is not being used. The call to vQueueAddToRegistry() will
be removed by the pre-processor if configQUEUE_REGISTRY_SIZE is not
defined or is defined to be less than 1. */
vQueueAddToRegistry( ( QueueHandle_t ) pxFirstSemaphoreParameters->xSemaphore, "Counting_Sem_1" );
}
}
/* Do exactly the same to create the second set of tasks, only this time
provide a block time for the semaphore calls. */
pxSecondSemaphoreParameters = ( xSemaphoreParameters * ) pvPortMalloc( sizeof( xSemaphoreParameters ) );
if( pxSecondSemaphoreParameters != NULL )
{
pxSecondSemaphoreParameters->xSemaphore = xSemaphoreCreateBinary();
if( pxSecondSemaphoreParameters->xSemaphore != NULL )
{
xSemaphoreGive( pxSecondSemaphoreParameters->xSemaphore );
pxSecondSemaphoreParameters->pulSharedVariable = ( uint32_t * ) pvPortMalloc( sizeof( uint32_t ) );
*( pxSecondSemaphoreParameters->pulSharedVariable ) = semtstBLOCKING_EXPECTED_VALUE;
pxSecondSemaphoreParameters->xBlockTime = xBlockTime / portTICK_PERIOD_MS;
xTaskCreate( prvSemaphoreTest, "BlkSEM1", semtstSTACK_SIZE, ( void * ) pxSecondSemaphoreParameters, uxPriority, ( TaskHandle_t * ) NULL );
xTaskCreate( prvSemaphoreTest, "BlkSEM2", semtstSTACK_SIZE, ( void * ) pxSecondSemaphoreParameters, uxPriority, ( TaskHandle_t * ) NULL );
/* vQueueAddToRegistry() adds the semaphore to the registry, if one
is in use. The registry is provided as a means for kernel aware
debuggers to locate semaphores and has no purpose if a kernel aware
debugger is not being used. The call to vQueueAddToRegistry() will
be removed by the pre-processor if configQUEUE_REGISTRY_SIZE is not
defined or is defined to be less than 1. */
vQueueAddToRegistry( ( QueueHandle_t ) pxSecondSemaphoreParameters->xSemaphore, "Counting_Sem_2" );
}
}
}
示例3: SdkEvalSpiInit
//.........这里部分代码省略.........
s_vectpxSpiPort = &s_vectpxSpiCsPortVersion[SdkEvalGetVersion()];
if(!SdkEvalGetVersion())
{
/* Enable SPI periph and SCLK, MOSI, MISO and CS GPIO clocks */
RCC_APB2PeriphClockCmd(SDK_EVAL_V2_SPI_PERIPH_RCC, ENABLE);
RCC_AHBPeriphClockCmd(SDK_EVAL_V2_SPI_PERIPH_MOSI_RCC | SDK_EVAL_V2_SPI_PERIPH_MISO_RCC | SDK_EVAL_V2_SPI_PERIPH_SCLK_RCC | SDK_EVAL_V2_SPI_PERIPH_CS_RCC, ENABLE);
/* Configure the AF for MOSI, MISO and SCLK GPIO pins*/
GPIO_PinAFConfig(SDK_EVAL_V2_SPI_PERIPH_MOSI_PORT, SDK_EVAL_V2_SPI_PERIPH_MOSI_RCC_SOURCE, SDK_EVAL_V2_SPI_PERIPH_MOSI_AF);
GPIO_PinAFConfig(SDK_EVAL_V2_SPI_PERIPH_MISO_PORT, SDK_EVAL_V2_SPI_PERIPH_MISO_RCC_SOURCE, SDK_EVAL_V2_SPI_PERIPH_MISO_AF);
GPIO_PinAFConfig(SDK_EVAL_V2_SPI_PERIPH_SCLK_PORT, SDK_EVAL_V2_SPI_PERIPH_SCLK_RCC_SOURCE, SDK_EVAL_V2_SPI_PERIPH_SCLK_AF);
/* Configure SPI pins:SCLK, MISO and MOSI */
GPIO_InitStructure.GPIO_Mode = GPIO_Mode_AF;
GPIO_InitStructure.GPIO_OType = GPIO_OType_PP;
GPIO_InitStructure.GPIO_PuPd = GPIO_PuPd_DOWN;
GPIO_InitStructure.GPIO_Speed = GPIO_Speed_40MHz;
GPIO_InitStructure.GPIO_Pin = SDK_EVAL_V2_SPI_PERIPH_SCLK_PIN;
GPIO_Init(SDK_EVAL_V2_SPI_PERIPH_SCLK_PORT, &GPIO_InitStructure);
GPIO_InitStructure.GPIO_Pin = SDK_EVAL_V2_SPI_PERIPH_MISO_PIN;
GPIO_Init(SDK_EVAL_V2_SPI_PERIPH_MISO_PORT, &GPIO_InitStructure);
GPIO_InitStructure.GPIO_Pin = SDK_EVAL_V2_SPI_PERIPH_MOSI_PIN;
GPIO_Init(SDK_EVAL_V2_SPI_PERIPH_MOSI_PORT, &GPIO_InitStructure);
/* Configure SPI pin: CS */
GPIO_InitStructure.GPIO_Pin = SDK_EVAL_V2_SPI_PERIPH_CS_PIN;
GPIO_InitStructure.GPIO_Mode = GPIO_Mode_OUT;
GPIO_InitStructure.GPIO_OType = GPIO_OType_PP;
GPIO_InitStructure.GPIO_PuPd = GPIO_PuPd_UP;
GPIO_InitStructure.GPIO_Speed = GPIO_Speed_40MHz;
GPIO_Init(SDK_EVAL_V2_SPI_PERIPH_CS_PORT, &GPIO_InitStructure);
}
else
{
/* Enable SPI periph and SCLK, MOSI, MISO and CS GPIO clocks */
RCC_AHBPeriphClockCmd(SDK_EVAL_V3_SPI_PERIPH_MOSI_RCC | SDK_EVAL_V3_SPI_PERIPH_MISO_RCC | SDK_EVAL_V3_SPI_PERIPH_SCLK_RCC | SDK_EVAL_V3_SPI_PERIPH_CS_RCC, ENABLE);
/* Configure the AF for MOSI, MISO and SCLK GPIO pins*/
GPIO_PinAFConfig(SDK_EVAL_V3_SPI_PERIPH_MOSI_PORT, SDK_EVAL_V3_SPI_PERIPH_MOSI_RCC_SOURCE, SDK_EVAL_V3_SPI_PERIPH_MOSI_AF);
GPIO_PinAFConfig(SDK_EVAL_V3_SPI_PERIPH_MISO_PORT, SDK_EVAL_V3_SPI_PERIPH_MISO_RCC_SOURCE, SDK_EVAL_V3_SPI_PERIPH_MISO_AF);
GPIO_PinAFConfig(SDK_EVAL_V3_SPI_PERIPH_SCLK_PORT, SDK_EVAL_V3_SPI_PERIPH_SCLK_RCC_SOURCE, SDK_EVAL_V3_SPI_PERIPH_SCLK_AF);
/* Configure SPI pins:SCLK, MISO and MOSI */
GPIO_InitStructure.GPIO_Mode = GPIO_Mode_AF;
GPIO_InitStructure.GPIO_OType = GPIO_OType_PP;
GPIO_InitStructure.GPIO_PuPd = GPIO_PuPd_DOWN;
GPIO_InitStructure.GPIO_Speed = GPIO_Speed_40MHz;
GPIO_InitStructure.GPIO_Pin = SDK_EVAL_V3_SPI_PERIPH_SCLK_PIN;
GPIO_Init(SDK_EVAL_V3_SPI_PERIPH_SCLK_PORT, &GPIO_InitStructure);
GPIO_InitStructure.GPIO_Pin = SDK_EVAL_V3_SPI_PERIPH_MISO_PIN;
GPIO_Init(SDK_EVAL_V3_SPI_PERIPH_MISO_PORT, &GPIO_InitStructure);
GPIO_InitStructure.GPIO_Pin = SDK_EVAL_V3_SPI_PERIPH_MOSI_PIN;
GPIO_Init(SDK_EVAL_V3_SPI_PERIPH_MOSI_PORT, &GPIO_InitStructure);
/* Configure SPI pin: CS */
GPIO_InitStructure.GPIO_Pin = SDK_EVAL_V3_SPI_PERIPH_CS_PIN;
GPIO_InitStructure.GPIO_Mode = GPIO_Mode_OUT;
GPIO_InitStructure.GPIO_OType = GPIO_OType_PP;
GPIO_InitStructure.GPIO_PuPd = GPIO_PuPd_UP;
GPIO_InitStructure.GPIO_Speed = GPIO_Speed_40MHz;
GPIO_Init(SDK_EVAL_V3_SPI_PERIPH_CS_PORT, &GPIO_InitStructure);
/* Enable SPI periph and SCLK, MOSI, MISO and CS GPIO clocks */
RCC_APB1PeriphClockCmd(SDK_EVAL_V3_SPI_PERIPH_RCC, ENABLE);
}
/* Configure SPI peripheral */
SPI_DeInit(s_SpiPort);
SPI_InitStructure.SPI_Mode = SPI_Mode_Master;
SPI_InitStructure.SPI_Direction = SPI_Direction_2Lines_FullDuplex;
SPI_InitStructure.SPI_DataSize = SPI_DataSize_8b;
SPI_InitStructure.SPI_CPOL = SPI_CPOL_Low;
SPI_InitStructure.SPI_CPHA = SPI_CPHA_1Edge;
SPI_InitStructure.SPI_NSS = SPI_NSS_Soft;
SPI_InitStructure.SPI_BaudRatePrescaler = SPI_BaudRatePrescaler_4;
SPI_InitStructure.SPI_FirstBit = SPI_FirstBit_MSB;
SPI_InitStructure.SPI_CRCPolynomial = 7;
SPI_Init(s_SpiPort, &SPI_InitStructure);
SPI_Cmd(s_SpiPort, ENABLE);
#ifdef FREERTOS
xSpiMutex = xSemaphoreCreateMutex();
if (!xSpiMutex)
/* Error in resource creation. */
for (;;);
xSemaphoreGive(xSpiMutex);
#endif
SdkEvalSPICSHigh();
}
示例4: unlock_spi
void unlock_spi() {
xSemaphoreGive(spiLock);
}
示例5: mp_thread_mutex_unlock
void mp_thread_mutex_unlock(mp_thread_mutex_t *mutex) {
xSemaphoreGive(mutex->handle);
}
示例6: logRunBlock
/* This function is usually called by the worker subsystem */
void logRunBlock(void * arg)
{
struct log_block *blk = arg;
struct log_ops *ops = blk->ops;
static CRTPPacket pk;
unsigned int timestamp;
xSemaphoreTake(logLock, portMAX_DELAY);
timestamp = ((long long)xTaskGetTickCount())/portTICK_RATE_MS;
pk.header = CRTP_HEADER(CRTP_PORT_LOG, LOG_CH);
pk.size = 4;
pk.data[0] = blk->id;
pk.data[1] = timestamp&0x0ff;
pk.data[2] = (timestamp>>8)&0x0ff;
pk.data[3] = (timestamp>>16)&0x0ff;
while (ops)
{
float variable;
int valuei = 0;
float valuef = 0;
// FPU instructions must run on aligned data. Make sure it is.
variable = *(float *)ops->variable;
switch(ops->storageType)
{
case LOG_UINT8:
valuei = *(uint8_t *)&variable;
break;
case LOG_INT8:
valuei = *(int8_t *)&variable;
break;
case LOG_UINT16:
valuei = *(uint16_t *)&variable;
break;
case LOG_INT16:
valuei = *(int16_t *)&variable;
break;
case LOG_UINT32:
valuei = *(uint32_t *)&variable;
break;
case LOG_INT32:
valuei = *(int32_t *)&variable;
break;
case LOG_FLOAT:
valuei = *(float *)&variable;
break;
}
if (ops->logType == LOG_FLOAT || ops->logType == LOG_FP16)
{
if (ops->storageType == LOG_FLOAT)
valuef = *(float *)&variable;
else
valuef = valuei;
// Try to append the next item to the packet. If we run out of space,
// drop this and subsequent items.
if (ops->logType == LOG_FLOAT)
{
if (!appendToPacket(&pk, &valuef, 4)) break;
}
else
{
valuei = single2half(valuef);
if (!appendToPacket(&pk, &valuei, 2)) break;
}
}
else //logType is an integer
{
if (!appendToPacket(&pk, &valuei, typeLength[ops->logType])) break;
}
ops = ops->next;
}
xSemaphoreGive(logLock);
// Check if the connection is still up, oherwise disable
// all the logging and flush all the CRTP queues.
if (!crtpIsConnected())
{
logReset();
crtpReset();
}
else
{
crtpSendPacket(&pk);
}
}
示例7: SetWidgetList
//.........这里部分代码省略.........
if (WGTLST_INDEX(pMsg->Options) == 0 &&
(pCurrWidget != pCurrWidgetList || (pNextWidget != &Widget[0] && pNextWidget != &Widget[MAX_WIDGET_NUM])))
{ // last SetWLst failed in the middle.Clean up whole list
PrintS("# Last SetWgtLst broken!");
pCurrWidget = pCurrWidgetList;
pNextWidget = &Widget[0] + (&Widget[MAX_WIDGET_NUM] - pCurrWidgetList);
}
}
while (WidgetNum) // number of list items
{
/* old clock widgets */
if (!IS_CLOCK_WIDGET(pMsgWgtLst->Layout) && pMsgWgtLst->Id <= CLOCK_WIDGET_ID_RANGE) TestFaceId(pMsgWgtLst);
unsigned char Change = GetWidgetChange(pCurrWidget->Id, pCurrWidget->Layout, pMsgWgtLst->Id, pMsgWgtLst->Layout);
switch (Change)
{
case WGT_CHG_CLK_FACE:
PrintS("Chg ClkFce");
if (ON_CURRENT_PAGE(pMsgWgtLst->Layout)) ChangedClockWidget = pMsgWgtLst->Id;
case WGT_CHG_SETTING:
//cpy layout to curr; cpy curr to next; msg, curr, next ++
PrintF("=%02X", pCurrWidget->Id);
pCurrWidget->Id = pMsgWgtLst->Id;
pCurrWidget->Layout = pMsgWgtLst->Layout;
*pNextWidget++ = *pCurrWidget++;
pMsgWgtLst ++;
WidgetNum --;
break;
case WGT_CHG_CLK_ADD:
PrintS("+Clk");
if (ON_CURRENT_PAGE(pMsgWgtLst->Layout)) ChangedClockWidget = pMsgWgtLst->Id;
case WGT_CHG_ADD: //pCurrWidget->Id > pMsgWgtLst->Id)
// add new widget: cpy msg to next; msg and next ++; curr stays
PrintF("+%02X", pMsgWgtLst->Id);
pNextWidget->Id = pMsgWgtLst->Id;
pNextWidget->Layout = pMsgWgtLst->Layout;
AssignWidgetBuffer(pNextWidget);
pNextWidget ++;
pMsgWgtLst ++;
WidgetNum --;
break;
case WGT_CHG_REMOVE:
// remove widget: curr ++
PrintF("-%02X", pCurrWidget->Id);
FreeWidgetBuffer(pCurrWidget);
pCurrWidget ++;
break;
default: break;
}
}
PrintR();
// if part index + 1 == parts, SetWidgetList complete
if (WGTLST_TOTAL(pMsg->Options) == WGTLST_INDEX(pMsg->Options) + 1)
{
// PrintS("C:");
// for (i=0; pCurrWidgetList[i].Id != INVALID_ID && i < MAX_WIDGET_NUM; ++i) PrintH(pCurrWidgetList[i].Id);
// PrintR();
while (pCurrWidget->Id != INVALID_ID && pCurrWidget < &pCurrWidgetList[MAX_WIDGET_NUM])
{
FreeWidgetBuffer(pCurrWidget);
pCurrWidget->Id = INVALID_ID;
pCurrWidget ++;
}
for (i = 0; i < MAX_WIDGET_NUM; ++i)
{
if (pCurrWidgetList[i].Id != INVALID_ID)
{ // clear the widget id in the curr list
pCurrWidgetList[i].Id = INVALID_ID;
}
}
pNextWidget = pCurrWidgetList;
pCurrWidgetList = &Widget[0] + (&Widget[MAX_WIDGET_NUM] - pCurrWidgetList);
pCurrWidget = pCurrWidgetList;
// PrintS("N:");
// for (i=0; pCurrWidgetList[i].Id != INVALID_ID; ++i) PrintH(pCurrWidgetList[i].Id);
// PrintR();
PrintF("Tg:%04X", BufTag);
if (ChangedClockWidget != INVALID_ID)
{
CreateAndSendMessage(DrawClockWidgetMsg, ChangedClockWidget);
ChangedClockWidget = INVALID_ID;
}
}
xSemaphoreGive(SramMutex);
}
示例8: xSemaphoreGive
void AnalyzerControl::WakeAnalysisRequest()
{
xSemaphoreGive(_semaphore);
}
示例9: GUI_X_Unlock
void GUI_X_Unlock(void)
{
xSemaphoreGive( xQueueMutex );
}
示例10: GUI_X_SignalEvent
void GUI_X_SignalEvent (void)
{
xSemaphoreGive( xSemaTxDone );
}
示例11: obp_uds
//.........这里部分代码省略.........
if (pdPASS !=
sendMsg(MSG_SERIAL_RELEASE, inputQueue,
NULL)) {
DEBUGPRINT
("FATAL ERROR: input queue is full!\n",
'a');
}
}
timeout--;
}
if (actSeparationTime_STTicks > 0) {
DEBUGPRINT
("Remaining CF Waitticks: %ld , remainingBytes: %ld\n",
actSeparationTime_STTicks, remainingBytes);
stateMachine_state = SM_UDS_SLEEP_UNTIL_SINGLE_CF;
actSeparationTime_STTicks--;
if (actSeparationTime_STTicks < 1) { //it's time for a new single CF
stateMachine_state = SM_UDS_SEND_SINGLE_CF;
actSeparationTime_STTicks = separationTime_ST / portTICK_PERIOD_MS; //"reload" the counter
actSeparationTime_STTicks++;
if (actSeparationTime_STTicks < 2) {
actSeparationTime_STTicks = 2;
}
DEBUGPRINT
("Reloaded CF Waitticks: %ld , remainingBytes: %ld\n",
actSeparationTime_STTicks, remainingBytes);
}
}
/* Start generating tester present messages */
odp_uds_generateTesterPresents(tpList,
&telegram, actBus_send);
//>>>> oobdtemple protocol final >>>>
break;
}
//if (Ticker oder sonstiges Consecutife Frame){
if (1) {
if (stateMachine_state == SM_UDS_SEND_CF
|| stateMachine_state == SM_UDS_SEND_SINGLE_CF) {
while (remainingBytes > 0
&& (stateMachine_state !=
SM_UDS_SLEEP_UNTIL_SINGLE_CF)
&& (actBlockSize_BS != 1)) {
if (stateMachine_state == SM_UDS_SEND_SINGLE_CF) {
stateMachine_state =
SM_UDS_SLEEP_UNTIL_SINGLE_CF;
}
DEBUGPRINT("Remaining bytes: %ld\n",
remainingBytes);
actFrameLen =
remainingBytes > 7 ? 7 : remainingBytes;
odp_uds_data2CAN(&protocolBuffer->data
[actBufferPos],
&telegram[0], actFrameLen, 1);
sequenceCounter =
sequenceCounter < 15 ? sequenceCounter + 1 : 0;
actBufferPos += actFrameLen;
remainingBytes -= actFrameLen;
actDataPacket.data[0] = 0x20 + sequenceCounter; // prepare CF
if (showBusTransfer > 0) {
odp_uds_dumpFrame(&actDataPacket,
printdata_CAN);
}
actBus_send(&actDataPacket);
if (actBlockSize_BS > 1) {
actBlockSize_BS--;
DEBUGPRINT("Blocksize REDUCED to %ld \n",
actBlockSize_BS);
}
}
if (actBlockSize_BS == 1) { //in case we had some block limitations, send them and then wait for another FC Frame
stateMachine_state = SM_UDS_WAIT_FOR_FC;
actBlockSize_BS = 0;
timeout = protocolConfig->timeout;
}
if (remainingBytes < 1) { // Buffer empty? Then finish
stateMachine_state = SM_UDS_WAIT_FOR_ANSWER;
actSeparationTime_STTicks = 0;
timeout = protocolConfig->timeout;
}
}
}
disposeMsg(msg);
}
/* vTaskDelay (5000 / portTICK_PERIOD_MS); */
}
/* Do all cleanup here to finish task */
actBus_close();
vPortFree(protocolConfig);
freeODPBuffer(protocolBuffer);
odp_uds_freeTPBuffers(tpList);
xSemaphoreGive(protocollBinarySemaphore);
vTaskDelete(NULL);
}
示例12: vSemaphoreCreateBinary
/**
* Should allocate a pbuf and transfer the bytes of the incoming
* packet from the interface into the pbuf.
*
* @param netif the lwip network interface structure for this ethernetif
* @return a pbuf filled with the received packet (including MAC header)
* NULL on memory error
*/
static struct pbuf *low_level_input(struct netif *netif)
{
struct pbuf *p = NULL;
struct pbuf *q;
u16_t len;
#ifdef FREERTOS_USED
static xSemaphoreHandle xRxSemaphore = NULL;
#endif
/* Parameter not used. */
( void ) netif;
#ifdef FREERTOS_USED
if( xRxSemaphore == NULL )
{
vSemaphoreCreateBinary( xRxSemaphore );
}
/* Access to the MACB is guarded using a semaphore. */
if( xSemaphoreTake( xRxSemaphore, netifGUARD_BLOCK_NBTICKS ) )
{
#endif
/* Obtain the size of the packet. */
len = ulMACBInputLength();
if( len )
{
#if ETH_PAD_SIZE
len += ETH_PAD_SIZE; /* allow room for Ethernet padding */
#endif
/* We allocate a pbuf chain of pbufs from the pool. */
p = pbuf_alloc( PBUF_RAW, len, PBUF_POOL );
if( p != NULL )
{
#if ETH_PAD_SIZE
pbuf_header( p, -ETH_PAD_SIZE ); /* drop the padding word */
#endif
/* Let the driver know we are going to read a new packet. */
vMACBRead( NULL, 0, len );
/* We iterate over the pbuf chain until we have read the entire
packet into the pbuf. */
for( q = p; q != NULL; q = q->next )
{
/* Read enough bytes to fill this pbuf in the chain. The
available data in the pbuf is given by the q->len variable. */
vMACBRead( q->payload, q->len, len );
}
#if ETH_PAD_SIZE
pbuf_header( p, ETH_PAD_SIZE ); /* reclaim the padding word */
#endif
LINK_STATS_INC(link.recv);
}
else
{
LINK_STATS_INC(link.memerr);
LINK_STATS_INC(link.drop);
}
}
#ifdef FREERTOS_USED
xSemaphoreGive( xRxSemaphore );
}
#endif
return p;
}
示例13: drawTask
//.........这里部分代码省略.........
}
else {
bullets_ship1 = objIter->next;
vPortFree(objIter);
objIter = bullets_ship1;
}
}
else {
objPrev = objIter;
objIter = objIter->next;
}
}
// Check hits from ship2
objPrev = NULL;
objIter = bullets_ship2;
while (objIter != NULL) {
vSpriteSetPosition(objIter->handle, (uint16_t)objIter->pos.x, (uint16_t)objIter->pos.y);
//// Check hits from ship2 on ship1
if (uCollide(objIter->handle, shipGroup1, &hit, 1) > 0) {
vSpriteDelete(objIter->handle);
if (objPrev != NULL) {
objPrev->next = objIter->next;
vPortFree(objIter);
objIter = objPrev->next;
}
else {
bullets_ship2 = objIter->next;
vPortFree(objIter);
objIter = bullets_ship2;
}
game_status = PLAYER_TWO_WIN;
}
else if (uCollide(objIter->handle, wallGroup, &hit, 1) > 0) {
vSpriteDelete(objIter->handle);
if (objPrev != NULL) {
objPrev->next = objIter->next;
vPortFree(objIter);
objIter = objPrev->next;
}
else {
bullets_ship2 = objIter->next;
vPortFree(objIter);
objIter = bullets_ship2;
}
}
else {
objPrev = objIter;
objIter = objIter->next;
}
}
switch(game_status)
{
case PLAYER_ONE_WIN:
vTaskDelete(updateTaskHandle);
vTaskDelete(bulletTaskHandle);
vTaskDelete(inputTaskHandle);
handle = xSpriteCreate("p1_win.png", SCREEN_W>>1, SCREEN_H>>1, 0, SCREEN_W>>1, SCREEN_H>>1, 100);
vTaskDelay(3000 / portTICK_RATE_MS);
vSpriteDelete(handle);
reset();
init();
xTaskCreate(inputTask, (signed char *) "p1", 80, NULL, 6, &inputTaskHandle);
xTaskCreate(bulletTask, (signed char *) "b", 250, NULL, 2, &bulletTaskHandle);
xTaskCreate(updateTask, (signed char *) "u", 200, NULL, 4, &updateTaskHandle);
game_status = IN_PLAY;
break;
case PLAYER_TWO_WIN:
vTaskDelete(updateTaskHandle);
vTaskDelete(bulletTaskHandle);
vTaskDelete(inputTaskHandle);
handle = xSpriteCreate("p2_win.png", SCREEN_W>>1, SCREEN_H>>1, 0, SCREEN_W>>1, SCREEN_H>>1, 100);
vTaskDelay(3000 / portTICK_RATE_MS);
vSpriteDelete(handle);
reset();
init();
xTaskCreate(inputTask, (signed char *) "p1", 80, NULL, 6, &inputTaskHandle);
xTaskCreate(bulletTask, (signed char *) "b", 250, NULL, 2, &bulletTaskHandle);
xTaskCreate(updateTask, (signed char *) "u", 200, NULL, 4, &updateTaskHandle);
game_status = IN_PLAY;
break;
default:
break;
}
xSemaphoreGive(usartMutex);
vTaskDelay(FRAME_DELAY_MS / portTICK_RATE_MS);
}
}
示例14: uart_task
/**
* \brief UART task
*
* This task runs in the background to handle the queued, incoming terminal
* characters and write them to the terminal text buffer. It does not print
* anything to the display -- that is done by \ref terminal_task().
*
* \param params Parameters for the task. (Not used.)
*/
static void uart_task(void *params)
{
uint8_t *current_line_ptr;
uint8_t *current_char_ptr;
uint8_t current_column = 0;
for (;;) {
// Show that task is executing
oled1_set_led_state(&oled1, OLED1_LED1_ID, true);
// Grab terminal mutex
xSemaphoreTake(terminal_mutex, portMAX_DELAY);
current_line_ptr = terminal_buffer[terminal_line_offset];
current_char_ptr = current_line_ptr + current_column;
// Any characters queued? Handle them!
while (xQueueReceive(terminal_in_queue, current_char_ptr, 0)) {
/* Newline-handling is difficult because all terminal emulators
* seem to do it their own way. The method below seems to work
* with Putty and Realterm out of the box.
*/
switch (*current_char_ptr) {
case '\r':
// Replace \r with \0 and move head to next line
*current_char_ptr = '\0';
current_column = 0;
terminal_line_offset = (terminal_line_offset + 1)
% TERMINAL_BUFFER_LINES;
current_line_ptr = terminal_buffer[terminal_line_offset];
current_char_ptr = current_line_ptr + current_column;
break;
case '\n':
// For \n, do nothing -- it is replaced with \0 later
break;
default:
// For all other characters, just move head to next char
current_column++;
if (current_column >= TERMINAL_COLUMNS) {
current_column = 0;
terminal_line_offset = (terminal_line_offset + 1)
% TERMINAL_BUFFER_LINES;
current_line_ptr = terminal_buffer[terminal_line_offset];
}
current_char_ptr = current_line_ptr + current_column;
}
// Set zero-terminator at head
*current_char_ptr = '\0';
}
xSemaphoreGive(terminal_mutex);
oled1_set_led_state(&oled1, OLED1_LED1_ID, false);
vTaskDelay(UART_TASK_DELAY);
}
}
示例15: update_neighbour_table
//.........这里部分代码省略.........
{
if(type==ADDR_802_15_4_PAN_LONG)
{
length=8;
}
if(type == ADDR_802_15_4_PAN_SHORT)
length=4;
delivery_mode = NOT_NEIGHBOR;
if(neighbor_table.count > 0 && remove != ADD_CHILD)
{
for(i=0; i < MAX_NEIGHBOR_COUNT ; i++)
{
b = &(neighbor_table.neighbor_info[i]);
if(b->type == ADDR_NONE)
b=0;
if(b && (type == b->type))
{
if(memcmp(b->address, address,length) == 0)
delivery_mode = NEIGHBOR;
/* Update lqi and compare sqn to old one */
if( delivery_mode == NEIGHBOR )
{
if(type != ADDR_802_15_4_PAN_SHORT)
{
for(j=0; j<2; j++)
{
b->address[length+j] = address[length+j];
}
}
if(remove == REMOVE_NEIGHBOUR)
{
if(b->child_dev)
neighbor_table.child_count--;
b->type=ADDR_NONE;
i=neighbor_table.count;
neighbor_table.count--;
}
else
{
/* Duplicated packet check */
if(b->last_sqn != last_sqn)
{
b->last_sqn = last_sqn;
sqn_check=1;
}
b->last_rssi = last_rssi;
b->ttl=TTL;
}
i=MAX_NEIGHBOR_COUNT;
}
}
}
}
/* Add new neighbor if addresstype is source */
if((delivery_mode == NOT_NEIGHBOR && remove != REMOVE_NEIGHBOUR) && neighbor_table.count < MAX_NEIGHBOR_COUNT)
{
for(i=0; i<MAX_NEIGHBOR_COUNT; i++)
{
b = &(neighbor_table.neighbor_info[i]);
if(b->type == ADDR_NONE)
{
i=MAX_NEIGHBOR_COUNT;
}
}
if(type==ADDR_802_15_4_PAN_LONG)
length+=2;
for(j=0; j < length ; j++)
{
b->address[j] = address[j];
}
/* add lqi value to neighbor */
if(remove == ADD_CHILD)
{
neighbor_table.child_count++;
b->child_dev=1;
}
b->last_rssi = last_rssi;
b->last_sqn = last_sqn;
b->child_dev = 0;
sqn_check=1;
b->ttl=TTL;
b->type = type;
/* Increace Neigbor count */
neighbor_table.count++;
}
xSemaphoreGive( table_lock ); /*free lock*/
}
else
{
debug("No sem\r\n");
sqn_check=1;
}
return sqn_check;
}