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.
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.
For details about the static API "variable_memorypool[]", refer to "19.15 Variable-sized Memory Pool Information (variable_memorypool[])"
In the current implementation of the RI600V4, the size of the variable-sized memory block to be acquired is selected from 12 (in maximum) kinds of variations. This variations are selected from 24 kinds of inside decided beforehand according to Upper limit of the variable-sized memory block (max_memsize) in Variable-sized Memory Pool Information (variable_memorypool[]). Table 7-1 shows variation of memory block size. Note, this behavior may be changed in the future version.
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.
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.
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.
|
|
#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 4 The alignment number of memory blocks is 1. To enlarge the alignment number to 4, specify unique section to Section name assigned to the memory pool area (mpl_section) in Variable-sized Memory Pool Information (variable_memorypool[]) and locate the section to 4-bytes boundary address when linking.
- 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.
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 3 The alignment number of memory blocks is 1. To enlarge the alignment number to 4, specify unique section to Section name assigned to the memory pool area (mpl_section) in Variable-sized Memory Pool Information (variable_memorypool[]) and locate the section to 4-bytes boundary address when linking.
- 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.
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.
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.
|
|
#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 4 The alignment number of memory blocks is 1. To enlarge the alignment number to 4, specify unique section to Section name assigned to the memory pool area (mpl_section) in Variable-sized Memory Pool Information (variable_memorypool[]) and locate the section to 4-bytes boundary address when linking.
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.
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.
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.
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.
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*/ /* ......... */ } |
Note For details about the variable-sized memory pool state packet, refer to "[Variable-sized memory pool state packet: T_RMPL]".