POK
/home/jaouen/pok_official/pok/trunk/libpok/arinc653/event.c
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 
00017 
00018 #ifdef POK_NEEDS_ARINC653_EVENT
00019 #include <arinc653/types.h>
00020 #include <arinc653/event.h>
00021 
00022 #include <core/event.h>       /* For core function */
00023 
00024 #include <libc/string.h>      /* For strcmp */
00025 
00026 #include <errno.h>            /* For POK_ERRNO_... maccros */
00027 
00028 #define CHECK_EVENTS_INIT if (pok_arinc653_events_initialized == 0) \
00029                        { \
00030                           uint16_t bla; \
00031                           for (bla = 0 ; bla < POK_CONFIG_ARINC653_NB_EVENTS ; bla++) \
00032                           {\
00033                              pok_arinc653_events_layers[bla].ready = 0;\
00034                           }\
00035                        }\
00036                        pok_arinc653_events_initialized = 1;
00037 
00038 
00039 
00040 
00041 bool_t pok_arinc653_events_initialized = 0;
00042 
00043 typedef struct
00044 {
00045    pok_event_id_t    core_id;
00046    pok_bool_t        ready;
00047 }pok_arinc653_event_layer_t;
00048 
00049 extern char*                  pok_arinc653_events_names[POK_CONFIG_ARINC653_NB_EVENTS];
00050 pok_arinc653_event_layer_t    pok_arinc653_events_layers[POK_CONFIG_NB_EVENTS];
00051 
00052 void CREATE_EVENT (EVENT_NAME_TYPE EVENT_NAME,
00053                    EVENT_ID_TYPE *EVENT_ID,
00054                    RETURN_CODE_TYPE *RETURN_CODE)
00055 {
00056    RETURN_CODE_TYPE  return_code_name;
00057    pok_event_id_t    core_id;
00058    pok_ret_t         core_ret;
00059 
00060    *RETURN_CODE = INVALID_CONFIG;
00061 
00062    CHECK_EVENTS_INIT
00063 
00064    GET_EVENT_ID (EVENT_NAME, EVENT_ID, &return_code_name);
00065 
00066    if (return_code_name == INVALID_CONFIG)
00067    {
00068       *RETURN_CODE = INVALID_CONFIG;
00069       return;
00070    }
00071 
00072    if (*EVENT_ID >= POK_CONFIG_ARINC653_NB_EVENTS)
00073    {
00074       *RETURN_CODE = INVALID_CONFIG;
00075       return;
00076    }
00077 
00078    if (pok_arinc653_events_layers[*EVENT_ID].ready)
00079    {
00080       *RETURN_CODE = NO_ACTION;
00081       return;
00082    }
00083 
00084    core_ret = pok_event_create (&core_id);
00085 
00086    /* DEBUG INFO
00087    printf("ID=%d\n", core_id);
00088    */
00089 
00090    if (core_ret != POK_ERRNO_OK)
00091    {
00092       *RETURN_CODE = INVALID_PARAM;
00093       return;
00094    }
00095 
00096    pok_arinc653_events_layers[*EVENT_ID].ready    = 1;
00097    pok_arinc653_events_layers[*EVENT_ID].core_id  = core_id;
00098    *RETURN_CODE = NO_ERROR;
00099 }
00100 
00101 void SET_EVENT (EVENT_ID_TYPE EVENT_ID,
00102                 RETURN_CODE_TYPE *RETURN_CODE)
00103 {
00104    pok_ret_t core_ret;
00105 
00106    *RETURN_CODE = INVALID_PARAM;
00107 
00108    CHECK_EVENTS_INIT
00109 
00110 
00111    if (EVENT_ID >= POK_CONFIG_ARINC653_NB_EVENTS)
00112    {
00113       *RETURN_CODE = INVALID_CONFIG;
00114       return;
00115    }
00116 
00117    if (pok_arinc653_events_layers[EVENT_ID].ready == 0)
00118    {
00119       *RETURN_CODE = NOT_AVAILABLE;
00120       return;
00121    }
00122 
00123    core_ret = pok_event_signal (pok_arinc653_events_layers[EVENT_ID].core_id);
00124    if (core_ret == POK_ERRNO_OK)
00125    {
00126       *RETURN_CODE = NO_ERROR;
00127       return;
00128    }
00129    else
00130    {
00131       *RETURN_CODE = INVALID_PARAM;
00132       return;
00133    }
00134 }
00135 
00136 void RESET_EVENT (EVENT_ID_TYPE EVENT_ID,
00137                   RETURN_CODE_TYPE *RETURN_CODE)
00138 {
00139    (void) EVENT_ID;
00140    (void) RETURN_CODE;
00141 
00142    /* Not yet implemented */
00143 }
00144 
00145 void WAIT_EVENT (EVENT_ID_TYPE EVENT_ID,
00146                  SYSTEM_TIME_TYPE TIME_OUT,
00147                  RETURN_CODE_TYPE *RETURN_CODE)
00148 {
00149    pok_ret_t core_ret;
00150 
00151    *RETURN_CODE = INVALID_PARAM;
00152 
00153    CHECK_EVENTS_INIT
00154 
00155    if (EVENT_ID >= POK_CONFIG_ARINC653_NB_EVENTS)
00156    {
00157       *RETURN_CODE = INVALID_CONFIG;
00158       return;
00159    }
00160 
00161    if (pok_arinc653_events_layers[EVENT_ID].ready == 0)
00162    {
00163       *RETURN_CODE = NOT_AVAILABLE;
00164       return;
00165    }
00166 
00167    core_ret = pok_event_wait (pok_arinc653_events_layers[EVENT_ID].core_id, TIME_OUT);
00168 
00169    switch (core_ret)
00170    {
00171       case POK_ERRNO_OK:
00172          *RETURN_CODE = NO_ERROR;
00173          break;
00174 
00175       case POK_ERRNO_TIMEOUT:
00176          *RETURN_CODE = TIMED_OUT;
00177          break;
00178 
00179       default:
00180          *RETURN_CODE = INVALID_PARAM;
00181          break;
00182    }
00183 }
00184 
00185 void GET_EVENT_ID (EVENT_NAME_TYPE EVENT_NAME,
00186                    EVENT_ID_TYPE *EVENT_ID,
00187                    RETURN_CODE_TYPE *RETURN_CODE)
00188 {
00189    uint16_t i;
00190    uint16_t len;
00191 
00192    *RETURN_CODE = INVALID_CONFIG;
00193 
00194    len = strlen (EVENT_NAME);
00195 
00196    CHECK_EVENTS_INIT
00197 
00198    for (i = 0 ; i < POK_CONFIG_ARINC653_NB_EVENTS ; i++)
00199    {
00200       if (strncmp (EVENT_NAME, pok_arinc653_events_names[i], len) == 0)
00201       {
00202          *EVENT_ID = i;
00203          *RETURN_CODE = NO_ERROR;
00204          return;
00205       }
00206    }
00207 }
00208 
00209 void GET_EVENT_STATUS (EVENT_ID_TYPE EVENT_ID,
00210                        EVENT_STATUS_TYPE *EVENT_STATUS,
00211                        RETURN_CODE_TYPE *RETURN_CODE)
00212 {
00213    (void) EVENT_ID;
00214    (void) EVENT_STATUS;
00215    (void) RETURN_CODE;
00216 }
00217 
00218 #endif