BRTOS  1.90
Brazilian Real-Time Operating System
 All Data Structures Files Functions Variables Macros
Data Structures | Macros | Functions | Variables
BRTOS.h File Reference

BRTOS kernel main defines, functions prototypes and structs declaration. More...

#include "OS_types.h"
#include "HAL.h"
#include "OSTime.h"
#include "BRTOSConfig.h"

Go to the source code of this file.

Data Structures

struct  BRTOS_Sem
 
struct  BRTOS_Mutex
 
struct  BRTOS_Mbox
 
struct  BRTOS_Queue
 
struct  OS_QUEUE
 

Macros

#define FALSE   0
 False and True defines.
 
#define READY   (uint8_t)0
 Task States. More...
 
#define SUSPENDED   (uint8_t)1
 Task is suspended.
 
#define BLOCKED   (uint8_t)2
 Task is blocked - Will not run until be released.
 
#define MAX_TIMER   0xffffffffffffffffULL
 Timer defines.
 
#define TICK_COUNT_OVERFLOW   (ostick_t)(MAX_TIMER - 3)
 Determines the tick timer overflow.
 
#define TickCountOverFlow   TICK_COUNT_OVERFLOW
 Compatibility with BRTOS less than or equal to 1.7.
 
#define OK   (uint8_t)0
 Error codes. More...
 
#define NO_MEMORY   (uint8_t)1
 Error - Lack of memory to allocate a task.
 
#define STACK_SIZE_TOO_SMALL   (uint8_t)2
 Error - Stack size too small to allocate a task.
 
#define END_OF_AVAILABLE_PRIORITIES   (uint8_t)3
 Error - There are no more priorities available.
 
#define BUSY_PRIORITY   (uint8_t)4
 Error - Priority is being used by another task.
 
#define INVALID_TIME   (uint8_t)5
 Error - Informed time is out of the limits.
 
#define TIMEOUT   (uint8_t)6
 Error - Timeout.
 
#define CANNOT_ASSIGN_IDLE_TASK_PRIO   (uint8_t)7
 Error - A task can not be assigned into the idle task slot.
 
#define NOT_VALID_TASK   (uint8_t)8
 There current task number is not valid for this function.
 
#define NO_TASK_DELAY   (uint8_t)9
 Error - No valid time to wait.
 
#define END_OF_AVAILABLE_TCB   (uint8_t)10
 Error - There are no more task control blocks (Context task)
 
#define EXIT_BY_NO_ENTRY_AVAILABLE   (uint8_t)11
 Error - There are no data into queues and mailboxes or semaphore value is zero with no timeout option.
 
#define TASK_WAITING_EVENT   (uint8_t)12
 Error - The task being uninstalled is waiting for an event (uninstall aborted)
 
#define CANNOT_UNINSTALL_IDLE_TASK   (uint8_t)13
 Error - It is not be allow to uninstall the idle task.
 
#define EXIT_BY_NO_RESOURCE_AVAILABLE   (uint8_t)14
 Error - The resource is not available with no timeout option.
 
#define ALLOC_EVENT_OK   (uint8_t)0
 Event allocated with success.
 
#define NO_AVAILABLE_EVENT   (uint8_t)1
 No event control blocks available.
 
#define NO_AVAILABLE_MEMORY   (uint8_t)2
 Error - Lack of memory to allocate an event.
 
#define INVALID_PARAMETERS   (uint8_t)3
 There is at least one invalid parameter.
 
#define IRQ_PEND_ERR   (uint8_t)4
 Function can not be called inside an interrupt.
 
#define ERR_SEM_OVF   (uint8_t)5
 Semaphore counter overflow.
 
#define ERR_MUTEX_OVF   (uint8_t)6
 Mutex counter overflow.
 
#define ERR_EVENT_NO_CREATED   (uint8_t)7
 There are no task waiting for the event.
 
#define NULL_EVENT_POINTER   (uint8_t)8
 The passed event pointer is NULL.
 
#define ERR_EVENT_OWNER   (uint8_t)9
 Function caller is not the owner of the event control block. Used to mutex implementation.
 
#define DELETE_EVENT_OK   (uint8_t)10
 Event deleted with success.
 
#define AVAILABLE_RESOURCE   (uint8_t)11
 The resource is available.
 
#define BUSY_RESOURCE   (uint8_t)12
 The resource is busy.
 
#define AVAILABLE_MESSAGE   (uint8_t)13
 There is a message.
 
#define NO_MESSAGE   (uint8_t)14
 There is no message.
 
#define READ_BUFFER_OK   0
 New data successfully read.
 
