FreeCalypso > hg > fc-tourmaline
comparison src/gpf/osl/os_com_ir.c @ 0:4e78acac3d88
src/{condat,cs,gpf,nucleus}: import from Selenite
| author | Mychaela Falconia <falcon@freecalypso.org> |
|---|---|
| date | Fri, 16 Oct 2020 06:23:26 +0000 |
| parents | |
| children |
comparison
equal
deleted
inserted
replaced
| -1:000000000000 | 0:4e78acac3d88 |
|---|---|
| 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 "nucleus.h" | |
| 10 #include "typedefs.h" | |
| 11 #include "os.h" | |
| 12 #include "gdi.h" | |
| 13 #include "os_types.h" | |
| 14 #include "os_glob.h" | |
| 15 | |
| 16 extern TC_PROTECT TCD_System_Protect; | |
| 17 extern VOID TCT_Protect(TC_PROTECT *protect); | |
| 18 extern VOID TCT_Unprotect(VOID); | |
| 19 extern VOID TCT_Unprotect_Specific(TC_PROTECT *protect); | |
| 20 | |
| 21 #define My_System_Protect() TCT_Protect(&TCD_System_Protect) | |
| 22 #define My_System_Unprotect() TCT_Unprotect_Specific(&TCD_System_Protect) | |
| 23 | |
| 24 extern T_OS_COM_TABLE_ENTRY ComTable[]; | |
| 25 extern unsigned os_tick_to_time_multiplier; | |
| 26 | |
| 27 extern int ObtainSemaphoreCB(NU_SEMAPHORE *SemCB, ULONG Timeout, | |
| 28 USHORT wait_check); | |
| 29 extern int ReleaseSemaphoreCB(NU_SEMAPHORE *SemCB); | |
| 30 | |
| 31 GLOBAL LONG | |
| 32 os_SendToQueue(OS_HANDLE TaskHandle, OS_HANDLE ComHandle, USHORT Priority, | |
| 33 ULONG Suspend, OS_QDATA *Msg) | |
| 34 { | |
| 35 T_OS_COM_TABLE_ENTRY *pTable; | |
| 36 T_QDATA_ELEMENT *elem; | |
| 37 T_QUEUE *queue; | |
| 38 int ret; | |
| 39 NU_SEMAPHORE *CBPtr; | |
| 40 USHORT watmark; | |
| 41 | |
| 42 if (ComHandle <= 0 || ComHandle > MaxCommunications) | |
| 43 return(OS_INVALID_QUEUE); | |
| 44 pTable = ComTable + ComHandle; | |
| 45 if (!pTable->Name[0]) | |
| 46 return(OS_INVALID_QUEUE); | |
| 47 CBPtr = &pTable->FreeSemCB; | |
| 48 ret = ObtainSemaphoreCB(CBPtr, Suspend, 1); | |
| 49 if (ret == OS_ERROR || ret == OS_TIMEOUT) | |
| 50 return(ret); | |
| 51 My_System_Protect(); | |
| 52 elem = pTable->pFreeElement; | |
| 53 pTable->pFreeElement = elem->pNext; | |
| 54 memcpy(&elem->Data, Msg, sizeof(OS_QDATA)); | |
| 55 queue = &pTable->Queue[Priority - OS_MIN_PRIORITY]; | |
| 56 *queue->pWrite++ = &elem->Data; | |
| 57 if (queue->pWrite - queue->pStart >= pTable->Entries + 1) | |
| 58 queue->pWrite = queue->pStart; | |
| 59 watmark = pTable->Entries - CBPtr->sm_semaphore_count; | |
| 60 if (pTable->MaxUsed < watmark) | |
| 61 pTable->MaxUsed = watmark; | |
| 62 My_System_Unprotect(); | |
| 63 ReleaseSemaphoreCB(&pTable->UsedSemCB); | |
| 64 return(ret); | |
| 65 } | |
| 66 | |
| 67 GLOBAL LONG | |
| 68 os_ReceiveFromQueue(OS_HANDLE TaskHandle, OS_HANDLE ComHandle, | |
| 69 OS_QDATA *Msg, ULONG Timeout) | |
| 70 { | |
| 71 T_QDATA_ELEMENT *pElem; | |
| 72 UNSIGNED c_time; | |
| 73 int ret; | |
| 74 USHORT i; | |
| 75 T_QUEUE *pQueue; | |
| 76 T_OS_COM_TABLE_ENTRY *pTable; | |
| 77 | |
| 78 pTable = ComTable + ComHandle; | |
| 79 if (!pTable->Name[0]) | |
| 80 return(OS_ERROR); | |
| 81 pTable->current_msg.type = 0; | |
| 82 ret = ObtainSemaphoreCB(&pTable->UsedSemCB, Timeout, 0); | |
| 83 if (ret == OS_ERROR || ret == OS_TIMEOUT) | |
| 84 return(ret); | |
| 85 My_System_Protect(); | |
| 86 for (i = OS_MAX_PRIORITY; i >= OS_MIN_PRIORITY; i--) { | |
| 87 pQueue = &pTable->Queue[i - OS_MIN_PRIORITY]; | |
| 88 if (pQueue->pWrite != pQueue->pRead) | |
| 89 break; | |
| 90 } | |
| 91 if (i < OS_MIN_PRIORITY) { | |
| 92 My_System_Unprotect(); | |
| 93 ReleaseSemaphoreCB(&pTable->FreeSemCB); | |
| 94 return(OS_ERROR); | |
| 95 } | |
| 96 memcpy(Msg, *pQueue->pRead, sizeof(OS_QDATA)); | |
| 97 pElem = (T_QDATA_ELEMENT *)*pQueue->pRead++; | |
| 98 pElem->Data.data16 = 0; | |
| 99 pElem->pNext = pTable->pFreeElement; | |
| 100 pTable->pFreeElement = pElem; | |
| 101 if (pQueue->pRead - pQueue->pStart >= pTable->Entries + 1) | |
| 102 pQueue->pRead = pQueue->pStart; | |
| 103 pTable->current_msg.type = Msg->data16; | |
| 104 pTable->current_msg.opc = Msg->data32; | |
| 105 c_time = NU_Retrieve_Clock(); | |
| 106 pTable->current_msg.time = SYSTEM_TICKS_TO_TIME(c_time); | |
| 107 pTable->current_msg.ptr = Msg->ptr; | |
| 108 My_System_Unprotect(); | |
| 109 ReleaseSemaphoreCB(&pTable->FreeSemCB); | |
| 110 return(OS_OK); | |
| 111 } |
