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