1 /*---------------------------------------------------------------------------*
2   Project:  Horizon
3   File:     nos_horizon.h
4 
5   Copyright (C)2009-2012 Nintendo Co., Ltd.  All rights reserved.
6 
7   These coded instructions, statements, and computer programs contain
8   proprietary information of Nintendo of America Inc. and/or Nintendo
9   Company Ltd., and are protected by Federal copyright law.  They may
10   not be disclosed to third parties or copied or duplicated in any form,
11   in whole or in part, without the prior written consent of Nintendo.
12 
13   $Rev: 46347 $
14  *---------------------------------------------------------------------------*/
15 
16 #include <nn/Handle.h>
17 #include <nn/os.h>
18 #include <nn/os/os_Thread.h>
19 #include <nn/os/os_CriticalSection.h>
20 #include <nn/os/os_LightAlarm.h>
21 #include <nn/os/os_Tick.h>
22 #include <nn/net/osl/osl_EventFlag.h>
23 #include <nn/net/osl/osl_Mbuf.h>
24 #include <nn/net/compatible/nlib.h>
25 #include <nn/net/compatible/ndebug.h>
26 
27 #ifndef NN_NET_COMPATIBLE_NOS_NOS_HORIZON_H_
28 #define NN_NET_COMPATIBLE_NOS_NOS_HORIZON_H_
29 
30 #ifdef  __cplusplus
31 extern "C" {
32 #endif
33 
34 /*
35  * System dependency arguments
36  *
37  *  When calling the system allocator, specify one of the following as the align size for each module.
38  *
39  * Define the value as appropriate.
40  */
41 #define NOS_MEM_ALIGN_STRUCT_SAFE      8    /* Please see man pages for details */
42 #define NOS_MEM_ALIGN_4                4    /* Please see man pages for details */
43 #define NOS_MEM_ALIGN_STACK            8    /* Please see man pages for details */
44 
45 #define NN_INLINE   extern __inline
46 #define BOOL        s32
47 #define TRUE        1
48 #define FALSE       0
49 
50 typedef void (*nnosThreadFunc)(uptr param);
51 
52 /* thread */
53 
54 /* Please see man pages for details
55 
56  */
57 typedef nnosThread NOSThread;
58 
59 /* Please see man pages for details
60 
61 
62 
63 
64  */
65 typedef nnosThread *NOSThreadId;
66 
67 /* Please see man pages for details
68 
69  */
70 typedef nnosEvent NOSThreadQueue;
71 
72 /* Please see man pages for details
73 
74 
75 
76 
77 
78 
79 
80 
81 
82 
83 
84 
85 
86 
87 
88 
89 
90 
91 
92 
93 
94 
95 
96 
97 
98 
99 
100 
101 
102 
103  */
NOS_CreateAndStartThread(NOSThread * thread,void (* func)(void *),void * arg,void * stack,u32 stackSize,u32 prio)104 NN_INLINE NOSThreadId NOS_CreateAndStartThread(
105      NOSThread*   thread,
106      void        (*func)(void*),
107      void*       arg,
108      void*       stack,
109      u32         stackSize,
110      u32         prio )
111 {
112     NN_UNUSED_VAR(stackSize);
113     bool result = nnosThreadTryInitializeAndStart(thread, (nnosThreadFunc)func, (uptr)arg, (uptr)stack, prio, NN_OS_CORE_NO_USE_PROCESS_VALUE);
114     if (!result)
115     {
116         return 0;
117     }
118     return (NOSThreadId)thread;
119 }
120 
121 /* Please see man pages for details
122 
123 
124 
125 
126 
127 
128 
129 
130 
131 
132 
133 
134  */
NOS_JoinAndDestroyThread(NOSThreadId threadId)135 NN_INLINE void NOS_JoinAndDestroyThread(NOSThreadId threadId)
136 {
137     nnosThreadJoin(threadId);
138     nnosThreadFinalize(threadId);
139 }
140 
141 /* Please see man pages for details
142 
143 
144 
145 
146 
147 
148 
149 
150 
151 
152 
153 
154 
155 
156 
157 
158 
159 
160 
161 
162 
163 
164 
165 
166 
167 
168 
169 
170 
171 
172 
173 
174  */
NOS_CreateThread(NOSThread * thread,void (* func)(void *),void * arg,void * stack,u32 stackSize,u32 prio)175 NN_INLINE NOSThreadId NOS_CreateThread(
176      NOSThread*   thread,
177      void        (*func)(void*),
178      void*       arg,
179      void*       stack,
180      u32         stackSize,
181      u32         prio )
182 {
183     NN_UNUSED_VAR(stackSize);
184     bool result = nnosThreadTryInitializeAndStart(thread, (nnosThreadFunc)func, (uptr)arg, (uptr)stack, prio, NN_OS_CORE_NO_USE_PROCESS_VALUE);
185     if (!result)
186     {
187         return 0;
188     }
189     return (NOSThreadId)thread;
190 }
191 
192 /* Please see man pages for details
193 
194 
195 
196 
197 
198 
199 
200 
201 
202 
203 
204 
205  */
NOS_DestroyThread(NOSThreadId threadId)206 NN_INLINE void NOS_DestroyThread(NOSThreadId threadId)
207 {
208     // Do not destroy threads that have not been terminated.
209     nnosThreadJoin(threadId);
210     nnosThreadFinalize(threadId);
211 }
212 
213 /* Please see man pages for details
214 
215 
216 
217 
218 
219 
220 
221 
222 
223  */
NOS_GetCurrentThread(void)224 NN_INLINE NOSThreadId NOS_GetCurrentThread(void)
225 {
226     return (NOSThreadId)nnosThreadGetCurrentId();
227 }
228 
229 /* Please see man pages for details
230 
231 
232 
233 
234 
235 
236 
237 
238 
239 
240 
241 
242 
243 
244  */
NOS_WakeupThreadDirect(NOSThreadId threadId)245 NN_INLINE void NOS_WakeupThreadDirect(NOSThreadId threadId)
246 {
247     NN_UNUSED_VAR(threadId);
248     return;
249 }
250 
251 /* Please see man pages for details
252 
253 
254 
255 
256 
257 
258 
259 
260 
261 
262 
263 
264 
265 
266  */
NOS_InitThreadQueue(NOSThreadQueue * queue)267 NN_INLINE void NOS_InitThreadQueue(NOSThreadQueue* queue)
268 {
269     nnosEventInitialize(queue, TRUE);
270 }
271 
272 /* Please see man pages for details
273 
274 
275 
276 
277 
278 
279 
280 
281 
282 
283 
284 
285 
286  */
NOS_WakeupThread(NOSThreadQueue * queue)287 NN_INLINE void NOS_WakeupThread(NOSThreadQueue* queue)
288 {
289     nnosEventSignal(queue);
290 }
291 
292 /* Please see man pages for details
293 
294 
295 
296 
297 
298 
299 
300 
301 
302 
303 
304 
305 
306 
307 
308 
309 
310 
311  */
NOS_SleepThread(NOSThreadQueue * queue)312 NN_INLINE void NOS_SleepThread(NOSThreadQueue* queue)
313 {
314     // This thread is not permitted to sleep without using a synchronized object
315     NN_TASSERT_(queue != NULL);
316     nnosEventClearSignal(queue);
317     nnosEventWaitSignal(queue);
318 }
319 
320 /* Please see man pages for details
321 
322 
323 
324 
325 
326 
327 
328 
329 
330 
331  */
NOS_JoinThread(NOSThreadId threadId)332 NN_INLINE void NOS_JoinThread(NOSThreadId threadId)
333 {
334     nnosThreadJoin(threadId);
335 }
336 
337 
338 /* Sleep. */
339 
340 /* Please see man pages for details
341 
342 
343 
344 
345 
346 
347 
348  */
NOS_Sleep(u32 msec)349 NN_INLINE void NOS_Sleep(u32 msec)
350 {
351     nnosThreadSleep((s64)msec*1000000 + 1);
352 }
353 
NOS_YieldThread(void)354 NN_INLINE void NOS_YieldThread(void)
355 {
356     nnosThreadYield();
357 }
358 
359 /* mutex */
360 
361 /* Please see man pages for details
362 
363  */
364 typedef nnosCriticalSection NOSMutex;
365 
366 /* Please see man pages for details
367 
368 
369 
370 
371 
372  */
373 typedef nnosCriticalSection *NOSMutexId;
374 
375 /* Please see man pages for details
376 
377 
378 
379 
380 
381 
382 
383 
384 
385 
386 
387 
388 
389  */
NOS_CreateMutex(NOSMutex * m)390 NN_INLINE NOSMutexId NOS_CreateMutex(NOSMutex *m)
391 {
392     NN_ASSERT(m != NULL);
393     bool result = nnosCriticalSectionTryInitialize(m);
394     if (!result)
395     {
396         return 0;
397     }
398     return (NOSMutexId)m;
399 }
400 
401 /* Please see man pages for details
402 
403 
404 
405 
406 
407 
408 
409 
410 
411  */
NOS_DestroyMutex(NOSMutexId mutexId)412 NN_INLINE void NOS_DestroyMutex(NOSMutexId mutexId)
413 {
414     NN_ASSERT(mutexId != NULL);
415     nnosCriticalSectionFinalize(mutexId);
416 }
417 
418 /* Please see man pages for details
419 
420 
421 
422 
423 
424 
425 
426 
427 
428 
429 
430 
431 
432 
433 
434 
435 
436  */
NOS_LockMutex(NOSMutexId mutexId)437 NN_INLINE void NOS_LockMutex(NOSMutexId mutexId)
438 {
439     NN_ASSERT(mutexId != NULL);
440     nnosCriticalSectionEnter(mutexId);
441 }
442 
443 /* Please see man pages for details
444 
445 
446 
447 
448 
449 
450 
451 
452 
453 
454 
455 
456 
457 
458 
459 
460 
461 
462  */
NOS_UnlockMutex(NOSMutexId mutexId)463 NN_INLINE void NOS_UnlockMutex(NOSMutexId mutexId)
464 {
465     NN_ASSERT(mutexId != NULL);
466     nnosCriticalSectionLeave(mutexId);
467 }
468 
469 /* Please see man pages for details
470 
471 
472 
473 
474 
475 
476 
477 
478 
479 
480 
481 
482 
483  */
NOS_TryLockMutex(NOSMutexId mutexId)484 NN_INLINE BOOL NOS_TryLockMutex(NOSMutexId mutexId)
485 {
486     NN_ASSERT(mutexId != NULL);
487     return nnosCriticalSectionTryEnter(mutexId);
488 }
489 
490 /* tick */
491 
492 /* Please see man pages for details
493 
494 
495 
496 
497  */
498 typedef u64 NOSTick;
499 
500 /* Please see man pages for details
501 
502 
503 
504 
505 
506 
507 
508  */
NOS_GetTick(void)509 NN_INLINE NOSTick NOS_GetTick(void)
510 {
511     return (NOSTick)(nnosTickGetSystemCurrent() << 1);
512 }
513 
514 /* Please see man pages for details
515 
516 
517 
518 
519 
520 
521 
522 
523 
524 
525 
526 
527  */
NOS_CmpTick(NOSTick a,NOSTick b)528 NN_INLINE s64 NOS_CmpTick(NOSTick a, NOSTick b)
529 {
530     return (s64)(a - b);
531 }
532 
533 
NOS_TicksToSeconds(s64 tick)534 NN_INLINE s64 NOS_TicksToSeconds(s64 tick)
535 {
536     return nnosTickConvertToSeconds(tick >> 1);
537 }
NOS_TicksToMilliSeconds(s64 tick)538 NN_INLINE s64 NOS_TicksToMilliSeconds(s64 tick)
539 {
540     return nnosTickConvertToMilliSeconds(tick >> 1);
541 }
NOS_TicksToMicroSeconds(s64 tick)542 NN_INLINE s64 NOS_TicksToMicroSeconds(s64 tick)
543 {
544     return nnosTickConvertToMicroSeconds(tick >> 1);
545 }
NOS_TicksToNanoSeconds(s64 tick)546 NN_INLINE s64 NOS_TicksToNanoSeconds(s64 tick)
547 {
548     return nnosTickConvertToNanoSeconds(tick >> 1);
549 }
NOS_SecondsToTicks(s64 s)550 NN_INLINE NOSTick NOS_SecondsToTicks(s64 s)
551 {
552     return nnosTickConvertFromSeconds(s) << 1;
553 }
NOS_MilliSecondsToTicks(s64 ms)554 NN_INLINE NOSTick NOS_MilliSecondsToTicks(s64 ms)
555 {
556     return nnosTickConvertFromMilliSeconds(ms) << 1;
557 }
NOS_MicroSecondsToTicks(s64 ms)558 NN_INLINE NOSTick NOS_MicroSecondsToTicks(s64 ms)
559 {
560     return nnosTickConvertFromMicroSeconds(ms) << 1;
561 }
NOS_NanoSecondsToTicks(s64 ns)562 NN_INLINE NOSTick NOS_NanoSecondsToTicks(s64 ns)
563 {
564     return nnosTickConvertFromNanoSeconds(ns) << 1;
565 }
566 
567 /* messagequeue */
568 
569 #define  NOS_MESSAGE_NOBLOCK   0
570 #define  NOS_MESSAGE_BLOCK     1
571 
572 /* Please see man pages for details
573 
574  */
575 typedef nnosBlockingQueue NOSMessageQueue;
576 
577 /* Please see man pages for details
578 
579  */
580 typedef nnosBlockingQueue *NOSMessageQueueId;
581 
582 /* Please see man pages for details
583 
584  */
585 typedef uptr NOSMessage;
586 
587 /* Please see man pages for details
588 
589 
590 
591 
592 
593 
594 
595 
596 
597 
598 
599 
600 
601 
602 
603 
604 
605 
606  */
NOS_CreateMessageQueue(NOSMessageQueue * mq,NOSMessage * msgArray,s32 msgCount)607 NN_INLINE NOSMessageQueueId NOS_CreateMessageQueue(NOSMessageQueue *mq, NOSMessage *msgArray, s32 msgCount)
608 {
609     bool result = nnosBlockingQueueTryInitialize(mq, msgArray, msgCount);
610     if (!result)
611     {
612         return 0;
613     }
614     return (NOSMessageQueueId)mq;
615 }
616 
617 /* Please see man pages for details
618 
619 
620 
621 
622 
623 
624 
625 
626 
627  */
NOS_DestroyMessageQueue(NOSMessageQueueId mqId)628 NN_INLINE void NOS_DestroyMessageQueue(NOSMessageQueueId mqId)
629 {
630     nnosBlockingQueueFinalize(mqId);
631 }
632 
633 /* Please see man pages for details
634 
635 
636 
637 
638 
639 
640 
641 
642 
643 
644 
645 
646 
647 
648 
649 
650 
651 
652 
653 
654 
655 
656 
657 
658 
659 
660 
661 
662  */
NOS_ReceiveMessage(NOSMessageQueueId mqId,NOSMessage * msg,s32 flag)663 NN_INLINE BOOL NOS_ReceiveMessage(NOSMessageQueueId mqId, NOSMessage *msg, s32 flag)
664 {
665     if (flag == NOS_MESSAGE_BLOCK)
666     {
667         *msg = nnosBlockingQueueDequeue(mqId);
668         return TRUE;
669     }
670     else
671     {
672         return nnosBlockingQueueTryDequeue(mqId, msg);
673     }
674 }
675 
676 /* Please see man pages for details
677 
678 
679 
680 
681 
682 
683 
684 
685 
686 
687 
688 
689 
690 
691 
692 
693 
694 
695 
696 
697 
698 
699 
700 
701 
702 
703  */
NOS_SendMessage(NOSMessageQueueId mqId,NOSMessage msg,s32 flag)704 NN_INLINE BOOL NOS_SendMessage(NOSMessageQueueId mqId, NOSMessage msg, s32 flag)
705 {
706     if (flag == NOS_MESSAGE_BLOCK)
707     {
708         nnosBlockingQueueEnqueue(mqId, msg);
709         return TRUE;
710     }
711     else
712     {
713         return nnosBlockingQueueTryEnqueue(mqId, msg);
714     }
715 }
716 
717 /* Please see man pages for details
718 
719 
720 
721 
722 
723 
724 
725 
726 
727 
728 
729 
730 
731 
732 
733 
734 
735 
736 
737 
738 
739 
740 
741 
742 
743 
744 
745 
746  */
NOS_ReadMessage(NOSMessageQueueId mqId,NOSMessage * msg,s32 flag)747 NN_INLINE BOOL NOS_ReadMessage(NOSMessageQueueId mqId, NOSMessage *msg, s32 flag)
748 {
749     if (flag == NOS_MESSAGE_BLOCK)
750     {
751         *msg = nnosBlockingQueueGetFront(mqId);
752         return TRUE;
753     }
754     else
755     {
756         return nnosBlockingQueueTryGetFront(mqId, msg);
757     }
758 }
759 
760 /* Please see man pages for details
761 
762 
763 
764 
765 
766 
767 
768 
769 
770 
771 
772 
773 
774 
775 
776 
777 
778 
779 
780 
781 
782 
783 
784 
785 
786 
787  */
NOS_JamMessage(NOSMessageQueueId mqId,NOSMessage msg,s32 flag)788 NN_INLINE BOOL NOS_JamMessage(NOSMessageQueueId mqId, NOSMessage msg, s32 flag)
789 {
790     if (flag == NOS_MESSAGE_BLOCK)
791     {
792         nnosBlockingQueueJam(mqId, msg);
793         return TRUE;
794     }
795     else
796     {
797         return nnosBlockingQueueTryJam(mqId, msg);
798     }
799 }
800 
801 typedef void (*NOSAlarmHandler) (void *);     /* Please see man pages for details */
802 
803 /* Please see man pages for details
804 
805  */
806 typedef struct NOSAlarm
807 {
808     nnosLightAlarm      alarm;
809     NOSAlarmHandler     handler;
810     void*               arg;
811 } NOSAlarm;
812 /* Please see man pages for details
813 
814  */
815 typedef NOSAlarm *NOSAlarmId;
816 
817 /* NOS_alarm.c */
NOS_InitAlarm(void)818 NN_INLINE s32 NOS_InitAlarm(void){ return 0; }
819 
820 NOSAlarmId NOS_CreateAlarm(NOSAlarm *pAlarm);
821 s32 NOS_SetAlarm(NOSAlarmId alarmId, NOSTick tick, NOSAlarmHandler callback, void *arg);
822 s32 NOS_CancelAlarm(NOSAlarmId alarmId);
823 void NOS_DestroyAlarm(NOSAlarmId alarmId);
824 s32 NOS_SetPeriodicAlarm(NOSAlarmId alarmId, NOSTick start, NOSTick period, NOSAlarmHandler callback, void *arg);
825 
826 
827 typedef struct
828 {
829     nnnetOslEventFlag   eventFlag;
830     NLIBLink            link;
831     s32                 priority;
832 } NOSEvent;
833 typedef NOSEvent *NOSEventId;
834 
835 #define NOS_TMO_FEVR    0xffffffffffffffff
836 
837 typedef enum
838 {
839     NOS_EVENT_MODE_AND = NN_NET_OSL_WAITMODE_AND,
840     NOS_EVENT_MODE_OR  = NN_NET_OSL_WAITMODE_OR
841 }
842 NOSEventMode;
843 
NOS_CreateEvent(NOSEvent * pEvent)844 NN_INLINE NOSEventId NOS_CreateEvent(NOSEvent* pEvent)
845 {
846     bool result = nnnetOslEventFlagTryInitialize(&pEvent->eventFlag);
847     if (!result)
848     {
849         return 0;
850     }
851     return (NOSEventId)pEvent;
852 }
853 
NOS_DestroyEvent(NOSEventId eventId)854 NN_INLINE void NOS_DestroyEvent(NOSEventId eventId)
855 {
856     NOSEvent* pEvent = (NOSEvent*)eventId;
857     nnnetOslEventFlagFinalize(&pEvent->eventFlag);
858 }
859 
NOS_WaitEvent(NOSEventId eventId,u32 pattern,NOSEventMode mode)860 NN_INLINE u32 NOS_WaitEvent(NOSEventId eventId, u32 pattern, NOSEventMode mode)
861 {
862     NOSEvent* pEvent = (NOSEvent*)eventId;
863     return nnnetOslEventFlagWaitSignal(&pEvent->eventFlag, pattern, (nnnetOslWaitMode)mode, NN_OS_WAIT_INFINITE);
864 }
865 
NOS_WaitEvent_And(NOSEventId eventId,u32 pattern)866 NN_INLINE u32 NOS_WaitEvent_And(NOSEventId eventId, u32 pattern)
867 {
868     NOSEvent* pEvent = (NOSEvent*)eventId;
869     return nnnetOslEventFlagWaitSignal(&pEvent->eventFlag, pattern, NN_NET_OSL_WAITMODE_AND, NN_OS_WAIT_INFINITE);
870 }
871 
NOS_WaitEvent_Or(NOSEventId eventId,u32 pattern)872 NN_INLINE u32 NOS_WaitEvent_Or(NOSEventId eventId, u32 pattern)
873 {
874     NOSEvent* pEvent = (NOSEvent*)eventId;
875     return nnnetOslEventFlagWaitSignal(&pEvent->eventFlag, pattern, NN_NET_OSL_WAITMODE_OR, NN_OS_WAIT_INFINITE);
876 }
877 
NOS_WaitEventEx(NOSEventId eventId,u32 pattern,NOSEventMode mode,u32 clearBit)878 NN_INLINE u32 NOS_WaitEventEx(NOSEventId eventId, u32 pattern, NOSEventMode mode, u32 clearBit)
879 {
880     NOSEvent* pEvent = (NOSEvent*)eventId;
881     return nnnetOslEventFlagWaitAndClear(&pEvent->eventFlag, pattern, (nnnetOslWaitMode)mode, clearBit, NN_OS_WAIT_INFINITE);
882 }
883 
NOS_WaitEventEx_And(NOSEventId eventId,u32 pattern,u32 clearBit)884 NN_INLINE u32 NOS_WaitEventEx_And(NOSEventId eventId, u32 pattern, u32 clearBit)
885 {
886     NOSEvent* pEvent = (NOSEvent*)eventId;
887     return nnnetOslEventFlagWaitAndClear(&pEvent->eventFlag, pattern, NN_NET_OSL_WAITMODE_AND, clearBit, NN_OS_WAIT_INFINITE);
888 }
889 
NOS_WaitEventEx_Or(NOSEventId eventId,u32 pattern,u32 clearBit)890 NN_INLINE u32 NOS_WaitEventEx_Or(NOSEventId eventId, u32 pattern, u32 clearBit)
891 {
892     NOSEvent* pEvent = (NOSEvent*)eventId;
893     return nnnetOslEventFlagWaitAndClear(&pEvent->eventFlag, pattern, NN_NET_OSL_WAITMODE_OR, clearBit, NN_OS_WAIT_INFINITE);
894 }
895 
NOS_SignalEvent(NOSEventId eventId,u32 setPattern)896 NN_INLINE void NOS_SignalEvent(NOSEventId eventId, u32 setPattern)
897 {
898     NOSEvent* pEvent = (NOSEvent*)eventId;
899     nnnetOslEventFlagSignal(&pEvent->eventFlag, setPattern);
900 }
901 
NOS_PollEvent(NOSEventId eventId,u32 pattern,NOSEventMode mode)902 NN_INLINE u32 NOS_PollEvent(NOSEventId eventId, u32 pattern, NOSEventMode mode)
903 {
904     NOSEvent* pEvent = (NOSEvent*)eventId;
905     return nnnetOslEventFlagWaitSignal(&pEvent->eventFlag, pattern, (nnnetOslWaitMode)mode, 0);
906 }
907 
NOS_ClearEvent(NOSEventId eventId,u32 clearBit)908 NN_INLINE void NOS_ClearEvent(NOSEventId eventId, u32 clearBit)
909 {
910     NOSEvent* pEvent = (NOSEvent*)eventId;
911     nnnetOslEventFlagClearSignal(&pEvent->eventFlag, clearBit);
912 }
913 
NOS_ClearAllEvent(NOSEventId eventId)914 NN_INLINE void NOS_ClearAllEvent(NOSEventId eventId)
915 {
916     NOSEvent* pEvent = (NOSEvent*)eventId;
917     nnnetOslEventFlagClearSignal(&pEvent->eventFlag, 0xffffffff);
918 }
919 
NOS_TimeWaitEventEx(NOSEventId eventId,u32 pattern,NOSEventMode mode,u32 clearBit,NOSTick timeout)920 NN_INLINE u32 NOS_TimeWaitEventEx(NOSEventId eventId, u32 pattern, NOSEventMode mode, u32 clearBit, NOSTick timeout)
921 {
922     NOSEvent* pEvent = (NOSEvent*)eventId;
923     if (timeout != NOS_TMO_FEVR)
924     {
925         return nnnetOslEventFlagWaitAndClear(&pEvent->eventFlag, pattern, (nnnetOslWaitMode)mode, clearBit, NOS_TicksToNanoSeconds(timeout));
926     }
927     else
928     {
929         return nnnetOslEventFlagWaitAndClear(&pEvent->eventFlag, pattern, (nnnetOslWaitMode)mode, clearBit, NN_OS_WAIT_INFINITE);
930     }
931 }
932 
933 /* EventQueue */
934 
935 typedef NLIBQueue NOSEventQueue;
936 typedef NOSEventQueue *NOSEventQueueId;
937 
938 /* Please see man pages for details
939 
940 
941 
942 
943 
944 
945 
946 
947 
948 
949 
950 
951 
952  */
NOS_CreateEventQueue(NOSEventQueue * eq)953 NN_INLINE NOSEventQueueId NOS_CreateEventQueue(NOSEventQueue *eq)
954 {
955 	NLIB_Queue_Init((NLIBQueue *)eq);
956     return (NOSEventQueueId)eq;
957 }
958 
959 /* Please see man pages for details
960 
961 
962 
963 
964 
965 
966 
967 
968 
969 
970 
971 
972  */
NOS_DestroyEventQueue(NOSEventQueueId eqId)973 NN_INLINE void NOS_DestroyEventQueue(NOSEventQueueId eqId)
974 {
975     NN_UNUSED_VAR(eqId)
976     ;
977 }
978 extern void NOS_EnqueueEventQueue(NOSEventQueueId queueId, NOSEventId eventId);
979 extern void NOS_DequeueEventQueue(NOSEventQueueId queueId, NOSEventId eventId);
980 extern void NOS_SignalEventQueue(NOSEventQueueId queueId, u32 pattern);
981 
982 
983 /* mbuf */
984 
985 //#define NOS_MBUF_SIZE       NN_NET_OSL_MBUF_DATA_SIZE   /**< Data size to put in a single mbuf */
986 //#define NOS_MBUF_NUM        512     /**< number of mbufs */
987 
988 #define NOS_M_BCAST         NN_NET_OSL_M_BCAST
989 #define NOS_M_MCAST         NN_NET_OSL_M_MCAST
990 #define NOS_M_LOOPBACK      NN_NET_OSL_M_LOOPBACK
991 
992 #define NOS_M_DONTWAIT      0       /* Please see man pages for details */
993 #define NOS_M_WAIT          1       /* Please see man pages for details */
994 #define NOS_M_FREELIST      0x8000  /* Please see man pages for details */
995 
996 #define NOS_MT_DATA         1       /* Please see man pages for details */
997 
998 #define NOS_MBUF_ADDR_SIZE  6       /* Please see man pages for details */
999 
1000 #define NOS_M_CAT_NWCM      0x01    /* Please see man pages for details */
1001 #define NOS_M_CAT_NWMETH    0x01    /* Please see man pages for details */
1002 #define NOS_M_CAT_ARP       0x02    /* Please see man pages for details */
1003 #define NOS_M_CAT_ICMPERR   0x03    /* Please see man pages for details */
1004 #define NOS_M_CAT_ICMPECHO  0x04    /* Please see man pages for details */
1005 #define NOS_M_CAT_IGMP      0x05    /* Please see man pages for details */
1006 #define NOS_M_CAT_IPREASM   0x06    /* Please see man pages for details */
1007 #define NOS_M_CAT_IPFRAG    0x07    /* Please see man pages for details */
1008 #define NOS_M_CAT_TCPRESP   0x08    /* Please see man pages for details */
1009 #define NOS_M_CAT_TCPSEND   0x09    /* Please see man pages for details */
1010 #define NOS_M_CAT_UDP       0x0a    /* Please see man pages for details */
1011 #define NOS_M_CAT_NDP       0x0b    /* Please see man pages for details */
1012 #define NOS_M_CAT_MLD       0x0c    /* Please see man pages for details */
1013 
1014 #define NOS_M_CAT_PPPOE     0x81    /* Please see man pages for details */
1015 #define NOS_M_CAT_PPP       0x82    /* Please see man pages for details */
1016 
1017 #ifdef NDEBUG_ENABLE
1018 #define NOS_M_OWN_NSOC      0x02    /* NSOC is in use */
1019 #define NOS_M_OWN_NPOE      0x03    /* NPOE is in use */
1020 #define NOS_M_OWN_NPPP      0x04    /* NPPP is in use */
1021 #endif
1022 
1023 typedef nnnetOslMbuf NOSMessageBuf;
1024 
1025 #define NOS_mtod(m, t)  ((t)(nnnetOslMbuf_tod(m)))
1026 
1027 NN_EXTERN_C s32 NOS_m_init(void);
1028 
1029 NN_EXTERN_C NOSMessageBuf* NOS_m_getm(u32 name, NOSMessageBuf *orig, s32 len, s32 how, u8 type);
1030 
NOS_m_freem(NOSMessageBuf * mbuf)1031 NN_INLINE void NOS_m_freem(NOSMessageBuf *mbuf)
1032 {
1033     nnnetOslMbuf_freem(mbuf);
1034 }
1035 
NOS_m_adj(NOSMessageBuf * mbuf,s32 len)1036 NN_INLINE s32 NOS_m_adj(NOSMessageBuf *mbuf, s32 len)
1037 {
1038     return nnnetOslMbuf_adj(mbuf, len);
1039 }
1040 
NOS_m_append(NOSMessageBuf * mbuf,s32 len,const u8 * cp)1041 NN_INLINE s32 NOS_m_append(NOSMessageBuf *mbuf, s32 len, const u8 *cp)
1042 {
1043     return nnnetOslMbuf_append(mbuf, len, cp);
1044 }
1045 
NOS_m_prepend(NOSMessageBuf * mbuf,s32 len,int how)1046 NN_INLINE NOSMessageBuf *NOS_m_prepend(NOSMessageBuf *mbuf, s32 len, int how)
1047 {
1048     return nnnetOslMbuf_prepend(mbuf, len, how);
1049 }
1050 
NOS_m_pullup(NOSMessageBuf * mbuf,s32 len)1051 NN_INLINE NOSMessageBuf *NOS_m_pullup(NOSMessageBuf *mbuf, s32 len)
1052 {
1053     return  nnnetOslMbuf_pullup(mbuf, len);
1054 }
1055 
NOS_m_dup(NOSMessageBuf * mbuf,int how)1056 NN_INLINE NOSMessageBuf *NOS_m_dup(NOSMessageBuf *mbuf, int how)
1057 {
1058     return nnnetOslMbuf_dup(mbuf, how);
1059 }
1060 
NOS_m_copydata(const NOSMessageBuf * mbuf,s32 offset,s32 len,u8 * buf)1061 NN_INLINE s32 NOS_m_copydata(const NOSMessageBuf *mbuf, s32 offset, s32 len, u8 *buf)
1062 {
1063     return nnnetOslMbuf_copydata(mbuf, offset, len, buf);
1064 }
1065 
NOS_m_copyback(NOSMessageBuf * mbuf,s32 offset,s32 len,const u8 * buf)1066 NN_INLINE s32 NOS_m_copyback(NOSMessageBuf *mbuf, s32 offset, s32 len, const u8 *buf)
1067 {
1068     return nnnetOslMbuf_copyback(mbuf, offset, len, buf);
1069 }
1070 
NOS_m_cat(NOSMessageBuf * mbuf,NOSMessageBuf * n)1071 NN_INLINE s32 NOS_m_cat(NOSMessageBuf *mbuf, NOSMessageBuf *n)
1072 {
1073     return nnnetOslMbuf_cat(mbuf, n);
1074 }
1075 
NOS_m_split(NOSMessageBuf * mbuf,s32 len,int how)1076 NN_INLINE NOSMessageBuf *NOS_m_split(NOSMessageBuf *mbuf, s32 len, int how)
1077 {
1078     return nnnetOslMbuf_split(mbuf, len, how);
1079 }
1080 
NOS_m_length(NOSMessageBuf * mbuf,NOSMessageBuf ** last)1081 NN_INLINE s32 NOS_m_length(NOSMessageBuf *mbuf, NOSMessageBuf **last)
1082 {
1083     return nnnetOslMbuf_length(mbuf, last);
1084 }
1085 
NOS_m_apply(NOSMessageBuf * mbuf,s32 offset,s32 len,s32 (* f)(void * arg,void * data,s32 len),void * arg)1086 NN_INLINE s32 NOS_m_apply(NOSMessageBuf *mbuf, s32 offset, s32 len, s32 (*f)(void *arg, void *data, s32 len), void *arg)
1087 {
1088     return nnnetOslMbuf_apply(mbuf, offset, len, f, arg);
1089 }
1090 
1091 #ifdef NDEBUG_ENABLE
NOS_m_getfree(void)1092 NN_INLINE s32 NOS_m_getfree(void)
1093 {
1094     return 0;
1095 }
1096 
NOS_m_setowner(NOSMessageBuf * mbuf,u16 owner)1097 NN_INLINE void NOS_m_setowner(NOSMessageBuf *mbuf, u16 owner)
1098 {
1099     NN_UNUSED_VAR(mbuf);
1100     NN_UNUSED_VAR(owner);
1101 }
1102 
NOS_m_getnum(u16 owner)1103 NN_INLINE s32 NOS_m_getnum(u16 owner)
1104 {
1105     NN_UNUSED_VAR(owner);
1106     return 0;
1107 }
1108 
NOS_m_getaddr(int index)1109 NN_INLINE NOSMessageBuf *NOS_m_getaddr(int index)
1110 {
1111     NN_UNUSED_VAR(index);
1112     return NULL;
1113 }
1114 #endif
1115 
1116 #ifdef NDEBUG_PRINT_ENABLE
NOS_m_dump(NOSMessageBuf * mbuf)1117 NN_INLINE void NOS_m_dump(NOSMessageBuf *mbuf)
1118 {
1119     nnnetOslMbuf_dump(mbuf);
1120 }
1121 #endif
1122 
1123 /* NOS_main.c */
1124 extern s32 NOS_Init(void);
1125 
1126 
1127 #ifdef  __cplusplus
1128 }
1129 #endif
1130 
1131 #endif
1132