Data Structures used in RTOS API - @CHIP-RTOS V1.04
IPC@Chip Documentation Index
Data Structures
Here are the data structures used by the RTOS API
.
All constants and data structures are defined in the header file rtxapi.h
Notes:
- Byte alignment is required
for all data structures used within the API.
Content
:
RTX_Msg
typedef struct tag_rtx_msg{
int msgID; // Unique Message Exchange ID
char name[4]; // 4 characters, not null terminated
int mb0; // Numbers of message envelopes which can reside
int mb1; // in each of the four exchange mailboxes,
int mb2; // maximum 4 envelopes.
int mb3;
} RTX_Msg;Comments
- This structure is defined in the header file rtxapi.h.
Prior to making the RTX_CREATE_MSG
API
call, the caller must set the
following members of the RTX_Msg
structure.
name
Here you can give the Message Exchange a unique four character name. This field
is optional. If you plan to use the RTX_FIND_MSG
API
then you should provide
a name here.
mb0
through mb3
State here the number of message envelopes for each of this Message Exchange's four
mailboxes. The system's maximum number of available messages envelopes is 64 (since @CHIP-RTOS version 1.02B, else 32).
The msgID
member is an output parameter from the
RTX_CREATE_MSG
API call.
Related Topics
-
- API function RTX_CREATE_MSG - Create a Message Exchange
-
- RTOS Message Exchange Manager
Top of list Index page
RTX_Wait_Event
typedef struct tag_rtx_event_wait
{
unsigned int mask; // 16-Bit mask identifying the flags of interest of the group.
unsigned int value; // 16 Bit value, which specifies the states of interest
// for each flag selected by the mask.
int match; // event match requirements, 0:only one flag must match
// with value, !=0: all by mask specified flags must match
long timeout; // Maximum time (milliseconds) for waiting for an event match
} RTX_Wait_Event;Comments
- This structure is defined in the header file rtxapi.h.
Related Topics
-
- API function RTX_WAIT_EVENTS - Wait for events in a group
-
- RTOS Event Manager
Top of list Index page
RTX_Wait_Msg
typedef struct tag_rtx_wait_msg{
int msgID; // ID of the message exchange
int prio; // priority for wait (0-3), 0=highest
char *msg; // Pointer to user buffer to store the arrived message
long timeout; // Maximum time (milliseconds) for waiting for a message
} RTX_Wait_Msg;Comments
- This structure is defined in the header file rtxapi.h.
Prior to making the RTX_WAIT_MSG
API
call, the caller must set the
following members of the RTX_Wait_Msg
structure.
msgID
Here you put the message exchange ID acquired by the RTX_CREATE_MSG
call
.
prio
Specify here the priority of the calling task's access to the messages.
To wait in FIFO order, have all RTX_WAIT_MSG
API callers use the
same value here. A task can cut in line ahead of other waiting tasks by setting
this field to a higher priority (lower number) than used by the other tasks.
msg
Put a far pointer to a 12 byte buffer allocated in your application program memory.
The Message Exchange Manager will output the message to this buffer if a message
is available.
timeout
Here you can specify the maximum number of milliseconds you are willing to wait for
a message. A value of zero indicates you will wait forever.
Related Topics
-
- API function RTX_WAIT_MSG - Wait for a message from a message exchange
-
- RTOS Message Exchange Manager
Top of list Index page
TaskDefBlock
typedef struct tag_taskdefblock
{
void (*proc)(); // Task entry vector (far)
char name[4]; // Task name, 4 characters not null terminated
unsigned int *stackptr; // Task stack pointer (far)
unsigned int stacksize; // size of stack (bytes)
unsigned short attrib; // task attributes (not supported by the RTOS API)
short int priority; // task priority, range: 3..127 inclusive
unsigned short time_slice; // 0: none, !=0: number of milliseconds before task
// is forced to relinquish processor
short mailboxlevel1; // depth of mailbox i: 0 not used, else 1 - 4 mail box depth
short mailboxlevel2; // maximum number of messages reside inside a task mail box
short mailboxlevel3;
short mailboxlevel4;
} TaskDefBlock;Comments
- This structure is defined in the header file rtxapi.h.
Prior to making the RTX_TASK_CREATE
API call, the caller must set the
following members of the TaskDefBlock
structure.
proc
Here you must set the far vector to your task's entry point. The task's main procedure
should be declared (depending on compiler used) as:
Borland C: void huge taskfunc(void)
Microsoft C: void far _saveregs _loadds taskfunc(void)
to assure that the data segment register (DS) is loaded on entry into your task.
name
Make up a four letter name for your task by which it can be uniquely identified.
Avoid names already occupied by the system
tasks.
stackptr
This far pointer should point to the top of you task's stack space (highest address).
Your tasks stack pointer will be initialized to this value, which points to the first
byte of memory following your actual stack space. (Note that x86 CPU decrements
the stack pointer prior to writing to the stack.)
The stack memory space resides within your application program.
stacksize
Here you specify the size of your task's stack space in bytes. The amount of stack
space required for your task depends on the nature of your task. If large automatic
objects are declared in your task's procedures, a large amount of stack space will be needed.
Caution:
Some of the system's interrupts use your task's stack. Consequently we
recommend a minimum stack space of 1024 bytes per task.
Since the problems resulting from stack overflow are often difficult to diagnose and analyze,
the following design steps are recommended:
- Initially allocate way more stack space then you believe you will need.
- When you have your task performing what it was designed to do, measure the amount
of stack space being used by your task. The
RTX_GET_TASK_STATE
API can be used
to obtain this measurement.
- Refine your stack allocation based on this measurement, arriving at a compromise between
the conflicting requirements: efficiency on the one hand (small stack desired) and
program maintainability and reliability on the other hand (big stack desired).
Software maintainability becomes an issue here if you have the stack space
wired so tight that the slightest code change will lead to stack overflow.
Reliability is an issue when paths in your task (or interrupts) are executed
that did not execute during your stack space measurement trials.
priority
Application program tasks can range in priority from 3 to 127 (inclusive), where
3 is higher priority. Task priorities between 20 and 30 are recommended. This
recommendation is based on the priority assignments of the
system
tasks. In particular, too high a priority
for an application task may block important system tasks: e.g.
the serial and Ethernet receiver tasks. A user application will be
started with priority 25.
time_slice
Set this value to zero if you do not want round-robin time slicing between this task
and others at the same priority level. If you do want round-robin switching, then
specify here the number of milliseconds of CPU time that this task should receive
before the system switches to the next task at this same priority. System timing
granularity is one millisecond.
mailboxlevelN
These four values specify whether or not this task is using mailboxes. See the
Message
Exchange Manager topic
for more details.
Related Topics
-
- API function RTX_TASK_CREATE - Create and start a task
Top of list Index page
TaskList
typedef struct tagtasklist
{
unsigned int taskID; // Task handle
char taskname[5]; // Four character string terminated with zero.
} TaskList;Comments
- This structure is defined in the header file rtxapi.h
Related Topics
-
- API function RTX_GET_TASK_LIST - Get list of current
tasks in the system
Top of list Index page
Task_StateData
typedef struct tag_task_statedata
{
unsigned int taskID; // Task handle
unsigned int taskPrio; // Task priority
unsigned int taskState; // Bit field, see below
unsigned int taskCount; // count of the task monitor, if task monitor is active
unsigned int stackused; // Percentage of stack space used
unsigned int stacksize; // Task's total stack size, in bytes
} Task_StateData;Comments
- This structure is defined in the header file rtxapi.h.
The taskState
bit field is coded as follows:
B0: timer wait (used with other bits)
B1: trigger wait (i.e. idle)
B2: semaphore wait
B3: event group wait
B4: message exchange wait
B5: message send wait
B6: suspended (waiting for resume)
B7: waiting for wakeup
B8 - B15 internal use only
Related Topics
-
- API function RTX_GET_TASK_STATE - Get state of a task
Top of list Index page
TimeDate_Structure
typedef struct tag_time
{
unsigned char sec; // Seconds (0-59)
unsigned char min; // Minutes (0-59)
unsigned char hr; // Hours (0-23)
unsigned char dy; // Day (1-31)
unsigned char mn; // Month (1-12)
unsigned char yr; // Year (0-99)
unsigned char dow; // Day of week (Mon=1 to Sun=7)
unsigned char dcen; // Century if time/date is correct
} TimeDate_Structure;Comments
- This structure is defined in the header file rtxapi.h.
Related Topics
-
- API function RTX_GET_TIMEDATE - Get system time and date
-
- API function RTX_SET_TIMEDATE - Set system time and date
Top of list Index page
TimerProc_Structure
typedef struct tag_timer_proc
{
int *timerID; // pointer to storage the unique timerID
void (*proc)(); // pointer to the procedure to be executed
void *dummyptr; // -- currently not used --
char name[4]; // unique 4 character task name
long interval; // timer execution interval in milliseconds
} TimerProc_Structure;Comments
- This structure is defined in the header file rtxapi.h.
Before calling the RTX_INSTALL_TIMER
API function the caller must allocate a TimerProc_Structure
with the
following members preset as specified here:
timerID
Put here a far pointer to a 16 bit location in your program's memory space. The
RTX_INSTALL_TIMER
API function will output a Timer ID to this referenced
location. This Timer ID value is used as handle for this new timer procedure within
the other Timer Procedure API functions
.
proc
This is a far vector to your timer procedure. This routine will be called periodically
from the kernel. Your timer procedure should be declared (depending on compiler used) as:
Borland C: void huge MyTimerProc(void)
Microsoft C: void far _saveregs _loadds MyTimerProc(void)
Turbo Pascal: procedure Timer1_Proc;interrupt;
begin
[... your code ...]
(************************************************)
(* This is needed at the end of the Timer Proc. *)
asm
POP BP
POP ES
POP DS
POP DI
POP SI
POP DX
POP CX
POP BX
POP AX
RETF
end;
(************************************************)
end;
so that the compiler will generate code to set the CPU's DS register, enabling access to your
program's data.
Have also a look to some important notes
reference to Timer Procedure.
name
Place here a four letter name for your timer procedure to uniquely identified it.
(This string is not
zero terminated.)
interval
Specify here the interval, in milliseconds, at which you want your timer procedure to be called.
Related Topics
-
- API function RTX_INSTALL_TIMER - Install a timer procedure
-
- RTOS Timer Procedures
Top of list Index page
End of document
|