POK
event.c
1 /*
2  * POK header
3  *
4  * The following file is a part of the POK project. Any modification should
5  * made according to the POK licence. You CANNOT use this file or a part of
6  * this file is this part of a file for your own project
7  *
8  * For more information on the POK licence, please see our LICENCE FILE
9  *
10  * Please follow the coding guidelines described in doc/CODING_GUIDELINES
11  *
12  * Copyright (c) 2007-2009 POK team
13  *
14  * Created by julien on Thu Jan 15 23:34:13 2009
15  */
16 
17 
18 #ifdef POK_NEEDS_ARINC653_EVENT
19 #include <arinc653/types.h>
20 #include <arinc653/event.h>
21 
22 #include <core/event.h> /* For core function */
23 
24 #include <libc/string.h> /* For strcmp */
25 
26 #include <errno.h> /* For POK_ERRNO_... maccros */
27 
28 #define CHECK_EVENTS_INIT if (pok_arinc653_events_initialized == 0) \
29  { \
30  uint16_t bla; \
31  for (bla = 0 ; bla < POK_CONFIG_ARINC653_NB_EVENTS ; bla++) \
32  {\
33  pok_arinc653_events_layers[bla].ready = 0;\
34  }\
35  }\
36  pok_arinc653_events_initialized = 1;
37 
38 
39 
40 
41 bool_t pok_arinc653_events_initialized = 0;
42 
43 typedef struct
44 {
45  pok_event_id_t core_id;
46  pok_bool_t ready;
48 
49 extern char* pok_arinc653_events_names[POK_CONFIG_ARINC653_NB_EVENTS];
50 pok_arinc653_event_layer_t pok_arinc653_events_layers[POK_CONFIG_NB_EVENTS];
51 
52 void CREATE_EVENT (EVENT_NAME_TYPE EVENT_NAME,
53  EVENT_ID_TYPE *EVENT_ID,
54  RETURN_CODE_TYPE *RETURN_CODE)
55 {
56  RETURN_CODE_TYPE return_code_name;
57  pok_event_id_t core_id;
58  pok_ret_t core_ret;
59 
60  *RETURN_CODE = INVALID_CONFIG;
61 
62  CHECK_EVENTS_INIT
63 
64  GET_EVENT_ID (EVENT_NAME, EVENT_ID, &return_code_name);
65 
66  if (return_code_name == INVALID_CONFIG)
67  {
68  *RETURN_CODE = INVALID_CONFIG;
69  return;
70  }
71 
72  if (*EVENT_ID >= POK_CONFIG_ARINC653_NB_EVENTS)
73  {
74  *RETURN_CODE = INVALID_CONFIG;
75  return;
76  }
77 
78  if (pok_arinc653_events_layers[*EVENT_ID].ready)
79  {
80  *RETURN_CODE = NO_ACTION;
81  return;
82  }
83 
84  core_ret = pok_event_create (&core_id);
85 
86  /* DEBUG INFO
87  printf("ID=%d\n", core_id);
88  */
89 
90  if (core_ret != POK_ERRNO_OK)
91  {
92  *RETURN_CODE = INVALID_PARAM;
93  return;
94  }
95 
96  pok_arinc653_events_layers[*EVENT_ID].ready = 1;
97  pok_arinc653_events_layers[*EVENT_ID].core_id = core_id;
98  *RETURN_CODE = NO_ERROR;
99 }
100 
101 void SET_EVENT (EVENT_ID_TYPE EVENT_ID,
102  RETURN_CODE_TYPE *RETURN_CODE)
103 {
104  pok_ret_t core_ret;
105 
106  *RETURN_CODE = INVALID_PARAM;
107 
108  CHECK_EVENTS_INIT
109 
110 
111  if (EVENT_ID >= POK_CONFIG_ARINC653_NB_EVENTS)
112  {
113  *RETURN_CODE = INVALID_CONFIG;
114  return;
115  }
116 
117  if (pok_arinc653_events_layers[EVENT_ID].ready == 0)
118  {
119  *RETURN_CODE = NOT_AVAILABLE;
120  return;
121  }
122 
123  core_ret = pok_event_signal (pok_arinc653_events_layers[EVENT_ID].core_id);
124  if (core_ret == POK_ERRNO_OK)
125  {
126  *RETURN_CODE = NO_ERROR;
127  return;
128  }
129  else
130  {
131  *RETURN_CODE = INVALID_PARAM;
132  return;
133  }
134 }
135 
136 void RESET_EVENT (EVENT_ID_TYPE EVENT_ID,
137  RETURN_CODE_TYPE *RETURN_CODE)
138 {
139  (void) EVENT_ID;
140  (void) RETURN_CODE;
141 
142  /* Not yet implemented */
143 }
144 
145 void WAIT_EVENT (EVENT_ID_TYPE EVENT_ID,
146  SYSTEM_TIME_TYPE TIME_OUT,
147  RETURN_CODE_TYPE *RETURN_CODE)
148 {
149  pok_ret_t core_ret;
150 
151  *RETURN_CODE = INVALID_PARAM;
152 
153  CHECK_EVENTS_INIT
154 
155  if (EVENT_ID >= POK_CONFIG_ARINC653_NB_EVENTS)
156  {
157  *RETURN_CODE = INVALID_CONFIG;
158  return;
159  }
160 
161  if (pok_arinc653_events_layers[EVENT_ID].ready == 0)
162  {
163  *RETURN_CODE = NOT_AVAILABLE;
164  return;
165  }
166 
167  core_ret = pok_event_wait (pok_arinc653_events_layers[EVENT_ID].core_id, TIME_OUT);
168 
169  switch (core_ret)
170  {
171  case POK_ERRNO_OK:
172  *RETURN_CODE = NO_ERROR;
173  break;
174 
175  case POK_ERRNO_TIMEOUT:
176  *RETURN_CODE = TIMED_OUT;
177  break;
178 
179  default:
180  *RETURN_CODE = INVALID_PARAM;
181  break;
182  }
183 }
184 
185 void GET_EVENT_ID (EVENT_NAME_TYPE EVENT_NAME,
186  EVENT_ID_TYPE *EVENT_ID,
187  RETURN_CODE_TYPE *RETURN_CODE)
188 {
189  uint16_t i;
190  uint16_t len;
191 
192  *RETURN_CODE = INVALID_CONFIG;
193 
194  len = strlen (EVENT_NAME);
195 
196  CHECK_EVENTS_INIT
197 
198  for (i = 0 ; i < POK_CONFIG_ARINC653_NB_EVENTS ; i++)
199  {
200  if (strncmp (EVENT_NAME, pok_arinc653_events_names[i], len) == 0)
201  {
202  *EVENT_ID = i;
203  *RETURN_CODE = NO_ERROR;
204  return;
205  }
206  }
207 }
208 
209 void GET_EVENT_STATUS (EVENT_ID_TYPE EVENT_ID,
210  EVENT_STATUS_TYPE *EVENT_STATUS,
211  RETURN_CODE_TYPE *RETURN_CODE)
212 {
213  (void) EVENT_ID;
214  (void) EVENT_STATUS;
215  (void) RETURN_CODE;
216 }
217 
218 #endif