Everything
5.4 Data Queues
Multitask processing requires the inter-task communication function (data transfer function) that reports the processing result of a task to another task. The RI600V4 therefore provides the data queues for transferring the prescribed size of data.
The following shows a processing flow when using a data queue.
Figure 5-3 Processing Flow (Data Queue)
Note Data units of 4 bytes are transmitted or received at a time.
5.4.1 Create data queue
In the RI600V4, the method of creating data queue is limited to "static creation".
Data queues therefore cannot be created dynamically using a method such as issuing a service call from a processing program.
Static data queue creation means defining of data queues using static API "dataqueue[]" in the system configuration file.
For details about the static API "dataqueue[]", refer to "19.10 Data Queue Information (dataqueue[])".
5.4.2 Send to data queue
A data is transmitted by issuing the following service call from the processing program.
- snd_dtq (Wait)
- psnd_dtq, ipsnd_dtq (Polling)
- tsnd_dtq (Wait with time-out)
- snd_dtq (Wait)
This service call processes as follows according to the situation of the data queue specified by the parameter dtqid.
- There is a task in the reception wait queue.
This service call transfers the data specified by parameter data to the task in the top of the reception wait queue. As a result, the task is unlinked from the reception wait queue and moves from the WAITING state (data reception wait state) to the READY state, or from the WAITING-SUSPENDED state to the SUSPENDED state.
- There is no task neither in the reception wait queue and transmission wait queue and there is available space in the data queue.
This service call stores the data specified by parameter data to the data queue.
- There is no task neither in the reception wait queue and transmission wait queue and there is no available space in the data queue, or there is a task in the transmission wait queue.
This service call queues the invoking task to the transmission wait queue of the target data queue and moves it from the RUNNING state to the WAITING state (data transmission wait state).
The sending WAITING state for a data queue is cancelled in the following cases.
Sending WAITING State for a Data Queue Cancel Operation
Return Value
Available space was secured in the data queue area as a result of issuing rcv_dtq.
E_OK
Available space was secured in the data queue area as a result of issuing prcv_dtq.
E_OK
Available space was secured in the data queue area as a result of issuing iprcv_dtq.
E_OK
Available space was secured in the data queue area as a result of issuing trcv_dtq.
E_OK
Forced release from waiting (accept rel_wai while waiting).
E_RLWAI
Forced release from waiting (accept irel_wai while waiting).
E_RLWAI
The data queue is reset as a result of issuing vrst_dtq.
EV_RST

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 cfg600*/
 
 void task (VP_INT exinf)
 {
     ER      ercd;                   /*Declares variable*/
     ID      dtqid = 1;              /*Declares and initializes variable*/
     VP_INT  data = 123;             /*Declares and initializes variable*/
 
     /* ......... */
 
     ercd = snd_dtq (dtqid, data);   /*Send to data queue*/
 
     if (ercd == E_OK) {
         /* ......... */             /*Normal termination processing*/
     } else if (ercd == E_RLWAI) {
         /* ......... */             /*Forced termination processing*/
     }
 
     /* ......... */
 }

Note 1 Data is written to the data queue area in the order of the data transmission request.
Note 2 Invoking tasks are queued to the transmission wait queue of the target data queue in the order defined during configuration (FIFO order or current priority order).
- psnd_dtq, ipsnd_dtq (Polling)
These service calls process as follows according to the situation of the data queue specified by the parameter dtqid.
- There is a task in the reception wait queue.
These service calls transfer the data specified by parameter data to the task in the top of the reception wait queue. As a result, the task is unlinked from the reception wait queue and moves from the WAITING state (data reception wait state) to the READY state, or from the WAITING-SUSPENDED state to the SUSPENDED state.
- There is no task neither in the reception wait queue and transmission wait queue and there is available space in the data queue.
These service calls store the data specified by parameter data to the data queue.
- There is no task neither in the reception wait queue and transmission wait queue and there is no available space in the data queue, or there is a task in the transmission wait queue.
These service calls return "E_TMOUT".
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 cfg600*/
 
 void task (VP_INT exinf)
 {
     ER      ercd;                   /*Declares variable*/
     ID      dtqid = 1;              /*Declares and initializes variable*/
     VP_INT  data = 123;             /*Declares and initializes variable*/
 
     /* ......... */
 
     ercd = psnd_dtq (dtqid, data);  /*Send to data queue*
 
     if (ercd == E_OK) {
         /* ......... */             /*Polling success processing*/
     } else if (ercd == E_TMOUT) {
         /* ......... */             /*Polling failure processing*/
     }
 
     /* ......... */
 }

