POK
|
00001 /* 00002 * POK header 00003 * 00004 * The following file is a part of the POK project. Any modification should 00005 * made according to the POK licence. You CANNOT use this file or a part of 00006 * this file is this part of a file for your own project 00007 * 00008 * For more information on the POK licence, please see our LICENCE FILE 00009 * 00010 * Please follow the coding guidelines described in doc/CODING_GUIDELINES 00011 * 00012 * Copyright (c) 2007-2009 POK team 00013 * 00014 * Created by julien on Thu Jan 15 23:34:13 2009 00015 */ 00016 00022 #ifdef POK_NEEDS_ARINC653_SEMAPHORE 00023 00024 #include <types.h> 00025 #include <libc/string.h> 00026 #include <arinc653/types.h> 00027 #include <arinc653/semaphore.h> 00028 #include <core/semaphore.h> 00029 00030 #define CHECK_SEM_INIT if (pok_arinc653_semaphores_initialized == 0) \ 00031 { \ 00032 uint16_t bla; \ 00033 for (bla = 0 ; bla < POK_CONFIG_ARINC653_NB_SEMAPHORES ; bla++) \ 00034 {\ 00035 pok_arinc653_semaphores_layers[bla].ready = 0;\ 00036 }\ 00037 }\ 00038 pok_arinc653_semaphores_initialized = 1; 00039 00040 pok_bool_t pok_arinc653_semaphores_initialized = 0; 00041 00042 typedef struct 00043 { 00044 pok_bool_t ready; 00045 pok_sem_id_t core_id; 00046 }pok_arinc653_semaphore_layer_t; 00047 00048 extern char* pok_arinc653_semaphores_names[POK_CONFIG_ARINC653_NB_SEMAPHORES]; 00049 pok_arinc653_semaphore_layer_t pok_arinc653_semaphores_layers[POK_CONFIG_ARINC653_NB_SEMAPHORES]; 00050 00051 void CREATE_SEMAPHORE (SEMAPHORE_NAME_TYPE SEMAPHORE_NAME, 00052 SEMAPHORE_VALUE_TYPE CURRENT_VALUE, 00053 SEMAPHORE_VALUE_TYPE MAXIMUM_VALUE, 00054 QUEUING_DISCIPLINE_TYPE QUEUING_DISCIPLINE, 00055 SEMAPHORE_ID_TYPE *SEMAPHORE_ID, 00056 RETURN_CODE_TYPE *RETURN_CODE ) 00057 { 00058 00059 RETURN_CODE_TYPE return_code_name; 00060 pok_sem_id_t sem_id; 00061 pok_ret_t core_ret; 00062 00063 CHECK_SEM_INIT; 00064 00065 *RETURN_CODE = INVALID_CONFIG; 00066 00067 GET_SEMAPHORE_ID (SEMAPHORE_NAME, SEMAPHORE_ID, &return_code_name); 00068 00069 if (return_code_name == INVALID_CONFIG) 00070 { 00071 *RETURN_CODE = INVALID_CONFIG; 00072 return; 00073 } 00074 00075 00076 if (*SEMAPHORE_ID > POK_CONFIG_ARINC653_NB_SEMAPHORES) 00077 { 00078 *RETURN_CODE = INVALID_CONFIG; 00079 return; 00080 } 00081 00082 if (pok_arinc653_semaphores_layers[*SEMAPHORE_ID].ready) 00083 { 00084 *RETURN_CODE = NO_ACTION; 00085 return; 00086 } 00087 00088 core_ret = pok_sem_create (&sem_id, CURRENT_VALUE, MAXIMUM_VALUE, QUEUING_DISCIPLINE); 00089 00090 if (core_ret != POK_ERRNO_OK) 00091 { 00092 *RETURN_CODE = INVALID_PARAM; 00093 return; 00094 } 00095 00096 pok_arinc653_semaphores_layers[*SEMAPHORE_ID].ready = 1; 00097 pok_arinc653_semaphores_layers[*SEMAPHORE_ID].core_id = sem_id; 00098 00099 *RETURN_CODE = NO_ERROR; 00100 } 00101 00102 void WAIT_SEMAPHORE (SEMAPHORE_ID_TYPE SEMAPHORE_ID, 00103 SYSTEM_TIME_TYPE TIME_OUT, 00104 RETURN_CODE_TYPE *RETURN_CODE ) 00105 { 00106 pok_ret_t core_ret; 00107 00108 CHECK_SEM_INIT; 00109 00110 if (SEMAPHORE_ID > POK_CONFIG_ARINC653_NB_SEMAPHORES) 00111 { 00112 *RETURN_CODE = INVALID_PARAM; 00113 return; 00114 } 00115 00116 core_ret = pok_sem_wait (pok_arinc653_semaphores_layers[SEMAPHORE_ID].core_id, TIME_OUT); 00117 00118 *RETURN_CODE = INVALID_PARAM; 00119 00120 if (core_ret == POK_ERRNO_OK) 00121 { 00122 *RETURN_CODE = NO_ERROR; 00123 } 00124 00125 if (core_ret == POK_ERRNO_TIMEOUT) 00126 { 00127 *RETURN_CODE = TIMED_OUT; 00128 } 00129 } 00130 00131 void SIGNAL_SEMAPHORE (SEMAPHORE_ID_TYPE SEMAPHORE_ID, 00132 RETURN_CODE_TYPE *RETURN_CODE ) 00133 { 00134 pok_ret_t core_ret; 00135 00136 CHECK_SEM_INIT; 00137 00138 if (SEMAPHORE_ID > POK_CONFIG_ARINC653_NB_SEMAPHORES) 00139 { 00140 *RETURN_CODE = INVALID_PARAM; 00141 return; 00142 } 00143 00144 core_ret = pok_sem_signal (pok_arinc653_semaphores_layers[SEMAPHORE_ID].core_id); 00145 00146 if (core_ret == POK_ERRNO_OK) 00147 { 00148 *RETURN_CODE = NO_ERROR; 00149 } 00150 else 00151 { 00152 *RETURN_CODE = INVALID_PARAM; 00153 } 00154 } 00155 00156 void GET_SEMAPHORE_ID (SEMAPHORE_NAME_TYPE SEMAPHORE_NAME, 00157 SEMAPHORE_ID_TYPE *SEMAPHORE_ID, 00158 RETURN_CODE_TYPE *RETURN_CODE ) 00159 { 00160 uint16_t i; 00161 uint16_t len; 00162 00163 CHECK_SEM_INIT; 00164 00165 len = strlen (SEMAPHORE_NAME); 00166 00167 *RETURN_CODE = INVALID_CONFIG; 00168 00169 for (i = 0 ; i < POK_CONFIG_ARINC653_NB_SEMAPHORES ; i++) 00170 { 00171 if (strncmp (pok_arinc653_semaphores_names[i], SEMAPHORE_NAME, len) == 0) 00172 { 00173 *SEMAPHORE_ID = i; 00174 *RETURN_CODE = NO_ERROR; 00175 break; 00176 } 00177 } 00178 } 00179 00180 void GET_SEMAPHORE_STATUS (SEMAPHORE_ID_TYPE SEMAPHORE_ID, 00181 SEMAPHORE_STATUS_TYPE *SEMAPHORE_STATUS, 00182 RETURN_CODE_TYPE *RETURN_CODE ) 00183 { 00184 (void) SEMAPHORE_ID; 00185 (void) SEMAPHORE_STATUS; 00186 00187 CHECK_SEM_INIT; 00188 00189 *RETURN_CODE = NO_ERROR; 00190 } 00191 00192 #endif