论坛元老
- 积分
- 7462
- 金钱
- 7462
- 注册时间
- 2015-1-15
- 在线时间
- 1367 小时
|
发表于 2018-10-25 19:34:42
|
显示全部楼层
static TaskHandle_t xTaskToNotify = NULL;
/* The peripheral driver's transmit function. */
void StartTransmission( uint8_t *pcData, size_t xDataLength )
{
/* At this point xTaskToNotify should be NULL as no transmission is in
progress. A mutex can be used to guard access to the peripheral if
necessary. */
configASSERT( xTaskToNotify == NULL );
/* Store the handle of the calling task. */
xTaskToNotify = xTaskGetCurrentTaskHandle();
/* Start the transmission - an interrupt is generated when the transmission
is complete. */
vStartTransmit( pcData, xDatalength );
}
/*-----------------------------------------------------------*/
/* The transmit end interrupt. */
void vTransmitEndISR( void )
{
BaseType_t xHigherPriorityTaskWoken = pdFALSE;
/* At this point xTaskToNotify should not be NULL as a transmission was
in progress. */
configASSERT( xTaskToNotify != NULL );
/* Notify the task that the transmission is complete. */
vTaskNotifyGiveFromISR( xTaskToNotify, &xHigherPriorityTaskWoken );
/* There are no transmissions in progress, so no tasks to notify. */
xTaskToNotify = NULL;
/* If xHigherPriorityTaskWoken is now set to pdTRUE then a context switch
should be performed to ensure the interrupt returns directly to the highest
priority task. The macro used for this purpose is dependent on the port in
use and may be called portEND_SWITCHING_ISR(). */
portYIELD_FROM_ISR( xHigherPriorityTaskWoken );
}
/*-----------------------------------------------------------*/
/* The task that initiates the transmission, then enters the Blocked state (so
not consuming any CPU time) to wait for it to complete. */
void vAFunctionCalledFromATask( uint8_t ucDataToTransmit, size_t xDataLength )
{
uint32_t ulNotificationValue;
const TickType_t xMaxBlockTime = pdMS_TO_TICKS( 200 );
/* Start the transmission by calling the function shown above. */
StartTransmission( ucDataToTransmit, xDataLength );
/* Wait for the transmission to complete. */
ulNotificationValue = ulTaskNotifyTake( pdFALSE, xMaxBlockTime );
if( ulNotificationValue == 1 )
{
/* The transmission ended as expected. */
}
else
{
/* The call to ulTaskNotifyTake() timed out. */
}
}
这是官网范例,按照范例来写 |
|