FreeCalypso > hg > freecalypso-sw
comparison gsm-fw/gpf/osl/os_com_ir.c @ 363:28a2965df6aa
OSL: os_ReceiveFromQueue() reconstructed
| author | Michael Spacefalcon <msokolov@ivan.Harhan.ORG> |
|---|---|
| date | Wed, 28 May 2014 22:51:59 +0000 |
| parents | 03d034db09fa |
| children |
comparison
equal
deleted
inserted
replaced
| 362:03d034db09fa | 363:28a2965df6aa |
|---|---|
| 55 pTable->MaxUsed = watmark; | 55 pTable->MaxUsed = watmark; |
| 56 TCT_System_Unprotect(); | 56 TCT_System_Unprotect(); |
| 57 ReleaseSemaphoreCB(&pTable->UsedSemCB); | 57 ReleaseSemaphoreCB(&pTable->UsedSemCB); |
| 58 return(ret); | 58 return(ret); |
| 59 } | 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 } |
