annotate src/gpf2/osl/os_com_ir.c @ 489:f89439ce0d45

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