blob: 9a37a13a698a92a91047712923d8e784f74d1887 [file] [log] [blame]
lh9ed821d2023-04-07 01:36:19 -07001/************************************************************************
2* °æÈ¨ËùÓÐ (C)2007,ÖÐÐËͨѶ¹É·ÝÓÐÏÞ¹«Ë¾¡£
3*
4* ÎļþÃû³Æ£º ms_os.h
5* Îļþ±êʶ£º
6* ÄÚÈÝÕªÒª£º External declarations of interface routines to the operation system.
7*
8* ÐÞ¸ÄÈÕÆÚ °æ±¾ºÅ Ð޸ıê¼Ç ÐÞ¸ÄÈË ÐÞ¸ÄÄÚÈÝ
9* -----------------------------------------------------------------------
10* 2008/06/27 V0.5 ¹¨Òí ´´½¨
11************************************************************************/
12
13#ifndef _MS_OS_H_
14#define _MS_OS_H_
15
16#include <stddef.h>
17#include "base_api.h"
18/*#include "ms_hwtrc.h"*/ /* Trace interface as standard out, hwtrc_print(). */
19
20#if MS_OS_CRITICAL_SECTION_SUPPORT > 0
21#include "ms_crit.h"
22#endif
23
24
25/*===========================================================================
26Exported Type Declarations
27===========================================================================*/
28
29/**B*************************************************************************
30 * Macro: OS_pid_t
31 *---------------------------------------------------------------------------
32 * Purpose: PID of an operation system process.
33 *
34 * Parameters: None.
35 *
36 * Returns: None.
37 ***E************************************************************************/
38
39#define OS_pid_t SDL_PId
40#define OS_SDL_NULL SDL_NULL
41
42
43/**B*************************************************************************
44 * Macro: OS_no_sig_params_t
45 *---------------------------------------------------------------------------
46 * Purpose: Used to allocate a signal without parameters.
47 *
48 * Parameters: None.
49 *
50 * Returns: None.
51 ***E************************************************************************/
52
53#define OS_no_sig_params_t XSIGNALHEADERTYPE
54
55
56/*===========================================================================
57Exported Macro Declarations
58===========================================================================*/
59
60/**B*************************************************************************
61 * Macro: os_mem_xalloc
62 *----------------------------------------------------------------------------
63 * Purpose: mallocs dynamic memory
64 *
65 * Parameters: size: number of bytes to be malloced
66 *
67 * Returns: pointer to first byte of memory
68 *
69 * Remarks:
70 ***E************************************************************************/
71/**B*************************************************************************
72 * Macro: os_mem_xfree
73 *----------------------------------------------------------------------------
74 * Purpose: frees dynamic memory
75 *
76 * Parameters: ptr: pointer to memory to be returned
77 *
78 * Returns: nothing
79 *
80 * Remarks:
81 ***E************************************************************************/
82
83#define os_mem_xalloc(ptr_, size_) (ptr_) = ps_malloc(size_);
84#define os_mem_xfree(ptr_) {ps_free( *((void **)&(ptr_))); *((void **)&(ptr_)) = NULL;}
85
86
87/**B*************************************************************************
88 * Macro: os_msleep
89 *---------------------------------------------------------------------------
90 * Purpose: see below os_sleep_ms
91 *
92 * Parameters: see below.
93 *
94 * Returns: see below.
95 ***E************************************************************************/
96
97#define os_msleep(millisec_) os_sleep_ms(millisec_)
98
99
100/**B*************************************************************************
101 * Macro: os_next_state
102 *---------------------------------------------------------------------------
103 * Purpose: Go back to the read entry point of the process.
104 *
105 * Parameters: None.
106 *
107 * Returns: None.
108 ***E************************************************************************/
109
110#define os_next_state(p_var_, state_) goto os_process_loop_l
111
112
113/**B*************************************************************************
114 * Macro: os_now
115 *---------------------------------------------------------------------------
116 * Purpose: Return the number of ticks since system start.
117 *
118 * Parameters: None.
119 *
120 * Returns: None.
121 ***E************************************************************************/
122
123#define os_now(sample_id) RetrieveClock(sample_id)
124
125
126
127/**B*************************************************************************
128 * Macro: os_outsig_declare
129 *---------------------------------------------------------------------------
130 * Purpose: Declaration of an output signal.
131 *
132 * Parameters: None.
133 *
134 * Returns: None.
135 ***E************************************************************************/
136
137#define os_outsig_declare xSignalHeaderRec *yOutputSignalPtr;
138
139
140/**B*************************************************************************
141 * Macro: os_outsig_get
142 *---------------------------------------------------------------------------
143 * Purpose: Get the pointer to the output signal.
144 *
145 * Parameters: None.
146 *
147 * Returns: Pointer to the output signal.
148 ***E************************************************************************/
149
150#define os_outsig_get() (void *)(yOutputSignalPtr)
151
152
153/**B*************************************************************************
154 * Macro: OS_PROCESS
155 *---------------------------------------------------------------------------
156 * Purpose: Declaration of an operating system task.
157 *
158 * Parameters: x: task name.
159 *
160 * Returns: None.
161 ***E************************************************************************/
162#ifdef OS_PROCESS
163#undef OS_PROCESS
164#endif
165#define OS_PROCESS(x) void x(UNSIGNED argc, VOID *argv)
166#define OS_PROCESS_RETURN(value_) return;
167
168
169/**B*************************************************************************
170 * Macro: os_process_begin
171 *---------------------------------------------------------------------------
172 * Purpose: Define the startup of an operting system process with
173 * input queue.
174 *
175 * Parameters: Process variables with the generic header os_process_var.
176 *
177 * Returns: None.
178 ***E************************************************************************/
179/*
180// P98C-YXS #if 0
181// P98C-YXS //#ifdef _OS_WIN
182// P98C-YXS #if defined UNITEST
183// P98C-YXS #define os_process_begin(var_, self_id_) \
184// P98C-YXS unsigned char SelfId = self_id_; \
185// P98C-YXS memset ( (void *) yVarP, 0, sizeof ( var_ ) ); \
186// P98C-YXS yVarP->Self = ( (struct args *) argv ) -> self; \
187// P98C-YXS yVarP->SelfId = (unsigned char)( ( (struct args *) argv ) -> self_id ); \
188// P98C-YXS yVarP->Offspring = SDL_NULL; \
189// P98C-YXS yVarP->SaveQ.succ = &(yVarP->SaveQ); \
190// P98C-YXS yVarP->SaveQ.pred = &(yVarP->SaveQ); \
191// P98C-YXS yVarP->CurrentInSaveQ = &(yVarP->SaveQ); \
192// P98C-YXS yVarP->yInSignalPtr = 0;
193// P98C-YXS #else
194// P98C-YXS #define os_process_begin(var_, self_id_) \
195// P98C-YXS unsigned char SelfId = self_id_; \
196// P98C-YXS (void) argc; \
197// P98C-YXS memset ( (void *) yVarP, 0, sizeof ( var_ ) ); \
198// P98C-YXS yVarP->Self = ( (struct args *) argv ) -> self; \
199// P98C-YXS yVarP->SelfId = (unsigned char)( ( (struct args *) argv ) -> self_id ); \
200// P98C-YXS yVarP->Offspring = SDL_NULL; \
201// P98C-YXS yVarP->SaveQ.succ = &(yVarP->SaveQ); \
202// P98C-YXS yVarP->SaveQ.pred = &(yVarP->SaveQ); \
203// P98C-YXS yVarP->CurrentInSaveQ = &(yVarP->SaveQ); \
204// P98C-YXS yVarP->yInSignalPtr = 0;
205// P98C-YXS #endif
206// P98C-YXS //#endif
207// P98C-YXS //#else
208// P98C-YXS #endif
209*/
210
211#if defined UNITEST
212#define os_process_begin(var_) \
213 TID SelfId; \
214 memset ( (void *) yVarP, 0, sizeof ( var_ ) ); \
215 yVarP->Self = ( (struct args *) argv ) -> self; \
216 yVarP->SelfId = (unsigned char)( ( (struct args *) argv ) -> self_id ); \
217 yVarP->Offspring = SDL_NULL; \
218 yVarP->SaveQ.succ = &(yVarP->SaveQ); \
219 yVarP->SaveQ.pred = &(yVarP->SaveQ); \
220 yVarP->CurrentInSaveQ = &(yVarP->SaveQ); \
221 yVarP->yInSignalPtr = 0;
222#else
223#define os_process_begin(var_) \
224 TID SelfId; \
225 (void) argc; \
226 memset ( (void *) yVarP, 0, sizeof ( var_ ) ); \
227 yVarP->Self = ( (struct args *) argv ) -> self; \
228 yVarP->SelfId = (unsigned char)( ( (struct args *) argv ) -> self_id ); \
229 yVarP->Offspring = SDL_NULL; \
230 yVarP->SaveQ.succ = &(yVarP->SaveQ); \
231 yVarP->SaveQ.pred = &(yVarP->SaveQ); \
232 yVarP->CurrentInSaveQ = &(yVarP->SaveQ); \
233 yVarP->yInSignalPtr = 0;
234#endif
235//#endif
236
237/**B*************************************************************************
238 * Macro: os_process_loop
239 *---------------------------------------------------------------------------
240 * Purpose: Free the consumed signal and wait for the next signal on the
241 * input queue with the blocked method.
242 *
243 * Parameters: None.
244 *
245 * Returns: None.
246 ***E************************************************************************/
247
248#define os_process_loop(var_) \
249 os_process_loop_l: \
250 os_signal_free (var_##.yInSignalPtr); \
251 var_##.yInSignalPtr = os_signal_receive (var_##.Self);
252
253
254/**B*************************************************************************
255 * Macro: os_process_vars
256 *---------------------------------------------------------------------------
257 * Purpose: Generic header of the process variables.
258 *
259 * Parameters: None.
260 *
261 * Returns: None.
262 ***E************************************************************************/
263
264#define os_process_vars PROCESS_VARS
265
266
267/**B*************************************************************************
268 * Macro: OS_PROCESS_ID
269 *---------------------------------------------------------------------------
270 * Purpose: Process Id of the current process
271 *
272 * Parameters: None.
273 *
274 * Returns: None.
275 ***E************************************************************************/
276
277#define os_current_process() (yVarP->Self)
278
279
280/**B*************************************************************************
281 * Macro: os_is_booting
282 *---------------------------------------------------------------------------
283 * Purpose: Return 1 if the OS executes the boot procedure otherwise 0.
284 *
285 * Parameters: None.
286 *
287 * Returns: None.
288 ***E************************************************************************/
289
290extern SINT32 nu_is_booting(VOID);
291#define os_is_booting() nu_is_booting()
292
293
294/**B*************************************************************************
295 * Macro: os_sem_t
296 *---------------------------------------------------------------------------
297 * Purpose: Semaphore data type
298 *
299 * Parameters: None.
300 *
301 * Returns: None.
302 ***E************************************************************************/
303
304typedef NU_SEMAPHORE os_sem_t;
305
306
307/**B*************************************************************************
308 * Macro: os_sem_p
309 *---------------------------------------------------------------------------
310 * Purpose: Semaphore pointer declaration
311 *
312 * Parameters: None.
313 *
314 * Returns: None.
315 ***E************************************************************************/
316
317typedef NU_SEMAPHORE *os_sem_p;
318
319
320/**B*************************************************************************
321 * Macro: os_protect_t
322 *---------------------------------------------------------------------------
323 * Purpose: Semaphore data type
324 * This can oly be used in HISR context for Tasks use
325 * os_sem_t
326 *
327 * Parameters: None.
328 *
329 * Returns: None.
330 ***E************************************************************************/
331
332typedef NU_PROTECT os_protect_t;
333
334
335/**B*************************************************************************
336 * Macro: os_sem_addr
337 *---------------------------------------------------------------------------
338 * Purpose: Address of a semaphore
339 *
340 * Parameters: None.
341 *
342 * Returns: None.
343 ***E************************************************************************/
344
345#define os_sem_addr(sem_) &sem_
346
347
348/**B*************************************************************************
349 * Macros: OS_SEM_[TYPE]
350 *---------------------------------------------------------------------------
351 * Purpose: Define several styles of semaphores
352 * order of pending task execution.
353 * semaphore obtainer task acceleration
354 * task preemption deactivation
355 *
356 * Parameters: None.
357 *
358 * Returns: None.
359 ***E************************************************************************/
360
361#define OS_SEM_FIFO 1
362#define OS_SEM_PRIORITY 2
363#define OS_SEM_CUSTOM_TYPES 3
364#define OS_SEM_CRIT_SECT OS_SEM_CUSTOM_TYPES
365#define OS_SEM_NO_PREEMPT (OS_SEM_CUSTOM_TYPES+1)
366#define OS_SEM_IRQ_LOCK (OS_SEM_CUSTOM_TYPES+2)
367#define OS_SEM_CRIT_SECT_SIMPLE (OS_SEM_CUSTOM_TYPES+3)
368#define OS_SEM_CS_DEFAULT OS_SEM_CRIT_SECT
369
370
371/**B*************************************************************************
372 * Macro: os_sem_create, os_ssem_create, os_protect_create
373 *---------------------------------------------------------------------------
374 * Purpose: Create a (static) semaphore and define the initial state. 1 means
375 * do not block after the first call, otherwise use 0.
376 *
377 * Parameters: sem_: Pointer to the semaphore.
378 * name_pref_: Prefix of the semaphore's name.
379 * name_no_: Postfix of the name to make the name unique.
380 * initial_count_: Initial semaphore count.
381 *
382 * Returns: None.
383 ***E************************************************************************/
384
385#define os_ssem_create os_sem_create
386#define os_protect_create(sem_, name_pref_, name_no_, initial_count_)
387
388#if MS_OS_CRITICAL_SECTION_SUPPORT > 0
389extern VOID os_sem_create_t_func(NU_SEMAPHORE *sem_p, CHAR const*name_pref,
390 SINT32 name_no, SINT32 initial_count_, SINT32 sema_style);
391
392#define os_sem_create_t(sem_, name_pref_, name_no_, initial_count_, sema_style) \
393os_sem_create_t_func(&(sem_), name_pref_, name_no_, initial_count_, sema_style)
394
395#define os_sem_create(sem_, name_pref_, name_no_, initial_count_) \
396 os_sem_create_t(sem_, name_pref_, name_no_, initial_count_, OS_SEM_FIFO)
397
398#else
399
400#define os_sem_create(sem_, name_pref_, name_no_, initial_count_) \
401do { \
402 UINT32 status; \
403 status = NU_Create_Semaphore( &(sem_), name_pref_, (initial_count_), NU_FIFO); \
404 if (status != ZOSS_SUCCESS) \
405 zOss_ASSERT(0); \
406} while (0)
407
408
409#endif
410
411
412/**B*************************************************************************
413 * Macro: os_sem_reset
414 *---------------------------------------------------------------------------
415 * Purpose: Set the semaphore counter to the initial value.
416 *
417 * Parameters: sem_: Pointer to the semaphore.
418 *
419 * Returns: None.
420 ***E************************************************************************/
421
422#define os_sem_reset(sem_) \
423do { \
424 STATUS status = NU_Reset_Semaphore ( &(sem_), 0 ); \
425 if (status != NU_SUCCESS) \
426 zOss_ASSERT(0); \
427} while (0)
428
429
430/**B*************************************************************************
431 * Macro: os_sem_signal, os_protect
432 *---------------------------------------------------------------------------
433 * Purpose: Releases a previously obtained semaphore. If one or
434 * more tasks are waiting, the first task is given the released
435 * instance of the semaphore. Otherwise, the semaphore instance
436 * counter is simply incremented.
437 *
438 * Parameters: sem_: Pointer to the semaphore.
439 *
440 * Returns: None.
441 ***E************************************************************************/
442
443#define os_protect(sem_)
444
445#if MS_OS_CRITICAL_SECTION_SUPPORT > 0
446
447extern VOID os_sem_signal_func(NU_SEMAPHORE *sem_p);
448#define os_sem_signal(sem_) \
449os_sem_signal_func(&(sem_))
450
451#else
452
453#define os_sem_signal(sem_) \
454do { \
455 UINT32 status = NU_Release_Semaphore(&(sem_)); \
456 if (status != ZOSS_SUCCESS) \
457 zOss_ASSERT(0); \
458} while (0)
459
460#endif
461
462
463/**B*************************************************************************
464 * Macro: os_sem_wait, os_unprotect
465 *---------------------------------------------------------------------------
466 * Purpose: Decrement the semphore counter by 1. If the counter is
467 * greater than zero at the time of this call, this function can
468 * be completed immediately, otherwise suspension.
469 *
470 * Parameters: sem_: Pointer to the semaphore.
471 *
472 * Returns: None.
473 ***E************************************************************************/
474
475
476#define os_unprotect(sem_)
477
478#if MS_OS_CRITICAL_SECTION_SUPPORT > 0
479
480extern VOID os_sem_wait_func (NU_SEMAPHORE *sem_p);
481#define os_sem_wait(sem_) os_sem_wait_func(&(sem_))
482
483#else
484#define os_sem_wait(sem_) \
485do { \
486 UINT32 status = NU_Obtain_Semaphore ( &(sem_), NU_SUSPEND ); \
487 if (status != ZOSS_SUCCESS) \
488 zOss_ASSERT(0); \
489} while (0)
490#endif
491
492
493/**B*************************************************************************
494 * Macro: os_sem_kill, os_ssem_kill, os_protect_kill
495
496 *---------------------------------------------------------------------------
497 * Purpose: Destroy a (static) semphore.
498 *
499 * Parameters: sem_: Pointer to the semaphore.
500 *
501 * Returns: None.
502 ***E************************************************************************/
503
504#define os_protect_kill
505#define os_ssem_kill os_sem_kill
506
507
508#if MS_OS_CRITICAL_SECTION_SUPPORT > 0
509
510extern VOID os_sem_kill_func(NU_SEMAPHORE *sem_p);
511
512#define os_sem_kill(sem_) \
513os_sem_kill_func(&(sem_))
514
515#else
516#define os_sem_kill(sem_) \
517do { \
518 STATUS status = NU_Delete_Semaphore ( &(sem_) ); \
519 if (status != NU_SUCCESS) \
520 zOss_ASSERT(0); \
521} while (0)
522#endif
523
524
525
526/**B*************************************************************************
527 * Macro: os_signal_t
528 *---------------------------------------------------------------------------
529 * Purpose: Generic part of an I/O signal.
530 *
531 * Parameters: None.
532 *
533 * Returns: None.
534 ***E************************************************************************/
535
536typedef xSignalHeaderRec os_signal_t;
537
538
539/**B*************************************************************************
540 * Macro: os_print
541 *---------------------------------------------------------------------------
542 * Purpose: Prints strings to the trace output.
543 *
544 * Parameters: str_: String to be printed.
545 *
546 * Returns: None
547 ***E************************************************************************/
548#if 0
549#define os_print(str_) hwtrc_print (str_)
550#define os_task_info(state_, self_id_, sig_cod_, msg_, len_) \
551 hwtrc_task_info(state_, self_id_, sig_cod_, msg_, len_)
552
553
554/**B*************************************************************************
555 * Macro: os_nprint
556 *---------------------------------------------------------------------------
557 * Purpose: Prints the first n chars of a string to the trace output.
558 *
559 * Parameters: str_: string
560 * n_: number of chars in str_
561 *
562 * Returns: None
563 ***E************************************************************************/
564
565#define os_nprint(str_, n_) hwtrc_write (str_, n_)
566
567
568/**B*************************************************************************
569 * Macro: os_write
570 *---------------------------------------------------------------------------
571 * Purpose: Send n bytes to the trace output.
572 *
573 * Parameters: buf_: char sequence
574 * n_: number of chars in buf_
575 *
576 * Returns: None
577 ***E************************************************************************/
578
579#define os_write(buf_, n_) hwtrc_write (buf_, n_)
580#endif
581
582/**B*************************************************************************
583 * Macro: os_signal_alloc
584 *---------------------------------------------------------------------------
585 * Purpose: Allocation of a message buffer for a signal from the
586 * specified partition pool.
587 *
588 * Parameters: signal_id_: Corresponding ID (process index + message id)
589 * to the message type.
590 * signal_type_: Message type used to allocate a message buffer.
591 *
592 * Returns: Pointer to the allocated message buffer.
593 ***E************************************************************************/
594
595#define os_signal_alloc(signal_id_, signal_type_) \
596 { xSignalHeader yOutputSignalPtr = \
597 alloc_sig( sizeof (signal_type_) ); \
598 yOutputSignalPtr->Sender = 0; \
599 yOutputSignalPtr->SignalCode = (signal_id_);
600
601
602/**B*************************************************************************
603 * Macro: os_signal_alloc_from
604 *---------------------------------------------------------------------------
605 * Purpose: Allocation of a message buffer for a signal from the
606 * specified partition pool.
607 *
608 * Parameters: sender_pid_: Used to send back signals.
609 * signal_id_: Corresponding ID (process index + message id)
610 * to the message type.
611 * signal_type_: Message type used to allocate a message buffer.
612 *
613 * Returns: Pointer to the allocated message buffer.
614 ***E************************************************************************/
615
616#define os_signal_alloc_from(sender_pid_, signal_id_, signal_type_) \
617 { xSignalHeader yOutputSignalPtr = \
618 alloc_sig( sizeof (signal_type_) ); \
619 yOutputSignalPtr->Sender = (sender_pid_); \
620 yOutputSignalPtr->SignalCode = (signal_id_);
621
622
623/**B*************************************************************************
624 * Macro: os_signal_alloc_from_to
625 *---------------------------------------------------------------------------
626 * Purpose: Allocation of a message buffer for a signal from the
627 * specified partition pool with generic receiver.
628 *
629 * Parameters: signal_id_: Corresponding ID (process index + message id)
630 * to the message type.
631 * signal_type_: Message type used to allocate a message buffer.
632 * receiver_: PID of the receiver process.*
633 *
634 * Returns: Pointer to the allocated message buffer.
635 ***E************************************************************************/
636
637#define os_signal_alloc_from_to(sender_pid_, receiver_, signal_id_, signal_type_) \
638 yOutputSignalPtr = \
639 alloc_sig(sizeof(signal_type_)); \
640 yOutputSignalPtr->Sender = (sender_pid_); \
641 yOutputSignalPtr->SignalCode = (signal_id_);
642
643
644/**B*************************************************************************
645 * Macro: os_signal_alloc_to
646 *---------------------------------------------------------------------------
647 * Purpose: Allocation of a message buffer for a signal from the
648 * specified partition pool with generic receiver.
649 *
650 * Parameters: signal_id_: Corresponding ID (process index + message id)
651 * to the message type.
652 * signal_type_: Message type used to allocate a message buffer.
653 * receiver_: PID of the receiver process.*
654 *
655 * Returns: Pointer to the allocated message buffer.
656 ***E************************************************************************/
657
658#define os_signal_alloc_to(receiver_, signal_id_, signal_type_) \
659 yOutputSignalPtr = \
660 alloc_sig(sizeof(signal_type_)); \
661 yOutputSignalPtr->SignalCode = (signal_id_);
662
663
664/**B*************************************************************************
665 * Macro: os_signal_paramassign
666 *---------------------------------------------------------------------------
667 * Purpose: Set a scalar paramter value.
668 *
669 * Parameters: sig_: Pointer to the signal header.
670 *
671 * param_no_: Number of the parameter to be set.
672 *
673 * value_: Source value.
674 *
675 * Returns: None
676 ***E************************************************************************/
677
678#define os_signal_paramassign(sig_, param_no_, value_) \
679 ((yPDef_##sig_ *) OUTSIGNAL_DATA_PTR)->Param##param_no_ = (value_)
680
681
682/**B*************************************************************************
683 * Macro: os_signal_paramcopy
684 *---------------------------------------------------------------------------
685 * Purpose: Copies parameter values into a signal message buffer.
686 *
687 * Parameters: sig_: Pointer to the signal header.
688 *
689 * param_no_: Number of the parameter to be set
690 *
691 * src_adr_: Source address
692 *
693 * size_t: Parameter size
694 *
695 * Returns: None
696 ***E************************************************************************/
697
698#define os_signal_paramcopy(sig_, param_no_, src_adr_, size_) \
699 memcpy( (void *) &(((yPDP_##sig_)(OUTSIGNAL_DATA_PTR))->Param##param_no_), \
700 (void *)(src_adr_), \
701 (size_) );
702
703
704/**B*************************************************************************
705 * Macro: os_signal_paramreset
706 *---------------------------------------------------------------------------
707 * Purpose: Resets parameter values of a signal message buffer.
708 *
709 * Parameters: sig_: Pointer to the signal header.
710 *
711 * param_no_: Number of the parameter to be reset
712 *
713 * size_t: Parameter size
714 *
715 * Returns: None
716 ***E************************************************************************/
717
718#define os_signal_paramreset(sig_, param_no_, size_)
719
720
721/**B*************************************************************************
722 * Macro: os_signal_free
723 *---------------------------------------------------------------------------
724 * Purpose: Deallocation of a message buffer for a signal.
725 *
726 * Parameters: signal_ptr: pointer to the signal allocated with
727 * os_signal_alloc().
728 *
729 * Returns: None.
730 ***E************************************************************************/
731
732#define os_signal_free free_sig
733
734
735/**B*************************************************************************
736 * Macro: os_signal_id
737 *---------------------------------------------------------------------------
738 * Purpose: Extract the signal id from the received input signal
739 *
740 * Parameters: signal_ptr:: pointer to the received signal.
741 *
742 * Returns: None.
743 ***E************************************************************************/
744
745#define os_signal_id(signal_ptr_) SIGNAL_NAME (signal_ptr_->SignalCode, 0)
746
747
748/**B*************************************************************************
749 * Macro: os_signal_receive
750 *---------------------------------------------------------------------------
751 * Purpose: Wait for a signal to arrive. After having performed a
752 * transition,
753 * each process waits here for the next signal to arrive. Once
754 * a signal is available, it is taken out of the queue and the
755 * next transition takes place.
756 *
757 * Parameters: None.
758 *
759 * Returns: Pointer to message buffer.
760 ***E************************************************************************/
761
762#define os_signal_receive(self_) receive_sig(self_)
763
764
765/**B*************************************************************************
766 * Macro: os_signal_route
767 *---------------------------------------------------------------------------
768 * Purpose: Route and send signal according to signal code.
769 * The signal code is an element of the generic signal header.
770 * This element is set in os_signal_alloc().
771 *
772 * Parameters: None.
773 *
774 * Returns: None.
775 ***E************************************************************************/
776
777#define os_signal_route(signal_id_, signal_name_) \
778 send_sig_no_to (yOutputSignalPtr, signal_id_, signal_name_); }
779
780
781/**B*************************************************************************
782 * Macro: os_signal_send
783 *---------------------------------------------------------------------------
784 * Purpose: The given signal is send to the specified task queue.
785 *
786 * Parameters: receiver_: PID of the receiver process.
787 *
788 * Returns: None.
789 ***E************************************************************************/
790
791#define os_signal_send(receiver_, signal_name_) \
792 SEND_SIG (yOutputSignalPtr, receiver_, signal_name_ );
793
794
795/**B*************************************************************************
796 * Macro: os_signal_vars
797 *---------------------------------------------------------------------------
798 * Purpose: Generic signal header.
799 *
800 * Parameters: None.
801 *
802 * Returns: None.
803 ***E************************************************************************/
804
805#define os_signal_vars SIGNAL_VARS
806
807
808/**B*************************************************************************
809 * Macro: os_timer_t
810 *---------------------------------------------------------------------------
811 * Purpose: Type definition of a timer mapped to an input signal.
812 *
813 * Parameters: None.
814 *
815 * Returns: None.
816 ***E************************************************************************/
817
818typedef char os_timer_t; /* It is a dummy type. */
819
820
821/**B*************************************************************************
822 * Macro: os_timer_start
823 *---------------------------------------------------------------------------
824 * Purpose: A timer is started with an expiry time relative to the
825 * current system time. The call of os_timer_start()
826 * causes an implicit stop of the timer.
827 * The timer queue, the processes' save and input queues are
828 * searched for the timer signal.
829 * If the timer signal can be found there, it is taken from the
830 * queue and the timer is started anew. If the timer is neither
831 * running nor can the timer signal be found in the process
832 * queues, a message buffer for the timer signal is allocated.
833 * This block (re-used or newly allocated) is
834 * then enqueued at the proper place in the timer queue.
835 *
836 * Parameters: Import of the process variables as yVarP with the generic
837 * header (os_process_var).
838 * t_name_: name of the timer variable, must be an element of
839 * the process variables.
840 * t_id_: timer id, used as input signal.
841 * secs_: number of seconds (long).
842 * nano_secs_: nano seconds (long).
843 *
844 * Returns: None.
845 ***E************************************************************************/
846
847#define os_timer_start(t_name_, t_id_, tick_expr_,sample_id) \
848do { \
849 SDL_SET_DUR (0, tick_expr_, t_id_, 0, t_name_, "",sample_id); \
850} while (0)
851
852
853/**B*************************************************************************
854 * Macro: os_timer_stop
855 *---------------------------------------------------------------------------
856 * Purpose: A timer is stopped.
857 * The timer queue, the processes' save and input queues are
858 * searched for the timer signal.
859 * If the timer signal can be found there, it is removed from
860 * the queue, and the timer signal (i. e. the message buffer)
861 * is freed.
862 *
863 * Parameters: Import of the process variables as yVarP with the generic
864 * header (os_process_var).
865 * t_name_: name of the timer variable,
866 * must be an element of the process variables.
867 * t_id_: timer id, used as input signal.
868 *
869 * Returns: None.
870 ***E************************************************************************/
871
872#define os_timer_stop(t_name_, t_id_) \
873do { \
874 SDL_RESET (t_id_, 0, t_name_, ""); \
875} while (0)
876
877
878/**B*************************************************************************
879 * Macro: os_timer_stop_with_para
880 *---------------------------------------------------------------------------
881 * Purpose: A timer is stopped.
882 * The timer queue, the processes' save and input queues are
883 * searched for the timer signal.
884 * If the timer signal can be found there, it is removed from
885 * the queue, and the timer signal (i. e. the message buffer)
886 * is freed.
887 *
888 * Parameters: Import of the process variables as yVarP with the generic
889 * header (os_process_var).
890 * t_name_: name of the timer variable,
891 * must be an element of the process variables.
892 * t_id_: timer id, used as input signal.
893 *
894 * Returns: None.
895 ***E************************************************************************/
896
897#define os_timer_stop_with_para(t_name_, t_id_, t_param,sample_id) \
898do { \
899 SDL_Reset (t_id_, t_param, (t_process_vars *) yVarP,sample_id); \
900} while (0)
901
902
903/**B*************************************************************************
904 * Macro: os_timer_start_with_para
905 *---------------------------------------------------------------------------
906 * Purpose: A timer is started with an expiry time relative to the
907 * current system time. The call of os_timer_start()
908 * causes an implicit stop of the timer.
909 * The timer queue, the processes' save and input queues are
910 * searched for the timer signal.
911 * If the timer signal can be found there, it is taken from the
912 * queue and the timer is started anew. If the timer is neither
913 * running nor can the timer signal be found in the process
914 * queues, a message buffer for the timer signal is allocated.
915 * This block (re-used or newly allocated) is
916 * then enqueued at the proper place in the timer queue.
917 *
918 * Parameters: Import of the process variables as yVarP with the generic
919 * header (os_process_var).
920 * t_name_: name of the timer variable, must be an element of
921 * the process variables.
922 * t_id_: timer id, used as input signal.
923 * secs_: number of seconds (long).
924 * nano_secs_: nano seconds (long).
925 *
926 * Returns: None.
927 ***E************************************************************************/
928
929#if defined (SDL_SET_DUR_EX)
930
931#define os_timer_soft_start_with_para(t_name_, t_id_, t_param, earliest_tick_expr_, latest_tick_expr_,sample_id) \
932do { \
933 SDL_Set_Dur_Ex (earliest_tick_expr_, latest_tick_expr_, t_id_, t_param, (t_process_vars *) yVarP,sample_id); \
934} while (0)
935
936#define os_timer_start_with_para(t_name_, t_id_, t_param, tick_expr_,sample_id) \
937do { \
938 SDL_Set_Dur (tick_expr_, t_id_, t_param, (t_process_vars *) yVarP,sample_id); \
939} while (0)
940
941#else
942
943#define os_timer_start_with_para(t_name_, t_id_, t_param, tick_expr_,sample_id) \
944do { \
945 SDL_Set_Dur (tick_expr_, t_id_, t_param, (t_process_vars *) yVarP,sample_id); \
946} while (0)
947
948#define os_timer_soft_start_with_para(t_name_, t_id_, t_param, earliest_tick_expr_, latest_tick_expr_,sample_id) \
949do { \
950 SDL_Set_Dur (earliest_tick_expr_, t_id_, t_param, (t_process_vars *) yVarP,sample_id); \
951} while (0)
952
953#endif
954
955
956/**B*************************************************************************
957 * Macro: os_is_task_call
958 *---------------------------------------------------------------------------
959 * Purpose: Nucleus often crashes if a TASK functions are called
960 * from HISR and LISR context
961 *
962 *
963 * Parameters: NONE
964 *
965 * Returns: 0 if it is a HISR or LISR context
966 * 1 if it is a TASK context
967 ***E************************************************************************/
968
969#define os_is_task_call() (NU_Current_Task_Pointer() != NULL)
970
971
972/*===========================================================================
973EXPORTED TYPE DECLARATIONS
974===========================================================================*/
975
976typedef void (* os_timeout_handler) (void *arg);
977
978
979/*============================================================================
980EXPORTED FUNCTIONS
981============================================================================*/
982
983/**B************************************************************************
984 * Function: os_init
985 *--------------------------------------------------------------------------
986 * Purpose: Module initialization for MS OS abstraction layer.
987 *
988 * Parameters: None
989 *
990 * Returns: None
991 ***E***********************************************************************/
992
993extern VOID os_init(VOID);
994
995
996/**B*************************************************************************
997 * Function: os_sdlpid_current
998 *---------------------------------------------------------------------------
999 * Purpose: Return the SDL pid of the current task.
1000 *
1001 * Parameters: None
1002 *
1003 * Returns: SDL pid.
1004 ***E************************************************************************/
1005
1006extern OS_pid_t os_sdlpid_current(VOID);
1007
1008
1009/**B*************************************************************************
1010 * Function: os_sdlpid_deregister
1011 *---------------------------------------------------------------------------
1012 * Purpose: Remove the pid of an SDL process.
1013 *
1014 * Parameters: None
1015 *
1016 * Returns: None
1017 ***E************************************************************************/
1018
1019extern VOID os_sdlpid_deregister(VOID);
1020
1021
1022/**B*************************************************************************
1023 * Function: os_sdlpid_register
1024 *---------------------------------------------------------------------------
1025 * Purpose: os_sdlpid_current
1026 *---------------------------------------------------------------------------
1027 * Purpose: Return the SDL pid of the current task.
1028 *
1029 * Parameters: None
1030 *
1031 * Returns: SDL pid.
1032 ***E************************************************************************/
1033
1034extern OS_pid_t os_sdlpid_current(VOID);
1035
1036
1037/**B*************************************************************************
1038 * Function: os_sdlpid_deregister
1039 *---------------------------------------------------------------------------
1040 * Purpose: Save the pid of an SDL process.
1041 *
1042 * Parameters: SDL pid
1043 *
1044 * Returns: None
1045 ***E************************************************************************/
1046
1047// P98C-YXS extern VOID os_sdlpid_register(OS_pid_t sdl_pid);
1048
1049
1050/**B*************************************************************************
1051 * Macro: os_sleep_ms
1052 *---------------------------------------------------------------------------
1053 * Purpose: os_sleep_ms() makes the current process sleep until ms
1054 * milliseconds have elapsed.
1055 *
1056 * Parameters: unsigned long ms: # of milliseconds
1057 *
1058 * Returns: None.
1059 ***E************************************************************************/
1060
1061extern VOID os_sleep_ms(UNSIGNED ms);
1062
1063
1064/**B*************************************************************************
1065 * Macro: os_task_create
1066 *---------------------------------------------------------------------------
1067 * Purpose: This procedure creates an application task.
1068 *
1069 * Parameters:
1070 * task Pointer to th user-supplied task control block.
1071 * name Pointer to an 8 character name for the task.
1072 * entry Specifies the entry function of the task.
1073 * stack Designates the starting memory location of the tasks
1074 * stack area.
1075 * stack_size Specifies the number of bytes in the stack.
1076 * priority Specifies a priority value between 0 and 255. The lower
1077 * numeric value, the higher the tasks priority.
1078 *
1079 * Returns: 1 indicates successful completion of the service,
1080 * otherwise 0 or soft crash..
1081 ***E************************************************************************/
1082typedef NU_TASK *os_task_id_t;
1083typedef VOID *os_task_stack_t;
1084typedef VOID (*os_task_func_t)(SINT32);
1085typedef OPTION os_task_prio_t;
1086
1087// P98C-YXS extern SINT32 os_task_create (os_task_id_t *id,
1088// P98C-YXS CHAR *name,
1089// P98C-YXS os_task_func_t entry,
1090// P98C-YXS os_task_stack_t *stack,
1091// P98C-YXS UNSIGNED stack_size,
1092// P98C-YXS os_task_prio_t priority);
1093
1094/**B*************************************************************************
1095 * Macro: os_timeout
1096 *---------------------------------------------------------------------------
1097 * Purpose: Schedule a timeout a specified amount of seconds in the
1098 * future. When the timeout occurs, the specified timeout
1099 * handler will be called. The handler will be passed the
1100 * "arg" argument when called.
1101 *
1102 * Parameters: unsigned char secs: # of seconds
1103 * os_timeout_handler h: timer handler.
1104 * void *arg: argument of the timer handler.
1105 *
1106 * Returns: None.
1107 ***E************************************************************************/
1108
1109// P98C-YXS extern VOID os_timeout(UINT8 secs, os_timeout_handler h, VOID *arg);
1110
1111
1112/**B*************************************************************************
1113 * Macro: os_timeout_ms
1114 *---------------------------------------------------------------------------
1115 * Purpose: Schedule a timeout a specified amount of milliseconds in the
1116 * future. When the timeout occurs, the specified timeout
1117 * handler will be called. The handler will be passed the
1118 * "arg" argument when called.
1119 *
1120 * Parameters: unsigned long ms: # of seconds
1121 * os_timeout_handler h: timer handler.
1122 * void *arg: argument of the timer handler.
1123 *
1124 * Returns: None.
1125 ***E************************************************************************/
1126
1127// P98C-YXS extern VOID os_timeout_ms(UNSIGNED ms, os_timeout_handler h, VOID *arg);
1128
1129
1130/**B*************************************************************************
1131 * Macro: os_untimeout
1132 *---------------------------------------------------------------------------
1133 * Purpose: Deinstall the timeout handler activated about os_timeout or
1134 * about os_timeout_ms.
1135 *
1136 * Parameters: os_timeout_handler h: timer handler.
1137 * void *arg: argument of the timer handler.
1138 *
1139 * Returns: None.
1140 ***E************************************************************************/
1141
1142// P98C-YXS extern VOID os_untimeout(os_timeout_handler h, VOID *arg);
1143
1144#endif
1145
1146/* ms_os.h ends here. */
1147