uint8_t OSSchedule(void) { uint8_t TaskSelect = 0xFF; uint8_t Priority = 0; Priority = SAScheduler(OSReadyList & OSBlockedList); TaskSelect = PriorityVector[Priority]; return TaskSelect; }
INT8U OSSchedule(void) { INT8U TaskSelect = 0xFF; INT8U Priority = 0; Priority = SAScheduler(OSReadyList & OSBlockedList); TaskSelect = PriorityVector[Priority]; return TaskSelect; }
INT8U OSSemPost(BRTOS_Sem *pont_event) { OS_SR_SAVE_VAR INT8U iPriority = (INT8U)0; #if (VERBOSE == 1) INT8U TaskSelect = 0; #endif #if (ERROR_CHECK == 1) // Verifies if the pointer is NULL if(pont_event == NULL) { return(NULL_EVENT_POINTER); } #endif // Enter Critical Section #if (NESTING_INT == 0) if (!iNesting) #endif OSEnterCritical(); #if (ERROR_CHECK == 1) // Verifies if the event is allocated if(pont_event->OSEventAllocated != TRUE) { // Exit Critical Section #if (NESTING_INT == 0) if (!iNesting) #endif OSExitCritical(); return(ERR_EVENT_NO_CREATED); } #endif // BRTOS TRACE SUPPORT #if (OSTRACE == 1) if(!iNesting){ #if(OS_TRACE_BY_TASK == 1) Update_OSTrace(currentTask, SEMPOST); #else Update_OSTrace(ContextTask[currentTask].Priority, SEMPOST); #endif }else{ Update_OSTrace(0, SEMPOST); } #endif // See if any task is waiting for semaphore if (pont_event->OSEventWait != 0) { // Selects the highest priority task iPriority = SAScheduler(pont_event->OSEventWaitList); // Remove the selected task from the semaphore wait list pont_event->OSEventWaitList = pont_event->OSEventWaitList & ~(PriorityMask[iPriority]); // Decreases the semaphore wait list counter pont_event->OSEventWait--; // Put the selected task into Ready List #if (VERBOSE == 1) TaskSelect = PriorityVector[iPriority]; ContextTask[TaskSelect].State = READY; #endif OSReadyList = OSReadyList | (PriorityMask[iPriority]); // If outside of an interrupt service routine, change context to the highest priority task // If inside of an interrupt, the interrupt itself will change the context to the highest priority task if (!iNesting) { // Verify if there is a higher priority task ready to run ChangeContext(); } // Exit Critical Section #if (NESTING_INT == 0) if (!iNesting) #endif OSExitCritical(); return OK; } // Make sure semaphore will not overflow if (pont_event->OSEventCount < 255) { // Increment semaphore count pont_event->OSEventCount++; // Exit Critical Section #if (NESTING_INT == 0) if (!iNesting) #endif OSExitCritical(); return OK; } else { // Exit Critical Section #if (NESTING_INT == 0) if (!iNesting) #endif OSExitCritical(); // Indicates semaphore overflow return ERR_SEM_OVF; } }
INT8U OSMboxPost(BRTOS_Mbox *pont_event, void *message) { OS_SR_SAVE_VAR INT8U iPriority = (INT8U)0; #if (VERBOSE == 1) INT8U TaskSelect = 0; #endif #if (ERROR_CHECK == 1) // Verifies if the pointer is NULL if(pont_event == NULL) { return(NULL_EVENT_POINTER); } #endif // Enter Critical Section #if (NESTING_INT == 0) if (!iNesting) #endif OSEnterCritical(); #if (ERROR_CHECK == 1) // Verifies if the event is allocated if(pont_event->OSEventAllocated != TRUE) { // Exit Critical Section #if (NESTING_INT == 0) if (!iNesting) #endif OSExitCritical(); return(ERR_EVENT_NO_CREATED); } #endif // See if any task is waiting for a message if (pont_event->OSEventWait != 0) { // Selects the highest priority task iPriority = SAScheduler(pont_event->OSEventWaitList); // Remove the selected task from the mailbox wait list pont_event->OSEventWaitList = pont_event->OSEventWaitList & ~(PriorityMask[iPriority]); // Decreases the mailbox wait list counter pont_event->OSEventWait--; // Put the selected task into Ready List #if (VERBOSE == 1) TaskSelect = PriorityVector[iPriority]; ContextTask[TaskSelect].State = READY; #endif OSReadyList = OSReadyList | (PriorityMask[iPriority]); // Copy message pointer pont_event->OSEventPointer = message; // Free message slot pont_event->OSEventState = AVAILABLE_MESSAGE; // If outside of an interrupt service routine, change context to the highest priority task // If inside of an interrupt, the interrupt itself will change the context to the highest priority task if (!iNesting) { // Verify if there is a higher priority task ready to run ChangeContext(); } // Exit Critical Section #if (NESTING_INT == 0) if (!iNesting) #endif OSExitCritical(); return OK; } else { // Copy message pointer pont_event->OSEventPointer = message; // Free message slot pont_event->OSEventState = AVAILABLE_MESSAGE; // Exit Critical Section #if (NESTING_INT == 0) if (!iNesting) #endif OSExitCritical(); return OK; } }
INT8U OSMutexRelease(BRTOS_Mutex *pont_event) { OS_SR_SAVE_VAR INT8U iPriority = (INT8U)0; #if (VERBOSE == 1) INT8U TaskSelect = 0; #endif #if (ERROR_CHECK == 1) /// Can not use mutex pend function from interrupt handling code if(iNesting > 0) { return(IRQ_PEND_ERR); } // Verifies if the pointer is NULL if(pont_event == NULL) { return(NULL_EVENT_POINTER); } #endif // Enter Critical Section OSEnterCritical(); #if (ERROR_CHECK == 1) // Verifies if the event is allocated if(pont_event->OSEventAllocated != TRUE) { // Exit Critical Section OSExitCritical(); return(ERR_EVENT_NO_CREATED); } #endif // BRTOS TRACE SUPPORT #if (OSTRACE == 1) if(!iNesting){ #if(OS_TRACE_BY_TASK == 1) Update_OSTrace(currentTask, MUTEXPOST); #else Update_OSTrace(ContextTask[currentTask].Priority, MUTEXPOST); #endif }else{ Update_OSTrace(0, MUTEXPOST); } #endif // Verify Mutex Owner if (pont_event->OSEventOwner != currentTask) { OSExitCritical(); return ERR_EVENT_OWNER; } // Returns to the original priority, if needed // Copy backuped original priority to the task context iPriority = ContextTask[currentTask].Priority; if (iPriority != pont_event->OSOriginalPriority) { // Since current task is executing with another priority, reallocate its priority to the original // into the Ready List // Remove "max priority current task" from the Ready List OSReadyList = OSReadyList & ~(PriorityMask[iPriority]); // Put the "original priority current task" into Ready List OSReadyList = OSReadyList | (PriorityMask[pont_event->OSOriginalPriority]); ContextTask[currentTask].Priority = pont_event->OSOriginalPriority; } // See if any task is waiting for mutex release if (pont_event->OSEventWait != 0) { // Selects the highest priority task iPriority = SAScheduler(pont_event->OSEventWaitList); // Remove the selected task from the mutex wait list pont_event->OSEventWaitList = pont_event->OSEventWaitList & ~(PriorityMask[iPriority]); // Decreases the mutex wait list counter pont_event->OSEventWait--; // Indicates that selected task is ready to run #if (VERBOSE == 1) TaskSelect = PriorityVector[iPriority]; ContextTask[TaskSelect].State = READY; #endif // Put the selected task into Ready List OSReadyList = OSReadyList | (PriorityMask[iPriority]); // Verify if there is a higher priority task ready to run ChangeContext(); // Exit Critical Section OSExitCritical(); return OK; } // Release Mutex pont_event->OSEventState = AVAILABLE_RESOURCE; PriorityVector[pont_event->OSMaxPriority] = MUTEX_PRIO; // Exit Critical Section OSExitCritical(); return OK; }