POK
/home/jaouen/pok_official/pok/trunk/libpok/arinc653/sampling.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_SAMPLING
00019 
00020 #include <types.h>
00021 #include <middleware/port.h>
00022 #include <arinc653/types.h>
00023 #include <arinc653/sampling.h>
00024 #include <arinc653/partition.h>
00025 #include <core/thread.h>
00026 
00027 void CREATE_SAMPLING_PORT (
00028                          /*in */ SAMPLING_PORT_NAME_TYPE    SAMPLING_PORT_NAME,
00029                          /*in */ MESSAGE_SIZE_TYPE          MAX_MESSAGE_SIZE,
00030                          /*in */ PORT_DIRECTION_TYPE        PORT_DIRECTION,
00031                          /*in */ SYSTEM_TIME_TYPE           REFRESH_PERIOD,
00032                          /*out*/ SAMPLING_PORT_ID_TYPE      *SAMPLING_PORT_ID,
00033                          /*out*/ RETURN_CODE_TYPE           *RETURN_CODE )
00034 {
00035          pok_port_direction_t core_direction;
00036          pok_port_id_t        core_id;
00037          pok_ret_t            core_ret;
00038          pok_thread_attr_t     attr;
00039          uint32_t                                                       process_id;
00040 
00041          pok_thread_id(&process_id);
00042          core_ret = pok_thread_status (process_id, &attr);
00043          if (attr.state == NORMAL)
00044                  {
00045                          *RETURN_CODE = INVALID_MODE;
00046                          return ;
00047                  }
00048          if (MAX_MESSAGE_SIZE <= 0 || REFRESH_PERIOD < 0)
00049                  {
00050                          *RETURN_CODE = INVALID_CONFIG;
00051                          return ;
00052                  }
00053 
00054          switch (PORT_DIRECTION)
00055          {
00056                         case SOURCE:
00057                                  core_direction = POK_PORT_DIRECTION_OUT;
00058                                  break;
00059 
00060                         case DESTINATION:
00061                                  core_direction = POK_PORT_DIRECTION_IN;
00062                                  break;
00063 
00064                         default:
00065                                  *RETURN_CODE = INVALID_PARAM;
00066                                  return;
00067          }
00068 
00069          core_ret = pok_port_sampling_create (SAMPLING_PORT_NAME, MAX_MESSAGE_SIZE, core_direction, REFRESH_PERIOD, &core_id);
00070 
00071          *SAMPLING_PORT_ID = core_id;
00072 
00073          *RETURN_CODE = core_ret;
00074 }
00075 
00076 void WRITE_SAMPLING_MESSAGE (
00077                          /*in */ SAMPLING_PORT_ID_TYPE      SAMPLING_PORT_ID,
00078                          /*in */ MESSAGE_ADDR_TYPE          MESSAGE_ADDR,     /* by reference */
00079                          /*in */ MESSAGE_SIZE_TYPE          LENGTH,
00080                          /*out*/ RETURN_CODE_TYPE           *RETURN_CODE )
00081 {
00082          pok_ret_t core_ret;
00083 
00084          if (LENGTH <= 0)
00085                  {
00086                          *RETURN_CODE = INVALID_PARAM;
00087                          return;
00088                  }
00089          core_ret = pok_port_sampling_write (SAMPLING_PORT_ID, MESSAGE_ADDR, LENGTH);
00090          *RETURN_CODE = core_ret;
00091 }
00092 
00093 void READ_SAMPLING_MESSAGE (
00094                          /*in */ SAMPLING_PORT_ID_TYPE      SAMPLING_PORT_ID,
00095                          /*out*/ MESSAGE_ADDR_TYPE          MESSAGE_ADDR,
00096                          /*out*/ MESSAGE_SIZE_TYPE          *LENGTH,
00097                          /*out*/ VALIDITY_TYPE              *VALIDITY,
00098                          /*out*/ RETURN_CODE_TYPE           *RETURN_CODE )
00099 {
00100          pok_ret_t core_ret;
00101          core_ret = pok_port_sampling_read (SAMPLING_PORT_ID, MESSAGE_ADDR, (pok_port_size_t*) LENGTH, (pok_bool_t*) VALIDITY);
00102          *RETURN_CODE = core_ret;
00103 }
00104 
00105 void GET_SAMPLING_PORT_ID (
00106                          /*in */ SAMPLING_PORT_NAME_TYPE    SAMPLING_PORT_NAME,
00107                          /*out*/ SAMPLING_PORT_ID_TYPE      *SAMPLING_PORT_ID,
00108                          /*out*/ RETURN_CODE_TYPE           *RETURN_CODE )
00109 {
00110         pok_ret_t core_ret;
00111         pok_port_id_t id;
00112 
00113         core_ret = pok_port_sampling_id(SAMPLING_PORT_NAME, &id);
00114         *SAMPLING_PORT_ID = id;
00115         *RETURN_CODE = core_ret;
00116 }
00117 
00118 void GET_SAMPLING_PORT_STATUS (
00119                          /*in */ SAMPLING_PORT_ID_TYPE      SAMPLING_PORT_ID,
00120                          /*out*/ SAMPLING_PORT_STATUS_TYPE  *SAMPLING_PORT_STATUS,
00121                          /*out*/ RETURN_CODE_TYPE           *RETURN_CODE )
00122 {
00123         pok_ret_t core_ret;
00124         pok_port_sampling_status_t status;
00125 
00126         core_ret = pok_port_sampling_status(SAMPLING_PORT_ID, &status);
00127         SAMPLING_PORT_STATUS->REFRESH_PERIOD = status.refresh;
00128         SAMPLING_PORT_STATUS->MAX_MESSAGE_SIZE = status.size;
00129         SAMPLING_PORT_STATUS->PORT_DIRECTION = status.direction;
00130         SAMPLING_PORT_STATUS->LAST_MSG_VALIDITY = status.validity;
00131         *RETURN_CODE = core_ret;
00132 }
00133 
00134 #endif