Everything

CHAPTER 8 SYSTEM STATE MANAGEMENT FUNCTIONS


This chapter describes the system management functions performed by the RI850V4.
8.1 Outline
The RI850V4's system status management function provides functions for referencing the system status such as the context type and CPU lock status, as well as functions for manipulating the system status such as ready queue rotation, scheduler activation, or the like.
8.2 Rotate Task Precedence
A ready queue is rotated by issuing the following service call from the processing program.
- rot_rdq, irot_rdq
This service call re-queues the first task of the ready queue corresponding to the priority specified by parameter tskpri to the end of the queue to change the task execution order explicitly.
The following shows the status transition when this service call is used.
Figure 8-1 Rotate Task Precedence
The following describes an example for coding this service call.
 #include    <kernel.h>              /*Standard header file definition*/
 #include    <kernel_id.h>           /*System information header file definition*/
 
 void cychdr (VP_INT exinf)
 {
     PRI     tskpri = 8;             /*Declares and initializes variable*/
 
     .........
 
     irot_rdq (tskpri);              /*Rotate task precedence*/
 
     .........
 
     return;                         /*Terminate cyclic handler*/
 }

Note 1 This service call does not perform queuing of rotation requests. If no task is queued to the ready queue corresponding to the relevant priority, therefore, no processing is performed but it is not handled as an error.
Note 2 Round-robin scheduling can be implemented by issuing this service call via a cyclic handler in a constant cycle.
Note 3 The ready queue is a hash table that uses priority as the key, and tasks that have entered an executable state (READY state or RUNNING state) are queued in FIFO order.
Therefore, the scheduler realizes the RI850V4's scheduling system (priority level method, FCFS method) by executing task detection processing from the highest priority level of the ready queue upon activation, and upon detection of queued tasks, giving the CPU use right to the first task of the proper priority level.
8.3 Forced Scheduler Activation
The scheduler can be forcibly activated by issuing the following service call from the processing program.
- vsta_sch
This service call explicitly forces the RI850V4 scheduler to activate. If a scheduling request has been kept pending, task switching may therefore occur.
The following describes an example for coding this service call.
 #include    <kernel.h>              /*Standard header file definition*/
 #include    <kernel_id.h>           /*System information header file definition*/
 
 void task (VP_INT exinf)
 {
 
     .........
 
     vsta_sch ();                    /*Forced scheduler*/
 
     .........
 }

Note The RI850V4 provides this service call as a function to activate a scheduler from a task for which preempt acknowledge status (TA_DISPREEMPT) disable is defined during configuration.
8.4 Reference Task ID in the RUNNING State
A RUNNING-state task is referenced by issuing the following service call from the processing program.
- get_tid, iget_tid
These service calls store the ID of a task in the RUNNING state in the area specified by parameter p_tskid.
The following describes an example for coding this service call.
 #include    <kernel.h>              /*Standard header file definition*/
 #include    <kernel_id.h>           /*System information header file definition*/
 
 void inthdr (void)
 {
     ID      p_tskid;                /*Declares variable*/
 
     .........
 
     iget_tid (&p_tskid);            /*Reference task ID in the RUNNING state*/
 
     .........
 
     return;                         /*Terminate interrupt handler*/
 }

Note This service call stores TSK_NONE in the area specified by parameter p_tskid if no tasks that have entered the RUNNING state exist (all tasks in the IDLE state).
8.5 Lock the CPU
A task is moved to the CPU locked state by issuing the following service call from the processing program.
- loc_cpu, iloc_cpu
These service calls change the system status type to the CPU locked state.
As a result, EI level maskable interrupt acknowledgment processing is prohibited during the interval from this service call is issued until unl_cpu or iunl_cpu is issued, and service call issue is also restricted.
The service calls that can be issued in the CPU locked state are limited to the one listed below.
Service Call
Function
Lock the CPU.
Unlock the CPU.
Reference CPU state.
Reference dispatching state.
Reference contexts.
Reference dispatch pending state.

If an EI level maskable interrupt is created during this period, the RI850V4 delays transition to the relevant interrupt processing (interrupt handler) until either unl_cpu or iunl_cpu is issued.
The following shows a processing flow when using this service call.
Figure 8-2 Lock the CPU
The following describes an example for coding this service call.
 #include    <kernel.h>              /*Standard header file definition*/
 #include    <kernel_id.h>           /*System information header file definition*/
 
 void task (VP_INT exinf)
 {
     .........
 
     loc_cpu ();                     /*Lock the CPU*/
 
     .........                       /*CPU locked state*/
 
     unl_cpu ();                     /*Unlock the CPU*/
 
     .........
 }

