FreeCalypso > hg > fc-magnetite
comparison src/gpf2/osl/os_com_ir.c @ 487:91e8dac34ada
src/gpf2/osl: initial import from old freecalypso-sw tree
author | Mychaela Falconia <falcon@freecalypso.org> |
---|---|
date | Fri, 22 Jun 2018 05:56:16 +0000 |
parents | |
children | f89439ce0d45 |
comparison
equal
deleted
inserted
replaced
486:c433cca731a3 | 487:91e8dac34ada |
---|---|
1 /* | |
2 * This C module is a reconstruction based on the disassembly of | |
3 * os_com.obj in frame_na7_db_ir.lib from the Leonardo package. | |
4 */ | |
5 | |
6 /* set of included headers from COFF symtab: */ | |
7 #include <stdio.h> | |
8 #include <string.h> | |
9 #include "gpfconf.h" /* FreeCalypso addition */ | |
10 #include "../../nucleus/nucleus.h" | |
11 #include "../../nucleus/tc_extr.h" /* not seen in original, but needed */ | |
12 #include "typedefs.h" | |
13 #include "os.h" | |
14 #include "gdi.h" | |
15 #include "os_types.h" | |
16 #include "os_glob.h" | |
17 | |
18 extern T_OS_COM_TABLE_ENTRY ComTable[]; | |
19 extern unsigned os_tick_to_time_multiplier; | |
20 | |
21 extern int ObtainSemaphoreCB(NU_SEMAPHORE *SemCB, ULONG Timeout, | |
22 USHORT wait_check); | |
23 extern int ReleaseSemaphoreCB(NU_SEMAPHORE *SemCB); | |
24 | |
25 GLOBAL LONG | |
26 os_SendToQueue(OS_HANDLE TaskHandle, OS_HANDLE ComHandle, USHORT Priority, | |
27 ULONG Suspend, OS_QDATA *Msg) | |
28 { | |
29 T_OS_COM_TABLE_ENTRY *pTable; | |
30 T_QDATA_ELEMENT *elem; | |
31 T_QUEUE *queue; | |
32 int ret; | |
33 NU_SEMAPHORE *CBPtr; | |
34 USHORT watmark; | |
35 | |
36 if (ComHandle <= 0 || ComHandle > MaxCommunications) | |
37 return(OS_INVALID_QUEUE); | |
38 pTable = ComTable + ComHandle; | |
39 if (!pTable->Name[0]) | |
40 return(OS_INVALID_QUEUE); | |
41 CBPtr = &pTable->FreeSemCB; | |
42 ret = ObtainSemaphoreCB(CBPtr, Suspend, 1); | |
43 if (ret == OS_ERROR || ret == OS_TIMEOUT) | |
44 return(ret); | |
45 TCT_System_Protect(); | |
46 elem = pTable->pFreeElement; | |
47 pTable->pFreeElement = elem->pNext; | |
48 bcopy(Msg, &elem->Data, sizeof(OS_QDATA)); | |
49 queue = &pTable->Queue[Priority - OS_MIN_PRIORITY]; | |
50 *queue->pWrite++ = &elem->Data; | |
51 if (queue->pWrite - queue->pStart >= pTable->Entries + 1) | |
52 queue->pWrite = queue->pStart; | |
53 watmark = pTable->Entries - CBPtr->sm_semaphore_count; | |
54 if (pTable->MaxUsed < watmark) | |
55 pTable->MaxUsed = watmark; | |
56 TCT_System_Unprotect(); | |
57 ReleaseSemaphoreCB(&pTable->UsedSemCB); | |
58 return(ret); | |
59 } | |
60 | |
61 GLOBAL LONG | |
62 os_ReceiveFromQueue(OS_HANDLE TaskHandle, OS_HANDLE ComHandle, | |
63 OS_QDATA *Msg, ULONG Timeout) | |
64 { | |
65 T_QDATA_ELEMENT *pElem; | |
66 UNSIGNED c_time; | |
67 int ret; | |
68 USHORT i; | |
69 T_QUEUE *pQueue; | |
70 T_OS_COM_TABLE_ENTRY *pTable; | |
71 | |
72 pTable = ComTable + ComHandle; | |
73 if (!pTable->Name[0]) | |
74 return(OS_ERROR); | |
75 pTable->current_msg.type = 0; | |
76 ret = ObtainSemaphoreCB(&pTable->UsedSemCB, Timeout, 0); | |
77 if (ret == OS_ERROR || ret == OS_TIMEOUT) | |
78 return(ret); | |
79 TCT_System_Protect(); | |
80 for (i = OS_MAX_PRIORITY; i >= OS_MIN_PRIORITY; i--) { | |
81 pQueue = &pTable->Queue[i - OS_MIN_PRIORITY]; | |
82 if (pQueue->pWrite != pQueue->pRead) | |
83 break; | |
84 } | |
85 if (i < OS_MIN_PRIORITY) { | |
86 TCT_System_Unprotect(); | |
87 ReleaseSemaphoreCB(&pTable->FreeSemCB); | |
88 return(OS_ERROR); | |
89 } | |
90 bcopy(*pQueue->pRead, Msg, sizeof(OS_QDATA)); | |
91 pElem = (T_QDATA_ELEMENT *)*pQueue->pRead++; | |
92 pElem->Data.data16 = 0; | |
93 pElem->pNext = pTable->pFreeElement; | |
94 pTable->pFreeElement = pElem; | |
95 if (pQueue->pRead - pQueue->pStart >= pTable->Entries + 1) | |
96 pQueue->pRead = pQueue->pStart; | |
97 pTable->current_msg.type = Msg->data16; | |
98 pTable->current_msg.opc = Msg->data32; | |
99 c_time = NU_Retrieve_Clock(); | |
100 pTable->current_msg.time = SYSTEM_TICKS_TO_TIME(c_time); | |
101 pTable->current_msg.ptr = Msg->ptr; | |
102 TCT_System_Unprotect(); | |
103 ReleaseSemaphoreCB(&pTable->FreeSemCB); | |
104 return(OS_OK); | |
105 } |