CHAPTER 6 TASK EXCEPTION HANDLING FUNCTIONS
This chapter describes the task exception handling functions performed by the RI600PX.
When task exception is requested to a task, the task exception handling routine defined for the task is invoked. The requested exception code is passed to the task exception handling routine.
By this function, exception handling in a task can be implemented easily.
The following shows the service calls as the task exception handling functions.
Table 6-1 Task Exception Handling Functions
|
|
|
|
Define task exception handling routine
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
Reference task exception disabled state
|
|
|
Reference task exception state
|
|
|
Reference task exception state
|
|
6.2 Task Exception Handling Routines
Exception handling according to the requested exception code should be implemented in a task exception handling routine.
6.2.1 Basic form of task exception handling routines
The following shows the basic form of ask exception handling routines.
#include "kernel.h" /*Standard header file definition*/
#include "kernel_id.h" /*Header file generated by cfg600px*/
#pragma taskexception Texrtn1 /*Refer to note 3*/
void Texrtn1 ( TEXPTN texptn, VP_INT exinf ); /*Refer to note 3*/
void Texrtn1 ( TEXPTN texptn, VP_INT exinf )
{
/* ......... */
}
|
Note 1 The accepted exception code is passed to
texptn.
Note 2 The extend information defined at creating the task is passed to
exinf.
Note 3 These statements are unnecessary for the task exception handling routine which is created by the system configuration file because the cfg600px generates these statement into the "kernel_id.h".
6.2.2 Internal processing of task exception handling routine
- Stack
Task exception handling routines use user stacks for the task.
- Service call
Tasks can issue service calls whose "Useful range" is "task".
- PSW register when processing is started
Table 6-2 PSW Register When Task Exception Handling Routine Processing is Started
|
|
|
|
|
|
|
Same as IPL in the task just before the task exception handling routine starts.
|
|
|
|
|
|
|
|
|
|
|
|
|
|
Table 6-3 FPSW Register When Task Processing is Started
|
|
|
|
|
|
0x00000100 (Only DN bit is 1.)
|
|
|
|
|
0x00000101 (Only DN bit and RM bit are 1.)
|
|
|
6.2.3 The starting conditions of task exception handling routines
When all the following conditions are fulfilled about a task which is scheduled according to "
16.4 Task Scheduling Method", the RI600PX starts the task exception handling routine in stead of the task itself. When the task exception handling routine is finished, execution of the task itself is resumed.
Table 6-4 The Starting Conditions of Task Exception Handling Routines
|
|
|
The task is in the task exception enabled state.
|
|
The pending exception code of the task is not 0.
|
The exception code is represented by
TEXPTN type bit pattern.
When task exception is requested by
ras_tex or
iras_tex, the pending exception code for the corresponded task is renewed to the logical add with specified exception code.
Tasks are in one of the state of task exception disabled state or task exception enabled state. Immediately after starting tasks, the task is in task exception disabled state. And the task is in task exception disabled state while the task exception handling routine is not defined. When
ena_tex is called, the invoking task enters in task exception enabled state. When
dis_tex is called, the invoking task enters in task exception disabled state.
When the task exception handling routine is started, the task enters in task exception disabled state. When the task exception handling routine is finished, the task enters in task exception enabled state.
Table 6-5 Operations to Disable Task Exception
|
|
|
|
|
|
|
|
|
|
Starting of task exception handling routine
|
|
|
|
|
Table 6-6 Operations to Enable Task Exception
|
|
|
|
|
|
|
Finishing of task exception handling routine
|
|
6.3 Define Task Exception Handling Routine
Task exception handling routines are defined by one of the following methods.
1 ) Definition by the system configuration file
The task exception handling routine can be defined by the static API "task[]", which creates a task, described in the system configuration file.
Refer to "
20.10 Task Information (task[])" for the details of "task[]".
2 ) Definition by
def_tex
The def_tex defines a task exception handling routine for the task indicated by parameter
tskid according to the content of parameter
pk_dtex.
The information specified is shown below.
- Task exception handling routine attribute (
texatr)
Only TA_HLNG can be specified as
texatr.
- Task exception handling routine start address (
texrtn)
This service call can be called from tasks that belong to
Trusted Domain.
The following describes an example for coding def_tex.
#include "kernel.h" /*Standard header file definition*/
#include "kernel_id.h" /*Header file generated by cfg600px*/
extern void Texrtn1 ( TEXPTN texptn, VP_INT exinf );
#pragma task Task1 /*Refer to note*/
void Task1 (VP_INT exinf); /*Refer to note*/
void Task1 (VP_INT exinf)
{
ER ercd; /*Declares variable*/
ID tskid = TSK_SELF; /*Declares and initializes variable*/
T_DTEX pk_dtex = { /*Declares and initializes variable*/
TA_HLNG, /*Task exception handling routine attribute (texatr)*/
(FP)Texrtn1 /*Start address (texrtn)*/
};
/* ......... */
ercd = def_tex ( tskid, &pk_dtex ); /*Define task exception handling routine*/
/* ......... */
}
|
Note These statements are unnecessary for the task which is created by the system configuration file because the cfg600px generates these statement into the "kernel_id.h".
6.4 Cancel a Definition of Task Exception Handling Routine
When NULL is specified as parameter
pk_dtex in the
def_tex, the def_tex cancels a definition of the task exception handling routine for the task indicated by parameter
tskid.
The def_tex can be called from tasks that belong to
Trusted Domain.
The following describes an example for coding to cancel the a definition of the task exception handling routine by using def_tex.
.
#include "kernel.h" /*Standard header file definition*/
#include "kernel_id.h" /*Header file generated by cfg600px*/
#pragma task Task1 /*Refer to note*/
void Task1 (VP_INT exinf); /*Refer to note*/
void Task1 (VP_INT exinf)
{
ER ercd; /*Declares variable*/
ID tskid = TSK_SELF; /*Declares and initializes variable*/
/* ......... */
ercd = def_tex ( tskid, (T_DTEX *)NULL ); /*Cancel a definition*/
/* ......... */
}
|
Note These statements are unnecessary for the task which is created by the system configuration file because the cfg600px generates these statement into the "kernel_id.h".
6.5 Request Task Exception
-
ras_tex,
iras_tex
These service calls requests task exception handling for the task indicated by parameter
tskid. The task pending exception code for the task is ORed with the value indicated by parameter
rasptn.
When all the conditions described in "
6.2.3 The starting conditions of task exception handling routines" are fulfilled by this service call, the RI600PX starts the task exception handling routine.
The following describes an example for coding this service call.
#include "kernel.h" /*Standard header file definition*/
#include "kernel_id.h" /*Header file generated by cfg600px*/
#pragma task Task1 /*Refer to note*/
void Task1 (VP_INT exinf); /*Refer to note*/
void Task1 (VP_INT exinf)
{
ID tskid = 8; /*Declares and initializes variable*/
TEXPTN rasptn = 0x00000001UL; /*Declares and initializes variable*/
/* ......... */
ras_tex ( tskid, rasptn ); /*Request task exception*/
/* ......... */
}
|
Note These statements are unnecessary for the task which is created by the system configuration file because the cfg600px generates these statement into the "kernel_id.h".
6.6 Disable and Enable Task Exception
The
dis_tex disables task exception for the invoking task, and the
ena_tex enables task exception for the invoking task.
The following describes an example for coding this service call.
#include "kernel.h" /*Standard header file definition*/
#include "kernel_id.h" /*Header file generated by cfg600px*/
#pragma task Task1 /*Refer to note*/
void Task1 (VP_INT exinf); /*Refer to note*/
void Task1 (VP_INT exinf)
{
/* ......... */
ena_tex (); /*Disable task exception*/
/* ......... */ /*Task exception enabled state*/
dis_tex (); /*Enable task exception*/
/* ......... */
}
|
Note These statements are unnecessary for the task which is created by the system configuration file because the cfg600px generates these statement into the "kernel_id.h".
6.7 Reference Task Exception Disabled State
It may be necessary to refer to task exception disabled state for the task of a calling agency in functions that are called from two or more tasks and handlers. In this case,
sns_tex is useful.
-
sns_tex
This service call returns TRUE when the task in the RUNNING state is in the task exception disabled state, and when other, this service call returns FALSE.
The following describes an example for coding this service call.
#include "kernel.h" /*Standard header file definition*/
#include "kernel_id.h" /*Header file generated by cfg600px*/
void CommonFunc ( void );
void CommonFunc ( void )
{
BOOL ctx; /*Declares variable*/
BOOL tex; /*Declares variable*/
/* ......... */
ctx = sns_ctx ( ); /*Reference context type*/
if (ctx == TRUE ) {
/* ......... */ /*Processing for non-task context*/
/* ......... */
} else if ( ctx == FALSE ) {
/* ......... */ /*Processing for task context*/
/* ......... */
tex = sns_tex (); /*Reference task exception disabled state*/
if ( tex == TRUE) {
/* ......... */ /*The invoking task is in the task*/
/* ......... */ /*exception disabled state.*/
} else if ( tex == FALSE) {
/* ......... */ /*The invoking task is in the task*/
/* ......... */ /*exception enabled state.*/
}
}
/* ......... */
}
|
6.8 Reference Task Exception State
-
ref_tex,
iref_tex
Stores task exception state packet of the task specified by parameter
tskid in the area specified by parameter
pk_rtex.
The following describes an example for coding these service calls.
#include "kernel.h" /*Standard header file definition*/
#include "kernel_id.h" /*Header file generated by cfg600px*/
#pragma task Task1 /*Refer to note 2*/
void Task1 (VP_INT exinf); /*Refer to note 2*/
void Task1 (VP_INT exinf)
{
ID tskid = 8; /*Declares and initializes variable*/
T_RTEX pk_rtex; /*Declares data structure*/
STAT texstat; /*Declares variable*/
TEXPTN texptn; /*Declares variable*/
/* ......... */
ref_tex (tskid, &pk_rtex); /*Reference task exception state*/
texstat = pk_rtex.texstat; /*Reference task exception handling state*/
texptn = pk_rtex.texptn; /*Reference pending exception code*/
/* ......... */
}
|
Note 2 These statements are unnecessary for the task which is created by the system configuration file because the cfg600px generates these statement into the "kernel_id.h".