comparison gpf/osl/os_sem_ir.c @ 0:75a11d740a02

initial import of gsm-fw from freecalypso-sw rev 1033:5ab737ac3ad7
author Mychaela Falconia <falcon@freecalypso.org>
date Thu, 09 Jun 2016 00:02:41 +0000
parents
children
comparison
equal deleted inserted replaced
-1:000000000000 0:75a11d740a02
1 /*
2 * This C module is a reconstruction based on the disassembly of
3 * os_sem.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 "typedefs.h"
12 #include "os.h"
13 #include "gdi.h"
14 #include "os_types.h"
15 #include "os_glob.h"
16
17 extern T_OS_SEM_TABLE_ENTRY SemTable[];
18 extern unsigned os_time_to_tick_multiplier;
19
20 int
21 ReleaseSemaphoreCB(NU_SEMAPHORE *SemCB)
22 {
23 if (NU_Release_Semaphore(SemCB) == NU_SUCCESS)
24 return(OS_OK);
25 else
26 return(OS_ERROR);
27 }
28
29 GLOBAL LONG
30 os_ReleaseSemaphore(OS_HANDLE TaskHandle, OS_HANDLE SemHandle)
31 {
32 if (NU_Release_Semaphore(&SemTable[SemHandle].SemCB) == NU_SUCCESS)
33 return(OS_OK);
34 else
35 return(OS_ERROR);
36 }
37
38 int
39 ObtainSemaphoreCB(NU_SEMAPHORE *SemCB, ULONG Timeout, USHORT wait_check)
40 {
41 UNSIGNED nu_timeout;
42 STATUS sts;
43 int ret;
44
45 ret = OS_OK;
46 if (Timeout != OS_SUSPEND)
47 nu_timeout = TIME_TO_SYSTEM_TICKS(Timeout);
48 else if (wait_check == 1)
49 nu_timeout = 1;
50 else
51 nu_timeout = NU_SUSPEND;
52 for (;;) {
53 sts = NU_Obtain_Semaphore(SemCB, nu_timeout);
54 switch (sts) {
55 case NU_SUCCESS:
56 return(ret);
57 case NU_INVALID_SEMAPHORE:
58 return(OS_ERROR);
59 case NU_INVALID_SUSPEND:
60 nu_timeout = 0;
61 continue;
62 case NU_TIMEOUT:
63 case NU_UNAVAILABLE:
64 if (nu_timeout == 1 && wait_check == 1) {
65 nu_timeout = NU_SUSPEND;
66 ret = OS_WAITED;
67 continue;
68 }
69 return(OS_TIMEOUT);
70 default:
71 /*
72 * Disassembly reveals that the original code
73 * has an endless loop here, the equivalent
74 * of continue. My guess is that they simply
75 * forgot the default case, and so control
76 * falls onto the closing brace of the switch
77 * and then onto the closing brace of the for
78 * loop. But I prefer better error handling,
79 * hence the present addition. - Space Falcon
80 */
81 return(OS_ERROR);
82 }
83 }
84 }
85
86 GLOBAL LONG
87 os_ObtainSemaphore(OS_HANDLE TaskHandle, OS_HANDLE SemHandle, ULONG Timeout)
88 {
89 if (SemHandle > MaxSemaphores)
90 return(OS_ERROR);
91 return ObtainSemaphoreCB(&SemTable[SemHandle].SemCB, Timeout, 0);
92 }