#define WRITE_BUFFER_OK   0
 New data successfully written.
 
#define BUFFER_UNDERRUN   1
 Queue overflow.
 
#define CLEAN_BUFFER_OK   2
 Queue successfully cleaned.
 
#define NO_ENTRY_AVAILABLE   3
 Queue is empty.
 
#define DELAY   0
 Suspended Types. More...
 
#define SEMAPHORE   1
 Task suspended by semaphore.
 
#define MAILBOX   2
 Task suspended by mailbox.
 
#define QUEUE   3
 Task suspended by queue.
 
#define MUTEX   4
 Task suspended by mutex.
 
#define configMAX_TASK_INSTALL   8
 Task Defines. More...
 

Functions

void Idle (void)
 Idle Task. May be used to implement low power commands. More...
 
void OS_TICK_HANDLER (void)
 Tick timer interrupt handler routine (Internal kernel function).
 
uint8_t BRTOSStart (void)
 Start the Operating System Scheduler The user must call this function to start the tasks execution. More...
 
BRTOS_TH OSGetCurrentTaskHandle (void)
 Return the handle of the current task. The user must call this function in order to receive the current task handle. More...
 
BRTOS_TH OSGetTaskPriority (BRTOS_TH task_handle)
 Return the priority of the specified task. The user must call this function in order to receive the priority of the specified task. More...
 
uint8_t OSDelayTask (ostick_t time_wait)
 Wait for a specified period. A task that calling this function will be suspended for a certain time. When this time is reached the task back to ready state. More...
 
uint8_t OSDelayTaskHMSM (uint8_t hours, uint8_t minutes, uint8_t seconds, uint16_t miliseconds)
 Wait for a specified period (in hours, minutes, seconds and miliseconds). A task that calling this function will be suspended for a certain time. When this time is reached the task back to ready state. More...
 
ostick_t OSGetTickCount (void)
 Return current tick count. The user must call this function in order to receive the current tick count. More...
 
ostick_t OSGetCount (void)
 Return current tick count. Internal BRTOS function. More...
 
void OSIncCounter (void)
 Update the tick counter. More...
 
void PreInstallTasks (void)
 Function that initialize the kernel main variables. This function resets the kernel main variables, preparing the system to be started. More...
 
uint8_t OSBlockPriority (uint8_t iPriority)
 Blocks a specific priority Blocks the task that is associated with the specified priority. The user must be careful when using this function in together with mutexes. This can lead to undesired results due the "cealing priority" property used in the mutex. More...
 
uint8_t OSUnBlockPriority (uint8_t iPriority)
 UnBlock a specific priority UnBlocks the task that is associated with the specified priority. The user must be careful when using this function in together with mutexes. This can lead to undesired results due the "cealing priority" property used in the mutex. More...
 
uint8_t OSBlockMultipleTask (uint8_t TaskStart, uint8_t TaskNumber)
 Blocks a set of tasks. More...
 
uint8_t OSUnBlockMultipleTask (uint8_t TaskStart, uint8_t TaskNumber)
 UnBlocks a set of tasks. More...
 
void BRTOSInit (void)
 Initialize BRTOS control blocks and tick timer (Internal kernel function).
 
uint8_t OSSchedule (void)
 Priority Preemptive Scheduler (Internal kernel function). More...
 
uint8_t SAScheduler (PriorityType ReadyList)
 Sucessive Aproximation Scheduler (Internal kernel function). More...
 
void initEvents (void)
 Initialize event control blocks. More...
 

Variables

uint8_t iNesting
 Used to inform if the current code position is an interrupt handler code.
 
volatile uint8_t currentTask
 Current task being executed.
 
ContextType ContextTask [NUMBER_OF_TASKS+1]
 
uint16_t iStackAddress
 Virtual stack counter - Informs the stack occupation in bytes.
 
uint8_t NumberOfInstalledTasks
 Number of Installed tasks at the moment.
 
volatile uint32_t OSDuty
 Used to compute the CPU load.
 
uint8_t PriorityVector [configMAX_TASK_INSTALL]
 Allocate task priorities.
 
volatile uint32_t OSDutyTmp
 Used to compute the CPU load.
 
volatile uint16_t LastOSDuty
 Last CPU load computed.
 
uint32_t TaskAlloc
 Used to search a empty task control block.
 
uint16_t iQueueAddress
 Queue heap control.
 
PGM_P CONST BRTOSStringTable[] PROGMEM
 Informs BRTOS version.
 
stack_pointer_t StackAddress
 Virtual stack pointer.
 

Detailed Description

BRTOS kernel main defines, functions prototypes and structs declaration.

