STR: Guided tour of Trampoline

This page make a quick overview of the API of Trampoline. Trampoline implements specification 2.2.3 of the OSEK/VDX operating system, and version 2.5 of the OSEK/VDX OSEK implementation language (OIL). For more details refer to OSEK/OS 2.2.3 and OSEK OIL 2.5.

Remarks on the Trampoline OSEK/VDX port to Nxt, or Trampoline specific features appear in green.

Shortcuts:

OSEK/VDX interface summary

Types

List of types defined by OSEK/VDX

StatusType This data type is used for all status information the API services offer. Naming convention: all errors for API services start with E_. Those reserved for the operating system will begin with E_OS_. E_OK means no error.
TaskType This data type identifies a task.
TaskRefType This data type points to a variable of TaskType.
TaskStateType This data type identifies the state of a task (RUNNING, WATING, READY, SUSPENDED, INVALID_TASK)
TaskStateRefType This data type points to a variable of the data type TaskStateType.
TickType This data type represents count values in ticks.
TickRefType This data type points to the data type TickType.
AlarmBaseType This data type represents a structure for storage of counter characteristics.
AlarmBaseRefType This data type points to the data type AlarmBaseType.
AlarmType This data type represents an alarm object.

Declarations

List of declarations. All objects have to be declared before being used. The function and use of these services are similar to that of the external declaration of variables in C.

DeclareTask ( ) DeclareTask serves as an external declaration of a task.
DeclareResource ( ) DeclareResource serves as an external declaration of a resource.
DeclareEvent ( ) DeclareEvent serves as an external declaration of an event.
DeclareAlarm ( ) DeclareAlarm serves as external declaration of an alarm element.

Task management

API of task management routines

StatusType ActivateTask ( TaskType ) The task is transferred from the suspended state into the ready state. The operating system ensures that the task code is being executed from the first statement. The task need not be executed immediately, depending of its priority and the scheduling mode (preemptive/non-preemptive) of callee.
StatusType TerminateTask ( void ) This service causes the termination of the calling task. The calling task is transferred from the running state into the suspended state. All tasks must end by a call to TerminateTask or ChainTask.
StatusType ChainTask ( TaskType ) This service causes the termination of the calling task. After termination of the calling task a succeeding task is activated. Using this service, it ensures that the succeeding task starts to run at the earliest after the calling task has been terminated.
StatusType Schedule ( void ) If a higher-priority task is ready, the internal resource of the task is released, the current task is put into the ready state, its context is saved and the higher-priority task is executed. Otherwise the calling task is continued.
StatusType GetTaskID ( TaskRefType ) GetTaskID returns the information about the TaskID of the task which is currently running.
StatusType GetTaskState ( TaskType , TaskStateRefType ) Returns the state of a task (RUNNING, WAITING, READY, SUSPENDED, INVALID_TASK) at the time of calling GetTaskState.

Interrupt management

API of interrupt management routines

void EnableAllInterrupts ( void ) This service restores the state saved by DisableAllInterrupts.
void DisableAllInterrupts ( void ) This service disables all interrupts for which the hardware supports disabling. The state before is saved for the EnableAllInterrupts call.
void ResumeAllInterrupts ( void ) This service restores the recognition status of all interrupts saved by the SuspendAllInterrupts service.
void SuspendAllInterrupts ( void ) This service saves the recognition status of all interrupts and disables all interrupts for which the hardware supports disabling.
void ResumeOSInterrupts ( void ) This service restores the recognition status of interrupts saved by the SuspendOSInterrupts service.
void SuspendOSInterrupts ( void ) This service saves the recognition status of interrupts of category 2 and disables the recognition of these interrupts.

Resource management

API of resource management routines. A specific pre-declared resource named RES_SCHEDULER represents the scheduler and can be used to implement non-preemptive regions in application code.

StatusType GetResource ( ResourceType ) This call serves to enter critical sections in the code that are assigned to the resource referenced by . A critical section shall always be left using ReleaseResource.
StatusType ReleaseResource ( ResourceType ) ReleaseResource is the counterpart of GetResource and serves to leave critical sections in the code that are assigned to the resource referenced by .

Event control

API of event control routines.

StatusType SetEvent ( TaskType , EventMaskType ) The service may be called from an interrupt service routine and from the task level, but not from hook routines.

The events of task are set according to the event mask . Calling SetEvent causes the task to be transferred to the ready state, if it was waiting for at least one of the events specified in .

StatusType ClearEvent ( EventMaskType ) The events of the extended task calling ClearEvent are cleared according to the event mask .
StatusType GetEvent ( TaskType , EventMaskRefType ) This service returns the current state of all event bits of the task , not the events that the task is waiting for.

