Добавил:
Опубликованный материал нарушает ваши авторские права? Сообщите нам.
Вуз: Предмет: Файл:
Sauermann J.Realtime operating systems.Concepts and implementation of microkernels for embedded systems.1997.pdf
Скачиваний:
27
Добавлен:
23.08.2013
Размер:
1.32 Mб
Скачать

3. Kernel Implementation

79

 

 

3.10 Miscellaneous Functions

So far, we have discussed most of the code comprising the kernel. What is missing is the code for starting up tasks (which is described in Section 4.3) and some functions that are conceptually of minor importance but nevertheless of certain practical use. They are described in less detail in the following sections.

3.10.1Miscellaneous Functions in Task.cc

The Monitor class uses member functions that are not used otherwise. Current() returns a pointer to the current task. Dsched() explicitly deschedules the current task. MyName() returns a string for the current task that is provided as an argument when a task is started; Name() returns that string for any task. MyPriority() returns the priority of the current task, Priority() returns the priority for any task. userStackBase() returns the base address of the user stack; userStackSize() returns the size of the user stack; and userStackUsed() returns the size of the user stack that has already been used by a task. When a task is created, its user stack is initialized to contain characters ’U’. userStackUsed() scans the user stack from the bottom until it finds a character which differs from ’U’ and so computes the size of the used part of the stack. Status() returns the task status bitmap.

Next() returns the next task in the ring of all existing tasks. If we need to perform a certain function for all tasks, we could do it as follows:

for (const Task * t = Task::Current();;)

{

...

 

t = t->Next();

 

if (t == Task::Current())

break;

}

Sleep(unsigned int ticks) puts the current task into sleep mode for ticks timer interrupts. That is, the task does not execute for a time of ticks*10ms without wasting CPU time.

When a task is created, its state is set to STARTED; i.e. the task is not in state RUN. This allows for setting up tasks before multitasking is actually enabled. Start() resets the task state to RUN.

Terminate() sets a task’s state to TERMINATED. This way, the task is prevented from execution without the task being deleted.

GetMessage(Message & dest) copies the next message sent to the current task into dest and removes it from the task’s message queue (msgQ).

80

3.10 Miscellaneous Functions

 

 

3.10.2Miscellaneous Functions in os.cc

getSystemTime() returns the time in millisecond since system start-up (more precisely since multitasking was enabled) as a long long. initChannel() initializes the data format (data bits, stop bits) of a DUART channel, setBaudRate() sets ??? What ???. Panic() disables all interrupts, turns on the red LED and then continuously dumps an exception stack frame on SERIAL_0. This function is used whenever an exception for which no handler exists is taken (label _fatal). That is, if a fatal system error occurs, the red LED is turned on, and we can connect a terminal to SERIAL_0. The exception stack frame can then be analyzed, together with the map file created by the linker, to locate the fault in the source code. readDuartRegister() is called to read a DUART register. writeRegister() is used to write into a hardware (i.e. DUART) register.