Macro Definition Documentation

#define configMAX_TASK_INSTALL   8

Task Defines.

Defines the maximum number of tasks that can be installed

#define DELAY   0

Suspended Types.

Task suspended by delay

#define OK   (uint8_t)0

Error codes.

OK define

#define READY   (uint8_t)0

Task States.

Task is ready to be executed - waiting for the scheduler authorization

Function Documentation

uint8_t BRTOSStart ( void  )

Start the Operating System Scheduler The user must call this function to start the tasks execution.

Returns
OK Success
NO_MEMORY There was not enough memory to start all tasks
void Idle ( void  )

Idle Task. May be used to implement low power commands.

Returns
NONE
void initEvents ( void  )

Initialize event control blocks.

Returns
NONE
uint8_t OSBlockMultipleTask ( uint8_t  TaskStart,
uint8_t  TaskNumber 
)

Blocks a set of tasks.

Parameters
TaskStartNumber of the first task to be blocked
TaskNumberNumber of tasks to be blocked from the specified task start
Returns
OK - Success
IRQ_PEND_ERR - Can not use block multiple tasks function from interrupt handler code
uint8_t OSBlockPriority ( uint8_t  iPriority)

Blocks a specific priority Blocks the task that is associated with the specified priority. The user must be careful when using this function in together with mutexes. This can lead to undesired results due the "cealing priority" property used in the mutex.

Parameters
iPriorityPriority to be blocked
Returns
OK - Success
IRQ_PEND_ERR - Can not use block priority function from interrupt handler code
uint8_t OSDelayTask ( ostick_t  time_wait)

Wait for a specified period. A task that calling this function will be suspended for a certain time. When this time is reached the task back to ready state.

Parameters
time_waitTime in ticks to delay. System default = 1ms. The user can change the time value.
Returns
OK Success
IRQ_PEND_ERR - Can not use block priority function from interrupt handler code
uint8_t OSDelayTaskHMSM ( uint8_t  hours,
uint8_t  minutes,
uint8_t  seconds,
uint16_t  miliseconds 
)

Wait for a specified period (in hours, minutes, seconds and miliseconds). A task that calling this function will be suspended for a certain time. When this time is reached the task back to ready state.

Parameters
hoursHours to delay
minutesMinutes to delay
secondsSeconds to delay
milisecondsMiliseconds to delay
Returns
OK Success
INVALID_TIME The specified parameters are outside of the permitted range
ostick_t OSGetCount ( void  )

Return current tick count. Internal BRTOS function.

Returns
current tick count
BRTOS_TH OSGetCurrentTaskHandle ( void  )

Return the handle of the current task. The user must call this function in order to receive the current task handle.

Returns
current task handle
BRTOS_TH OSGetTaskPriority ( BRTOS_TH  task_handle)

Return the priority of the specified task. The user must call this function in order to receive the priority of the specified task.

Returns
task priority
ostick_t OSGetTickCount ( void  )

Return current tick count. The user must call this function in order to receive the current tick count.

Returns
current tick count
void OSIncCounter ( void  )

Update the tick counter.

Returns
NONE
uint8_t OSSchedule ( void  )

Priority Preemptive Scheduler (Internal kernel function).

BRTOS Scheduler function (Internal kernel function).

uint8_t OSUnBlockMultipleTask ( uint8_t  TaskStart,
uint8_t  TaskNumber 
)

UnBlocks a set of tasks.

Parameters
TaskStartNumber of the first task to be unblocked
TaskNumberNumber of tasks to be unblocked from the specified task start
Returns
OK - Success
IRQ_PEND_ERR - Can not use unblock multiple tasks function from interrupt handler code
uint8_t OSUnBlockPriority ( uint8_t  iPriority)

UnBlock a specific priority UnBlocks the task that is associated with the specified priority. The user must be careful when using this function in together with mutexes. This can lead to undesired results due the "cealing priority" property used in the mutex.

Parameters
iPriorityPriority to be unblocked
Returns
OK - Success
IRQ_PEND_ERR - Can not use unblock priority function from interrupt handler code
void PreInstallTasks ( void  )

Function that initialize the kernel main variables. This function resets the kernel main variables, preparing the system to be started.

Returns
NONE
uint8_t SAScheduler ( PriorityType  ReadyList)

Sucessive Aproximation Scheduler (Internal kernel function).

Parameters
ReadyListList of the tasks ready to run
Returns
The priority of the highest priority task ready to run

Variable Documentation

ContextType ContextTask[NUMBER_OF_TASKS+1]

Task context info ContextTask[0] not used Last ContexTask is the Idle Task