Go to the documentation of this file.
56 GRTOS_USER_CRITICAL_SECTION_GET;
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;
69 presource->RCBState = GK_RCBState_SEM;
70 presource->RCBType = GK_RCBType_SEM;
71 presource->RCBWaitingTimeout = (
TIMEPRIORITY) RCBWaitingTimeout;
72 presource->semaphore.SEMMaxCount = initial_count;
74 GRTOS_CMD_CRITICAL_SECTION_RELEASE;
88 if (presource->RCB_NextRCBWEL == (
struct gs_ecb *) 0 &&
89 presource->RCB_NextRCBGEL == (
struct gs_ecb *) 0)
92 return((
INT32) G_TRUE);
94 return((
INT32) G_FALSE);
120 int retorno = G_FALSE;
123 GRTOS_USER_CRITICAL_SECTION_GET;
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;
135 if (presource->RCBCount > 0) {
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) {
144 peventime->ECBValue.i64 = (
INT64) G_LATEST_TIME - (
INT64) 100;
151 pevent->ECBType = G_ECBType_SEM_WAITING;
152 if (blocking == G_TRUE) {
155 pevent->ECBValue.i64 = (
INT64) prrds->RRDSWaitingPriority.i64;
156 if (prrds->RRDSWaitingTimeout.i64 != (
INT64) 0) {
159 peventime->ECBValue.i64 = (
INT64) G_LATEST_TIME - (
INT64) 100;
161 peventime->ECBType = G_ECBType_TIMEOUT_SEM_WAITING;
168 GRTOS_USER_CRITICAL_SECTION_GET;
177 if (pevent->ECBType == G_ECBType_SEM_GRANTED)
182 if (pevent->ECBType == G_ECBType_SEM_WAITING) {
192 GRTOS_CMD_CRITICAL_SECTION_RELEASE;
217 int granted = G_FALSE;
219 GRTOS_USER_CRITICAL_SECTION_GET;
225 if (pevent != (
GS_ECB *) 0) {
227 if (granted == G_TRUE) {
234 GRTOS_CMD_CRITICAL_SECTION_RELEASE; PRINT_DEBUG_LINE
249 return (presource->RCBCount);
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)
274 pevent->ECBType = G_ECBType_SEM_WAITING;
276 if (prrds->RRDSWaitingTimeout.i64 != (
INT64) 0) {
279 peventime->ECBValue.i64 = (
INT64) G_LATEST_TIME - (
INT64) 100;
281 peventime->ECBType = G_ECBType_TIMEOUT_SEM_WAITING;
285 G_DEBUG_WHILEFOREVER;
313 if (peventime->ECBState == GS_ECBState_WAITING_TIME) {
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;
339 switch (presource->RCBType)
342 presource->RCBCount--;
343 pevent->ECBType = G_ECBType_SEM_GRANTED;
344 peventime->ECBType = G_ECBType_TIMEOUT_SEM_GRANTED;
346 if (prrds->RRDSGrantedTimeout.i64 != (
INT64) 0) {
349 peventime->ECBValue.i64 = (
INT64) G_LATEST_TIME - (
INT64) 100;
353 G_DEBUG_WHILEFOREVER;
376 int retorno = G_FALSE;
379 if (pevent->ECB_RRDS == (
struct gs_rrds *) 0) pevent = pevent->ECB_NextECBAEL;
380 peventime = pevent->ECB_NextECBAEL;
383 ptcb = pevent->ECB_AssocTCB;
386 if (pevent->ECB_AssocRCB == (
struct g_rcb *) presource) {
387 switch (presource->RCBType)
390 presource->RCBCount++;
393 G_DEBUG_WHILEFOREVER;
397 if (peventime->ECBState == GS_ECBState_WAITING_TIME) {
402 pevent = presource->RCB_NextRCBWEL;
403 if (pevent != (
GS_ECB *) 0)
409 ptcb = pevent->ECB_AssocTCB;
439 INT64 waiting_priority,
440 INT64 RCBGrantedPriority,
441 INT64 RCBWaitingTimeout,
442 INT64 RCBGrantedTimeout)
452 if (pevent == (
GS_ECB *) 0) {
457 if (peventime == (
GS_ECB *) 0) {
463 pevent->ECB_RRDS = (
struct gs_rrds *) prrds;
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;
515 GS_TCB *ptcb = peventime->ECB_AssocTCB;
519 printf(
"\n\n\n ################## WAITING TIMEOUT ###########\n\n\n");
535 GS_TCB *ptcb = peventime->ECB_AssocTCB;
539 printf(
"\n\n\n ################## GRANTING TIMEOUT ###########\n\n\n");
542 if (psignal != (
struct gs_scb *) 0)
558 gk_TCBWL_Link(ptcb, G_TCBState_WAITING_COMPLETED); PRINT_DEBUG_LINE
struct gs_ecb* ECB_NextECBAEL
Pointer to the event associated with this (ie timeout)
GS_RRDS* gk_RRDS_GetFree(void)
Gets the pointer of a free RRDS from the free list.
INT32 gk_TASK_RESOURCE_UNWAIT(G_RCB *presource, GS_ECB *pevent)
Unlinks the ECB waiting and timed set for waiting a semaphore.
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.
INT32 gk_TCB_Unlink(GS_TCB *ptcb)
Unlinks the TCB according to the list it is linked.
INT32 gk_TCBAEL_Link(GS_ECB *pevent, GS_TCB *ptcb)
Links an ECB to the associated ECB list of TCB.
unsigned long long gt_time
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.
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.
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.
unsigned long long gt_priority
void gk_KERNEL_TASK_SUSPEND_CURRENT(void)
Suspends the execution of the current task and switch to Highest Priority Task.
GS_ECB* gk_TCB_in_RCBGEL(G_RCB *presource, GS_TCB *ptcb)
Returns the event of the TCB that grants the resource.
INT32 gu_sem_post(t_semaphore_resource *presource)
Unlocks the semaphore (release the semaphore). Set ready the task waiting for semaphore.
void gk_RCBWEL_Unlink(GS_ECB *pevent)
Unlinks ECB from RCB waiting list.
INT32 gu_sem_getvalue(t_semaphore_resource *presource)
Return the current value of the semaphore.
INT32 gk_TASK_PRIORITY_SET(GS_TCB *ptcb, INT32 task_state)
Computes the current priority of the task.
INT32 gk_ECBAEL_Link(GS_ECB *pevent1, GS_ECB *pevent2)
GS_ECB Event Control Block structure.
INT32 gk_TCBWL_Link(GS_TCB *ptcb, unsigned int state)
Links a TCB in the waiting list.
INT32 gk_RRDSFL_Link(GS_RRDS *prrds)
Links a RRDS to the Free List.
t_semaphore_resource* gu_sem_create(gt_time RCB_Priority, int initial_count, gt_time RCBWaitingTimeout, gt_time RCBGrantedTimeout)
GS_SCB Signal Control Block structure.
INT32 gk_ECBASL_Unlink(GS_ECB *pevent, GS_SCB *psignal)
Unlinks a signal SCB from the ECB Associated Signal List of and event.
INT32 gk_SEM_granted_kill(GS_ECB *pevent1)
Removes the ECBs from a the granted list of a semaphore resource.
INT32 gk_TCBWL_Unlink(GS_TCB *ptcb)
Unlinks the TCB from the waiting list.
INT32 gk_TCBPSL_Link(GS_TCB *ptcb, GS_SCB *psignal)
Link a SCB to TCB Pending Signal List.
TIMEPRIORITY RRDSGrantedPriority
Priority for granting the resource
INT32 gk_TASK_IS_BLOCKED(GS_TCB *ptcb)
Returns G_TRUE when TCB is blocked waiting for a resource.
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...
union timepriority TIMEPRIORITY
struct g_rgb t_semaphore_resource
INT32 gk_ECBTL_Link(GS_ECB *pevent)
Links the ECB from the Time Event List.
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.
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.
INT32 gk_TASK_RESOURCE_UNGRANT(G_RCB *presource, GS_ECB *pevent)
Unlinks the granted and timed events of a granted task.
GS_TCB* gk_PCB_GetCurrentTCB(void)
Returns the task that the current processor was executing.
TIMEPRIORITY RRDSWaitingPriority
Priority for waiting the resource
INT32 gk_TASK_RESOURCE_WAIT(G_RCB *presource, GS_ECB *pevent)
Sets the waiting and timed event for waiting the semaphore.
INT32 gk_TCBRDYL_Link(GS_TCB *ptcb)
Links the TCB in the Ready Task List sorted by its priority.
GS_RRDS Resource Request Data Structure.
INT32 gk_SEM_waiting_kill(GS_ECB *pevent1)
Removes the ECBs from a the waiting list of a semaphore resource.
INT64 gk_TASK_GRANTED_PRIORITY_GET(GS_TCB *ptcb)
Determine the priority of a taks according to the resources granted.
void gk_RCBGEL_Unlink(GS_ECB *pevent)
Unlinks ECB from RCB granted list.
GEmRTOS CORE definitions.
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.
INT32 gk_RCBFL_Link(G_RCB *presource)
Links the RCB of a resource to Free List.
INT32 gk_ECBFL_Link(GS_ECB *pevent)
Link ECB to Free List. Removes the signals from ECB.
GS_ECB* gk_RCBGEL_Link(G_RCB *presource, GS_ECB *pevent)
Links ECB to RCB granted list and return pointer to the ECB linked.
GS_ECB* gk_ECB_GetFree(void)
Returns a pointer to a Free ECB, NULL if there is not ECB available.
INT32 gk_TASK_RESOURCE_DESTROY(GS_ECB *pevent)
Destroy the events associated to a task and semaphore and returns them to the free lists.
INT32 gk_ECBTL_Unlink(GS_ECB *pevent)
Unlinks the ECB from the Time Event List.
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.
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.