GeMRTOS
sem.c
Go to the documentation of this file.
1 
22 /******************************************************************************
23 * *
24 * License Agreement *
25 * Copyright (c) Ricardo L. Cayssials *
26 * All rights reserved. *
27 * *
28 ******************************************************************************/
29 
30 
31 #include <gemrtos_core.h>
32 
34 
35 /***********************************************************************************
36 *********************** SEMAPHORE ***************************
37 ***********************************************************************************/
38 
39 
51  int initial_count,
52  gt_time RCBWaitingTimeout,
53  gt_time RCBGrantedTimeout)
54 {
55  G_RCB *presource = (G_RCB * ) 0;
56  GRTOS_USER_CRITICAL_SECTION_GET;
57  // Get a Free resource
58  presource = gk_RCB_GetFree();
59  if (presource != 0) {
60  // Set the default values of the semaphore
61  presource->RCBCount = initial_count;
62  presource->RCBGrantedPriority = (TIMEPRIORITY) RCB_Priority;
63  presource->RCBGrantedTimeout = (TIMEPRIORITY) RCBGrantedTimeout;
64  presource->RCB_NextRCBGEL = (struct gs_ecb *) 0;
65  presource->RCB_NextRCB = (struct g_rcb *) 0;
66  presource->RCB_NextRCBASL = (struct gs_scb *) 0;
67  presource->RCB_NextRCBWEL = (struct gs_ecb *) 0;
68  presource->RCBPriority = (TIMEPRIORITY) RCB_Priority;
69  presource->RCBState = GK_RCBState_SEM;
70  presource->RCBType = GK_RCBType_SEM;
71  presource->RCBWaitingTimeout = (TIMEPRIORITY) RCBWaitingTimeout;
72  presource->semaphore.SEMMaxCount = initial_count;
73  }
74  GRTOS_CMD_CRITICAL_SECTION_RELEASE;
75  return((t_semaphore_resource *) presource);
76 }
77 
87 {
88  if (presource->RCB_NextRCBWEL == (struct gs_ecb *) 0 &&
89  presource->RCB_NextRCBGEL == (struct gs_ecb *) 0)
90  {
91  gk_RCBFL_Link((G_RCB *) presource);
92  return((INT32) G_TRUE);
93  }
94  return((INT32) G_FALSE);
95 }
96 
110  gt_priority waiting_priority,
111  gt_priority RCBGrantedPriority,
112  gt_time RCBWaitingTimeout,
113  gt_time RCBGrantedTimeout,
114  int blocking)
115 {
116  GS_RRDS *prrds;
117  GS_TCB *ptcb;
118  GS_ECB *pevent;
119  GS_ECB *peventime;
120  int retorno = G_FALSE;
121 
122  if (presource != (t_semaphore_resource *) 0) {
123  GRTOS_USER_CRITICAL_SECTION_GET;
124  ptcb = gk_PCB_GetCurrentTCB();
125  pevent = gk_TASK_RESOURCE_CREATE((G_RCB *) presource,
126  (GS_TCB *) ptcb,
127  (INT64) waiting_priority,
128  (INT64) RCBGrantedPriority,
129  (INT64) RCBWaitingTimeout,
130  (INT64) RCBGrantedTimeout);
131  if (pevent != (GS_ECB *) 0) {
132  peventime = pevent->ECB_NextECBAEL;
133  prrds = (GS_RRDS *) pevent->ECB_RRDS;
134 
135  if (presource->RCBCount > 0) {
136  // gk_TASK_RESOURCE_GRANT(presource, pevent);
137  presource->RCBCount--;
138  pevent->ECBType = G_ECBType_SEM_GRANTED;
139  peventime->ECBType = G_ECBType_TIMEOUT_SEM_GRANTED;
140  pevent->ECBValue.i64 = (INT64) prrds->RRDSGrantedPriority.i64;
141  if (prrds->RRDSGrantedTimeout.i64 != (INT64) 0) {
142  peventime->ECBValue.i64 = (INT64) GRTOS_now + (INT64) prrds->RRDSGrantedTimeout.i64;
143  } else {
144  peventime->ECBValue.i64 = (INT64) G_LATEST_TIME - (INT64) 100;
145  }
146  gk_RCBGEL_Link((G_RCB *) presource, pevent);
147  gk_ECBTL_Link(peventime);
148  retorno = G_TRUE; // resource available granted without waiting
149 
150  } else {
151  pevent->ECBType = G_ECBType_SEM_WAITING;
152  if (blocking == G_TRUE) {
153  // gk_TASK_RESOURCE_WAIT((G_RCB *)presource, (GS_ECB *) pevent);
154  // pevent->ECBType = G_ECBType_SEM_WAITING;
155  pevent->ECBValue.i64 = (INT64) prrds->RRDSWaitingPriority.i64; // Insert it in waiting event list
156  if (prrds->RRDSWaitingTimeout.i64 != (INT64) 0) {
157  peventime->ECBValue.i64 = (INT64) GRTOS_now + (INT64) prrds->RRDSWaitingTimeout.i64;
158  } else {
159  peventime->ECBValue.i64 = (INT64) G_LATEST_TIME - (INT64) 100;
160  }
161  peventime->ECBType = G_ECBType_TIMEOUT_SEM_WAITING;
162  gk_ECBTL_Link(peventime);
163  gk_RCBWEL_Link((G_RCB *) presource, pevent);
164 
165  gk_KERNEL_TASK_SUSPEND_CURRENT(); //Switch tasks
166  // #################################################
167  // #################################################
168  GRTOS_USER_CRITICAL_SECTION_GET;
169  // 1) Resource was granted
170  // pevent->ECBState = GS_ECBState_GRANTED_RESOURCE
171  // pevent->ECBType = G_ECBType_SEM_GRANTED
172  // peventime->ECBState = GS_ECBState_WAITING_TIME
173  // 2) Waiting Timeout happened (gk_timeout_ECB_SEM_wait was executed)
174  // pevent->ECBState = GS_ECBState_UNLINKED
175  // peventime->ECBState = GS_ECBState_UNLINKED
176 
177  if (pevent->ECBType == G_ECBType_SEM_GRANTED)
178  { // The resource is granted to task
179  retorno = G_TRUE; // resource available after waiting
180  }
181  }
182  if (pevent->ECBType == G_ECBType_SEM_WAITING) {
183  gk_TASK_RESOURCE_DESTROY((GS_ECB *) pevent);
184  retorno = G_FALSE; // resource no available without waiting
185  }
186  }
187  }
188  else
189  {
190  retorno = G_FALSE; // no control blocks for task resource
191  }
192  GRTOS_CMD_CRITICAL_SECTION_RELEASE;
193  }
194  else
195  {
196  retorno = G_FALSE; // presource is not a valid resource
197  }
198  return retorno;
199 }
200 
201 // #################################################
202 
212 {
213  GS_TCB *ptcb;
214  // GS_RRDS *prrds;
215  GS_ECB *pevent;
216  // GS_ECB *peventime;
217  int granted = G_FALSE;
218 
219  GRTOS_USER_CRITICAL_SECTION_GET;
220 
221  ptcb = gk_PCB_GetCurrentTCB(); PRINT_DEBUG_LINE
222 
223  //Check if task is granted for this resource
224  pevent = gk_TCB_in_RCBGEL((G_RCB *) presource, ptcb);
225  if (pevent != (GS_ECB *) 0) {
226  granted = gk_TASK_RESOURCE_UNGRANT((G_RCB *) presource, (GS_ECB *) pevent);
227  if (granted == G_TRUE) {
228  gk_TASK_RESOURCE_DESTROY((GS_ECB *) pevent);
229  // peventime = pevent->ECB_NextECBAEL;
230  // gk_ECBFL_Link(peventime);
231  // gk_ECBFL_Link(pevent);
232  }
233  }
234  GRTOS_CMD_CRITICAL_SECTION_RELEASE; PRINT_DEBUG_LINE
235 
236  return(G_TRUE);
237 }
238 
248 {
249  return (presource->RCBCount);
250 }
251 
252 
263 {
264  GS_ECB *peventime;
265  GS_RRDS *prrds;
266 
267  // Event with ECB_RRDS != 0 is the resource event, otherwise time event
268  if (pevent->ECB_RRDS == (struct gs_rrds *) 0) pevent = pevent->ECB_NextECBAEL;
269  peventime = pevent->ECB_NextECBAEL;
270  prrds = (GS_RRDS *) pevent->ECB_RRDS;
271  switch (presource->RCBType)
272  {
273  case GK_RCBType_SEM:
274  pevent->ECBType = G_ECBType_SEM_WAITING;
275  pevent->ECBValue.i64 = (INT64) prrds->RRDSWaitingPriority.i64; // Insert it in waiting event list
276  if (prrds->RRDSWaitingTimeout.i64 != (INT64) 0) {
277  peventime->ECBValue.i64 = (INT64) GRTOS_now + (INT64) prrds->RRDSWaitingTimeout.i64;
278  } else {
279  peventime->ECBValue.i64 = (INT64) G_LATEST_TIME - (INT64) 100;
280  }
281  peventime->ECBType = G_ECBType_TIMEOUT_SEM_WAITING;
282  break;
283 
284  default:
285  G_DEBUG_WHILEFOREVER;
286  break;
287  }
288  gk_ECBTL_Link(peventime);
289  gk_RCBWEL_Link((G_RCB *) presource, pevent);
290 
291  gk_KERNEL_TASK_SUSPEND_CURRENT(); //Switch tasks
292  return(G_TRUE);
293 }
294 
305 {
306  GS_ECB * peventime;
307 
308  // Event with ECB_RRDS != 0 is the resource event, otherwise time event
309  if (pevent->ECB_RRDS == (struct gs_rrds *) 0) pevent = pevent->ECB_NextECBAEL;
310  peventime = pevent->ECB_NextECBAEL;
311 
312  gk_RCBWEL_Unlink(pevent); PRINT_DEBUG_LINE // It is waiting: unlink from waiting list
313  if (peventime->ECBState == GS_ECBState_WAITING_TIME) {
314  gk_ECBTL_Unlink(peventime); PRINT_DEBUG_LINE // Unlink waiting timeout event
315  }
316  return(G_TRUE);
317 }
318 
329 {
330  GS_ECB * peventime;
331  GS_RRDS *prrds;
332 
333  // Event with ECB_RRDS != 0 is the resource event, otherwise time event
334  if (pevent->ECB_RRDS == (struct gs_rrds *) 0) pevent = pevent->ECB_NextECBAEL;
335  peventime = pevent->ECB_NextECBAEL;
336  prrds = (GS_RRDS *) pevent->ECB_RRDS;
337 
338  // Assign event type according the resource type
339  switch (presource->RCBType)
340  {
341  case GK_RCBType_SEM:
342  presource->RCBCount--;
343  pevent->ECBType = G_ECBType_SEM_GRANTED;
344  peventime->ECBType = G_ECBType_TIMEOUT_SEM_GRANTED;
345  pevent->ECBValue.i64 = (INT64) prrds->RRDSGrantedPriority.i64;
346  if (prrds->RRDSGrantedTimeout.i64 != (INT64) 0) {
347  peventime->ECBValue.i64 = (INT64) GRTOS_now + (INT64) prrds->RRDSGrantedTimeout.i64;
348  } else {
349  peventime->ECBValue.i64 = (INT64) G_LATEST_TIME - (INT64) 100;
350  }
351  break;
352  default:
353  G_DEBUG_WHILEFOREVER;
354  break;
355  }
356  // Link the events
357  gk_RCBGEL_Link((G_RCB *) presource, pevent);
358  gk_ECBTL_Link(peventime);
359  return(G_TRUE);
360 }
361 
372 {
373  GS_ECB * peventime;
374  // GS_RRDS *prrds;
375  GS_TCB *ptcb;
376  int retorno = G_FALSE;
377 
378  // Event with ECB_RRDS != 0 is the resource event, otherwise time event
379  if (pevent->ECB_RRDS == (struct gs_rrds *) 0) pevent = pevent->ECB_NextECBAEL;
380  peventime = pevent->ECB_NextECBAEL;
381  // prrds = (GS_RRDS *) pevent->ECB_RRDS;
382 
383  ptcb = pevent->ECB_AssocTCB;
384 
385  //Check if task is granted for this resource
386  if (pevent->ECB_AssocRCB == (struct g_rcb *) presource) {
387  switch (presource->RCBType)
388  {
389  case GK_RCBType_SEM:
390  presource->RCBCount++;
391  break;
392  default:
393  G_DEBUG_WHILEFOREVER;
394  break;
395  }
396  gk_RCBGEL_Unlink(pevent);
397  if (peventime->ECBState == GS_ECBState_WAITING_TIME) {
398  gk_ECBTL_Unlink(peventime);
399  }
400 
401  // Check if there is a waiting task
402  pevent = presource->RCB_NextRCBWEL;
403  if (pevent != (GS_ECB *) 0)
404  {
405  gk_TASK_RESOURCE_UNWAIT((G_RCB *) presource, (GS_ECB *) pevent);
406  gk_TASK_RESOURCE_GRANT((G_RCB *)presource, (GS_ECB *) pevent);
407 
408  // Check if inheriate priority of the task changes
409  ptcb = pevent->ECB_AssocTCB;
410  ptcb->TCBInherPriority = gk_TASK_GRANTED_PRIORITY_GET(ptcb);
411  gk_TCBWL_Unlink(ptcb);
412  gk_TASK_PRIORITY_SET(ptcb, G_TCBState_READY);
413  gk_TCBRDYL_Link(ptcb);
414  }
415  retorno = G_TRUE;
416  }
417 
418  return retorno;
419 }
420 
421 
422 
423 //
438  GS_TCB *ptcb,
439  INT64 waiting_priority,
440  INT64 RCBGrantedPriority,
441  INT64 RCBWaitingTimeout,
442  INT64 RCBGrantedTimeout)
443 {
444  GS_RRDS *prrds;
445  GS_ECB *pevent;
446  GS_ECB *peventime;
447 
448  prrds = gk_RRDS_GetFree();
449  if (prrds == (GS_RRDS *) 0) return (GS_ECB *) 0;
450 
451  pevent = gk_ECB_GetFree();
452  if (pevent == (GS_ECB *) 0) {
453  gk_RRDSFL_Link(prrds);
454  return (GS_ECB *) 0;
455  }
456  peventime = gk_ECB_GetFree();
457  if (peventime == (GS_ECB *) 0) {
458  gk_RRDSFL_Link(prrds);
459  gk_ECBFL_Link(pevent);
460  return (GS_ECB *) 0;
461  }
462 
463  pevent->ECB_RRDS = (struct gs_rrds *) prrds; // Set resource request properties
464  prrds->RRDSWaitingPriority.i64 = (INT64) waiting_priority;
465  prrds->RRDSGrantedPriority.i64 = (INT64) RCBGrantedPriority;
466  prrds->RRDSWaitingTimeout.i64 = (INT64) RCBWaitingTimeout;
467  prrds->RRDSGrantedTimeout.i64 = (INT64) RCBGrantedTimeout;
468  prrds->RRDS_NextSCB = (struct gs_scb *) 0;
469 
470  gk_TCBAEL_Link(peventime,ptcb);
471  gk_TCBAEL_Link(pevent,ptcb);
472  gk_ECBAEL_Link(pevent, peventime);
473 
474  return pevent;
475 }
476 
487 {
488  GS_ECB * peventime;
489  // GS_RRDS *prrds;
490  // GS_TCB *ptcb;
491  // int retorno = G_FALSE;
492 
493  // Event with ECB_RRDS != 0 is the resource event, otherwise time event
494  if (pevent->ECB_RRDS == (struct gs_rrds *) 0) pevent = pevent->ECB_NextECBAEL;
495  peventime = pevent->ECB_NextECBAEL;
496 
497  gk_ECBFL_Link(peventime);
498  gk_ECBFL_Link(pevent);
499  return(G_TRUE);
500 }
501 
502 
503 
513 
514  GS_ECB *pevent = peventime->ECB_NextECBAEL; PRINT_DEBUG_LINE // Get the associated event linked to resource
515  GS_TCB *ptcb = peventime->ECB_AssocTCB;
516 
517  gk_TASK_RESOURCE_UNWAIT((G_RCB *) pevent->ECB_AssocRCB, (GS_ECB *) pevent);
518 
519  printf("\n\n\n ################## WAITING TIMEOUT ###########\n\n\n");
520  gk_TCB_Unlink(ptcb); PRINT_DEBUG_LINE
521  gk_TCBRDYL_Link(ptcb); PRINT_DEBUG_LINE
522  return G_TRUE;
523 }
524 
534  GS_ECB *pevent = peventime->ECB_NextECBAEL;
535  GS_TCB *ptcb = peventime->ECB_AssocTCB;
536  GS_SCB *psignal = gk_ECBASL_GetSCB(peventime, G_ECBType_TIMEOUT_SEM_GRANTED);
537 
538  /* It is the timeout of a waiting event *************************************/
539  printf("\n\n\n ################## GRANTING TIMEOUT ###########\n\n\n");
540 
541  /* It is the timeout of a waiting event *************************************/
542  if (psignal != (struct gs_scb *) 0)
543  {
544  gk_ECBASL_Unlink(peventime, psignal); PRINT_DEBUG_LINE
545  gk_TCBPSL_Link(ptcb, psignal); PRINT_DEBUG_LINE
546  }
547 
548  gk_TASK_RESOURCE_UNGRANT((G_RCB *) pevent->ECB_AssocRCB, (GS_ECB *) pevent);
549  gk_TASK_RESOURCE_DESTROY((GS_ECB *) pevent);
550 
551  gk_TCB_Unlink(ptcb); PRINT_DEBUG_LINE
552  if (gk_TASK_IS_BLOCKED(ptcb) == G_FALSE)
553  {
554  gk_TCBRDYL_Link(ptcb); PRINT_DEBUG_LINE
555  }
556  else
557  {
558  gk_TCBWL_Link(ptcb, G_TCBState_WAITING_COMPLETED); PRINT_DEBUG_LINE
559  }
560  return(G_TRUE);
561 }
562 
574  int granted;
575  granted = gk_TASK_RESOURCE_UNGRANT((G_RCB *) pevent1->ECB_AssocRCB, (GS_ECB *) pevent1);
576  if (granted == G_TRUE) gk_TASK_RESOURCE_DESTROY((GS_ECB *) pevent1);
577  return G_TRUE;
578 }
579 
591  gk_TASK_RESOURCE_UNWAIT((G_RCB *) pevent1->ECB_AssocRCB, (GS_ECB *) pevent1);
592  gk_TASK_RESOURCE_DESTROY((GS_ECB *) pevent1);
593  return G_TRUE;
594 }
595 
596 OPTIMEZE_RESTORE
gs_ecb::ECB_NextECBAEL
struct gs_ecb* ECB_NextECBAEL
Pointer to the event associated with this (ie timeout)
Definition: gemrtos_core.h:119
INT32
unsigned INT32
Definition: gemrtos_core.h:62
RRDS::gk_RRDS_GetFree
GS_RRDS* gk_RRDS_GetFree(void)
Gets the pointer of a free RRDS from the free list.
Definition: gemrtos_core.c:230
Semaphore::gk_TASK_RESOURCE_UNWAIT
INT32 gk_TASK_RESOURCE_UNWAIT(G_RCB *presource, GS_ECB *pevent)
Unlinks the ECB waiting and timed set for waiting a semaphore.
Definition: sem.c:304
Semaphore::gk_timeout_ECB_SEM_post
INT32 gk_timeout_ECB_SEM_post(GS_ECB *peventime)
Time routine for event G_ECBType_TIMEOUT_SEM_GRANTED. It is called from the time interrupt ISR.
Definition: sem.c:533
GS_TCB
struct gs_tcb GS_TCB
Definition: gemrtos_core.h:50
Task::gk_TCB_Unlink
INT32 gk_TCB_Unlink(GS_TCB *ptcb)
Unlinks the TCB according to the list it is linked.
Definition: listfunctions.c:2550
Task::gk_TCBAEL_Link
INT32 gk_TCBAEL_Link(GS_ECB *pevent, GS_TCB *ptcb)
Links an ECB to the associated ECB list of TCB.
Definition: listfunctions.c:1284
gt_time
unsigned long long gt_time
Definition: gemrtos_core.h:65
Semaphore::gk_TASK_RESOURCE_GRANT
INT32 gk_TASK_RESOURCE_GRANT(G_RCB *presource, GS_ECB *pevent)
Sets the granted and timed events when a semaphore is granted to a TCB.
Definition: sem.c:328
Time::GRTOS_now
GRTOS_now({ \ TIMEPRIORITY value64 \ do { \ value64.i32[1] = (unsigned) IORD(GRTOS_DRIVER_GRTOS_BASE, ADDR_TM_CNT_HGH) \ value64.i32[0] = (unsigned) IORD(GRTOS_DRIVER_GRTOS_BASE, ADDR_SMP) \ } while(0) \ value64.i64 \ })
GRTOS_now Return the current system time.
Definition: grtos_regs.h:97
Resource::gk_RCB_GetFree
G_RCB* gk_RCB_GetFree(void)
Unlinks an RCB from the RCBFL list and returns its pointer or NULL if no free RCB is available.
Definition: gemrtos_core.c:155
gt_priority
unsigned long long gt_priority
Definition: gemrtos_core.h:66
gk_KERNEL_TASK_SUSPEND_CURRENT
void gk_KERNEL_TASK_SUSPEND_CURRENT(void)
Suspends the execution of the current task and switch to Highest Priority Task.
Definition: grtos_kernel.c:502
Task::gk_TCB_in_RCBGEL
GS_ECB* gk_TCB_in_RCBGEL(G_RCB *presource, GS_TCB *ptcb)
Returns the event of the TCB that grants the resource.
Definition: listfunctions.c:2081
Semaphore::gu_sem_post
INT32 gu_sem_post(t_semaphore_resource *presource)
Unlocks the semaphore (release the semaphore). Set ready the task waiting for semaphore.
Definition: sem.c:211
Event::gk_RCBWEL_Unlink
void gk_RCBWEL_Unlink(GS_ECB *pevent)
Unlinks ECB from RCB waiting list.
Definition: listfunctions.c:1135
Semaphore::gu_sem_getvalue
INT32 gu_sem_getvalue(t_semaphore_resource *presource)
Return the current value of the semaphore.
Definition: sem.c:247
Task::gk_TASK_PRIORITY_SET
INT32 gk_TASK_PRIORITY_SET(GS_TCB *ptcb, INT32 task_state)
Computes the current priority of the task.
Definition: listfunctions.c:2474
gk_ECBAEL_Link
INT32 gk_ECBAEL_Link(GS_ECB *pevent1, GS_ECB *pevent2)
gs_ecb
GS_ECB Event Control Block structure.
Definition: gemrtos_core.h:107
Task::gk_TCBWL_Link
INT32 gk_TCBWL_Link(GS_TCB *ptcb, unsigned int state)
Links a TCB in the waiting list.
Definition: listfunctions.c:1990
gk_RRDSFL_Link
INT32 gk_RRDSFL_Link(GS_RRDS *prrds)
Links a RRDS to the Free List.
Definition: listfunctions.c:2105
gu_sem_create
t_semaphore_resource* gu_sem_create(gt_time RCB_Priority, int initial_count, gt_time RCBWaitingTimeout, gt_time RCBGrantedTimeout)
gs_scb
GS_SCB Signal Control Block structure.
Definition: gemrtos_core.h:393
GS_SCB
struct gs_scb GS_SCB
Definition: gemrtos_core.h:52
Event::gk_ECBASL_Unlink
INT32 gk_ECBASL_Unlink(GS_ECB *pevent, GS_SCB *psignal)
Unlinks a signal SCB from the ECB Associated Signal List of and event.
Definition: listfunctions.c:203
Semaphore::gk_SEM_granted_kill
INT32 gk_SEM_granted_kill(GS_ECB *pevent1)
Removes the ECBs from a the granted list of a semaphore resource.
Definition: sem.c:573
Task::gk_TCBWL_Unlink
INT32 gk_TCBWL_Unlink(GS_TCB *ptcb)
Unlinks the TCB from the waiting list.
Definition: listfunctions.c:2020
GS_RRDS
struct gs_rrds GS_RRDS
Definition: gemrtos_core.h:53
Task::gk_TCBPSL_Link
INT32 gk_TCBPSL_Link(GS_TCB *ptcb, GS_SCB *psignal)
Link a SCB to TCB Pending Signal List.
Definition: listfunctions.c:1543
gs_rrds::RRDSGrantedPriority
TIMEPRIORITY RRDSGrantedPriority
Priority for granting the resource
Definition: gemrtos_core.h:376
Resource::gk_TASK_IS_BLOCKED
INT32 gk_TASK_IS_BLOCKED(GS_TCB *ptcb)
Returns G_TRUE when TCB is blocked waiting for a resource.
Definition: listfunctions.c:2046
Resource::gk_RCBWEL_Link
GS_ECB* gk_RCBWEL_Link(G_RCB *presource, GS_ECB *pevent)
Links an event ECB to the resource waiting list of RCB. If no ECB is given then a new ECB is obtained...
Definition: listfunctions.c:1054
TIMEPRIORITY
union timepriority TIMEPRIORITY
t_semaphore_resource
struct g_rgb t_semaphore_resource
Definition: gemrtos_core.h:57
Event::gk_ECBTL_Link
INT32 gk_ECBTL_Link(GS_ECB *pevent)
Links the ECB from the Time Event List.
Definition: listfunctions.c:355
Semaphore::gu_sem_destroy
INT32 gu_sem_destroy(t_semaphore_resource *presource)
Links the RCB of a semaphore to the free list if there is no event granted or waiting.
Definition: sem.c:86
Semaphore::gk_timeout_ECB_SEM_wait
INT32 gk_timeout_ECB_SEM_wait(GS_ECB *peventime)
Time routine for event G_ECBType_TIMEOUT_SEM_WAITING. It is called from the time interrupt ISR.
Definition: sem.c:512
Semaphore::gk_TASK_RESOURCE_UNGRANT
INT32 gk_TASK_RESOURCE_UNGRANT(G_RCB *presource, GS_ECB *pevent)
Unlinks the granted and timed events of a granted task.
Definition: sem.c:371
INT64
unsigned long long INT64
Definition: gemrtos_core.h:61
Task::gk_PCB_GetCurrentTCB
GS_TCB* gk_PCB_GetCurrentTCB(void)
Returns the task that the current processor was executing.
Definition: listfunctions.c:2262
gs_rrds::RRDSWaitingPriority
TIMEPRIORITY RRDSWaitingPriority
Priority for waiting the resource
Definition: gemrtos_core.h:375
GS_ECB
struct gs_ecb GS_ECB
Definition: gemrtos_core.h:51
Semaphore::gk_TASK_RESOURCE_WAIT
INT32 gk_TASK_RESOURCE_WAIT(G_RCB *presource, GS_ECB *pevent)
Sets the waiting and timed event for waiting the semaphore.
Definition: sem.c:262
Task::gk_TCBRDYL_Link
INT32 gk_TCBRDYL_Link(GS_TCB *ptcb)
Links the TCB in the Ready Task List sorted by its priority.
Definition: listfunctions.c:1653
gs_rrds
GS_RRDS Resource Request Data Structure.
Definition: gemrtos_core.h:357
Semaphore::OPTIMEZE_CODE
OPTIMEZE_CODE(3)
Definition: sem.c:33
Semaphore::gk_SEM_waiting_kill
INT32 gk_SEM_waiting_kill(GS_ECB *pevent1)
Removes the ECBs from a the waiting list of a semaphore resource.
Definition: sem.c:590
Task::gk_TASK_GRANTED_PRIORITY_GET
INT64 gk_TASK_GRANTED_PRIORITY_GET(GS_TCB *ptcb)
Determine the priority of a taks according to the resources granted.
Definition: listfunctions.c:2912
Event::gk_RCBGEL_Unlink
void gk_RCBGEL_Unlink(GS_ECB *pevent)
Unlinks ECB from RCB granted list.
Definition: listfunctions.c:1012
gemrtos_core.h
GEmRTOS CORE definitions.
Semaphore::gk_TASK_RESOURCE_CREATE
GS_ECB* gk_TASK_RESOURCE_CREATE(G_RCB *presource, GS_TCB *ptcb, INT64 waiting_priority, INT64 RCBGrantedPriority, INT64 RCBWaitingTimeout, INT64 RCBGrantedTimeout)
Creates the structure to sopport a resource from a task.
Definition: sem.c:437
Resource::gk_RCBFL_Link
INT32 gk_RCBFL_Link(G_RCB *presource)
Links the RCB of a resource to Free List.
Definition: listfunctions.c:851
Event::gk_ECBFL_Link
INT32 gk_ECBFL_Link(GS_ECB *pevent)
Link ECB to Free List. Removes the signals from ECB.
Definition: listfunctions.c:324
Resource::gk_RCBGEL_Link
GS_ECB* gk_RCBGEL_Link(G_RCB *presource, GS_ECB *pevent)
Links ECB to RCB granted list and return pointer to the ECB linked.
Definition: listfunctions.c:935
Event::gk_ECB_GetFree
GS_ECB* gk_ECB_GetFree(void)
Returns a pointer to a Free ECB, NULL if there is not ECB available.
Definition: gemrtos_core.c:107
G_RCB
struct g_rgb G_RCB
Definition: gemrtos_core.h:54
Semaphore::gk_TASK_RESOURCE_DESTROY
INT32 gk_TASK_RESOURCE_DESTROY(GS_ECB *pevent)
Destroy the events associated to a task and semaphore and returns them to the free lists.
Definition: sem.c:486
Event::gk_ECBTL_Unlink
INT32 gk_ECBTL_Unlink(GS_ECB *pevent)
Unlinks the ECB from the Time Event List.
Definition: listfunctions.c:405
Event::gk_ECBASL_GetSCB
GS_SCB* gk_ECBASL_GetSCB(GS_ECB *pecb, INT32 SignalType)
Returns a pointer to the GS_SCB in the associated GS_SCBs of an event or NULL if any.
Definition: listfunctions.c:2740
Resource::gu_sem_wait
INT32 gu_sem_wait(t_semaphore_resource *presource, gt_priority waiting_priority, gt_priority RCBGrantedPriority, gt_time RCBWaitingTimeout, gt_time RCBGrantedTimeout, int blocking)
Lock the semaphore (get the semaphore) if it is avaible, otherwise waits for grant it.
Definition: sem.c:109