POK
error.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_ERROR
19 #include <types.h>
20 #include <errno.h>
21 #include <arinc653/types.h>
22 #include <arinc653/error.h>
23 #include <core/error.h>
24 #include <core/syscall.h>
25 #include <libc/string.h>
26 
27  /*
28 #define HIGHEST_ERROR_CODE_VALUE POWER_FAIL
29 #define LOWEST_ERROR_CODE_VALUE DEADLINE_MISSED
30 #define CONVERT_ARINC_TO_POK_ERROR(arinc_error,pok_error) \
31  switch (arinc_error ){ \
32  case DEADLINE_MISSED: \
33  *pok_error = POK_ERROR_KIND_DEADLINE_MISSED; \
34  return 1; \
35  break; \
36  case APPLICATION_ERROR: \
37  *pok_error = POK_ERROR_KIND_APPLICATION_ERROR; \
38  return 1; \
39  break; \
40  case NUMERIC_ERROR: \
41  *pok_error = POK_ERROR_KIND_NUMERIC_ERROR; \
42  return 1; \
43  break; \
44  case ILLEGAL_REQUEST: \
45  *pok_error = POK_ERROR_KIND_ILLEGAL_REQUEST; \
46  return 1; \
47  break; \
48  case STACK_OVERFLOW: \
49  *pok_error = POK_ERROR_KIND_STACK_OVERFLOW; \
50  return 1; \
51  break; \
52  case MEMORY_VIOLATION: \
53  *pok_error = POK_ERROR_KIND_MEMORY_VIOLATION; \
54  return 1; \
55  break; \
56  case HARDWARE_FAULT: \
57  *pok_error = POK_ERROR_KIND_HARDWARE_FAULT; \
58  return 1; \
59  break; \
60  case POWER_FAIL: \
61  *pok_error = POK_ERROR_KIND_POWER_FAIL; \
62  return 1; \
63  break; \
64  default: \
65  return 0; \
66  }
67  */
68 
69  #define CONVERT_ERROR_POK_TO_ARINC(pok_error,arinc_error) \
70  switch (pok_error){ \
71  case POK_ERROR_KIND_DEADLINE_MISSED: \
72  arinc_error = DEADLINE_MISSED; \
73  break; \
74  case POK_ERROR_KIND_APPLICATION_ERROR: \
75  arinc_error = APPLICATION_ERROR; \
76  break; \
77  case POK_ERROR_KIND_NUMERIC_ERROR: \
78  arinc_error = NUMERIC_ERROR; \
79  break; \
80  case POK_ERROR_KIND_ILLEGAL_REQUEST: \
81  arinc_error = ILLEGAL_REQUEST; \
82  break; \
83  case POK_ERROR_KIND_STACK_OVERFLOW: \
84  arinc_error = STACK_OVERFLOW; \
85  break; \
86  case POK_ERROR_KIND_MEMORY_VIOLATION: \
87  arinc_error = MEMORY_VIOLATION; \
88  break; \
89  case POK_ERROR_KIND_HARDWARE_FAULT: \
90  arinc_error = HARDWARE_FAULT; \
91  break; \
92  case POK_ERROR_KIND_POWER_FAIL: \
93  arinc_error = POWER_FAIL; \
94  break; \
95  }
96 
97 
102 void REPORT_APPLICATION_MESSAGE (MESSAGE_ADDR_TYPE MESSAGE,
103  MESSAGE_SIZE_TYPE LENGTH,
104  RETURN_CODE_TYPE *RETURN_CODE )
105 {
106  if (LENGTH > 64)
107  {
108  *RETURN_CODE = INVALID_PARAM;
109  return;
110  }
111 
112  pok_error_raise_application_error ((char*) MESSAGE, LENGTH);
113 
114  *RETURN_CODE = NO_ERROR;
115 }
116 
117 void CREATE_ERROR_HANDLER (SYSTEM_ADDRESS_TYPE ENTRY_POINT,
118  STACK_SIZE_TYPE STACK_SIZE,
119  RETURN_CODE_TYPE *RETURN_CODE)
120 {
121  pok_ret_t core_ret;
122  core_ret = pok_syscall2 (POK_SYSCALL_ERROR_HANDLER_CREATE, (uint32_t)STACK_SIZE, (uint32_t)ENTRY_POINT);
123  if (core_ret == POK_ERRNO_OK)
124  {
125  *RETURN_CODE = NO_ERROR;
126  }
127  else
128  {
129  /* NEEDS TO COMPLETE WITH THE STANDARD ! */
130  *RETURN_CODE = INVALID_CONFIG;
131  }
132 }
133 
134 void GET_ERROR_STATUS (ERROR_STATUS_TYPE *ERROR_STATUS,
135  RETURN_CODE_TYPE *RETURN_CODE )
136 {
142  pok_error_status_t core_status;
143  pok_ret_t core_ret;
144 
145  core_ret = pok_error_get (&core_status);
146 
147  if (core_ret != POK_ERRNO_OK)
148  {
149  *RETURN_CODE = NO_ACTION; /* Must be improved later ! */
150  return;
151  }
152 
153  CONVERT_ERROR_POK_TO_ARINC (core_status.error_kind, ERROR_STATUS->ERROR_CODE);
154  ERROR_STATUS->LENGTH = core_status.msg_size;
155  memcpy (ERROR_STATUS->MESSAGE, core_status.msg, MAX_ERROR_MESSAGE_SIZE);
156  ERROR_STATUS->FAILED_PROCESS_ID = core_status.failed_thread;
157  ERROR_STATUS->FAILED_ADDRESS = (SYSTEM_ADDRESS_TYPE)core_status.failed_addr;
158 
159 }
160 
161 void RAISE_APPLICATION_ERROR (ERROR_CODE_TYPE ERROR_CODE,
162  MESSAGE_ADDR_TYPE MESSAGE,
163  ERROR_MESSAGE_SIZE_TYPE LENGTH,
164  RETURN_CODE_TYPE *RETURN_CODE)
165 {
166  if (LENGTH > 64)
167  {
168  *RETURN_CODE = INVALID_PARAM;
169  return;
170  }
171 
172  if ( (ERROR_CODE != APPLICATION_ERROR))
173  {
174  *RETURN_CODE = INVALID_PARAM;
175  return;
176  }
177 
178  pok_error_raise_application_error ((char*) MESSAGE, LENGTH);
179 
180  *RETURN_CODE = NO_ERROR;
181 }
182 
183 #endif