Note 1 The CPU locked state changed by issuing this service call must be cancelled before the processing program that issued this service call ends.
Note 2 This service call does not perform queuing of lock requests. If the system is in the CPU locked state, therefore, no processing is performed but it is not handled as an error.
Note 3 This service call manipulates PMn bits in the priority mask register (PMR) to disable acceptance of EI level maskable interrupts.
The PMn bits to be manipulated correspond to the interrupt priority range defined as the Maximum interrupt priority: maxintpri during configuration.
Note 4 This service call does not manipulate the ID bit in the program status word (PSW).
Note 5 The RI850V4 realizes the TIME MANAGEMENT FUNCTIONS by using base clock timer interrupts that occur at constant intervals. If acknowledgment of the relevant base clock timer interrupt is disabled by issuing this service call, the TIME MANAGEMENT FUNCTIONS may no longer operate normally.
Note 6 If this service call or a service call other than sns_xxx is issued from when this service call is issued until unl_cpu or iunl_cpu is issued, the RI850V4 returns E_CTX.
8.6 Unlock the CPU
The CPU locked state is cancelled by issuing the following service call from the processing program.
- unl_cpu, iunl_cpu
These service calls change the system status to the CPU unlocked state.
As a result, acknowledge processing of EI level maskable interrupts prohibited through issue of either loc_cpu or iloc_cpu is enabled, and the restriction on service call issue is released.
If an EI level maskable interrupt is created during the interval from when either loc_cpu or iloc_cpu is issued until this service call is issued, the RI850V4 delays transition to the relevant interrupt processing (interrupt handler) until this service call is issued.
The following shows a processing flow when using this service call.
Figure 8-3 Unlock the CPU
The following describes an example for coding this service call.
 #include    <kernel.h>              /*Standard header file definition*/
 #include    <kernel_id.h>           /*System information header file definition*/
 
 void task (VP_INT exinf)
 {
     .........
 
     loc_cpu ();                     /*Lock the CPU*/
 
     .........                       /*CPU locked state*/
 
     unl_cpu ();                     /*Unlock the CPU*/
 
     .........
 }

Note 1 This service call does not perform queuing of cancellation requests. If the system is in the CPU unlocked state, therefore, no processing is performed but it is not handled as an error.
Note 2 This service call manipulates PMn bits in the priority mask register (PMR) to disable acceptance of EI level maskable interrupts.
The PMn bits to be manipulated correspond to the interrupt priority range defined as the Maximum interrupt priority: maxintpri during configuration.
Note 3 This service call does not cancel the dispatch disabled state that was set by issuing dis_dsp. If the system status before the CPU locked state is entered was the dispatch disabled state, the system status becomes the dispatch disabled state after this service call is issued.
Note 4 If a service call other than loc_cpu, iloc_cpu and sns_xxx is issued from when loc_cpu or iloc_cpu is issued until this service call is issued, the RI850V4 returns E_CTX.
8.7 Reference CPU State
The CPU locked state is referenced by issuing the following service call from the processing program.
- sns_loc
This service call acquires the system status type when this service call is issued (CPU locked state or CPU unlocked state).
When this service call is terminated normally, the acquired system state type (TRUE: CPU locked state, FALSE: CPU unlocked state) is returned.
The following describes an example for coding this service call.
 #include    <kernel.h>              /*Standard header file definition*/
 #include    <kernel_id.h>           /*System information header file definition*/
 
 void task (VP_INT exinf)
 {
     BOOL ercd;                      /*Declares variable*/
 
     .........
 
     ercd = sns_loc ();              /*Reference CPU state*/
 
     if (ercd == TRUE) {
         .........                   /*CPU locked state*/
     } else if (ercd == FALSE) {
         .........                   /*CPU unlocked state*/
     }
 
     .........
 }

8.8 Disable Dispatching
A task is moved to the dispatch disabled state by issuing the following service call from the processing program.
- dis_dsp
This service call changes the system status to the dispatch disabled state.
As a result, dispatch processing (task scheduling) is disabled from when this service call is issued until ena_dsp is issued.
If a service call (chg_pri, sig_sem, etc.) accompanying dispatch processing is issued during the interval from when this service call is issued until ena_dsp is issued, the RI850V4 executes only processing such as queue manipulation, counter manipulation, etc., and the actual dispatch processing is delayed until ena_dsp is issued, upon which the actual dispatch processing is performed in batch.
The following shows a processing flow when using this service call.
Figure 8-4 Disable Dispatching
The following describes an example for coding this service call.
 #include    <kernel.h>              /*Standard header file definition*/
 #include    <kernel_id.h>           /*System information header file definition*/
 
 #pragma rtos_task   task            /*#pragma directive definition*/
 
 void task (VP_INT exinf)
 {
     .........
 
     dis_dsp ();                     /*Disable dispatching*/
 
     .........                       /*Dispatching disabled state*/
 
     ena_dsp ();                     /*Enable dispatching*/
 
     .........
 }

