FreeCalypso > hg > freecalypso-sw
comparison gsm-fw/gpf/osl/os_com_fl.c @ 352:39b5b18e26b2
os_com_fl.c: os_CreateQueue() done
author | Michael Spacefalcon <msokolov@ivan.Harhan.ORG> |
---|---|
date | Mon, 12 May 2014 00:04:13 +0000 |
parents | fd015570cacc |
children | ee4eb0eacfaf |
comparison
equal
deleted
inserted
replaced
351:fd015570cacc | 352:39b5b18e26b2 |
---|---|
201 ComTable[ComHandle].Name[0] = 0; | 201 ComTable[ComHandle].Name[0] = 0; |
202 if (sts == NU_SUCCESS) | 202 if (sts == NU_SUCCESS) |
203 NU_Release_Semaphore(&ComSemCB); | 203 NU_Release_Semaphore(&ComSemCB); |
204 return(OS_OK); | 204 return(OS_OK); |
205 } | 205 } |
206 | |
207 static short | |
208 InitQueueMemory(OS_HANDLE TaskHandle, OS_HANDLE ComHandle, USHORT Entries, | |
209 OS_HANDLE MemPoolHandle) | |
210 { | |
211 T_QDATA_ELEMENT *pElem; | |
212 OS_QDATA **ptrs; | |
213 USHORT i; | |
214 | |
215 if (os_AllocateMemory(TaskHandle, &ComTable[ComHandle].QueueData, | |
216 sizeof(T_QDATA_ELEMENT) * Entries + | |
217 sizeof(OS_QDATA *) * (Entries + 1) | |
218 * OS_MAX_PRIORITY, | |
219 0, MemPoolHandle) == OS_TIMEOUT) | |
220 return(OS_ERROR); | |
221 pElem = (T_QDATA_ELEMENT *) ComTable[ComHandle].QueueData; | |
222 ComTable[ComHandle].pQueueMemory = pElem; | |
223 ComTable[ComHandle].pFreeElement = pElem; | |
224 for (i = 0; i < Entries; i++) { | |
225 if (i < Entries - 1) | |
226 pElem->pNext = pElem + 1; | |
227 else | |
228 pElem->pNext = pElem; | |
229 pElem++; | |
230 } | |
231 ptrs = (OS_QDATA **) pElem; | |
232 for (i = 0; i < OS_MAX_PRIORITY; i++) { | |
233 ComTable[ComHandle].Queue[i].pStart = ptrs; | |
234 ComTable[ComHandle].Queue[i].pRead = ptrs; | |
235 ComTable[ComHandle].Queue[i].pWrite = ptrs; | |
236 ptrs += Entries + 1; | |
237 } | |
238 return(OS_OK); | |
239 } | |
240 | |
241 GLOBAL LONG | |
242 os_CreateQueue(OS_HANDLE TaskHandle, OS_HANDLE ComHandle, char *Name, | |
243 USHORT Entries, OS_HANDLE *ActHandle, OS_HANDLE MemPoolHandle) | |
244 { | |
245 STATUS sts; | |
246 OS_HANDLE i; | |
247 char Buffer[RESOURCE_NAMELEN + 1]; | |
248 | |
249 if (os_OpenQueue(TaskHandle, Name, ActHandle) == OS_OK) | |
250 return(OS_ERROR); | |
251 if (!Entries) | |
252 return(OS_ERROR); | |
253 sts = NU_Obtain_Semaphore(&ComSemCB, NU_SUSPEND); | |
254 if (!ComHandle) { | |
255 for (i = 1; i <= MaxCommunications; i++) | |
256 if (!ComTable[i].Name[0]) | |
257 goto good_slot; | |
258 release_sem_error: | |
259 if (sts == NU_SUCCESS) | |
260 NU_Release_Semaphore(&ComSemCB); | |
261 return(OS_ERROR); | |
262 } else { | |
263 i = ComHandle; | |
264 if (i > MaxCommunications) | |
265 goto release_sem_error; | |
266 if (ComTable[i].Name[0]) | |
267 goto release_sem_error; | |
268 } | |
269 good_slot: | |
270 if (InitQueueMemory(TaskHandle, i, Entries, MemPoolHandle) == OS_ERROR) | |
271 goto release_sem_error; | |
272 strncpy(Buffer + 1, Name, RESOURCE_NAMELEN - 1); | |
273 Buffer[RESOURCE_NAMELEN] = 0; | |
274 Buffer[0] = 'U'; | |
275 if (NU_Create_Semaphore(&ComTable[i].UsedSemCB, Buffer, 0, NU_PRIORITY) | |
276 != NU_SUCCESS) | |
277 goto release_sem_error; | |
278 Buffer[0] = 'F'; | |
279 if (NU_Create_Semaphore(&ComTable[i].FreeSemCB, Buffer, Entries, | |
280 NU_PRIORITY) != NU_SUCCESS) | |
281 goto release_sem_error; | |
282 strncpy(ComTable[i].Name, Name, RESOURCE_NAMELEN); | |
283 ComTable[i].Name[RESOURCE_NAMELEN-1] = 0; | |
284 *ActHandle = i; | |
285 ComTable[i].Entries = Entries; | |
286 ComTable[i].MaxUsed = 0; | |
287 if (sts == NU_SUCCESS) | |
288 NU_Release_Semaphore(&ComSemCB); | |
289 return(OS_OK); | |
290 } |