Note Data is written to the data queue area in the order of the data transmission request.
- tsnd_dtq (Wait with time-out)
This service call processes as follows according to the situation of the data queue specified by the parameter dtqid.
- There is a task in the reception wait queue.
This service call transfers the data specified by parameter data to the task in the top of the reception wait queue. As a result, the task is unlinked from the reception wait queue and moves from the WAITING state (data reception wait state) to the READY state, or from the WAITING-SUSPENDED state to the SUSPENDED state.
- There is no task neither in the reception wait queue and transmission wait queue and there is available space in the data queue.
This service call stores the data specified by parameter data to the data queue.
- There is no task neither in the reception wait queue and transmission wait queue and there is no available space in the data queue, or there is a task in the transmission wait queue.
This service call queues the invoking task to the transmission wait queue of the target data queue and moves it from the RUNNING state to the WAITING state with time (data transmission wait state).
The sending WAITING state for a data queue is cancelled in the following cases.
Sending WAITING State for a Data Queue Cancel Operation
Return Value
Available space was secured in the data queue area as a result of issuing rcv_dtq.
E_OK
Available space was secured in the data queue area as a result of issuing prcv_dtq.
E_OK
Available space was secured in the data queue area as a result of issuing iprcv_dtq.
E_OK
Available space was secured in the data queue area as a result of issuing trcv_dtq.
E_OK
Forced release from waiting (accept rel_wai while waiting).
E_RLWAI
Forced release from waiting (accept irel_wai while waiting).
E_RLWAI
The data queue is reset as a result of issuing vrst_dtq.
EV_RST
The time specified by tmout has elapsed.
E_TMOUT

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 cfg600*/
 
 void task (VP_INT exinf)
 {
     ER      ercd;                   /*Declares variable*/
     ID      dtqid = 1;              /*Declares and initializes variable*/
     VP_INT  data = 123;             /*Declares and initializes variable*/
     TMO     tmout = 3600;           /*Declares and initializes variable*/
 
     /* ......... */
 
                                     /*Send to data queue*/
     ercd = tsnd_dtq (dtqid, data, tmout);
 
     if (ercd == E_OK) {
         /* ......... */             /*Normal termination processing*/
     } else if (ercd == E_RLWAI) {
         /* ......... */             /*Forced termination processing*/
     } else if (ercd == E_TMOUT) {
         /* ......... */             /*Time-out processing*/
     }
 
     /* ......... */
 }

Note 1 Data is written to the data queue area in the order of the data transmission request.
Note 2 Invoking tasks are queued to the transmission wait queue of the target data queue in the order defined during configuration (FIFO order or current priority order).
Note 3 TMO_FEVR is specified for wait time tmout, processing equivalent to snd_dtq will be executed. When TMO_POL is specified, processing equivalent to psnd_dtq will be executed.
5.4.3 Forced send to data queue
Data is forcibly transmitted by issuing the following service call from the processing program.
- fsnd_dtq, ifsnd_dtq
This service call processes as follows according to the situation of the data queue specified by the parameter dtqid.
- There is a task in the reception wait queue.
This service call transfers the data specified by parameter data to the task in the top of the reception wait queue. As a result, the task is unlinked from the reception wait queue and moves from the WAITING state (data reception wait state) to the READY state, or from the WAITING-SUSPENDED state to the SUSPENDED state.
- There is no task neither in the reception wait queue and transmission wait queue.
This service call stores the data specified by parameter data to the data queue.
If there is no available space in the data queue, this service call deletes the oldest data in the data queue before storing the data specified by data to the data queue.
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 cfg600*/
 
 void task (VP_INT exinf)
 {
     ID      dtqid = 1;              /*Declares and initializes variable*/
     VP_INT  data = 123;             /*Declares and initializes variable*/
 
     /* ......... */
 
     fsnd_dtq (dtqid, data);         /*Forced send to data queue*/
 
     /* ......... */
 }

