1 |
//**************************************************************************** |
2 |
/* F i l e D a t a |
3 |
/* |
4 |
/* Module : BasicSW |
5 |
/* C.I. No. : |
6 |
/* $Revision: 1.11 $ |
7 |
/* $Date: 2005/03/10 11:34:20 $ |
8 |
/* Belonging to : |
9 |
/* : |
10 |
/* $RCSfile: OS_rtems_p.c,v $ |
11 |
/* Program Type : |
12 |
/* Sub-modules : |
13 |
/* |
14 |
/**************************************************************************** |
15 |
/* S W D e v e l o p m e n t E n v i r o n m e n t |
16 |
/* |
17 |
/* Host system : |
18 |
/* SW Compiler : |
19 |
/* $Author: faber $ |
20 |
/* : |
21 |
/**************************************************************************** |
22 |
/* U p d a t i n g |
23 |
/* |
24 |
/* $Log: OS_rtems_p.c,v $ |
25 |
/* Revision 1.11 2005/03/10 11:34:20 faber |
26 |
/* tmacros include excluded |
27 |
/* |
28 |
/* Revision 1.10 2005/02/24 16:44:59 sebastiani |
29 |
/* uncomment log info loading |
30 |
/* |
31 |
/* Revision 1.9 2005/02/21 08:58:28 sebastiani |
32 |
/* all log comments completed |
33 |
/* |
34 |
/* Revision 1.8 2004/11/10 16:59:58 sebastiani |
35 |
/* - GS_COMPILE directive introduced and be undef by default |
36 |
/* - automatic flush mechanism by run manager mailbox timeout |
37 |
/* |
38 |
/* Revision 1.7 2004/09/17 15:01:00 faber |
39 |
/* LU_INFN_LOG flags fixing |
40 |
/* |
41 |
/* Revision 1.6 2004/08/26 16:53:56 sebastiani |
42 |
/* fix some bug |
43 |
/* |
44 |
/* Revision 1.5 2004/05/12 08:10:11 faber |
45 |
/* *** empty log message *** |
46 |
/* |
47 |
/* Revision 1.4 2004/03/09 09:39:27 faber |
48 |
/* LU_TRACE system introduced |
49 |
/* |
50 |
/* Revision 1.3 2003/11/20 10:24:46 faber |
51 |
/* - interrupt_is_in_progress check inside the OS_Obtain |
52 |
/* - CM_RETURN_CODE type starting from RTEMS_STATUS_CODES_LAST, in order to have a unique error space coding |
53 |
/* |
54 |
/* Revision 1.2 2003/10/21 16:09:12 alfarano |
55 |
/* LU_LOG_INFN replacement for all remaining original log functions |
56 |
/* |
57 |
/* Revision 1.1.1.1 2003/08/04 09:40:21 sebastiani |
58 |
/* Imported sources laben rel. 19.06.2003 integrated with pam2 |
59 |
/* |
60 |
/* Revision 1.4 2003/08/01 09:46:36 sebastiani |
61 |
/* *** empty log message *** |
62 |
/* |
63 |
/* Revision 1.3 2003/07/25 10:30:17 sebastiani |
64 |
/* bug fix semaphore creation and mailbox creation |
65 |
/* |
66 |
/* Revision 1.2 2003/07/03 12:39:29 sebastiani |
67 |
/* *** empty log message *** |
68 |
/* |
69 |
/* Revision 1.1.1.1 2003/05/27 08:13:24 wizard |
70 |
/* Import of the Official Laben CD Release Software as the pamela-EM_delivery_20030521_1454.tar.bz2 |
71 |
/* |
72 |
/* Revision 1.5 2002/11/14 09:45:56 zulia |
73 |
/* removed unsed status variable |
74 |
/* |
75 |
/* Revision 1.4 2002/05/09 08:16:34 zulia |
76 |
/* * acceptance release |
77 |
/* |
78 |
/* |
79 |
/*****************************************************************************/ |
80 |
|
81 |
|
82 |
/*============================= Include File ================================*/ |
83 |
|
84 |
//#include <tmacros.h> |
85 |
#include <src/BasicSW/RTEMSInterface/OS_rtems_p.h> |
86 |
#include <src/BasicSW/RTEMSInterface/OS_rtems_op.h> |
87 |
#include <src/HKManager/HistoryArea/HA_HistoryArea_p.h> |
88 |
|
89 |
#include <src/INFN/LU_SourceFileID_INFN.h> |
90 |
#define __FILEID__ _OS_rtems_p__c |
91 |
#include <src/INFN/PRH_ParamHandler_INFN_auto.h> |
92 |
#include <src/INFN/PRH_ParamHandler_INFN.h> |
93 |
#include <src/INFN/LU_LogUtility_INFN.h> |
94 |
|
95 |
LU_DECL_MASK(); |
96 |
|
97 |
|
98 |
#ifdef TEST_I |
99 |
#include <src/INFN/OS_rtems_INFN_p.h> |
100 |
#endif |
101 |
|
102 |
#include <src/INFN/CM_Common_INFN.h> |
103 |
|
104 |
/*****************************************************************************/ |
105 |
/*==================== RTEMS configuration variables ========================*/ |
106 |
|
107 |
/*****************************************************************************/ |
108 |
/* @Variable: Task_id */ |
109 |
/* @Purpose : */ |
110 |
/* Array of retems_id */ |
111 |
/* RTEMS tasks identification. */ |
112 |
/* @@ */ |
113 |
/*****************************************************************************/ |
114 |
static rtems_id Task_id [MAX_TASK]; |
115 |
|
116 |
/*****************************************************************************/ |
117 |
/* @Variable: Task_name */ |
118 |
/* @Purpose : */ |
119 |
/* Array of retems_id */ |
120 |
/* RTEMS tasks name. */ |
121 |
/* @@ */ |
122 |
/*****************************************************************************/ |
123 |
static rtems_name Task_name [MAX_TASK]; |
124 |
|
125 |
/*****************************************************************************/ |
126 |
/* @Variable: Msg_id */ |
127 |
/* @Purpose : */ |
128 |
/* Array of retems_id */ |
129 |
/* RTEMS mailboxes identification. */ |
130 |
/* @@ */ |
131 |
/*****************************************************************************/ |
132 |
static rtems_id Msg_id [MAX_MBOX]; |
133 |
|
134 |
/*****************************************************************************/ |
135 |
/* @Variable: Msg_name */ |
136 |
/* @Purpose : */ |
137 |
/* Array of retems_id */ |
138 |
/* RTEMS mailboxes name. */ |
139 |
/* @@ */ |
140 |
/*****************************************************************************/ |
141 |
static rtems_name Msg_name [MAX_MBOX]; |
142 |
|
143 |
/*****************************************************************************/ |
144 |
/* @Variable: Sem_id */ |
145 |
/* @Purpose : */ |
146 |
/* Array of retems_id */ |
147 |
/* RTEMS semaphores identification. */ |
148 |
/* @@ */ |
149 |
/*****************************************************************************/ |
150 |
static rtems_id Sem_id [MAX_RES]; |
151 |
|
152 |
/*****************************************************************************/ |
153 |
/* @Variable: Sem_name */ |
154 |
/* @Purpose : */ |
155 |
/* Array of retems_id */ |
156 |
/* RTEMS semaphores name. */ |
157 |
/* @@ */ |
158 |
/*****************************************************************************/ |
159 |
static rtems_name Sem_name [MAX_RES]; |
160 |
|
161 |
/*****************************************************************************/ |
162 |
/* @Variable: Part_id */ |
163 |
/* @Purpose : */ |
164 |
/* Array of retems_id */ |
165 |
/* RTEMS patitios identification. */ |
166 |
/* @@ */ |
167 |
/*****************************************************************************/ |
168 |
static rtems_id Part_id [MAX_PART]; |
169 |
|
170 |
/*****************************************************************************/ |
171 |
/* @Variable: Part_name */ |
172 |
/* @Purpose : */ |
173 |
/* Array of retems_id */ |
174 |
/* RTEMS patitios name. */ |
175 |
/* @@ */ |
176 |
/*****************************************************************************/ |
177 |
static rtems_name Part_name [MAX_PART]; |
178 |
|
179 |
/*****************************************************************************/ |
180 |
/* @Variable: Tim_id */ |
181 |
/* @Purpose : */ |
182 |
/* Array of retems_id */ |
183 |
/* RTEMS timers identification. */ |
184 |
/* @@ */ |
185 |
/*****************************************************************************/ |
186 |
static rtems_id Tim_id [MAX_TIM]; |
187 |
|
188 |
/*****************************************************************************/ |
189 |
/* @Variable: Tim_name */ |
190 |
/* @Purpose : */ |
191 |
/* Array of retems_id */ |
192 |
/* RTEMS timers name. */ |
193 |
/* @@ */ |
194 |
/*****************************************************************************/ |
195 |
static rtems_name Tim_name [MAX_TIM]; |
196 |
|
197 |
/*****************************************************************************/ |
198 |
/* @Variable: MA_Partition */ |
199 |
/* @Purpose : */ |
200 |
/* Array of rtems_unsigned32 */ |
201 |
/* MCMD area patition. */ |
202 |
/* @@ */ |
203 |
/*****************************************************************************/ |
204 |
static rtems_unsigned32 MA_Partition [TOTAL_MCMD_PART]; |
205 |
|
206 |
|
207 |
|
208 |
|
209 |
/* for debugging : */ |
210 |
|
211 |
#ifdef DEBUG |
212 |
#define OS_MAX_PARTITIONS_STORE 1024 |
213 |
static BYTE *max_partitions_store [OS_MAX_PARTITIONS_STORE]; |
214 |
#endif |
215 |
|
216 |
/*****************************************************************************/ |
217 |
|
218 |
/*============ R T E M S P R O V I D E D I N T E R F A C E =============*/ |
219 |
|
220 |
/*****************************************************************************/ |
221 |
/* @Function: OS_piInitOS */ |
222 |
/* @Purpose : */ |
223 |
/* Initialization of the Operating System global resources. */ |
224 |
/* All Task, mailboxes, semaphores, partitons, timers are created and */ |
225 |
/* allocated. RTEMS directives are called for resources creation. */ |
226 |
/* */ |
227 |
/* @@ */ |
228 |
/* @Parameter Name @Mode @Description */ |
229 |
/* IN */ |
230 |
/* status_code OUT Return code */ |
231 |
/* @@ */ |
232 |
/*****************************************************************************/ |
233 |
|
234 |
|
235 |
status_code OS_piInitOS(void) |
236 |
{ |
237 |
rtems_status_code status; |
238 |
rtems_time_of_day time; |
239 |
rtems_unsigned32 tmpPart; |
240 |
unsigned long statusRc; |
241 |
unsigned int i; |
242 |
unsigned char c; |
243 |
|
244 |
status =SUCCESSFUL; |
245 |
statusRc =SUCCESSFUL; |
246 |
|
247 |
/*===========================================================================*/ |
248 |
/*==== TASKS CREATION ========================*/ |
249 |
for (i=1,c='A'; i<MAX_TASK; i++,c++) |
250 |
{ |
251 |
Task_name[i] =rtems_build_name( 'T', 'A', c, ' ' ); |
252 |
status =rtems_task_create(Task_name[i],255, RTEMS_MINIMUM_STACK_SIZE, |
253 |
RTEMS_DEFAULT_MODES,RTEMS_DEFAULT_ATTRIBUTES, |
254 |
&Task_id[i]); |
255 |
if (status!=SUCCESSFUL) |
256 |
{ |
257 |
/* Error during task resource creation, log in history area */ |
258 |
// LOG_INFN HA_piLogHistoryEntry10(HA_E10_SW_OS,HA_E10_TSK_CREATION_ERR,status); |
259 |
/*@LOG Error in task creation - status */ |
260 |
LU_INFN_LOG(LU_FATAL,LU_MASK(__FILEID__),__FILEID__,__LINE__,status); |
261 |
statusRc =HA_E2_INTERNAL_ERR; |
262 |
}else |
263 |
LU_TRACE_LOAD_TASK_INFO(i+1000,Task_id[i]); |
264 |
|
265 |
} |
266 |
|
267 |
/*===========================================================================*/ |
268 |
/*==== TASKS MAILBOXES CREATION ===================*/ |
269 |
for (i=1,c='A'; i<MAX_MBOX_1; i++,c++) |
270 |
{ |
271 |
|
272 |
Msg_name[i] = rtems_build_name( 'M', 'A', c, ' ' ); |
273 |
status =rtems_message_queue_create(Msg_name[i], MAX_MSG_FOR_MBOX_1, |
274 |
MAX_MSG_MBOX_SIZE_1, RTEMS_PRIORITY, |
275 |
&Msg_id[i]); |
276 |
if (status!=SUCCESSFUL) |
277 |
{ |
278 |
/* Error during task mailbox resource creation, log in history area */ |
279 |
// LOG_INFN HA_piLogHistoryEntry10(HA_E10_SW_OS,HA_E10_MBOX_CREATION_ERR,status); |
280 |
/*@LOG Error during mailbox creation - status */ |
281 |
LU_INFN_LOG(LU_FATAL,LU_MASK(__FILEID__),__FILEID__,__LINE__,status); |
282 |
statusRc =HA_E2_INTERNAL_ERR; |
283 |
} |
284 |
} |
285 |
/*==== GENEREIC MAILBOXES CREATION ================*/ |
286 |
for ( ; i<MAX_MBOX; i++,c++) |
287 |
{ |
288 |
|
289 |
Msg_name[i] = rtems_build_name( 'M', 'A', c, ' ' ); |
290 |
status =rtems_message_queue_create(Msg_name[i], MAX_MSG_FOR_MBOX_2, |
291 |
MAX_MSG_MBOX_SIZE_2, RTEMS_PRIORITY, |
292 |
&Msg_id[i]); |
293 |
if (status!=SUCCESSFUL) |
294 |
{ |
295 |
/* Error during mailbox resource creation, log in history area */ |
296 |
// LOG_INFN HA_piLogHistoryEntry10(HA_E10_SW_OS,HA_E10_MBOX_CREATION_ERR,status); |
297 |
/*@LOG Error during generic mailbox creation - status */ |
298 |
LU_INFN_LOG(LU_FATAL|LU_HA,LU_MASK(__FILEID__),__FILEID__,__LINE__,status); |
299 |
statusRc =HA_E2_INTERNAL_ERR; |
300 |
} |
301 |
} |
302 |
|
303 |
|
304 |
/*===========================================================================*/ |
305 |
/*==== SEMAPHORES CREATION ========================*/ |
306 |
for (i=1,c='A'; i<MAX_RES; i++,c++) |
307 |
{ |
308 |
Sem_name[i] =rtems_build_name( 'S', 'A', c, ' ' ); |
309 |
/* |
310 |
status =rtems_semaphore_create(Sem_name[i], 1, |
311 |
RTEMS_FIFO | RTEMS_INHERIT_PRIORITY | RTEMS_BINARY_SEMAPHORE | RTEMS_LOCAL , |
312 |
RTEMS_NO_PRIORITY_CEILING,&Sem_id[i]); |
313 |
*/ |
314 |
status =rtems_semaphore_create(Sem_name[i], 1,RTEMS_DEFAULT_ATTRIBUTES, |
315 |
RTEMS_NO_PRIORITY_CEILING,&Sem_id[i]); |
316 |
|
317 |
if (status!=SUCCESSFUL) |
318 |
{ |
319 |
/* Error during semaphore resource creation, log in history area */ |
320 |
// LOG_INFN HA_piLogHistoryEntry10(HA_E10_SW_OS,HA_E10_SEM_CREATION_ERR,status); |
321 |
/*@LOG Error during semaphore creation - status */ |
322 |
LU_INFN_LOG(LU_FATAL|LU_HA,LU_MASK(__FILEID__),__FILEID__,__LINE__,status); |
323 |
statusRc =HA_E2_INTERNAL_ERR; |
324 |
} |
325 |
} |
326 |
|
327 |
/*===========================================================================*/ |
328 |
/*==== PARTITIONS CREATION ========================*/ |
329 |
for (i=1,c='A'; i<MAX_PART; i++,c++) |
330 |
{ |
331 |
Part_name[i] =rtems_build_name( 'P', 'A', c, ' ' ); |
332 |
} |
333 |
|
334 |
for (i=0 ; i < TOTAL_MCMD_PART; i++) |
335 |
MA_Partition[i] =0; |
336 |
|
337 |
/* MCMD partion creation */ |
338 |
tmpPart =(rtems_unsigned32)(&MA_Partition[START_MA_PART_IM]); |
339 |
tmpPart &= 0xfffffff0; |
340 |
status =rtems_partition_create(Part_name[MA_PART_IM],(rtems_unsigned32*)tmpPart, |
341 |
MAX_MCMD_SIZE_IM << 2, |
342 |
MAX_MCMD_LEN_IM << 2, |
343 |
RTEMS_LOCAL,&Part_id[MA_PART_IM]); |
344 |
if (status!=SUCCESSFUL) |
345 |
{ |
346 |
/* Error during partition resource creation, log in history area */ |
347 |
// LOG_INFN HA_piLogHistoryEntry10(HA_E10_SW_OS,HA_E10_PAR_CREATION_ERR,status); |
348 |
/*@LOG error in partition creation - status */ |
349 |
LU_INFN_LOG(LU_FATAL|LU_HA ,LU_MASK(__FILEID__),__FILEID__,__LINE__,status); |
350 |
statusRc =HA_E2_INTERNAL_ERR; |
351 |
} |
352 |
|
353 |
/* MCMD timetag table partion creation */ |
354 |
tmpPart =(rtems_unsigned32)(&MA_Partition[START_MA_PART_TT]); |
355 |
tmpPart &= 0xfffffff0; |
356 |
status =rtems_partition_create(Part_name[MA_PART_TT],(rtems_unsigned32*)tmpPart, |
357 |
MAX_MCMD_SIZE_TT << 2, |
358 |
MAX_MCMD_LEN_TT << 2, |
359 |
RTEMS_LOCAL,&Part_id[MA_PART_TT]); |
360 |
if (status!=SUCCESSFUL) |
361 |
{ |
362 |
/* Error during partition resource creation, log in history area */ |
363 |
// LOG_INFN HA_piLogHistoryEntry10(HA_E10_SW_OS,HA_E10_PAR_CREATION_ERR,status); |
364 |
/*@LOG error in partition creation - status */ |
365 |
LU_INFN_LOG(LU_FATAL|LU_HA ,LU_MASK(__FILEID__),__FILEID__,__LINE__,status); |
366 |
statusRc =HA_E2_INTERNAL_ERR; |
367 |
} |
368 |
|
369 |
/*===========================================================================*/ |
370 |
/*==== TIMERS CREATION ========================*/ |
371 |
for (i=1,c='A'; i<MAX_TIM; i++,c++) |
372 |
{ |
373 |
Tim_name[i] = rtems_build_name( 'T', 'A', c, ' ' ); |
374 |
status =rtems_timer_create(Tim_name[i], &Tim_id[i]); |
375 |
if (status!=SUCCESSFUL) |
376 |
{ |
377 |
/* Error during timer resource creation, log in history area */ |
378 |
// LOG_INFN HA_piLogHistoryEntry10(HA_E10_SW_OS,HA_E10_TIM_CREATION_ERR,status); |
379 |
/*@LOG error in timer creation - status */ |
380 |
LU_INFN_LOG(LU_FATAL|LU_HA,LU_MASK(__FILEID__),__FILEID__,__LINE__,status); |
381 |
statusRc =HA_E2_INTERNAL_ERR; |
382 |
} |
383 |
} |
384 |
|
385 |
/*===========================================================================*/ |
386 |
|
387 |
#ifdef DEBUG |
388 |
for (i=0;i<OS_MAX_PARTITIONS_STORE;i++) |
389 |
max_partitions_store[i]=NULL; |
390 |
#endif |
391 |
|
392 |
return (statusRc); |
393 |
|
394 |
} |
395 |
|
396 |
|
397 |
/*****************************************************************************/ |
398 |
/* @Function: OS_piTaskReady */ |
399 |
/* @Purpose : */ |
400 |
/* The function readies the task specified (Task param.). The starting */ |
401 |
/* address of the task is given Entry parameter. */ |
402 |
/* The RTEMS directive is called to performs the start task. */ |
403 |
/* */ |
404 |
/* @@ */ |
405 |
/* @Parameter Name @Mode @Description */ |
406 |
/* Task IN Task ID */ |
407 |
/* Entry IN Function entry point */ |
408 |
/* status_code OUT Return code (RTEMS directive status code) */ |
409 |
/* @@ */ |
410 |
/*****************************************************************************/ |
411 |
|
412 |
status_code OS_piTaskReady ( unsigned int Task, |
413 |
void* Entry) |
414 |
{ |
415 |
rtems_status_code status; |
416 |
|
417 |
/* Check Task ID validity */ |
418 |
if(Task < MAX_TASK) |
419 |
{ |
420 |
/* Start task */ |
421 |
status =rtems_task_start(Task_id[Task],(rtems_task_entry)Entry,Task); |
422 |
} |
423 |
else |
424 |
{ |
425 |
status =RTEMS_INVALID_ID; |
426 |
} |
427 |
return (status); |
428 |
} |
429 |
|
430 |
|
431 |
|
432 |
/*****************************************************************************/ |
433 |
/* @Function: OS_piTaskPriority */ |
434 |
/* @Purpose : */ |
435 |
/* The function manipulates the task priority. The parameters -Task- and */ |
436 |
/* and -NewPriority_ identifies respectively the task ID and the new */ |
437 |
/* priority. The RTEMS directive is called to performs priority setting. */ |
438 |
/* */ |
439 |
/* @@ */ |
440 |
/* @Parameter Name @Mode @Description */ |
441 |
/* Task IN Task ID */ |
442 |
/* NewPriority IN Priority value */ |
443 |
/* status_code OUT Return code (RTEMS directive status code) */ |
444 |
/* OldPriority OUT Current priority */ |
445 |
/* @@ */ |
446 |
/*****************************************************************************/ |
447 |
|
448 |
status_code OS_piTaskPriority ( unsigned int Task, |
449 |
unsigned int NewPriority, |
450 |
unsigned int* OldPriority) |
451 |
{ |
452 |
rtems_status_code status; |
453 |
|
454 |
/* Check Task ID validity and Priority parameters range */ |
455 |
if(Task<MAX_TASK && NewPriority<MAX_PRIORITY_RANGE) |
456 |
{ |
457 |
/* Call RTEMS directive for priority setting */ |
458 |
status =rtems_task_set_priority(Task_id[Task],NewPriority, |
459 |
(rtems_task_priority*)OldPriority); |
460 |
} |
461 |
else |
462 |
{ |
463 |
status =RTEMS_INVALID_ID; |
464 |
} |
465 |
return (status); |
466 |
} |
467 |
|
468 |
|
469 |
|
470 |
/*****************************************************************************/ |
471 |
/* @Function: OS_piTaskSuspend */ |
472 |
/* @Purpose : */ |
473 |
/* The function suspends the current active task from further execution */ |
474 |
/* by placing it in the suspend state for a number of system ticks specified */ |
475 |
/* into the Ticks parameter. */ |
476 |
/* */ |
477 |
/* @@ */ |
478 |
/* @Parameter Name @Mode @Description */ |
479 |
/* Ticks IN System ticks */ |
480 |
/* status_code OUT Return code (RTEMS directive status code) */ |
481 |
/* @@ */ |
482 |
/*****************************************************************************/ |
483 |
|
484 |
status_code OS_piTaskSuspend (unsigned int Ticks ) |
485 |
{ |
486 |
rtems_status_code status; |
487 |
|
488 |
/* Put task in wait state */ |
489 |
status =rtems_task_wake_after(Ticks); |
490 |
return (SUCCESSFUL); |
491 |
} |
492 |
|
493 |
|
494 |
|
495 |
/*****************************************************************************/ |
496 |
/* @Function: OS_piTaskDelete */ |
497 |
/* @Purpose : */ |
498 |
/* The function deletes the task specified (Task param.). */ |
499 |
/* The RTEMS directive is called to performs task delete */ |
500 |
/* */ |
501 |
/* @@ */ |
502 |
/* @Parameter Name @Mode @Description */ |
503 |
/* Task IN Task ID */ |
504 |
/* status_code OUT Return code (RTEMS directive status code) */ |
505 |
/* @@ */ |
506 |
/*****************************************************************************/ |
507 |
|
508 |
status_code OS_piTaskDelete ( unsigned int Task) |
509 |
{ |
510 |
rtems_status_code status; |
511 |
|
512 |
/* Check Task ID validity */ |
513 |
if(Task < MAX_TASK) |
514 |
{ |
515 |
/* RTEMS directive for task delete */ |
516 |
status =rtems_task_delete(Task); |
517 |
} |
518 |
else |
519 |
{ |
520 |
status =RTEMS_INVALID_ID; |
521 |
} |
522 |
|
523 |
return (status); |
524 |
|
525 |
} |
526 |
|
527 |
|
528 |
|
529 |
/*****************************************************************************/ |
530 |
/* @Function: OS_piMsgQueueSend */ |
531 |
/* @Purpose : */ |
532 |
/* The function interface performs the send masssge to a mail box queue */ |
533 |
/* addressed. */ |
534 |
/* The RTEMS directive is called to performs the mailbox send message. */ |
535 |
/* */ |
536 |
/* @@ */ |
537 |
/* @Parameter Name @Mode @Description */ |
538 |
/* mBox IN Mailbox ID */ |
539 |
/* MsgToSend IN Poniter to message information */ |
540 |
/* MsgLenght IN Message lenght */ |
541 |
/* status_code OUT Return code (RTEMS directive status code) */ |
542 |
/* @@ */ |
543 |
/*****************************************************************************/ |
544 |
|
545 |
status_code OS_piMsgQueueSend(unsigned int mBox, |
546 |
void* MsgToSend, |
547 |
unsigned int MsgLenght) |
548 |
{ |
549 |
rtems_status_code status; |
550 |
|
551 |
/* Check Mailbox queue address validity */ |
552 |
if(mBox < MAX_MBOX) |
553 |
{ |
554 |
/* RTEMS directive to send message to mailbox */ |
555 |
status =rtems_message_queue_send(Msg_id[mBox],MsgToSend, |
556 |
(rtems_unsigned32)MsgLenght); |
557 |
} |
558 |
else |
559 |
{ |
560 |
status =RTEMS_INVALID_ID; |
561 |
} |
562 |
return (status); |
563 |
|
564 |
} |
565 |
|
566 |
|
567 |
|
568 |
/*****************************************************************************/ |
569 |
/* @Function: OS_piMsgQueueReceive */ |
570 |
/* @Purpose : */ |
571 |
/* The function receives a message from the message queue specified in mBox */ |
572 |
/* parameter. The WAIT and NO_WAIT options of the -OptionSet- parameter */ |
573 |
/* allow the calling task to specify whether to wait for a message to become*/ |
574 |
/* available o return immediately. The -Timeout- parameter specifies the */ |
575 |
/* timeout value for WAIT option. If NO_TIMEOUT value is set the calling */ |
576 |
/* task wait forever. */ |
577 |
/* The RTEMS directive is called to performs the receive message. */ |
578 |
/* */ |
579 |
/* @@ */ |
580 |
/* @Parameter Name @Mode @Description */ |
581 |
/* mBox IN Mailbox ID */ |
582 |
/* OptionSet IN WAITt and NO_WAIT option */ |
583 |
/* Timeout IN Timeout value for Wait option */ |
584 |
/* status_code OUT Return code (RTEMS directive status code) */ |
585 |
/* MsgToRx OUT Buffer pointer where message is returned */ |
586 |
/* MsgSize OUT Size pointer where message size is returned */ |
587 |
/* @@ */ |
588 |
/*****************************************************************************/ |
589 |
|
590 |
status_code OS_piMsgQueueReceive ( unsigned int mBox, |
591 |
void* MsgToRx, |
592 |
unsigned int* MsgSize, |
593 |
unsigned int OptionSet, |
594 |
unsigned int Timeout) |
595 |
{ |
596 |
rtems_status_code status; |
597 |
|
598 |
/* Check Mailbox queue address validity */ |
599 |
if(mBox < MAX_MBOX) |
600 |
{ |
601 |
/* RTEMS directive to receive message from the message queue */ |
602 |
status =rtems_message_queue_receive(Msg_id[mBox],MsgToRx, |
603 |
(rtems_unsigned32 *)MsgSize, |
604 |
OptionSet,Timeout); |
605 |
} |
606 |
else |
607 |
{ |
608 |
status =RTEMS_INVALID_ID; |
609 |
} |
610 |
return (status); |
611 |
|
612 |
} |
613 |
|
614 |
|
615 |
|
616 |
/*****************************************************************************/ |
617 |
/* @Function: OS_piPartGetBuffer */ |
618 |
/* @Purpose : */ |
619 |
/* The function allows a buffer to be obtained from the partition specified */ |
620 |
/* in -Part- parameter. */ |
621 |
/* The RTEMS directive is called to performs the get buffer from a */ |
622 |
/* partition. */ |
623 |
/* */ |
624 |
/* @@ */ |
625 |
/* @Parameter Name @Mode @Description */ |
626 |
/* Part IN Partition ID */ |
627 |
/* status_code OUT Return code (RTEMS directive status code) */ |
628 |
/* pBuf OUT Partition buffer pointer returned */ |
629 |
/* @@ */ |
630 |
/*****************************************************************************/ |
631 |
|
632 |
status_code OS_piPartGetBuffer ( unsigned int Part, |
633 |
void** pBuf) |
634 |
{ |
635 |
rtems_status_code status; |
636 |
|
637 |
/* Check partition ID validity */ |
638 |
if(Part < MAX_PART) |
639 |
{ |
640 |
switch (Part) |
641 |
{ |
642 |
case MA_TAB_PART : |
643 |
/* MCMD timetag list partition */ |
644 |
*pBuf =&MA_Partition[0]; |
645 |
status =SUCCESSFUL; |
646 |
break; |
647 |
case MA_PART_IM : |
648 |
case MA_PART_TT : |
649 |
/* MCMD timetag partition */ |
650 |
status =rtems_partition_get_buffer(Part_id[Part],pBuf); |
651 |
#ifdef DEBUG |
652 |
// if(status==RTEMS_SUCCESSFUL) { |
653 |
// for (i=0;i<OS_MAX_PARTITIONS_STORE && max_partitions_stored;i++) |
654 |
#endif |
655 |
|
656 |
|
657 |
break; |
658 |
default: |
659 |
status =RTEMS_INVALID_ID; |
660 |
break; |
661 |
} |
662 |
|
663 |
} |
664 |
else |
665 |
{ |
666 |
status =RTEMS_INVALID_ID; |
667 |
} |
668 |
return (status); |
669 |
} |
670 |
|
671 |
|
672 |
|
673 |
/*****************************************************************************/ |
674 |
/* @Function: OS_piPartReturnBuffer */ |
675 |
/* @Purpose : */ |
676 |
/* The function returns the buffer specified to the partition. */ |
677 |
/* The RTEMS directive is called to performs the return buffer to a */ |
678 |
/* partition. */ |
679 |
/* */ |
680 |
/* @@ */ |
681 |
/* @Parameter Name @Mode @Description */ |
682 |
/* Part IN Partition ID */ |
683 |
/* pBuf IN Partition buffer pointer released */ |
684 |
/* status_code OUT Return code (RTEMS directive status code) */ |
685 |
/* @@ */ |
686 |
/*****************************************************************************/ |
687 |
|
688 |
status_code OS_piPartReturnBuffer ( unsigned int Part, |
689 |
void* pBuf) |
690 |
{ |
691 |
rtems_status_code status; |
692 |
|
693 |
/* Check partition ID validity */ |
694 |
if(Part < MAX_PART) |
695 |
{ |
696 |
switch (Part) |
697 |
{ |
698 |
case MA_TAB_PART : |
699 |
break; |
700 |
case MA_PART_IM : |
701 |
case MA_PART_TT : |
702 |
/* MCMD timetag partition */ |
703 |
status =rtems_partition_return_buffer(Part_id[Part],pBuf); |
704 |
break; |
705 |
default: |
706 |
status =RTEMS_INVALID_ID; |
707 |
break; |
708 |
} |
709 |
} |
710 |
else |
711 |
{ |
712 |
status =RTEMS_INVALID_ID; |
713 |
} |
714 |
return (status); |
715 |
|
716 |
} |
717 |
|
718 |
|
719 |
|
720 |
/*****************************************************************************/ |
721 |
/* @Function: OS_piResourceObtain */ |
722 |
/* @Purpose : */ |
723 |
/* The function acquires the semaphore specified in the -Res- parameter. */ |
724 |
/* The WAIT and NO_WAIT options of the -OptionSet- parameter allow */ |
725 |
/* the calling task to specify whether to wait for a message to become */ |
726 |
/* available o return immediately. The -Timeout- parameter specifies the */ |
727 |
/* timeout value for WAIT option. If NO_TIMEOUT value is set the calling */ |
728 |
/* task wait forever. */ |
729 |
/* The RTEMS directive is called to performs the semaphore acquisition. */ |
730 |
/* */ |
731 |
/* @@ */ |
732 |
/* @Parameter Name @Mode @Description */ |
733 |
/* Res IN Semaphore ID */ |
734 |
/* OptionSet IN WAIT and NO_WAIT option */ |
735 |
/* Timeout IN Timeout value for Wait option */ |
736 |
/* status_code OUT Return code (RTEMS directive status code) */ |
737 |
/* @@ */ |
738 |
/*****************************************************************************/ |
739 |
|
740 |
status_code OS_piResourceObtain ( unsigned int Res, |
741 |
unsigned int OptionSet, |
742 |
unsigned int Timeout) |
743 |
{ |
744 |
rtems_status_code status; |
745 |
if(rtems_interrupt_is_in_progress()) { |
746 |
/*@LOG OS_piResourceObtain during interrupt. this is a bug! */ |
747 |
LU_INFN_LOG(LU_INTERNAL,LU_MASK(__FILEID__),__FILEID__,__LINE__,0xffff); |
748 |
return CM_RC_INTERRUPT_IS_IN_PROGRESS; |
749 |
} |
750 |
/* Check semaphore ID validity */ |
751 |
if(Res < MAX_RES) |
752 |
{ |
753 |
/* RTEMS directive to obtain semaphore resource */ |
754 |
status =rtems_semaphore_obtain(Sem_id[Res], OptionSet, Timeout); |
755 |
if(status) |
756 |
/*@LOG OS_piResourceObtain: error code - status */ |
757 |
LU_INFN_LOG(LU_INTERNAL|LU_HA,LU_MASK(__FILEID__),__FILEID__,__LINE__,status); |
758 |
} |
759 |
else |
760 |
{ |
761 |
status =RTEMS_INVALID_ID; |
762 |
} |
763 |
return (status); |
764 |
} |
765 |
|
766 |
|
767 |
|
768 |
/*****************************************************************************/ |
769 |
/* @Function: OS_piResourceRelease */ |
770 |
/* @Purpose : */ |
771 |
/* The function releases the semaphore specified in the -Res- parameter. */ |
772 |
/* The RTEMS directive is called to performs the semaphore release. */ |
773 |
/* */ |
774 |
/* @@ */ |
775 |
/* @Parameter Name @Mode @Description */ |
776 |
/* Res IN Semaphore ID */ |
777 |
/* status_code OUT Return code (RTEMS directive status code) */ |
778 |
/* @@ */ |
779 |
/*****************************************************************************/ |
780 |
|
781 |
status_code OS_piResourceRelease ( unsigned int Res ) |
782 |
{ |
783 |
rtems_status_code status; |
784 |
|
785 |
/* Check semaphore ID validity */ |
786 |
if(Res < MAX_RES) |
787 |
{ |
788 |
/* RTEMS directive to release semaphore resource */ |
789 |
status =rtems_semaphore_release (Sem_id[Res]); |
790 |
} |
791 |
else |
792 |
{ |
793 |
status =RTEMS_INVALID_ID; |
794 |
} |
795 |
return (status); |
796 |
|
797 |
} |
798 |
|
799 |
|
800 |
|
801 |
/*****************************************************************************/ |
802 |
/* @Function: OS_piStartTimer */ |
803 |
/* @Purpose : */ |
804 |
/* The function initiates the timer specified by -Tim- parameter. */ |
805 |
/* The timer is scheduled to fire after a time interval expressed in system */ |
806 |
/* ticks into -Time- parameter. When the timer fires, the timer service */ |
807 |
/* routine will be invoked with user data. */ |
808 |
/* The RTEMS directive is called to performs the start timer after interval.*/ |
809 |
/* */ |
810 |
/* @@ */ |
811 |
/* @Parameter Name @Mode @Description */ |
812 |
/* Tim IN Timer ID */ |
813 |
/* Time IN Interval time */ |
814 |
/* Routine IN Pointer to timer service routine */ |
815 |
/* UserData IN Pointer to user data */ |
816 |
/* status_code OUT Return code (RTEMS directive status code) */ |
817 |
/* @@ */ |
818 |
/*****************************************************************************/ |
819 |
|
820 |
status_code OS_piStartTimer ( unsigned int Tim, |
821 |
unsigned int Time, |
822 |
void* Routine, |
823 |
void* UserData) |
824 |
{ |
825 |
rtems_status_code status; |
826 |
|
827 |
/* Check timer ID validity */ |
828 |
if (Tim < MAX_TIM) |
829 |
{ |
830 |
/* RTEMS directive to start timeer */ |
831 |
status =rtems_timer_fire_after(Tim_id[Tim],Time,Routine,UserData); |
832 |
} |
833 |
else |
834 |
{ |
835 |
status =RTEMS_INVALID_ID; |
836 |
} |
837 |
return (status); |
838 |
|
839 |
} |
840 |
|
841 |
|
842 |
|
843 |
/*****************************************************************************/ |
844 |
/* @Function: OS_piCancelTimer */ |
845 |
/* @Purpose : */ |
846 |
/* The function cancels the timer specified by -Tim- parameter. */ |
847 |
/* The RTEMS directive is called to performs the timer cancelation */ |
848 |
/* */ |
849 |
/* @@ */ |
850 |
/* @Parameter Name @Mode @Description */ |
851 |
/* Tim IN Timer ID */ |
852 |
/* status_code OUT Return code (RTEMS directive status code) */ |
853 |
/* @@ */ |
854 |
/*****************************************************************************/ |
855 |
|
856 |
status_code OS_piCancelTimer ( unsigned int Tim) |
857 |
{ |
858 |
rtems_status_code status; |
859 |
|
860 |
/* Check timer ID validity */ |
861 |
if (Tim < MAX_TIM) |
862 |
{ |
863 |
/* RTEMS directive to cancel timer */ |
864 |
status =rtems_timer_cancel(Tim_id[Tim]); |
865 |
} |
866 |
else |
867 |
{ |
868 |
status =RTEMS_INVALID_ID; |
869 |
} |
870 |
return (status); |
871 |
} |
872 |
|
873 |
|
874 |
|
875 |
/*****************************************************************************/ |
876 |
/* @Function: OS_piIsrCatch */ |
877 |
/* @Purpose : */ |
878 |
/* The function establishes an interrupt service routine (ISR) fotr the */ |
879 |
/* specified interrupt vector number. */ |
880 |
/* The RTEMS directive is called to performs the establish an ISR */ |
881 |
/* */ |
882 |
/* @@ */ |
883 |
/* @Parameter Name @Mode @Description */ |
884 |
/* IsrHandler IN Pointer to ISR handler */ |
885 |
/* Vector IN Vector interrupt number */ |
886 |
/* status_code OUT Return code (RTEMS directive status code) */ |
887 |
/* OldIsrHandler OUT Previous pointer to ISR handler */ |
888 |
/* @@ */ |
889 |
/*****************************************************************************/ |
890 |
|
891 |
status_code OS_piIsrCatch ( void* IsrHandler, |
892 |
unsigned int Vector, |
893 |
void** OldIsrHandler) |
894 |
{ |
895 |
rtems_status_code status; |
896 |
|
897 |
/* RTEMS directive to establish an interrupt ISR */ |
898 |
status =rtems_interrupt_catch( (rtems_isr_entry) IsrHandler, |
899 |
(rtems_vector_number) Vector, |
900 |
(rtems_isr_entry*) &OldIsrHandler); |
901 |
return (status); |
902 |
|
903 |
} |
904 |
|
905 |
/*****************************************************************************/ |
906 |
/* @Function: OS_piInterEnable */ |
907 |
/* @Purpose : */ |
908 |
/* The function enable the interrupt specified in -Level- parameter. */ |
909 |
/* The RTEMS directive is called to performs the establish an ISR */ |
910 |
/* */ |
911 |
/* @@ */ |
912 |
/* @Parameter Name @Mode @Description */ |
913 |
/* Level IN Interrupt type */ |
914 |
/* status_code OUT Return code (RTEMS directive status code) */ |
915 |
/* @@ */ |
916 |
/*****************************************************************************/ |
917 |
|
918 |
status_code OS_piInterEnable ( unsigned int Level ) |
919 |
{ |
920 |
|
921 |
/* RTEMS directive to enable interrupt */ |
922 |
rtems_interrupt_enable(Level); |
923 |
return (RTEMS_SUCCESSFUL); |
924 |
|
925 |
} |
926 |
|
927 |
|
928 |
|
929 |
/*****************************************************************************/ |
930 |
/* @Function: OS_piInterDisable */ |
931 |
/* @Purpose : */ |
932 |
/* The function disable the interrupt specified in -Level- parameter. */ |
933 |
/* The RTEMS directive is called to performs the establish an ISR */ |
934 |
/* */ |
935 |
/* @@ */ |
936 |
/* @Parameter Name @Mode @Description */ |
937 |
/* Level IN Interrupt type */ |
938 |
/* status_code OUT Return code (RTEMS directive status code) */ |
939 |
/* @@ */ |
940 |
/*****************************************************************************/ |
941 |
|
942 |
status_code OS_piInterDisable ( unsigned int *Level) |
943 |
{ |
944 |
|
945 |
/* RTEMS directive to disable interrupt */ |
946 |
rtems_interrupt_disable(*Level); |
947 |
return (RTEMS_SUCCESSFUL); |
948 |
} |