Note 1 The dispatch disabled state changed by issuing this service call must be cancelled before the task that issued this service call moves to the DORMANT state.
Note 2 This service call does not perform queuing of disable requests. If the system is in the dispatch disabled state, therefore, no processing is performed but it is not handled as an error.
Note 3 If a service call (such as wai_sem, wai_flg) that may move the status of an invoking task is issued from when this service call is issued until ena_dsp is issued, the RI850V4 returns E_CTX regardless of whether the required condition is immediately satisfied.
8.9 Enable Dispatching
The dispatch disabled state is cancelled by issuing the following service call from the processing program.
- ena_dsp
This service call changes the system status to the dispatch enabled state.
As a result, dispatch processing (task scheduling) that has been disabled by issuing dis_dsp is enabled.
If a service call (chg_pri, sig_sem, etc.) accompanying dispatch processing is issued during the interval from when dis_dsp is issued until this service call is issued, the RI850V4 executes only processing such as queue manipulation, counter manipulation, etc., and the actual dispatch processing is delayed until this service call is issued, upon which the actual dispatch processing is performed in batch.
The following shows a processing flow when using this service call.
Figure 8-5 Enable Dispatching
The following describes an example for coding this service call.
 #include    <kernel.h>              /*Standard header file definition*/
 #include    <kernel_id.h>           /*System information header file definition*/
 
 void task (VP_INT exinf)
 {
     .........
 
     dis_dsp ();                     /*Disable dispatching*/
 
     .........                       /*Dispatching disabled state*/
 
     ena_dsp ();                     /*Enable dispatching*/
 
     .........
 }

Note 1 This service call does not perform queuing of enable requests. If the system is in the dispatch enabled state, therefore, no processing is performed but it is not handled as an error.
Note 2 If a service call (such as wai_sem, wai_flg) that may move the status of an invoking task is issued from when dis_dsp is issued until this service call is issued, the RI850V4 returns E_CTX regardless of whether the required condition is immediately satisfied.
8.10 Reference Dispatching State
The dispatch disabled state is referenced by issuing the following service call from the processing program.
- sns_dsp
This service call acquires the system status type when this service call is issued (dispatch disabled state or dispatch enabled state).
When this service call is terminated normally, the acquired system state type (TRUE: dispatch disabled state, FALSE: dispatch enabled state) is returned.
The following describes an example for coding this service call.
 #include    <kernel.h>              /*Standard header file definition*/
 #include    <kernel_id.h>           /*System information header file definition*/
 
 void task (VP_INT exinf)
 {
     BOOL ercd;                      /*Declares variable*/
 
     .........
 
     ercd = sns_dsp ();              /*Reference dispatching state*/
 
     if (ercd == TRUE) {
         .........                   /*Dispatching disabled state*/
     } else if (ercd == FALSE) {
         .........                  /*Dispatching enabled state*/
     }
 
     .........
 }

8.11 Reference Contexts
The context type is referenced by issuing the following service call from the processing program.
- sns_ctx
This service call acquires the context type of the processing program that issued this service call (non-task context or task context).
When this service call is terminated normally, the acquired context type (TRUE: non-task context, FALSE: task context) is returned.
The following describes an example for coding this service call.
 #include    <kernel.h>              /*Standard header file definition*/
 #include    <kernel_id.h>           /*System information header file definition*/
 
 void task (VP_INT exinf)
 {
     BOOL ercd;                      /*Declares variable*/
 
     .........
 
     ercd = sns_ctx ();              /*Reference contexts*/
 
     if (ercd == TRUE) {
         .........                   /*Non-task contexts*/
     } else if (ercd == FALSE) {
         .........                   /*Task contexts*/
     }
 
     .........
 }

8.12 Reference Dispatch Pending State
The dispatch pending state is referenced by issuing the following service call from the processing program.
- sns_dpn
This service call acquires the system status type when this service call is issued (whether in dispatch pending state or not).
When this service call is terminated normally, the acquired system state type (TRUE: dispatch pending state, FALSE: dispatch not-pending state) is returned.
The following describes an example for coding this service call.
 #include    <kernel.h>              /*Standard header file definition*/
 #include    <kernel_id.h>           /*System information header file definition*/
 
 void task (VP_INT exinf)
 {
     BOOL ercd;                      /*Declares variable*/
 
     .........
 
     ercd = sns_dpn ();              /*Reference dispatch pending state*/
 
     if (ercd == TRUE) {
         .........                   /*Dispatch pending state*/
     } else if (ercd == FALSE) {
         .........                   /*Other state*/
     }
 
     .........
 }