Note Data is written to the data queue area in the order of the data transmission request.
5.4.4 Receive from data queue
A data is received (waiting forever, polling, or with time-out) by issuing the following service call from the processing program.
- rcv_dtq (Wait)
- prcv_dtq, iprcv_dtq (Polling)
- trcv_dtq (Wait with time-out)
- rcv_dtq (Wait)
This service call processes as follows according to the situation of the data queue specified by the parameter dtqid.
- There is a data in the data queue.
This service call takes out the oldest data from the data queue and stores the data to the area specified by p_data.
When there is a task in the transmission wait queue, this service call stores the data sent by the task in the top of the transmission wait queue and moves it from the WAITING state (data transmission wait state) to the READY state.
- There is no data in the data queue and there is a task in the transmission wait queue.
This service call stores the data specified by the task in the top of the transmission wait queue to the area specified by p_data. As a result, the task is unlinked from the transmission wait queue and moves from the WAITING state (data transmission wait state) to the READY state, or from the WAITING-SUSPENDED state to the SUSPENDED state.
Note, this situation is caused only when the capacity of the data queue is 0.
- There is no data in the data queue and there is no task in the transmission wait queue.
This service call queues the invoking task to the reception wait queue of the target data queue and moves it from the RUNNING state to the WAITING state (data reception wait state).
The receiving WAITING state for a data queue is cancelled in the following cases.
Receiving WAITING State for a Data Queue Cancel Operation
Return Value
Data was sent to the data queue area as a result of issuing snd_dtq.
E_OK
Data was sent to the data queue area as a result of issuing psnd_dtq.
E_OK
Data was sent to the data queue area as a result of issuing ipsnd_dtq.
E_OK
Data was sent to the data queue area as a result of issuing tsnd_dtq.
E_OK
Data was sent to the data queue area as a result of issuing fsnd_dtq.
E_OK
Data was sent to the data queue area as a result of issuing ifsnd_dtq.
E_OK
Forced release from waiting (accept rel_wai while waiting).
E_RLWAI
Forced release from waiting (accept irel_wai while waiting).
E_RLWAI

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 cfg600*/
 
 void task (VP_INT exinf)
 {
     ER      ercd;                   /*Declares variable*/
     ID      dtqid = 1;              /*Declares and initializes variable*/
     VP_INT  p_data;                 /*Declares variable*/
 
     /* ......... */
 
                                     /*Receive from data queue*/
     ercd = rcv_dtq (dtqid, &p_data);
 
     if (ercd == E_OK) {
         /* ......... */             /*Normal termination processing*/
     } else if (ercd == E_RLWAI) {
         /* ......... */             /*Forced termination processing*/
     }
 
     /* ......... */
 }

Note Invoking tasks are queued to the reception wait queue of the target data queue in the order of the data reception request.
- prcv_dtq, iprcv_dtq (Polling)
These service calls process as follows according to the situation of the data queue specified by the parameter dtqid.
- There is a data in the data queue.
This service call takes out the oldest data from the data queue and stores the data to the area specified by p_data.
When there is a task in the transmission wait queue, this service call stores the data sent by the task in the top of the transmission wait queue and moves it from the WAITING state (data transmission wait state) to the READY state.
- There is no data in the data queue and there is a task in the transmission wait queue.
These service calls store the data specified by the task in the top of the transmission wait queue to the area specified by p_data. As a result, the task is unlinked from the transmission wait queue and moves from the WAITING state (data transmission wait state) to the READY state, or from the WAITING-SUSPENDED state to the SUSPENDED state.
Note, this situation is caused only when the capacity of the data queue is 0.
- There is no data in the data queue and there is no task in the transmission wait queue.
These service calls return "E_TMOUT".
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 cfg600*/
 
 void task (VP_INT exinf)
 {
     ER      ercd;                   /*Declares variable*/
     ID      dtqid = 1;              /*Declares and initializes variable*/
     VP_INT  p_data;                 /*Declares variable*/
 
     /* ......... */
 
                                     /*Receive from data queue*/
     ercd = prcv_dtq (dtqid, &p_data);
 
     if (ercd == E_OK) {
         /* ......... */             /*Polling success processing*/
     } else if (ercd == E_TMOUT) {
         /* ......... */             /*Polling failure processing*/
     }
 
     /* ......... */
 }

