7.3 Variable-Sized Memory Pools
When a dynamic memory manipulation request is issued from a processing program in the RI600V4, the variable-sized memory pool is provided as a usable memory area.
Dynamic memory manipulation for variable-size memory pools is performed in the units of the specified variable-size memory block size.
7.3.1 Create variable-sized memory pool
In the RI600V4, the method of creating a variable-sized memory pool is limited to "static creation".
Variable-sized memory pools therefore cannot be created dynamically using a method such as issuing a service call from a processing program.
Static variable-size memory pool creation means defining of variable-size memory pools using static API "variable_memorypool[]" in the system configuration file.
7.3.2 Size of Variable-sized memory block
Table 7-1 Variation of memory block size
|
Size of memory block (Hexadecimal)
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
7.3.3 Acquire variable-sized memory block
A variable-sized memory block is acquired (waiting forever, polling, or with time-out) by issuing the following service call from the processing program.
The RI600V4 does not perform memory clear processing when a variable-sized memory block is acquired. The contents of the acquired variable-size memory block are therefore undefined.
-
get_mpl (Wait)
This service call acquires a variable-size memory block of the size specified by parameter blksz from the variable-size memory pool specified by parameter
mplid, and stores its start address into the area specified by parameter
p_blk.
If no variable-size memory blocks could be acquired from the target variable-size memory pool (no successive areas equivalent to the requested size were available) when this service call is issued, this service call does not acquire variable-size memory blocks but queues the invoking task to the target variable-size memory pool wait queue and moves it from the RUNNING state to the WAITING state (variable-size memory block acquisition wait state).
The WAITING state for a variable-sized memory block is cancelled in the following cases.
WAITING State for a Variable-sized Memory Block Cancel Operation
|
|
The variable-size memory block that satisfies the requested size was returned to the target variable-size memory pool as a result of issuing rel_mpl.
|
|
The task at the top of the transmission wait queue was forcedly released from waiting by following either.
- Forced release from waiting (accept rel_wai while waiting).
- Forced release from waiting (accept irel_wai while waiting).
- Forced release from waiting (accept ter_tsk while waiting).
- The time specified by tmout for tget_mpl has elapsed.
|
|
Forced release from waiting (accept rel_wai while waiting).
|
|
Forced release from waiting (accept irel_wai while waiting).
|
|
The variable-sized memory pool is reset as a result of issuing vrst_mpl.
|
|
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 mplid = 1; /*Declares and initializes variable*/
UINT blksz = 256; /*Declares and initializes variable*/
VP p_blk; /*Declares variable*/
/* ......... */
/*Acquire variable-sized memory block */
ercd = get_mpl (mplid, blksz, &p_blk);
if (ercd == E_OK) {
/* ......... */ /*Normal termination processing*/
rel_mpl (mplid, p_blk); /*Release variable-sized memory block*/
} else if (ercd == E_RLWAI) {
/* ......... */ /*Forced termination processing*/
}
/* ......... */
}
|
Note 2 Invoking tasks are queued to the target variable-size memory pool wait queue in the FIFO order.
Note 3 The contents of the block are undefined.
-
pget_mpl,
ipget_mpl (Polling)
This service call acquires a variable-size memory block of the size specified by parameter
blksz from the variable-size memory pool specified by parameter
mplid, and stores its start address into the area specified by parameter
p_blk.
If no variable-size memory blocks could be acquired from the target variable-size memory pool (no successive areas equivalent to the requested size were available) when this service call is issued, this service call does not acquire variable-size memory block but returns 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 mplid = 1; /*Declares and initializes variable*/
UINT blksz = 256; /*Declares and initializes variable*/
VP p_blk; /*Declares variable*/
/* ......... */
/*Acquire variable-sized memory block*/
ercd = pget_mpl (mplid, blksz, &p_blk);
if (ercd == E_OK) {
/* ......... */ /*Polling success processing*/
rel_mpl (mplid, p_blk); /*Release variable-sized memory block*/
} else if (ercd == E_TMOUT) {
/* ......... */ /*Polling failure processing*/
}
/* ......... */
}
|
Note 2 The contents of the block are undefined.
-
tget_mpl (Wait with time-out)
This service call acquires a variable-size memory block of the size specified by parameter
blksz from the variable-size memory pool specified by parameter
mplid, and stores its start address into the area specified by parameter
p_blk.
If no variable-size memory blocks could be acquired from the target variable-size memory pool (no successive areas equivalent to the requested size were available) when this service call is issued, this service call does not acquire variable-size memory blocks but queues the invoking task to the target variable-size memory pool wait queue and moves it from the RUNNING state to the WAITING state with time-out (variable-size memory block acquisition wait state).
The WAITING state for a variable-sized memory block is cancelled in the following cases.
WAITING State for a Variable-sized Memory Block Cancel Operation
|
|
The variable-size memory block that satisfies the requested size was returned to the target variable-size memory pool as a result of issuing rel_mpl.
|
|
The task at the top of the transmission wait queue was forcedly released from waiting by following either.
- Forced release from waiting (accept rel_wai while waiting).
- Forced release from waiting (accept irel_wai while waiting).
- Forced release from waiting (accept ter_tsk while waiting).
- The time specified by tmout for tget_mpl has elapsed.
|
|
Forced release from waiting (accept rel_wai while waiting).
|
|
Forced release from waiting (accept irel_wai while waiting).
|
|
The variable-sized memory pool is reset as a result of issuing vrst_mpl.
|
|
The time specified by tmout has elapsed.
|
|
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 mplid = 1; /*Declares and initializes variable*/
UINT blksz = 256; /*Declares and initializes variable*/
VP p_blk; /*Declares variable*/
TMO tmout = 3600; /*Declares and initializes variable*/
/* ......... */
/*Acquire variable-sized memory block*/
ercd = tget_mpl (mplid, blksz, &p_blk, tmout);
if (ercd == E_OK) {
/* ......... */ /*Normal termination processing*/
rel_mpl (mplid, p_blk ; /*Release variable-sized memory block*/
} else if (ercd == E_RLWAI) {
/* ......... */ /*Forced termination processing*/
} else if (ercd == E_TMOUT) {
/* ......... */ /*Time-out processing*/
}
/* ......... */
}
|
Note 2 Invoking tasks are queued to the target variable-size memory pool wait queue in the FIFO order.
Note 3 The contents of the block are undefined.
Note 5
TMO_FEVR is specified for wait time
tmout, processing equivalent to
get_mpl will be executed. When
TMO_POL is specified, processing equivalent to
pget_mpl will be executed.
7.3.4 Release variable-sized memory block
A variable-sized memory block is returned by issuing the following service call from the processing program.
-
rel_mpl
This service call returns the variable-sized memory block specified by parameter
blk to the variable-sized memory pool specified by parameter
mplid.
After returning the variable-size memory blocks, these service calls check the tasks queued to the target variable-size memory pool wait queue from the top, and assigns the memory if the size of memory requested by the wait queue is available. This operation continues until no tasks queued to the wait queue remain or no memory space is available. As a result, the task that acquired the memory is unlinked from the queue and moved from the WAITING state (variable-size memory block acquisition wait state) to the READY state, or from the WAITING-SUSPENDED state to the SUSPENDED state.
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 mplid = 1; /*Declares and initializes variable*/
UINT blksz = 256; /*Declares and initializes variable*/
VP blk; /*Declares variable*/
/* ......... */
/*Acquire variable-sized memory block*/
ercd = get_mpl (mplid, blksz, &blk);
if (ercd == E_OK) {
/* ......... */ /*Normal termination processing*/
rel_mpl (mplid, blk); /*Release variable-sized memory block*/
} else if (ercd == E_RLWAI) {
/* ......... */ /*Forced termination processing*/
}
/* ......... */
}
|
Note The RI600V4 do only simple error detection for
blk. If
blk is illegal and the error is not detected, the operation is not guaranteed after that.
7.3.5 Reference variable-sized memory pool state
A variable-sized memory pool status is referenced by issuing the following service call from the processing program.
-
ref_mpl,
iref_mpl
These service calls store the detailed information (ID number of the task at the head of the wait queue, total size of free memory blocks, etc.) of the variable-size memory pool specified by parameter
mplid into the area specified by parameter
pk_rmpl.
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 mplid = 1; /*Declares and initializes variable*/
T_RMPL pk_rmpl; /*Declares data structure*/
ID wtskid; /*Declares variable*/
SIZE fmplsz; /*Declares variable*/
UINT fblksz; /*Declares variable*/
/* ......... */
ref_mpl (mplid, &pk_rmpl); /*Reference variable-sized memory pool state*/
wtskid = pk_rmpl.wtskid; /*Reference ID number of the task at the */
/*head of the wait queue*/
fmplsz = pk_rmpl.fmplsz; /*Reference total size of free memory blocks*/
fblksz = pk_rmpl.fblksz; /*Reference maximum memory block size*/
/* ......... */
}
|