The service may be called from interrupt service routines, task level and some hook routines (see Figure 12-1 of OSEK/VDX manual).

The current status of the event mask of task is copied to .

StatusType WaitEvent ( EventMaskType ) The state of the calling task is set to waiting, unless at least one of the events specified in has already been set.

Alarms

StatusType GetAlarmBase ( AlarmType , AlarmBaseRefType ) The system service GetAlarmBase reads the alarm base characteristics. The return value is a structure in which the information of data type AlarmBaseType is stored.
StatusType GetAlarm ( AlarmType TickRefType ) The system service GetAlarm returns the relative value in ticks before the alarm expires.
StatusType SetRelAlarm ( AlarmType , TickType , TickType ) The system service occupies the alarm element. After ticks have elapsed, the task assigned to the alarm is activated or the assigned event (only for extended tasks) is set or the alarm-callback routine is called.
StatusType SetAbsAlarm ( AlarmType , TickType , TickType ) The system service occupies the alarm element. When ticks are reached, the task assigned to the alarm is activated or the assigned event (only for extended tasks) is set or the alarm-callback routine is called.
StatusType CancelAlarm ( AlarmType ) This service cancels an alarm that has been set. If the application wants to restart an alarm that is currently running, it must first invoke this service before it can reset the value of the alarm.

OS management

API of operating system management routines

void StartOS ( AppModeType ) The user can call this system service to start the operating system in a specific mode, see chapter 5, Application modes.
void ShutdownOS ( StatusType ) The user can call this system service to abort the overall system (e.g. emergency off). The operating system also calls this function internally, if it has reached an undefined internal state and is no longer ready to run.

Hook routines

API of hook routines (called at specific points when executing applications)

void ErrorHook (StatusType ) This hook routine is called by the operating system at the end of a system service which returns StatusType not equal E_OK. It is called before returning to the task level.

This hook routine is called when an alarm expires and an error is detected during task activation or event setting.

The ErrorHook is not called, if a system service called from ErrorHook does not return E_OK as status value. Any error by calling of system services from the ErrorHook can only be detected by evaluating the status value.

void PreTaskHook ( void ) This hook routine is called by the operating system before executing a new task, but after the transition of the task to the running state (to allow evaluation of the TaskID by GetTaskID).
void PostTaskHook ( void ) This hook routine is called by the operating system after executing the current task, but before leaving the task’s running state (to allow evaluation of the TaskID by GetTaskID).
void StartupHook ( void ) This hook routine is called by the operating system at the end of the operating system initialisation and before the scheduler is running. At this time the application can initialise device drivers etc.
void ShutdownHook ( StatusType ) This hook routine is called by the operating system when the OS service ShutdownOS has been called. This routine is called during the operating system shut down.

Commented OIL configuration file

Below are the most commonly used OIL attributes. For more details, see the OIL reference manual. Attributes of type MESSAGE are not documented, because there will not be used during the labs. All events and resources used by a task must be declared within the TASK declaration. Line in red have to be changed, they depend on the installation paths of gcc-arm, Trampoline, and on the name of your application files.

OIL_VERSION = “2.5” : “test” ; // OIL version
IMPLEMENTATION trampoline {
TASK {
UINT32 STACKSIZE = 500 ;
UINT32 PRIORITY = 1 ;
} ;
ISR {
UINT32 STACKSIZE = 500 ;
} ;
};
// Implementation section, defines default values for attributes when not specified

// Task default stack size
// Task default priority (1 = lowest)

// ISR default stack size