- trcv_dtq (Wait with time-out)
This service call processes as follows according to the situation of the data queue specified by the parameter dtqid.
- There is a data in the data queue.
This service call takes out the oldest data from the data queue and stores the data to the area specified by p_data.
When there is a task in the transmission wait queue, this service call stores the data sent by the task in the top of the transmission wait queue and moves it from the WAITING state (data transmission wait state) to the READY state.
- There is no data in the data queue and there is a task in the transmission wait queue.
This service call stores the data specified by the task in the top of the transmission wait queue to the area specified by p_data. As a result, the task is unlinked from the transmission wait queue and moves from the WAITING state (data transmission wait state) to the READY state, or from the WAITING-SUSPENDED state to the SUSPENDED state.
Note, this situation is caused only when the capacity of the data queue is 0.
- There is no data in the data queue and there is no task in the transmission wait queue.
This service call queues the invoking task to the reception wait queue of the target data queue and moves it from the RUNNING state to the WAITING state with time (data reception wait state).
The receiving WAITING state for a data queue is cancelled in the following cases.
Receiving WAITING State for a Data Queue Cancel Operation
Return Value
Data was sent to the data queue area as a result of issuing snd_dtq.
E_OK
Data was sent to the data queue area as a result of issuing psnd_dtq.
E_OK
Data was sent to the data queue area as a result of issuing ipsnd_dtq.
E_OK
Data was sent to the data queue area as a result of issuing tsnd_dtq.
E_OK
Data was sent to the data queue area as a result of issuing fsnd_dtq.
E_OK
Data was sent to the data queue area as a result of issuing ifsnd_dtq.
E_OK
Forced release from waiting (accept rel_wai while waiting).
E_RLWAI
Forced release from waiting (accept irel_wai while waiting).
E_RLWAI
The time specified by tmout has elapsed.
E_TMOUT

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 cfg600*/
 
 void task (VP_INT exinf)
 {
     ER      ercd;                   /*Declares variable*/
     ID      dtqid = 1;              /*Declares and initializes variable*/
     VP_INT  p_data;                 /*Declares variable*/
     TMO     tmout = 3600;           /*Declares and initializes variable*/
 
     /* ......... */
 
                                     /*Receive from data queue*/
     ercd = trcv_dtq (dtqid, &p_data, tmout);
 
     if (ercd == E_OK) {
             /* ......... */         /*Normal termination processing*/
     } else if (ercd == E_RLWAI) {
             /* ......... */         /*Forced termination processing*/
     } else if (ercd == E_TMOUT) {
             /* ......... */         /*Time-out processing*/
     }
 
     /* ......... */
 }

Note 1 Invoking tasks are queued to the reception wait queue of the target data queue in the order of the data reception request.
Note 2 TMO_FEVR is specified for wait time tmout, processing equivalent to rcv_dtq will be executed. When TMO_POL is specified, processing equivalent to prcv_dtq will be executed.
5.4.5 Reference data queue state
A data queue status is referenced by issuing the following service call from the processing program.
- ref_dtq, iref_dtq
These service calls store the detailed information of the data queue (existence of waiting tasks, number of data elements in the data queue, etc.) specified by parameter dtqid into the area specified by parameter pk_rdtq.
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 cfg600*/
 
 void task (VP_INT exinf)
 {
     ID      dtqid = 1;              /*Declares and initializes variable*/
     T_RDTQ  pk_rdtq;                /*Declares data structure*/
     ID      stskid;                 /*Declares variable*/
     ID      rtskid;                 /*Declares variable*/
     UINT    sdtqcnt;                /*Declares variable*/
 
     /* ......... */
 
     ref_dtq (dtqid, &pk_rdtq);      /*Reference data queue state*/
 
     stskid = pk_rdtq.stskid;        /*Acquires existence of tasks waiting for */
                                     /*data transmission*/
     rtskid = pk_rdtq.rtskid;        /*Acquires existence of tasks waiting for */
                                     /*data reception*/
     sdtqcnt = pk_rdtq.sdtqcnt;      /*Reference the number of data elements in */
                                     /*data queue*/
 
     /* ......... */
 }

Note For details about the data queue state packet, refer to "[Data queue state packet: T_RDTQ]".