POK
process.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_PROCESS
19 
20 #include <core/dependencies.h>
21 
22 #include <core/thread.h>
23 #include <arinc653/arincutils.h>
24 #include <arinc653/types.h>
25 #include <arinc653/process.h>
26 #include <libc/string.h>
27 
28 void GET_PROCESS_ID (PROCESS_NAME_TYPE process_name[MAX_NAME_LENGTH],
29  PROCESS_ID_TYPE *process_id,
30  RETURN_CODE_TYPE *return_code )
31 {
32  int id;
33 
34  if ((id = process_name_exist(process_name)) == 0)
35  {
36  *process_id = id;
37  *return_code = INVALID_CONFIG;
38  }
39  else
40  {
41  *process_id = id;
42  *return_code = NO_ERROR;
43  }
44 }
45 
46 void GET_MY_ID (PROCESS_ID_TYPE *process_id,
47  RETURN_CODE_TYPE *return_code )
48 {
49  pok_ret_t core_ret;
50  uint32_t thread_id;
51 
52  core_ret = pok_thread_id (&thread_id);
53  if (core_ret != 0)
54  *return_code = INVALID_MODE;
55  *process_id = thread_id;
56  *return_code = NO_ERROR;
57 }
58 
59 void GET_PROCESS_STATUS (PROCESS_ID_TYPE process_id,
60  PROCESS_STATUS_TYPE *process_status,
61  RETURN_CODE_TYPE *return_code )
62 {
63  pok_thread_attr_t attr;
64  pok_ret_t core_ret;
65 
66  core_ret = pok_thread_status (process_id, &attr);
67  if (core_ret != 0)
68  {
69  *return_code = INVALID_CONFIG;
70  return ;
71  }
72  process_status->DEADLINE_TIME = attr.deadline;
73  process_status->PROCESS_STATE = attr.state;
74  strcpy(process_status->ATTRIBUTES.NAME, arinc_process_attribute[process_id].NAME);
75  process_status->ATTRIBUTES.BASE_PRIORITY = arinc_process_attribute[process_id].BASE_PRIORITY;
76  process_status->ATTRIBUTES.DEADLINE = HARD;
77  process_status->CURRENT_PRIORITY = attr.priority;
78  process_status->ATTRIBUTES.PERIOD = attr.period;
79  process_status->ATTRIBUTES.TIME_CAPACITY = attr.time_capacity;
80  process_status->ATTRIBUTES.ENTRY_POINT = attr.entry;
81  process_status->ATTRIBUTES.STACK_SIZE = attr.stack_size;
82  *return_code = NO_ERROR;
83 }
84 
85 void CREATE_PROCESS (PROCESS_ATTRIBUTE_TYPE *attributes,
86  PROCESS_ID_TYPE *process_id,
87  RETURN_CODE_TYPE *return_code )
88 {
89  pok_thread_attr_t core_attr;
90  pok_ret_t core_ret;
91  uint32_t core_process_id;
92 
93  if (process_name_exist(&attributes->NAME))
94  {
95  *return_code = NO_ACTION;
96  return;
97  }
98  if (attributes->BASE_PRIORITY > MAX_PRIORITY_VALUE || attributes->BASE_PRIORITY < MIN_PRIORITY_VALUE)
99  {
100  *return_code = INVALID_PARAM;
101  return;
102  }
103  core_attr.priority = (uint8_t) attributes->BASE_PRIORITY;
104  core_attr.entry = attributes->ENTRY_POINT;
105  core_attr.period = attributes->PERIOD;
106  core_attr.deadline = attributes->DEADLINE;
107  core_attr.time_capacity = attributes->TIME_CAPACITY;
108  core_attr.stack_size = attributes->STACK_SIZE;
109 
110  core_ret = pok_thread_create (&core_process_id, &core_attr);
111  arinc_process_attribute[core_process_id].BASE_PRIORITY = attributes->BASE_PRIORITY;
112  strcpy(arinc_process_attribute[core_process_id].NAME, attributes->NAME);
113  *process_id = core_process_id;
114  *return_code = core_ret;
115 }
116 
117 void STOP_SELF ()
118 {
119  pok_thread_stop_self ();
120 }
121 
122 
123 
124 #ifndef POK_CONFIG_OPTIMIZE_FOR_GENERATED_CODE
125 void SET_PRIORITY (PROCESS_ID_TYPE process_id,
126  PRIORITY_TYPE priority,
127  RETURN_CODE_TYPE *return_code )
128 {
129  (void) process_id;
130  (void) priority;
131  *return_code = NOT_AVAILABLE;
132 }
133 
134 void SUSPEND_SELF (SYSTEM_TIME_TYPE time_out,
135  RETURN_CODE_TYPE *return_code )
136 {
137  (void) time_out;
138  *return_code = NOT_AVAILABLE;
139 }
140 
141 void SUSPEND (PROCESS_ID_TYPE process_id,
142  RETURN_CODE_TYPE *return_code )
143 {
144  (void) process_id;
145  *return_code = NOT_AVAILABLE;
146 }
147 
148 void RESUME (PROCESS_ID_TYPE process_id,
149  RETURN_CODE_TYPE *return_code )
150 {
151  (void) process_id;
152  *return_code = NOT_AVAILABLE;
153 }
154 
155 void STOP (PROCESS_ID_TYPE process_id,
156  RETURN_CODE_TYPE *return_code )
157 {
158  (void) process_id;
159  *return_code = NOT_AVAILABLE;
160 }
161 
162 void START (PROCESS_ID_TYPE process_id,
163  RETURN_CODE_TYPE *return_code )
164 {
165  (void) process_id;
166  *return_code = NOT_AVAILABLE;
167 }
168 
169 void DELAYED_START (PROCESS_ID_TYPE process_id,
170  SYSTEM_TIME_TYPE delay_time,
171  RETURN_CODE_TYPE *return_code )
172 {
173  (void) process_id;
174  (void) delay_time;
175  *return_code = NOT_AVAILABLE;
176 }
177 
178 void LOCK_PREEMPTION (LOCK_LEVEL_TYPE *lock_level,
179  RETURN_CODE_TYPE *return_code )
180 {
181  (void) lock_level;
182  *return_code = NOT_AVAILABLE;
183 }
184 
185 void UNLOCK_PREEMPTION (LOCK_LEVEL_TYPE *lock_level,
186  RETURN_CODE_TYPE *return_code )
187 
188 {
189  (void) lock_level;
190  *return_code = NOT_AVAILABLE;
191 }
192 #endif
193 
194 #endif