annotate src/gpf2/osl/os_sem_fl.c @ 680:ee3ac8c617cb

armio.c: set GPIO2 output high initially On TI-canonical platforms GPIO2 is DCD modem control output. In TI's original code the AI_InitIOConfig() function called from Init_Target() would configure GPIO2 as an output and set the initial output value to low, but then the init code in uartfax.c called from Init_Serial_Flows() would immediately change it to high, corresponding to DCD not asserted. The result is a momentary asserted-state glitch on the DCD output. The present change eliminates this glitch, setting DCD output to not-asserted initially like it should be.
author Mychaela Falconia <falcon@freecalypso.org>
date Thu, 25 Jun 2020 03:17:43 +0000
parents 27db9775cbab
children
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_sem.obj in frame_na7_db_fl.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>
499
27db9775cbab OSL: os_sem_fl.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_SEM_TABLE_ENTRY SemTable[];
91e8dac34ada src/gpf2/osl: initial import from old freecalypso-sw tree
Mychaela Falconia <falcon@freecalypso.org>
parents:
diff changeset
17
91e8dac34ada src/gpf2/osl: initial import from old freecalypso-sw tree
Mychaela Falconia <falcon@freecalypso.org>
parents:
diff changeset
18 static NU_SEMAPHORE SemSemCB;
91e8dac34ada src/gpf2/osl: initial import from old freecalypso-sw tree
Mychaela Falconia <falcon@freecalypso.org>
parents:
diff changeset
19
91e8dac34ada src/gpf2/osl: initial import from old freecalypso-sw tree
Mychaela Falconia <falcon@freecalypso.org>
parents:
diff changeset
20 static int
91e8dac34ada src/gpf2/osl: initial import from old freecalypso-sw tree
Mychaela Falconia <falcon@freecalypso.org>
parents:
diff changeset
21 os_GetSemaphoreEntry(USHORT Index, OS_HANDLE *Handle)
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 static USHORT Idx;
91e8dac34ada src/gpf2/osl: initial import from old freecalypso-sw tree
Mychaela Falconia <falcon@freecalypso.org>
parents:
diff changeset
24
91e8dac34ada src/gpf2/osl: initial import from old freecalypso-sw tree
Mychaela Falconia <falcon@freecalypso.org>
parents:
diff changeset
25 if (Index == FIRST_ENTRY)
91e8dac34ada src/gpf2/osl: initial import from old freecalypso-sw tree
Mychaela Falconia <falcon@freecalypso.org>
parents:
diff changeset
26 Idx = 0;
91e8dac34ada src/gpf2/osl: initial import from old freecalypso-sw tree
Mychaela Falconia <falcon@freecalypso.org>
parents:
diff changeset
27 if (Index == FIRST_ENTRY || Index == NEXT_ENTRY) {
91e8dac34ada src/gpf2/osl: initial import from old freecalypso-sw tree
Mychaela Falconia <falcon@freecalypso.org>
parents:
diff changeset
28 for (;;) {
91e8dac34ada src/gpf2/osl: initial import from old freecalypso-sw tree
Mychaela Falconia <falcon@freecalypso.org>
parents:
diff changeset
29 Idx++;
91e8dac34ada src/gpf2/osl: initial import from old freecalypso-sw tree
Mychaela Falconia <falcon@freecalypso.org>
parents:
diff changeset
30 if (Idx > MaxSemaphores)
91e8dac34ada src/gpf2/osl: initial import from old freecalypso-sw tree
Mychaela Falconia <falcon@freecalypso.org>
parents:
diff changeset
31 return(OS_ERROR);
91e8dac34ada src/gpf2/osl: initial import from old freecalypso-sw tree
Mychaela Falconia <falcon@freecalypso.org>
parents:
diff changeset
32 if (SemTable[Idx].Name[0])
91e8dac34ada src/gpf2/osl: initial import from old freecalypso-sw tree
Mychaela Falconia <falcon@freecalypso.org>
parents:
diff changeset
33 break;
91e8dac34ada src/gpf2/osl: initial import from old freecalypso-sw tree
Mychaela Falconia <falcon@freecalypso.org>
parents:
diff changeset
34 }
91e8dac34ada src/gpf2/osl: initial import from old freecalypso-sw tree
Mychaela Falconia <falcon@freecalypso.org>
parents:
diff changeset
35 } else
91e8dac34ada src/gpf2/osl: initial import from old freecalypso-sw tree
Mychaela Falconia <falcon@freecalypso.org>
parents:
diff changeset
36 Idx = Index;
91e8dac34ada src/gpf2/osl: initial import from old freecalypso-sw tree
Mychaela Falconia <falcon@freecalypso.org>
parents:
diff changeset
37 if (Idx > MaxSemaphores)
91e8dac34ada src/gpf2/osl: initial import from old freecalypso-sw tree
Mychaela Falconia <falcon@freecalypso.org>
parents:
diff changeset
38 return(OS_ERROR);
91e8dac34ada src/gpf2/osl: initial import from old freecalypso-sw tree
Mychaela Falconia <falcon@freecalypso.org>
parents:
diff changeset
39 if (SemTable[Idx].Name[0]) {
91e8dac34ada src/gpf2/osl: initial import from old freecalypso-sw tree
Mychaela Falconia <falcon@freecalypso.org>
parents:
diff changeset
40 *Handle = Idx;
91e8dac34ada src/gpf2/osl: initial import from old freecalypso-sw tree
Mychaela Falconia <falcon@freecalypso.org>
parents:
diff changeset
41 return(OS_OK);
91e8dac34ada src/gpf2/osl: initial import from old freecalypso-sw tree
Mychaela Falconia <falcon@freecalypso.org>
parents:
diff changeset
42 } else
91e8dac34ada src/gpf2/osl: initial import from old freecalypso-sw tree
Mychaela Falconia <falcon@freecalypso.org>
parents:
diff changeset
43 return(OS_ERROR);
91e8dac34ada src/gpf2/osl: initial import from old freecalypso-sw tree
Mychaela Falconia <falcon@freecalypso.org>
parents:
diff changeset
44 }
91e8dac34ada src/gpf2/osl: initial import from old freecalypso-sw tree
Mychaela Falconia <falcon@freecalypso.org>
parents:
diff changeset
45
91e8dac34ada src/gpf2/osl: initial import from old freecalypso-sw tree
Mychaela Falconia <falcon@freecalypso.org>
parents:
diff changeset
46 GLOBAL LONG
91e8dac34ada src/gpf2/osl: initial import from old freecalypso-sw tree
Mychaela Falconia <falcon@freecalypso.org>
parents:
diff changeset
47 os_SemaphoreInformation(USHORT Index, char *Buffer)
91e8dac34ada src/gpf2/osl: initial import from old freecalypso-sw tree
Mychaela Falconia <falcon@freecalypso.org>
parents:
diff changeset
48 {
91e8dac34ada src/gpf2/osl: initial import from old freecalypso-sw tree
Mychaela Falconia <falcon@freecalypso.org>
parents:
diff changeset
49 OS_HANDLE Handle;
91e8dac34ada src/gpf2/osl: initial import from old freecalypso-sw tree
Mychaela Falconia <falcon@freecalypso.org>
parents:
diff changeset
50 OPTION SuspendType;
91e8dac34ada src/gpf2/osl: initial import from old freecalypso-sw tree
Mychaela Falconia <falcon@freecalypso.org>
parents:
diff changeset
51 UNSIGNED Current, TasksWaiting;
91e8dac34ada src/gpf2/osl: initial import from old freecalypso-sw tree
Mychaela Falconia <falcon@freecalypso.org>
parents:
diff changeset
52 NU_TASK *First;
91e8dac34ada src/gpf2/osl: initial import from old freecalypso-sw tree
Mychaela Falconia <falcon@freecalypso.org>
parents:
diff changeset
53 CHAR Name[NU_MAX_NAME];
91e8dac34ada src/gpf2/osl: initial import from old freecalypso-sw tree
Mychaela Falconia <falcon@freecalypso.org>
parents:
diff changeset
54
91e8dac34ada src/gpf2/osl: initial import from old freecalypso-sw tree
Mychaela Falconia <falcon@freecalypso.org>
parents:
diff changeset
55 if (os_GetSemaphoreEntry(Index, &Handle) < 0)
91e8dac34ada src/gpf2/osl: initial import from old freecalypso-sw tree
Mychaela Falconia <falcon@freecalypso.org>
parents:
diff changeset
56 return(OS_ERROR);
91e8dac34ada src/gpf2/osl: initial import from old freecalypso-sw tree
Mychaela Falconia <falcon@freecalypso.org>
parents:
diff changeset
57 if (NU_Semaphore_Information(&SemTable[Handle].SemCB, Name, &Current,
91e8dac34ada src/gpf2/osl: initial import from old freecalypso-sw tree
Mychaela Falconia <falcon@freecalypso.org>
parents:
diff changeset
58 &SuspendType, &TasksWaiting, &First)
91e8dac34ada src/gpf2/osl: initial import from old freecalypso-sw tree
Mychaela Falconia <falcon@freecalypso.org>
parents:
diff changeset
59 != NU_SUCCESS)
91e8dac34ada src/gpf2/osl: initial import from old freecalypso-sw tree
Mychaela Falconia <falcon@freecalypso.org>
parents:
diff changeset
60 return(OS_ERROR);
91e8dac34ada src/gpf2/osl: initial import from old freecalypso-sw tree
Mychaela Falconia <falcon@freecalypso.org>
parents:
diff changeset
61 sprintf(Buffer, "Semname:%s Count:%ld Suspend:%d Waiting:%ld", Name,
91e8dac34ada src/gpf2/osl: initial import from old freecalypso-sw tree
Mychaela Falconia <falcon@freecalypso.org>
parents:
diff changeset
62 Current, SuspendType, TasksWaiting);
91e8dac34ada src/gpf2/osl: initial import from old freecalypso-sw tree
Mychaela Falconia <falcon@freecalypso.org>
parents:
diff changeset
63 return(OS_OK);
91e8dac34ada src/gpf2/osl: initial import from old freecalypso-sw tree
Mychaela Falconia <falcon@freecalypso.org>
parents:
diff changeset
64 }
91e8dac34ada src/gpf2/osl: initial import from old freecalypso-sw tree
Mychaela Falconia <falcon@freecalypso.org>
parents:
diff changeset
65
91e8dac34ada src/gpf2/osl: initial import from old freecalypso-sw tree
Mychaela Falconia <falcon@freecalypso.org>
parents:
diff changeset
66 GLOBAL LONG
91e8dac34ada src/gpf2/osl: initial import from old freecalypso-sw tree
Mychaela Falconia <falcon@freecalypso.org>
parents:
diff changeset
67 os_SemInit(void)
91e8dac34ada src/gpf2/osl: initial import from old freecalypso-sw tree
Mychaela Falconia <falcon@freecalypso.org>
parents:
diff changeset
68 {
91e8dac34ada src/gpf2/osl: initial import from old freecalypso-sw tree
Mychaela Falconia <falcon@freecalypso.org>
parents:
diff changeset
69 USHORT i;
91e8dac34ada src/gpf2/osl: initial import from old freecalypso-sw tree
Mychaela Falconia <falcon@freecalypso.org>
parents:
diff changeset
70
91e8dac34ada src/gpf2/osl: initial import from old freecalypso-sw tree
Mychaela Falconia <falcon@freecalypso.org>
parents:
diff changeset
71 if (NU_Create_Semaphore(&SemSemCB, "SEMSEM", 1, NU_PRIORITY)
91e8dac34ada src/gpf2/osl: initial import from old freecalypso-sw tree
Mychaela Falconia <falcon@freecalypso.org>
parents:
diff changeset
72 != NU_SUCCESS)
91e8dac34ada src/gpf2/osl: initial import from old freecalypso-sw tree
Mychaela Falconia <falcon@freecalypso.org>
parents:
diff changeset
73 return(OS_ERROR);
91e8dac34ada src/gpf2/osl: initial import from old freecalypso-sw tree
Mychaela Falconia <falcon@freecalypso.org>
parents:
diff changeset
74 for (i = 1; i <= MaxSemaphores; i++)
499
27db9775cbab OSL: os_sem_fl.c compiles
Mychaela Falconia <falcon@freecalypso.org>
parents: 487
diff changeset
75 memset(&SemTable[i], 0, sizeof(T_OS_SEM_TABLE_ENTRY));
487
91e8dac34ada src/gpf2/osl: initial import from old freecalypso-sw tree
Mychaela Falconia <falcon@freecalypso.org>
parents:
diff changeset
76 return(OS_OK);
91e8dac34ada src/gpf2/osl: initial import from old freecalypso-sw tree
Mychaela Falconia <falcon@freecalypso.org>
parents:
diff changeset
77 }
91e8dac34ada src/gpf2/osl: initial import from old freecalypso-sw tree
Mychaela Falconia <falcon@freecalypso.org>
parents:
diff changeset
78
91e8dac34ada src/gpf2/osl: initial import from old freecalypso-sw tree
Mychaela Falconia <falcon@freecalypso.org>
parents:
diff changeset
79 GLOBAL LONG
91e8dac34ada src/gpf2/osl: initial import from old freecalypso-sw tree
Mychaela Falconia <falcon@freecalypso.org>
parents:
diff changeset
80 os_ResetSemaphore(OS_HANDLE TaskHandle, OS_HANDLE SemHandle,
91e8dac34ada src/gpf2/osl: initial import from old freecalypso-sw tree
Mychaela Falconia <falcon@freecalypso.org>
parents:
diff changeset
81 USHORT init_counter)
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 STATUS sts;
91e8dac34ada src/gpf2/osl: initial import from old freecalypso-sw tree
Mychaela Falconia <falcon@freecalypso.org>
parents:
diff changeset
84
91e8dac34ada src/gpf2/osl: initial import from old freecalypso-sw tree
Mychaela Falconia <falcon@freecalypso.org>
parents:
diff changeset
85 sts = NU_Obtain_Semaphore(&SemSemCB, NU_SUSPEND);
91e8dac34ada src/gpf2/osl: initial import from old freecalypso-sw tree
Mychaela Falconia <falcon@freecalypso.org>
parents:
diff changeset
86 if (!SemTable[SemHandle].Name[0]) {
91e8dac34ada src/gpf2/osl: initial import from old freecalypso-sw tree
Mychaela Falconia <falcon@freecalypso.org>
parents:
diff changeset
87 error_out: if (sts == NU_SUCCESS)
91e8dac34ada src/gpf2/osl: initial import from old freecalypso-sw tree
Mychaela Falconia <falcon@freecalypso.org>
parents:
diff changeset
88 NU_Release_Semaphore(&SemSemCB);
91e8dac34ada src/gpf2/osl: initial import from old freecalypso-sw tree
Mychaela Falconia <falcon@freecalypso.org>
parents:
diff changeset
89 return(OS_ERROR);
91e8dac34ada src/gpf2/osl: initial import from old freecalypso-sw tree
Mychaela Falconia <falcon@freecalypso.org>
parents:
diff changeset
90 }
91e8dac34ada src/gpf2/osl: initial import from old freecalypso-sw tree
Mychaela Falconia <falcon@freecalypso.org>
parents:
diff changeset
91 if (NU_Reset_Semaphore(&SemTable[SemHandle].SemCB, init_counter)
91e8dac34ada src/gpf2/osl: initial import from old freecalypso-sw tree
Mychaela Falconia <falcon@freecalypso.org>
parents:
diff changeset
92 != NU_SUCCESS)
91e8dac34ada src/gpf2/osl: initial import from old freecalypso-sw tree
Mychaela Falconia <falcon@freecalypso.org>
parents:
diff changeset
93 goto error_out;
91e8dac34ada src/gpf2/osl: initial import from old freecalypso-sw tree
Mychaela Falconia <falcon@freecalypso.org>
parents:
diff changeset
94 if (sts == NU_SUCCESS)
91e8dac34ada src/gpf2/osl: initial import from old freecalypso-sw tree
Mychaela Falconia <falcon@freecalypso.org>
parents:
diff changeset
95 NU_Release_Semaphore(&SemSemCB);
91e8dac34ada src/gpf2/osl: initial import from old freecalypso-sw tree
Mychaela Falconia <falcon@freecalypso.org>
parents:
diff changeset
96 return(OS_OK);
91e8dac34ada src/gpf2/osl: initial import from old freecalypso-sw tree
Mychaela Falconia <falcon@freecalypso.org>
parents:
diff changeset
97 }
91e8dac34ada src/gpf2/osl: initial import from old freecalypso-sw tree
Mychaela Falconia <falcon@freecalypso.org>
parents:
diff changeset
98
91e8dac34ada src/gpf2/osl: initial import from old freecalypso-sw tree
Mychaela Falconia <falcon@freecalypso.org>
parents:
diff changeset
99 GLOBAL LONG
91e8dac34ada src/gpf2/osl: initial import from old freecalypso-sw tree
Mychaela Falconia <falcon@freecalypso.org>
parents:
diff changeset
100 os_QuerySemaphore(OS_HANDLE TaskHandle, OS_HANDLE SemHandle, USHORT *Count)
91e8dac34ada src/gpf2/osl: initial import from old freecalypso-sw tree
Mychaela Falconia <falcon@freecalypso.org>
parents:
diff changeset
101 {
91e8dac34ada src/gpf2/osl: initial import from old freecalypso-sw tree
Mychaela Falconia <falcon@freecalypso.org>
parents:
diff changeset
102 OPTION SuspendType;
91e8dac34ada src/gpf2/osl: initial import from old freecalypso-sw tree
Mychaela Falconia <falcon@freecalypso.org>
parents:
diff changeset
103 UNSIGNED SemCount, TasksWaiting;
91e8dac34ada src/gpf2/osl: initial import from old freecalypso-sw tree
Mychaela Falconia <falcon@freecalypso.org>
parents:
diff changeset
104 NU_TASK *First;
91e8dac34ada src/gpf2/osl: initial import from old freecalypso-sw tree
Mychaela Falconia <falcon@freecalypso.org>
parents:
diff changeset
105 CHAR Name[NU_MAX_NAME];
91e8dac34ada src/gpf2/osl: initial import from old freecalypso-sw tree
Mychaela Falconia <falcon@freecalypso.org>
parents:
diff changeset
106
91e8dac34ada src/gpf2/osl: initial import from old freecalypso-sw tree
Mychaela Falconia <falcon@freecalypso.org>
parents:
diff changeset
107 if (NU_Semaphore_Information(&SemTable[SemHandle].SemCB, Name,
91e8dac34ada src/gpf2/osl: initial import from old freecalypso-sw tree
Mychaela Falconia <falcon@freecalypso.org>
parents:
diff changeset
108 &SemCount, &SuspendType, &TasksWaiting,
91e8dac34ada src/gpf2/osl: initial import from old freecalypso-sw tree
Mychaela Falconia <falcon@freecalypso.org>
parents:
diff changeset
109 &First) != NU_SUCCESS)
91e8dac34ada src/gpf2/osl: initial import from old freecalypso-sw tree
Mychaela Falconia <falcon@freecalypso.org>
parents:
diff changeset
110 return(OS_ERROR);
91e8dac34ada src/gpf2/osl: initial import from old freecalypso-sw tree
Mychaela Falconia <falcon@freecalypso.org>
parents:
diff changeset
111 *Count = SemCount;
91e8dac34ada src/gpf2/osl: initial import from old freecalypso-sw tree
Mychaela Falconia <falcon@freecalypso.org>
parents:
diff changeset
112 return(OS_OK);
91e8dac34ada src/gpf2/osl: initial import from old freecalypso-sw tree
Mychaela Falconia <falcon@freecalypso.org>
parents:
diff changeset
113 }
91e8dac34ada src/gpf2/osl: initial import from old freecalypso-sw tree
Mychaela Falconia <falcon@freecalypso.org>
parents:
diff changeset
114
91e8dac34ada src/gpf2/osl: initial import from old freecalypso-sw tree
Mychaela Falconia <falcon@freecalypso.org>
parents:
diff changeset
115 GLOBAL LONG
91e8dac34ada src/gpf2/osl: initial import from old freecalypso-sw tree
Mychaela Falconia <falcon@freecalypso.org>
parents:
diff changeset
116 os_OpenSemaphore(OS_HANDLE TaskHandle, char *Name, OS_HANDLE *SemHandle)
91e8dac34ada src/gpf2/osl: initial import from old freecalypso-sw tree
Mychaela Falconia <falcon@freecalypso.org>
parents:
diff changeset
117 {
91e8dac34ada src/gpf2/osl: initial import from old freecalypso-sw tree
Mychaela Falconia <falcon@freecalypso.org>
parents:
diff changeset
118 USHORT i;
91e8dac34ada src/gpf2/osl: initial import from old freecalypso-sw tree
Mychaela Falconia <falcon@freecalypso.org>
parents:
diff changeset
119
91e8dac34ada src/gpf2/osl: initial import from old freecalypso-sw tree
Mychaela Falconia <falcon@freecalypso.org>
parents:
diff changeset
120 for (i = 1; i <= MaxSemaphores; i++) {
91e8dac34ada src/gpf2/osl: initial import from old freecalypso-sw tree
Mychaela Falconia <falcon@freecalypso.org>
parents:
diff changeset
121 if (!SemTable[i].Name[0])
91e8dac34ada src/gpf2/osl: initial import from old freecalypso-sw tree
Mychaela Falconia <falcon@freecalypso.org>
parents:
diff changeset
122 continue;
91e8dac34ada src/gpf2/osl: initial import from old freecalypso-sw tree
Mychaela Falconia <falcon@freecalypso.org>
parents:
diff changeset
123 if (strncmp(Name, SemTable[i].Name, RESOURCE_NAMELEN-1))
91e8dac34ada src/gpf2/osl: initial import from old freecalypso-sw tree
Mychaela Falconia <falcon@freecalypso.org>
parents:
diff changeset
124 continue;
91e8dac34ada src/gpf2/osl: initial import from old freecalypso-sw tree
Mychaela Falconia <falcon@freecalypso.org>
parents:
diff changeset
125 *SemHandle = i;
91e8dac34ada src/gpf2/osl: initial import from old freecalypso-sw tree
Mychaela Falconia <falcon@freecalypso.org>
parents:
diff changeset
126 return(OS_OK);
91e8dac34ada src/gpf2/osl: initial import from old freecalypso-sw tree
Mychaela Falconia <falcon@freecalypso.org>
parents:
diff changeset
127 }
91e8dac34ada src/gpf2/osl: initial import from old freecalypso-sw tree
Mychaela Falconia <falcon@freecalypso.org>
parents:
diff changeset
128 return(OS_ERROR);
91e8dac34ada src/gpf2/osl: initial import from old freecalypso-sw tree
Mychaela Falconia <falcon@freecalypso.org>
parents:
diff changeset
129 }
91e8dac34ada src/gpf2/osl: initial import from old freecalypso-sw tree
Mychaela Falconia <falcon@freecalypso.org>
parents:
diff changeset
130
91e8dac34ada src/gpf2/osl: initial import from old freecalypso-sw tree
Mychaela Falconia <falcon@freecalypso.org>
parents:
diff changeset
131 GLOBAL unsigned char *
91e8dac34ada src/gpf2/osl: initial import from old freecalypso-sw tree
Mychaela Falconia <falcon@freecalypso.org>
parents:
diff changeset
132 os_FindSuspendingSema(unsigned int *tcb)
91e8dac34ada src/gpf2/osl: initial import from old freecalypso-sw tree
Mychaela Falconia <falcon@freecalypso.org>
parents:
diff changeset
133 {
91e8dac34ada src/gpf2/osl: initial import from old freecalypso-sw tree
Mychaela Falconia <falcon@freecalypso.org>
parents:
diff changeset
134 USHORT i;
91e8dac34ada src/gpf2/osl: initial import from old freecalypso-sw tree
Mychaela Falconia <falcon@freecalypso.org>
parents:
diff changeset
135 SM_SUSPEND *susp, *susp_loopchk;
91e8dac34ada src/gpf2/osl: initial import from old freecalypso-sw tree
Mychaela Falconia <falcon@freecalypso.org>
parents:
diff changeset
136
91e8dac34ada src/gpf2/osl: initial import from old freecalypso-sw tree
Mychaela Falconia <falcon@freecalypso.org>
parents:
diff changeset
137 for (i = 1; i <= MaxSemaphores; i++) {
91e8dac34ada src/gpf2/osl: initial import from old freecalypso-sw tree
Mychaela Falconia <falcon@freecalypso.org>
parents:
diff changeset
138 if (!SemTable[i].Name[0])
91e8dac34ada src/gpf2/osl: initial import from old freecalypso-sw tree
Mychaela Falconia <falcon@freecalypso.org>
parents:
diff changeset
139 continue;
91e8dac34ada src/gpf2/osl: initial import from old freecalypso-sw tree
Mychaela Falconia <falcon@freecalypso.org>
parents:
diff changeset
140 susp = SemTable[i].SemCB.sm_suspension_list;
91e8dac34ada src/gpf2/osl: initial import from old freecalypso-sw tree
Mychaela Falconia <falcon@freecalypso.org>
parents:
diff changeset
141 if (!susp)
91e8dac34ada src/gpf2/osl: initial import from old freecalypso-sw tree
Mychaela Falconia <falcon@freecalypso.org>
parents:
diff changeset
142 continue;
91e8dac34ada src/gpf2/osl: initial import from old freecalypso-sw tree
Mychaela Falconia <falcon@freecalypso.org>
parents:
diff changeset
143 if (susp->sm_suspended_task == (NU_TASK *)tcb)
499
27db9775cbab OSL: os_sem_fl.c compiles
Mychaela Falconia <falcon@freecalypso.org>
parents: 487
diff changeset
144 return((unsigned char *) SemTable[i].SemCB.sm_name);
487
91e8dac34ada src/gpf2/osl: initial import from old freecalypso-sw tree
Mychaela Falconia <falcon@freecalypso.org>
parents:
diff changeset
145 susp = (SM_SUSPEND *)susp->sm_suspend_link.cs_next;
91e8dac34ada src/gpf2/osl: initial import from old freecalypso-sw tree
Mychaela Falconia <falcon@freecalypso.org>
parents:
diff changeset
146 for (susp_loopchk = susp; susp != susp_loopchk;
91e8dac34ada src/gpf2/osl: initial import from old freecalypso-sw tree
Mychaela Falconia <falcon@freecalypso.org>
parents:
diff changeset
147 susp = (SM_SUSPEND *)susp->sm_suspend_link.cs_next)
91e8dac34ada src/gpf2/osl: initial import from old freecalypso-sw tree
Mychaela Falconia <falcon@freecalypso.org>
parents:
diff changeset
148 if (susp->sm_suspended_task == (NU_TASK *)tcb)
499
27db9775cbab OSL: os_sem_fl.c compiles
Mychaela Falconia <falcon@freecalypso.org>
parents: 487
diff changeset
149 return((unsigned char *)
27db9775cbab OSL: os_sem_fl.c compiles
Mychaela Falconia <falcon@freecalypso.org>
parents: 487
diff changeset
150 SemTable[i].SemCB.sm_name);
487
91e8dac34ada src/gpf2/osl: initial import from old freecalypso-sw tree
Mychaela Falconia <falcon@freecalypso.org>
parents:
diff changeset
151 }
91e8dac34ada src/gpf2/osl: initial import from old freecalypso-sw tree
Mychaela Falconia <falcon@freecalypso.org>
parents:
diff changeset
152 return(0);
91e8dac34ada src/gpf2/osl: initial import from old freecalypso-sw tree
Mychaela Falconia <falcon@freecalypso.org>
parents:
diff changeset
153 }
91e8dac34ada src/gpf2/osl: initial import from old freecalypso-sw tree
Mychaela Falconia <falcon@freecalypso.org>
parents:
diff changeset
154
91e8dac34ada src/gpf2/osl: initial import from old freecalypso-sw tree
Mychaela Falconia <falcon@freecalypso.org>
parents:
diff changeset
155 GLOBAL LONG
91e8dac34ada src/gpf2/osl: initial import from old freecalypso-sw tree
Mychaela Falconia <falcon@freecalypso.org>
parents:
diff changeset
156 os_DestroySemaphore(OS_HANDLE TaskHandle, OS_HANDLE SemHandle)
91e8dac34ada src/gpf2/osl: initial import from old freecalypso-sw tree
Mychaela Falconia <falcon@freecalypso.org>
parents:
diff changeset
157 {
91e8dac34ada src/gpf2/osl: initial import from old freecalypso-sw tree
Mychaela Falconia <falcon@freecalypso.org>
parents:
diff changeset
158 STATUS sts;
91e8dac34ada src/gpf2/osl: initial import from old freecalypso-sw tree
Mychaela Falconia <falcon@freecalypso.org>
parents:
diff changeset
159
91e8dac34ada src/gpf2/osl: initial import from old freecalypso-sw tree
Mychaela Falconia <falcon@freecalypso.org>
parents:
diff changeset
160 sts = NU_Obtain_Semaphore(&SemSemCB, NU_SUSPEND);
91e8dac34ada src/gpf2/osl: initial import from old freecalypso-sw tree
Mychaela Falconia <falcon@freecalypso.org>
parents:
diff changeset
161 if (!SemTable[SemHandle].Name[0]) {
91e8dac34ada src/gpf2/osl: initial import from old freecalypso-sw tree
Mychaela Falconia <falcon@freecalypso.org>
parents:
diff changeset
162 error_out: if (sts == NU_SUCCESS)
91e8dac34ada src/gpf2/osl: initial import from old freecalypso-sw tree
Mychaela Falconia <falcon@freecalypso.org>
parents:
diff changeset
163 NU_Release_Semaphore(&SemSemCB);
91e8dac34ada src/gpf2/osl: initial import from old freecalypso-sw tree
Mychaela Falconia <falcon@freecalypso.org>
parents:
diff changeset
164 return(OS_ERROR);
91e8dac34ada src/gpf2/osl: initial import from old freecalypso-sw tree
Mychaela Falconia <falcon@freecalypso.org>
parents:
diff changeset
165 }
91e8dac34ada src/gpf2/osl: initial import from old freecalypso-sw tree
Mychaela Falconia <falcon@freecalypso.org>
parents:
diff changeset
166 if (NU_Delete_Semaphore(&SemTable[SemHandle].SemCB) != NU_SUCCESS)
91e8dac34ada src/gpf2/osl: initial import from old freecalypso-sw tree
Mychaela Falconia <falcon@freecalypso.org>
parents:
diff changeset
167 goto error_out;
91e8dac34ada src/gpf2/osl: initial import from old freecalypso-sw tree
Mychaela Falconia <falcon@freecalypso.org>
parents:
diff changeset
168 SemTable[SemHandle].Name[0] = 0;
91e8dac34ada src/gpf2/osl: initial import from old freecalypso-sw tree
Mychaela Falconia <falcon@freecalypso.org>
parents:
diff changeset
169 if (sts == NU_SUCCESS)
91e8dac34ada src/gpf2/osl: initial import from old freecalypso-sw tree
Mychaela Falconia <falcon@freecalypso.org>
parents:
diff changeset
170 NU_Release_Semaphore(&SemSemCB);
91e8dac34ada src/gpf2/osl: initial import from old freecalypso-sw tree
Mychaela Falconia <falcon@freecalypso.org>
parents:
diff changeset
171 return(OS_OK);
91e8dac34ada src/gpf2/osl: initial import from old freecalypso-sw tree
Mychaela Falconia <falcon@freecalypso.org>
parents:
diff changeset
172 }
91e8dac34ada src/gpf2/osl: initial import from old freecalypso-sw tree
Mychaela Falconia <falcon@freecalypso.org>
parents:
diff changeset
173
91e8dac34ada src/gpf2/osl: initial import from old freecalypso-sw tree
Mychaela Falconia <falcon@freecalypso.org>
parents:
diff changeset
174 GLOBAL LONG
91e8dac34ada src/gpf2/osl: initial import from old freecalypso-sw tree
Mychaela Falconia <falcon@freecalypso.org>
parents:
diff changeset
175 os_CreateSemaphore(OS_HANDLE TaskHandle, char *Name, USHORT Count,
91e8dac34ada src/gpf2/osl: initial import from old freecalypso-sw tree
Mychaela Falconia <falcon@freecalypso.org>
parents:
diff changeset
176 OS_HANDLE *SemHandle, OS_HANDLE MemPoolHandle)
91e8dac34ada src/gpf2/osl: initial import from old freecalypso-sw tree
Mychaela Falconia <falcon@freecalypso.org>
parents:
diff changeset
177 {
91e8dac34ada src/gpf2/osl: initial import from old freecalypso-sw tree
Mychaela Falconia <falcon@freecalypso.org>
parents:
diff changeset
178 USHORT i;
91e8dac34ada src/gpf2/osl: initial import from old freecalypso-sw tree
Mychaela Falconia <falcon@freecalypso.org>
parents:
diff changeset
179 STATUS sts;
91e8dac34ada src/gpf2/osl: initial import from old freecalypso-sw tree
Mychaela Falconia <falcon@freecalypso.org>
parents:
diff changeset
180
91e8dac34ada src/gpf2/osl: initial import from old freecalypso-sw tree
Mychaela Falconia <falcon@freecalypso.org>
parents:
diff changeset
181 if (os_OpenSemaphore(TaskHandle, Name, SemHandle) == OS_OK)
91e8dac34ada src/gpf2/osl: initial import from old freecalypso-sw tree
Mychaela Falconia <falcon@freecalypso.org>
parents:
diff changeset
182 return(OS_ERROR);
91e8dac34ada src/gpf2/osl: initial import from old freecalypso-sw tree
Mychaela Falconia <falcon@freecalypso.org>
parents:
diff changeset
183 sts = NU_Obtain_Semaphore(&SemSemCB, NU_SUSPEND);
91e8dac34ada src/gpf2/osl: initial import from old freecalypso-sw tree
Mychaela Falconia <falcon@freecalypso.org>
parents:
diff changeset
184 for (i = 1; i <= MaxSemaphores; i++) {
91e8dac34ada src/gpf2/osl: initial import from old freecalypso-sw tree
Mychaela Falconia <falcon@freecalypso.org>
parents:
diff changeset
185 if (SemTable[i].Name[0])
91e8dac34ada src/gpf2/osl: initial import from old freecalypso-sw tree
Mychaela Falconia <falcon@freecalypso.org>
parents:
diff changeset
186 continue;
91e8dac34ada src/gpf2/osl: initial import from old freecalypso-sw tree
Mychaela Falconia <falcon@freecalypso.org>
parents:
diff changeset
187 if (NU_Create_Semaphore(&SemTable[i].SemCB, Name, Count,
91e8dac34ada src/gpf2/osl: initial import from old freecalypso-sw tree
Mychaela Falconia <falcon@freecalypso.org>
parents:
diff changeset
188 NU_PRIORITY) != NU_SUCCESS)
91e8dac34ada src/gpf2/osl: initial import from old freecalypso-sw tree
Mychaela Falconia <falcon@freecalypso.org>
parents:
diff changeset
189 break;
91e8dac34ada src/gpf2/osl: initial import from old freecalypso-sw tree
Mychaela Falconia <falcon@freecalypso.org>
parents:
diff changeset
190 strncpy(SemTable[i].Name, Name, RESOURCE_NAMELEN);
91e8dac34ada src/gpf2/osl: initial import from old freecalypso-sw tree
Mychaela Falconia <falcon@freecalypso.org>
parents:
diff changeset
191 SemTable[i].Name[RESOURCE_NAMELEN-1] = 0;
91e8dac34ada src/gpf2/osl: initial import from old freecalypso-sw tree
Mychaela Falconia <falcon@freecalypso.org>
parents:
diff changeset
192 *SemHandle = i;
91e8dac34ada src/gpf2/osl: initial import from old freecalypso-sw tree
Mychaela Falconia <falcon@freecalypso.org>
parents:
diff changeset
193 if (sts == NU_SUCCESS)
91e8dac34ada src/gpf2/osl: initial import from old freecalypso-sw tree
Mychaela Falconia <falcon@freecalypso.org>
parents:
diff changeset
194 NU_Release_Semaphore(&SemSemCB);
91e8dac34ada src/gpf2/osl: initial import from old freecalypso-sw tree
Mychaela Falconia <falcon@freecalypso.org>
parents:
diff changeset
195 return(OS_OK);
91e8dac34ada src/gpf2/osl: initial import from old freecalypso-sw tree
Mychaela Falconia <falcon@freecalypso.org>
parents:
diff changeset
196 }
91e8dac34ada src/gpf2/osl: initial import from old freecalypso-sw tree
Mychaela Falconia <falcon@freecalypso.org>
parents:
diff changeset
197 if (sts == NU_SUCCESS)
91e8dac34ada src/gpf2/osl: initial import from old freecalypso-sw tree
Mychaela Falconia <falcon@freecalypso.org>
parents:
diff changeset
198 NU_Release_Semaphore(&SemSemCB);
91e8dac34ada src/gpf2/osl: initial import from old freecalypso-sw tree
Mychaela Falconia <falcon@freecalypso.org>
parents:
diff changeset
199 return(OS_ERROR);
91e8dac34ada src/gpf2/osl: initial import from old freecalypso-sw tree
Mychaela Falconia <falcon@freecalypso.org>
parents:
diff changeset
200 }
91e8dac34ada src/gpf2/osl: initial import from old freecalypso-sw tree
Mychaela Falconia <falcon@freecalypso.org>
parents:
diff changeset
201
91e8dac34ada src/gpf2/osl: initial import from old freecalypso-sw tree
Mychaela Falconia <falcon@freecalypso.org>
parents:
diff changeset
202 GLOBAL LONG
91e8dac34ada src/gpf2/osl: initial import from old freecalypso-sw tree
Mychaela Falconia <falcon@freecalypso.org>
parents:
diff changeset
203 os_CloseSemaphore(OS_HANDLE TaskHandle, OS_HANDLE SemHandle)
91e8dac34ada src/gpf2/osl: initial import from old freecalypso-sw tree
Mychaela Falconia <falcon@freecalypso.org>
parents:
diff changeset
204 {
91e8dac34ada src/gpf2/osl: initial import from old freecalypso-sw tree
Mychaela Falconia <falcon@freecalypso.org>
parents:
diff changeset
205 return(OS_OK);
91e8dac34ada src/gpf2/osl: initial import from old freecalypso-sw tree
Mychaela Falconia <falcon@freecalypso.org>
parents:
diff changeset
206 }