tk_cre_tsk
Create Task
See Also
ID tskid = tk_cre_tsk ( T_CTSK *pk_ctsk ) ;
T_CTSK* pk_ctsk Information about the task to be created
pk_ctsk detail:
VP exinf Extended information
ATR tskatr Task attributes
FP task Task start address
PRI itskpri Initial task priority
W stksz Stack size (bytes)
UB dsname[8] DS object name
VP bufptr User buffer pointer
(Other implementation-dependent parameters may be added beyond this point.)
ID tskid Task ID
or Error Code
E_NOMEM Insufficient memory (memory for control block or user stack cannot be allocated)
E_LIMIT Number of tasks exceeds the system limit
E_RSATR Reserved attribute (tskatr is invalid or cannot be used), or the specified co-processor does not exist
E_PAR Parameter Error
Creates a task, assigning to it a task ID number. This system call allocates a TCB (Task Control Block) to the created task and initializes it based on itskpri, task, stksz and other parameters.
After the task is created, it is initially in the DORMANT state.
itskpri specifies the initial priority at the time the task is started.
Task priority values are specified from 1 to 140, with smaller numbers indicating higher priority.
exinf can be used freely by the user to store miscellaneous information about the task. The information set here is passed to the task as a startup parameter and can be referred to by calling tk_ref_tsk. If a larger area is needed for indicating user information, or if the information needs to be changed after the task is created, it can be done by allocating separate memory for this purpose and putting the memory packet address in exinf. The OS pays no attention to the contents of exinf.
tskatr indicates system attributes in its low bits and implementation-dependent information in the high bits. The system attributes part of tskatr is as follows.
tskatr :=(TA_ASM||TA_HLNG)
|[TA_USERBUF]|[TA_DSNAME]|(TA_RNG0||TA_RNG1||TA_RNG2||TA_RNG3)
TA_ASM Indicates that the task is written in assembly language
TA_HLNG Indicates that the task is written in high-level language
TA_USERBUF Indicates that the task uses an area specified by user as stack
TA_DSNAME Specifies DS object name
TA_RNGn Indicates that the task runs at protection level n
The ability to specify implementation-dependent attributes can be used, for example, to specify that a task is subject to debugging. One use of the remaining system attribute fields is for indicating multiprocessor attributes in the future.
#define TA_ASM 0x00000000 /* Assembly program */
#define TA_HLNG 0x00000001 /* High-level language program */
#define TA_USERBUF 0x00000020 /* User buffer */
#define TA_DSNAME 0x00000040 /* DS object name */
#define TA_RNG0 0x00000000 /* Run at protection level 0 */
#define TA_RNG1 0x00000100 /* Run at protection level 1 */
#define TA_RNG2 0x00000200 /* Run at protection level 2 */
#define TA_RNG3 0x00000300 /* Run at protection level 3 */
When TA_HLNG is specified, starting the task jumps to the task address not directly but by going through a high-level language environment configuration program (high-level language support routine). The task takes the following form in this case.
void task( INT stacd, VP exinf )
{
/*
(processing)
*/
tk_ext_tsk(); or tk_exd_tsk(); /* Exit task */
}
The startup parameters passed to the task include the task startup code stacd specified in tk_sta_tsk, and the extended information exinf specified in tk_cre_tsk.
The task cannot (must not) be terminated by a simple return from the function.
The form of the task when the TA_ASM attribute is specified is implementation-dependent, but stacd and exinf must be passed as startup parameters.
If TA_USERBUF is specified, bufptr becomes valid, and the memory area of stksz bytes with bufptr at the head is used as a stack area. In this case, the stack is not prepared by OS. If TA_USERBUF is not specified, bufptr is ignored, and a stack area is allocated by the OS.
Each task has a stack area. There is no partition between system stack and user stack like T-Kernel because each protection level is always handled as protection level 0 in µT-Kernel.
When TA_DSNAME is specified, dsname is valid and specifies the DS object name. DS object name is used by the debugger to identify objects and is handled only by the debugger support functions API, td_ref_dsname and td_set_dsname. For more details, refer to td_ref_dsname and td_set_dsname. If TA_DSNAME is not specified, dsname is ignored. Then, td_ref_dsname and td_set_dsname return E_OBJ error.
A task always runs as protection level 0 because functions concerning protection level are not supported in µT-Kernel.
In a system with a separate interrupt stack, interrupt handlers also use the system stack. An interrupt handler runs at protection level 0.
The stack default size is decided taking into account the amount taken up by system call execution and, in a system with separate interrupt stack, the amount used by interrupt handlers.
There is no system stack size (sstksz), user space page table (uatb), logical space ID (lsid), or resource ID (resid) in pk_ctsk. TA_TASKSPACE, TA_RESID, and TA_COPn are not specified as attributes allowable for tskatr. TA_USERBUF and bufptr have been added.
In µT-Kernel, a system without MMU is assumed, system stack and user stack are automatically bifurcated by the system, and the number of stacks is supposed to be only one. Consequently, there is no specification concerning system stack. For the same reason, functions concerning user space are omitted.
Also, subsystem functions are focused only on extended SVCs, so functions concerning resource IDs are omitted.
There is no coprocessor specification because in small systems targeted by µT-Kernel, the function to generically handle the coprocessor is deemed to be unnecessary.
In µT-Kernel, systems without MMU are assumed, so functions concerning protection level are not supported. Nevertheless, TA_RNGn attributes have been retained to maintain compatibility with T-Kernel.
The type of stksz (stack size), the member of T_CTSK, is W instead of INT.
TA_USERBUF and bufptr are not present in T-Kernel. So, if this ability is used , modifications are needed when porting to T-Kernel. However, if stksz is set correctly, you can port it by simply deleting TA_USERBUF and bufptr.
1 void tk_my_isr(UINT dintno) 2 { 3 /* 4 * Perform hardware-related work 5 * 6 * This is where you should put code for reading or writing to the 7 * specific peripheral. This part depends on your device 8 */ 9 10 /* Sample: */ 11 c = ReadDatafromSerialDevice(); 12 13 /* 14 * Remove the Interrupt Request 15 * 16 * If the hardware requires a specific method for removing the 17 * interrupt request, you should deal with it. Devices like 18 * UART usually de-assert the interrupt when you read the data 19 * but devices like timer require a special write request to 20 * de-assert the interrupt. 21 */ 22 23 /* Inform the application that the interrupt happened */ 24 25 /* Sample: */ 26 tk_sig_sem(sem_id, 1); 27 28 return; 29 }

Comments
Click here to Post a Comment