comparison gsm-fw/gpf/osl/os_com_ir.c @ 362:03d034db09fa

OSL: os_SendToQueue() reconstructed
author Michael Spacefalcon <msokolov@ivan.Harhan.ORG>
date Wed, 28 May 2014 19:54:10 +0000
parents 4a92b7261e23
children 28a2965df6aa
comparison
equal deleted inserted replaced
361:62f850da5d49 362:03d034db09fa
6 /* set of included headers from COFF symtab: */ 6 /* set of included headers from COFF symtab: */
7 #include <stdio.h> 7 #include <stdio.h>
8 #include <string.h> 8 #include <string.h>
9 #include "gpfconf.h" /* FreeCalypso addition */ 9 #include "gpfconf.h" /* FreeCalypso addition */
10 #include "../../nucleus/nucleus.h" 10 #include "../../nucleus/nucleus.h"
11 #include "../../nucleus/tc_extr.h" /* not seen in original, but needed */
11 #include "typedefs.h" 12 #include "typedefs.h"
12 #include "os.h" 13 #include "os.h"
13 #include "gdi.h" 14 #include "gdi.h"
14 #include "os_types.h" 15 #include "os_types.h"
15 #include "os_glob.h" 16 #include "os_glob.h"
16 17
17 extern TC_PROTECT TCD_System_Protect;
18 extern T_OS_COM_TABLE_ENTRY ComTable[]; 18 extern T_OS_COM_TABLE_ENTRY ComTable[];
19 extern unsigned os_tick_to_time_multiplier; 19 extern unsigned os_tick_to_time_multiplier;
20 20
21 extern int ObtainSemaphoreCB(NU_SEMAPHORE *SemCB, ULONG Timeout, 21 extern int ObtainSemaphoreCB(NU_SEMAPHORE *SemCB, ULONG Timeout,
22 USHORT wait_check); 22 USHORT wait_check);
25 GLOBAL LONG 25 GLOBAL LONG
26 os_SendToQueue(OS_HANDLE TaskHandle, OS_HANDLE ComHandle, USHORT Priority, 26 os_SendToQueue(OS_HANDLE TaskHandle, OS_HANDLE ComHandle, USHORT Priority,
27 ULONG Suspend, OS_QDATA *Msg) 27 ULONG Suspend, OS_QDATA *Msg)
28 { 28 {
29 T_OS_COM_TABLE_ENTRY *pTable; 29 T_OS_COM_TABLE_ENTRY *pTable;
30 T_QDATA_ELEMENT *pFreeElement, *pRet; 30 T_QDATA_ELEMENT *elem;
31 T_QUEUE *queue;
31 int ret; 32 int ret;
32 NU_SEMAPHORE *CBPtr; 33 NU_SEMAPHORE *CBPtr;
34 USHORT watmark;
33 35
34 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);
35 } 59 }