POK
/home/jaouen/pok_official/pok/trunk/libpok/arinc653/error.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_ERROR
00019 #include <types.h>
00020 #include <errno.h>
00021 #include <arinc653/types.h>
00022 #include <arinc653/error.h>
00023 #include <core/error.h>
00024 #include <core/syscall.h>
00025 #include <libc/string.h>
00026 
00027    /*
00028 #define HIGHEST_ERROR_CODE_VALUE POWER_FAIL
00029 #define LOWEST_ERROR_CODE_VALUE DEADLINE_MISSED
00030 #define CONVERT_ARINC_TO_POK_ERROR(arinc_error,pok_error) \
00031                switch (arinc_error ){ \
00032                   case DEADLINE_MISSED: \
00033                      *pok_error = POK_ERROR_KIND_DEADLINE_MISSED; \
00034                      return 1; \
00035                      break; \
00036                   case APPLICATION_ERROR: \
00037                      *pok_error = POK_ERROR_KIND_APPLICATION_ERROR; \
00038                      return 1; \
00039                      break; \
00040                   case NUMERIC_ERROR: \
00041                      *pok_error = POK_ERROR_KIND_NUMERIC_ERROR; \
00042                      return 1; \
00043                      break; \
00044                   case ILLEGAL_REQUEST: \
00045                      *pok_error = POK_ERROR_KIND_ILLEGAL_REQUEST; \
00046                      return 1; \
00047                      break; \
00048                   case STACK_OVERFLOW: \
00049                      *pok_error = POK_ERROR_KIND_STACK_OVERFLOW; \
00050                      return 1; \
00051                      break; \
00052                   case MEMORY_VIOLATION: \
00053                      *pok_error = POK_ERROR_KIND_MEMORY_VIOLATION; \
00054                      return 1; \
00055                      break; \
00056                   case HARDWARE_FAULT: \
00057                      *pok_error = POK_ERROR_KIND_HARDWARE_FAULT; \
00058                      return 1; \
00059                      break; \
00060                   case POWER_FAIL: \
00061                      *pok_error = POK_ERROR_KIND_POWER_FAIL; \
00062                      return 1; \
00063                      break; \
00064                   default: \
00065                      return 0; \
00066                }
00067    */
00068 
00069  #define CONVERT_ERROR_POK_TO_ARINC(pok_error,arinc_error) \
00070                switch (pok_error){ \
00071                   case POK_ERROR_KIND_DEADLINE_MISSED: \
00072                      arinc_error = DEADLINE_MISSED; \
00073                      break; \
00074                   case POK_ERROR_KIND_APPLICATION_ERROR: \
00075                      arinc_error = APPLICATION_ERROR; \
00076                      break; \
00077                   case POK_ERROR_KIND_NUMERIC_ERROR: \
00078                      arinc_error = NUMERIC_ERROR; \
00079                      break; \
00080                   case POK_ERROR_KIND_ILLEGAL_REQUEST: \
00081                      arinc_error = ILLEGAL_REQUEST; \
00082                      break; \
00083                   case POK_ERROR_KIND_STACK_OVERFLOW: \
00084                      arinc_error = STACK_OVERFLOW; \
00085                      break; \
00086                   case POK_ERROR_KIND_MEMORY_VIOLATION: \
00087                      arinc_error = MEMORY_VIOLATION; \
00088                      break; \
00089                   case POK_ERROR_KIND_HARDWARE_FAULT: \
00090                      arinc_error = HARDWARE_FAULT; \
00091                      break; \
00092                   case POK_ERROR_KIND_POWER_FAIL: \
00093                      arinc_error = POWER_FAIL; \
00094                      break; \
00095                }
00096 
00097 
00102 void REPORT_APPLICATION_MESSAGE (MESSAGE_ADDR_TYPE    MESSAGE,
00103                                  MESSAGE_SIZE_TYPE    LENGTH,
00104                                  RETURN_CODE_TYPE     *RETURN_CODE )
00105 {
00106    if (LENGTH > 64)
00107    {
00108       *RETURN_CODE = INVALID_PARAM;
00109       return;
00110    }
00111 
00112    pok_error_raise_application_error ((char*) MESSAGE, LENGTH);
00113 
00114    *RETURN_CODE = NO_ERROR;
00115 }
00116 
00117 void CREATE_ERROR_HANDLER (SYSTEM_ADDRESS_TYPE  ENTRY_POINT,
00118                            STACK_SIZE_TYPE      STACK_SIZE,
00119                            RETURN_CODE_TYPE     *RETURN_CODE)
00120 {
00121    pok_ret_t core_ret;
00122    core_ret = pok_syscall2 (POK_SYSCALL_ERROR_HANDLER_CREATE, (uint32_t)STACK_SIZE, (uint32_t)ENTRY_POINT);
00123    if (core_ret == POK_ERRNO_OK)
00124    {
00125       *RETURN_CODE = NO_ERROR;
00126    }
00127    else
00128    {
00129       /* NEEDS TO COMPLETE WITH THE STANDARD ! */
00130       *RETURN_CODE = INVALID_CONFIG;
00131    }
00132 }
00133 
00134 void GET_ERROR_STATUS (ERROR_STATUS_TYPE  *ERROR_STATUS,
00135                        RETURN_CODE_TYPE   *RETURN_CODE )
00136 {
00142    pok_error_status_t   core_status;
00143    pok_ret_t            core_ret;
00144 
00145    core_ret = pok_error_get (&core_status);
00146 
00147    if (core_ret != POK_ERRNO_OK)
00148    {
00149       *RETURN_CODE = NO_ACTION; /* Must be improved later ! */
00150       return;
00151    }
00152 
00153    CONVERT_ERROR_POK_TO_ARINC (core_status.error_kind, ERROR_STATUS->ERROR_CODE);
00154    ERROR_STATUS->LENGTH             = core_status.msg_size;
00155    memcpy (ERROR_STATUS->MESSAGE, core_status.msg, MAX_ERROR_MESSAGE_SIZE);
00156    ERROR_STATUS->FAILED_PROCESS_ID  = core_status.failed_thread;
00157    ERROR_STATUS->FAILED_ADDRESS     = (SYSTEM_ADDRESS_TYPE)core_status.failed_addr;
00158 
00159 }
00160 
00161 void RAISE_APPLICATION_ERROR (ERROR_CODE_TYPE            ERROR_CODE,
00162                               MESSAGE_ADDR_TYPE          MESSAGE,
00163                               ERROR_MESSAGE_SIZE_TYPE    LENGTH,
00164                               RETURN_CODE_TYPE           *RETURN_CODE)
00165 {
00166   if (LENGTH > 64)
00167    {
00168       *RETURN_CODE = INVALID_PARAM;
00169       return;
00170    }
00171 
00172    if ( (ERROR_CODE != APPLICATION_ERROR))
00173    {
00174       *RETURN_CODE = INVALID_PARAM;
00175       return;
00176    }
00177 
00178    pok_error_raise_application_error ((char*) MESSAGE, LENGTH);
00179 
00180    *RETURN_CODE = NO_ERROR;
00181 }
00182 
00183 #endif