CPU test {

OS config {
STATUS = EXTENDED;
ERRORHOOK = FALSE;
PRETASKHOOK = FALSE;
POSTTASKHOOK = FALSE;
STARTUPHOOK = FALSE;
SHUTDOWNHOOK = FALSE;
SYSTEM_CALL = TRUE;
APP_SRC = “TP.c”;
APP_NAME = “TP_exe”;
TRAMPOLINE_BASE_PATH = “/Users/puaut/Home/Sources/trampoline”;
CFLAGS = “-g -c -ffreestanding -fsigned-char -mcpu=arm7tdmi -Os -Winline -Wall -Werror-implicit-function-declaration –param max-inline-insns-single=1000 -ffunction-sections -fdata-sections -std=gnu99”;
ASFLAGS = “-mcpu=arm7tdmi –fatal-warnings “;
LDFLAGS = “-g –cref –allow-multiple-definition –gc-sections”;
LDFLAGS = “-L/usr/local/arm/lib/gcc/arm-elf/4.1.0 -lgcc -L/usr/local/arm/arm-elf/lib -lc”;
COMPILER = “arm-elf-gcc”;
ASSEMBLER = “arm-elf-as”;
LINKER = “arm-elf-ld”;
MEMMAP = TRUE {
COMPILER = gcc;
LINKER = gnu_ld { SCRIPT = “script.ld”; };
ASSEMBLER = gnu_as;
MEMORY_PROTECTION = FALSE;
};
} ;

// the CPU on whch the application runs under the control of OSEK

// the OSEK OS that runs on the CPU.
// system with extended status (other value = STANDARD)
// OSEK hooks (value = TRUE or FALSE)

// Application source file (add several APP_SRC if several source files)
// Name of generated binary
// Trampoline base path (change depending on Tampoline installation path)
// gcc-arm compilation flags (do not change)

// as-arm assembly flags (do not change)
// ld-arm link flags (do not change)
// ld-arm link flags defining libraries to use (change depending on where gcc-arm is installed)

// name of gcc-arm binary
// name of as-arm binary
// name of ld-arm binary
// use of Trampoline memory map (do not change)

APPMODE std {
};
// At least one application mode per CPU has to be defined
TASK taskContact {
PRIORITY = 10;
AUTOSTART = FALSE;
ACTIVATION = 1;
SCHEDULE = FULL;
RESOURCE = ResDistance;
EVENT = EvDistance;
};
// Task declaration (put as many as tasks in your system)

// Task priority (1 = lowest)

// Task is not activated at startup (to change, set AUTOSTART to TRUE)

// Number of allowed simultaneous

// Preemption mode (FULL = preemptive, NON = non preemptive)

// Resources used (put several lines if several resources are used)

// Events the task may react to (put several lines if needed)

COUNTER SystemCounter {
SOURCE = it_timer1;
MAXALLOWEDVALUE = 10000;
TICKSPERBASE = 1;
MINCYCLE = 1;
};
// Counter declaration. Here, Trampoline system counter (do not change)
// Trampoline-dependent. Counter incremented every ms by it_timer1
// Maximum allowed counter value
// Number of ticks required to reach a counter-specific unit
// Minimum allowed number of counter ticks for cyclic alarm linked to the counter
ALARM AlarmContact {

COUNTER = SystemCounter;
ACTION = ACTIVATETASK {
TASK = taskContact;
};
AUTOSTART = TRUE {
ALARMTIME = 100;
CYCLETIME = 500;
APPMODE = std;
};
};

// Alarm declaration (put as many as alarms in your system)

// Counter assigned to the alarm

// Action associated to the alarm (ACTIVATE_TASK, SETEVENT, ALARMCALLBACK)

// Activated task when the alarm is triggered// (TRUE/FALSE) Defines if the alarm is started automatically at system startup

// Time when the alarm shall expire first

// Cycle (0 if the alarm is programmed to expire only once). Here, 500 ms

// Application mode

EVENT EvDistance {
MASK = AUTO;
};
// Event declaration

// Event mask is generated automatically (else put MASK = hex value, ex: MASK = 0x01)

RESOURCE ResDistance {
RESOURCEPROPERTY = STANDARD ;
};
// Resource declaration

// Resource mode (STANDARD, LINKED, INTERNAL)

ISR isr_button_start {
CATEGORY = 2;
PRIORITY = 1;
RESOURCE = ResDistance;
SOURCE = button_start;
};
// Interrupt Service Routine (ISR) declaration
// Event category (1 or 2, see OSEK manual for explanations)
// ISR priority (for level 2 ISRs only, 1 = lowest)
// Resources used by the ISR (for level 2 ISRs only)
// Trampoline specific. Means that interrupt is triggered when start button is pressed.
// Other values are button_stop, button_left, button_right

Some Autosar/OSEK extensions

Schedule tables

DeclareScheduleTable(<scheduletable_id>) DeclareScheduleTable serves as an external declaration of a schedule table
StatusType StartScheduleTableRel(ScheduleTableType <sched_table_id>, TickType ) Start a schedule table at a relative date
StatusType StartScheduleTableAbs(ScheduleTableType <sched_table_id>, TickType <tick_val>) Start a schedule table at an absolute date.
StatusType StartScheduleTableSynchron(

ScheduleTableType <sched_table_id>)

Start a schedule table synchronized with global time
StatusType StopScheduleTable(ScheduleTableType <sched_table_id>) Stop a schedule table.
StatusType NextScheduleTable(ScheduleTableType <current_st_id>,ScheduleTableType <next_st_id>) Switch the processing from one schedule table to another.
StatusType GetScheduleTableStatus(ScheduleTableType <sched_table_id>,ScheduleTableStatusRefType ) Get the status of a schedule table
StatusType SyncScheduleTable(ScheduleTableType <sched_table_id>,TickType ); Synchronize a schedule table with global time
StatusType SetScheduleTableAsync(ScheduleTableType, <sched_table_id>) Set a schedule table asynchrone to global time

Comments are closed.