22 #ifdef POK_NEEDS_ARINC653_SEMAPHORE
25 #include <libc/string.h>
26 #include <arinc653/types.h>
27 #include <arinc653/semaphore.h>
28 #include <core/semaphore.h>
30 #define CHECK_SEM_INIT if (pok_arinc653_semaphores_initialized == 0) \
33 for (bla = 0 ; bla < POK_CONFIG_ARINC653_NB_SEMAPHORES ; bla++) \
35 pok_arinc653_semaphores_layers[bla].ready = 0;\
38 pok_arinc653_semaphores_initialized = 1;
40 pok_bool_t pok_arinc653_semaphores_initialized = 0;
48 extern char* pok_arinc653_semaphores_names[POK_CONFIG_ARINC653_NB_SEMAPHORES];
51 void CREATE_SEMAPHORE (SEMAPHORE_NAME_TYPE SEMAPHORE_NAME,
52 SEMAPHORE_VALUE_TYPE CURRENT_VALUE,
53 SEMAPHORE_VALUE_TYPE MAXIMUM_VALUE,
54 QUEUING_DISCIPLINE_TYPE QUEUING_DISCIPLINE,
55 SEMAPHORE_ID_TYPE *SEMAPHORE_ID,
56 RETURN_CODE_TYPE *RETURN_CODE )
59 RETURN_CODE_TYPE return_code_name;
65 *RETURN_CODE = INVALID_CONFIG;
67 GET_SEMAPHORE_ID (SEMAPHORE_NAME, SEMAPHORE_ID, &return_code_name);
69 if (return_code_name == INVALID_CONFIG)
71 *RETURN_CODE = INVALID_CONFIG;
76 if (*SEMAPHORE_ID > POK_CONFIG_ARINC653_NB_SEMAPHORES)
78 *RETURN_CODE = INVALID_CONFIG;
82 if (pok_arinc653_semaphores_layers[*SEMAPHORE_ID].ready)
84 *RETURN_CODE = NO_ACTION;
88 core_ret = pok_sem_create (&sem_id, CURRENT_VALUE, MAXIMUM_VALUE, QUEUING_DISCIPLINE);
90 if (core_ret != POK_ERRNO_OK)
92 *RETURN_CODE = INVALID_PARAM;
96 pok_arinc653_semaphores_layers[*SEMAPHORE_ID].ready = 1;
97 pok_arinc653_semaphores_layers[*SEMAPHORE_ID].core_id = sem_id;
99 *RETURN_CODE = NO_ERROR;
102 void WAIT_SEMAPHORE (SEMAPHORE_ID_TYPE SEMAPHORE_ID,
103 SYSTEM_TIME_TYPE TIME_OUT,
104 RETURN_CODE_TYPE *RETURN_CODE )
110 if (SEMAPHORE_ID > POK_CONFIG_ARINC653_NB_SEMAPHORES)
112 *RETURN_CODE = INVALID_PARAM;
116 core_ret = pok_sem_wait (pok_arinc653_semaphores_layers[SEMAPHORE_ID].core_id, TIME_OUT);
118 *RETURN_CODE = INVALID_PARAM;
120 if (core_ret == POK_ERRNO_OK)
122 *RETURN_CODE = NO_ERROR;
125 if (core_ret == POK_ERRNO_TIMEOUT)
127 *RETURN_CODE = TIMED_OUT;
131 void SIGNAL_SEMAPHORE (SEMAPHORE_ID_TYPE SEMAPHORE_ID,
132 RETURN_CODE_TYPE *RETURN_CODE )
138 if (SEMAPHORE_ID > POK_CONFIG_ARINC653_NB_SEMAPHORES)
140 *RETURN_CODE = INVALID_PARAM;
144 core_ret = pok_sem_signal (pok_arinc653_semaphores_layers[SEMAPHORE_ID].core_id);
146 if (core_ret == POK_ERRNO_OK)
148 *RETURN_CODE = NO_ERROR;
152 *RETURN_CODE = INVALID_PARAM;
156 void GET_SEMAPHORE_ID (SEMAPHORE_NAME_TYPE SEMAPHORE_NAME,
157 SEMAPHORE_ID_TYPE *SEMAPHORE_ID,
158 RETURN_CODE_TYPE *RETURN_CODE )
165 len = strlen (SEMAPHORE_NAME);
167 *RETURN_CODE = INVALID_CONFIG;
169 for (i = 0 ; i < POK_CONFIG_ARINC653_NB_SEMAPHORES ; i++)
171 if (strncmp (pok_arinc653_semaphores_names[i], SEMAPHORE_NAME, len) == 0)
174 *RETURN_CODE = NO_ERROR;
180 void GET_SEMAPHORE_STATUS (SEMAPHORE_ID_TYPE SEMAPHORE_ID,
182 RETURN_CODE_TYPE *RETURN_CODE )
185 (void) SEMAPHORE_STATUS;
189 *RETURN_CODE = NO_ERROR;