firmware
IEM Firmware Documentation
Loading...
Searching...
No Matches
croutine.h
Go to the documentation of this file.
1/*
2 * FreeRTOS Kernel V11.1.0
3 * Copyright (C) 2021 Amazon.com, Inc. or its affiliates. All Rights Reserved.
4 *
5 * SPDX-License-Identifier: MIT
6 *
7 * Permission is hereby granted, free of charge, to any person obtaining a copy of
8 * this software and associated documentation files (the "Software"), to deal in
9 * the Software without restriction, including without limitation the rights to
10 * use, copy, modify, merge, publish, distribute, sublicense, and/or sell copies of
11 * the Software, and to permit persons to whom the Software is furnished to do so,
12 * subject to the following conditions:
13 *
14 * The above copyright notice and this permission notice shall be included in all
15 * copies or substantial portions of the Software.
16 *
17 * THE SOFTWARE IS PROVIDED "AS IS", WITHOUT WARRANTY OF ANY KIND, EXPRESS OR
18 * IMPLIED, INCLUDING BUT NOT LIMITED TO THE WARRANTIES OF MERCHANTABILITY, FITNESS
19 * FOR A PARTICULAR PURPOSE AND NONINFRINGEMENT. IN NO EVENT SHALL THE AUTHORS OR
20 * COPYRIGHT HOLDERS BE LIABLE FOR ANY CLAIM, DAMAGES OR OTHER LIABILITY, WHETHER
21 * IN AN ACTION OF CONTRACT, TORT OR OTHERWISE, ARISING FROM, OUT OF OR IN
22 * CONNECTION WITH THE SOFTWARE OR THE USE OR OTHER DEALINGS IN THE SOFTWARE.
23 *
24 * https://www.FreeRTOS.org
25 * https://github.com/FreeRTOS
26 *
27 */
28
29#ifndef CO_ROUTINE_H
30#define CO_ROUTINE_H
31
32#ifndef INC_FREERTOS_H
33 #error "include FreeRTOS.h must appear in source files before include croutine.h"
34#endif
35
36#include "list.h"
37
38/* *INDENT-OFF* */
39#ifdef __cplusplus
40 extern "C" {
41#endif
42/* *INDENT-ON* */
43
44/* Used to hide the implementation of the co-routine control block. The
45 * control block structure however has to be included in the header due to
46 * the macro implementation of the co-routine functionality. */
47typedef void * CoRoutineHandle_t;
48
49/* Defines the prototype to which co-routine functions must conform. */
50typedef void (* crCOROUTINE_CODE)( CoRoutineHandle_t xHandle,
51 UBaseType_t uxIndex );
52
54{
60 uint16_t uxState;
61} CRCB_t; /* Co-routine control block. Note must be identical in size down to uxPriority with TCB_t. */
62
137 UBaseType_t uxPriority,
138 UBaseType_t uxIndex );
139
140
182
214#define crSTART( pxCRCB ) \
215 switch( ( ( CRCB_t * ) ( pxCRCB ) )->uxState ) { \
216 case 0:
217
249#define crEND() }
250
251/*
252 * These macros are intended for internal use by the co-routine implementation
253 * only. The macros should not be used directly by application writers.
254 */
255#define crSET_STATE0( xHandle ) \
256 ( ( CRCB_t * ) ( xHandle ) )->uxState = ( __LINE__ * 2 ); return; \
257 case ( __LINE__ * 2 ):
258#define crSET_STATE1( xHandle ) \
259 ( ( CRCB_t * ) ( xHandle ) )->uxState = ( ( __LINE__ * 2 ) + 1 ); return; \
260 case ( ( __LINE__ * 2 ) + 1 ):
261
310#define crDELAY( xHandle, xTicksToDelay ) \
311 do { \
312 if( ( xTicksToDelay ) > 0 ) \
313 { \
314 vCoRoutineAddToDelayedList( ( xTicksToDelay ), NULL ); \
315 } \
316 crSET_STATE0( ( xHandle ) ); \
317 } while( 0 )
318
404#define crQUEUE_SEND( xHandle, pxQueue, pvItemToQueue, xTicksToWait, pxResult ) \
405 do { \
406 *( pxResult ) = xQueueCRSend( ( pxQueue ), ( pvItemToQueue ), ( xTicksToWait ) ); \
407 if( *( pxResult ) == errQUEUE_BLOCKED ) \
408 { \
409 crSET_STATE0( ( xHandle ) ); \
410 *pxResult = xQueueCRSend( ( pxQueue ), ( pvItemToQueue ), 0 ); \
411 } \
412 if( *pxResult == errQUEUE_YIELD ) \
413 { \
414 crSET_STATE1( ( xHandle ) ); \
415 *pxResult = pdPASS; \
416 } \
417 } while( 0 )
418
498#define crQUEUE_RECEIVE( xHandle, pxQueue, pvBuffer, xTicksToWait, pxResult ) \
499 do { \
500 *( pxResult ) = xQueueCRReceive( ( pxQueue ), ( pvBuffer ), ( xTicksToWait ) ); \
501 if( *( pxResult ) == errQUEUE_BLOCKED ) \
502 { \
503 crSET_STATE0( ( xHandle ) ); \
504 *( pxResult ) = xQueueCRReceive( ( pxQueue ), ( pvBuffer ), 0 ); \
505 } \
506 if( *( pxResult ) == errQUEUE_YIELD ) \
507 { \
508 crSET_STATE1( ( xHandle ) ); \
509 *( pxResult ) = pdPASS; \
510 } \
511 } while( 0 )
512
609#define crQUEUE_SEND_FROM_ISR( pxQueue, pvItemToQueue, xCoRoutinePreviouslyWoken ) \
610 xQueueCRSendFromISR( ( pxQueue ), ( pvItemToQueue ), ( xCoRoutinePreviouslyWoken ) )
611
612
725#define crQUEUE_RECEIVE_FROM_ISR( pxQueue, pvBuffer, pxCoRoutineWoken ) \
726 xQueueCRReceiveFromISR( ( pxQueue ), ( pvBuffer ), ( pxCoRoutineWoken ) )
727
728/*
729 * This function is intended for internal use by the co-routine macros only.
730 * The macro nature of the co-routine implementation requires that the
731 * prototype appears here. The function should not be used by application
732 * writers.
733 *
734 * Removes the current co-routine from its ready list and places it in the
735 * appropriate delayed list.
736 */
738 List_t * pxEventList );
739
740/*
741 * This function is intended for internal use by the queue implementation only.
742 * The function should not be used by application writers.
743 *
744 * Removes the highest priority co-routine from the event list and places it in
745 * the pending ready list.
746 */
748
749
750/*
751 * This function resets the internal state of the coroutine module. It must be
752 * called by the application before restarting the scheduler.
753 */
755
756/* *INDENT-OFF* */
757#ifdef __cplusplus
758 }
759#endif
760/* *INDENT-ON* */
761
762#endif /* CO_ROUTINE_H */
struct corCoRoutineControlBlock CRCB_t
void * CoRoutineHandle_t
Definition croutine.h:47
void vCoRoutineSchedule(void)
void vCoRoutineAddToDelayedList(TickType_t xTicksToDelay, List_t *pxEventList)
void vCoRoutineResetState(void) PRIVILEGED_FUNCTION
void(* crCOROUTINE_CODE)(CoRoutineHandle_t xHandle, UBaseType_t uxIndex)
Definition croutine.h:50
BaseType_t xCoRoutineCreate(crCOROUTINE_CODE pxCoRoutineCode, UBaseType_t uxPriority, UBaseType_t uxIndex)
BaseType_t xCoRoutineRemoveFromEventList(const List_t *pxEventList)
struct xLIST_ITEM ListItem_t
Definition list.h:154
struct xLIST List_t
#define PRIVILEGED_FUNCTION
Definition mpu_wrappers.h:269
long BaseType_t
Definition portmacro.h:59
unsigned long UBaseType_t
Definition portmacro.h:60
uint16_t TickType_t
Definition portmacro.h:63
Definition croutine.h:54
ListItem_t xEventListItem
Definition croutine.h:57
UBaseType_t uxIndex
Definition croutine.h:59
UBaseType_t uxPriority
Definition croutine.h:58
uint16_t uxState
Definition croutine.h:60
ListItem_t xGenericListItem
Definition croutine.h:56
crCOROUTINE_CODE pxCoRoutineFunction
Definition croutine.h:55