9.3 Variable-Sized Memory Pools
When a dynamic memory manipulation request is issued from a processing program in the RI600PX, 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 current implementation of the RI600PX, 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 the maximum memory block size that is defined at creating the variable-sized memory pool. Table 9-1 shows variation of memory block size. Note, this behavior may be changed in the future version.
1 ) Creation by the system configuration file
The static API variable_memorypool[] described in the system configuration file creates a variable-sized memory pool.
Refer to 20.18 Variable-sized Memory Pool Information (variable_memorypool[]) for the details of variable_memorypool[].
The static API variable_memorypool[] described in the system configuration file creates a variable-sized memory pool.
Refer to 20.18 Variable-sized Memory Pool Information (variable_memorypool[]) for the details of variable_memorypool[].
2 ) Creation by cre_mpl or acre_mpl
The cre_mpl creates a variable-sized memory pool with variable-sized memory pool ID indicated by parameter mplid according to the content of parameter pk_cmpl.
The acre_mpl creates a variable-sized memory pool according to the content of parameter pk_cmpl, and returns the created variable-sized memory pool ID.
The information specified is shown below.
The cre_mpl creates a variable-sized memory pool with variable-sized memory pool ID indicated by parameter mplid according to the content of parameter pk_cmpl.
The acre_mpl creates a variable-sized memory pool according to the content of parameter pk_cmpl, and returns the created variable-sized memory pool ID.
The information specified is shown below.
- Variable-sized memory pool attribute (mplatr)
Only TA_TFIFO (the order of task wait queue is managed by FIFO order.) can be specified for mplatr.
Only TA_TFIFO (the order of task wait queue is managed by FIFO order.) can be specified for mplatr.
- Size of variable-sized memory pool area (mplsz), Start address of the variable-sized memory pool area (mpl)
The start adderess of the variable-sized memory pool area must be 4-bytes boundary.
The variable-sized memory pool area should be in the memory object to be able to access by tasks which uses memory blocks.
The start adderess of the variable-sized memory pool area must be 4-bytes boundary.
The variable-sized memory pool area should be in the memory object to be able to access by tasks which uses memory blocks.
- Maximum memory block size (maxblksz)
Specify the maximum memory block size for maxblksz. For details, refer to 9.3.1 Size of Variable-sized memory block.
Specify the maximum memory block size for maxblksz. For details, refer to 9.3.1 Size of Variable-sized memory block.
These service calls can be called from tasks that belong to Trusted Domain.
The following describes an example for coding acre_mpl as a representative.
The following describes an example for coding acre_mpl as a representative.
#include "kernel.h" /*Standard header file definition*/ #include "kernel_id.h" /*Header file generated by cfg600px*/ #define MPLSZ 1024 /*Size of variable-sized memory pool area (in bytes)*/ #define MAXBLKSZ 128 /*Maximum memory block size (in bytes)*/ #pragma section B BU_SH /*Section for the variable-sized memory pool area*/ static UW mpl_area[ MPLSZ/sizeof(UW) ]; /*Variable-sized memory pool area*/ #pragma section #pragma task Task1 /*Refer to note*/ void Task1 (VP_INT exinf); /*Refer to note*/ void Task1 (VP_INT exinf) { ER mplid; /*Declares variable*/ T_CMPF pk_cmpl = { /*Declares and initializes variable*/ TA_TFIFO, /*Variable-sized memory pool attribute (mplatr)*/ MPLSZ, /*Size of variable-sized memory pool area (in bytes) (mplsz)*/ (VP)mpl_area,/*Start address of the variable-sized memory pool area (mpl)*/ MAXBLKLSZ /*Maximum memory block size (in bytes) (maxblksz)*/ }; /* ......... */ mplid = acre_mpl ( &pk_cmpf ); /*Create variable-sized memory pool/ /* ......... */ } |
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".
- del_mpl
This service call deletes the variable-sized memory pool specified by parameter mplid.
When there are waiting tasks for the target variable-sized memory pool by using get_mpl or tget_mpl, this service call cancels the WAITING state of the tasks and returns E_DLT as a return value of the get_mpl or tget_mpl.
This service call can be called from tasks that belong to Trusted Domain.
The following describes an example for coding this service call.
This service call deletes the variable-sized memory pool specified by parameter mplid.
When there are waiting tasks for the target variable-sized memory pool by using get_mpl or tget_mpl, this service call cancels the WAITING state of the tasks and returns E_DLT as a return value of the get_mpl or tget_mpl.
This service call can be called from tasks that belong to Trusted Domain.
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 mplid = 8; /*Declares and initializes variable*/ /* ......... */ ercd = del_mpl ( mplid ); /*Delete variable-sized memory pool*/ /* ......... */ } |
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".
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 RI600PX 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 cfg600px*/ #pragma task Task1 /*Refer to note 5*/ void Task1 (VP_INT exinf); /*Refer to note 5*/ void Task1 (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 changes with creation method of the variable-sized memory pool.
- Created by system configuration file
The alignment number 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.
The alignment number 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 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".
- 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 cfg600px*/ #pragma task Task1 /*Refer to note 4*/ void Task1 (VP_INT exinf); /*Refer to note 4*/ void Task1 (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 changes with creation method of the variable-sized memory pool.
- Created by system configuration file
The alignment number 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.
The alignment number 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 4 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".
- 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 cfg600px*/ #pragma task Task1 /*Refer to note 4*/ void Task1 (VP_INT exinf); /*Refer to note 4*/ void Task1 (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 changes with creation method of the variable-sized memory pool.
- Created by system configuration file
The alignment number 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.
The alignment number 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.
Note 6 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".
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 cfg600px*/ #pragma task Task1 /*Refer to note 2*/ void Task1 (VP_INT exinf); /*Refer to note 2*/ void Task1 (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 1 The RI600PX do only simple error detection for blk. If blk is illegal and the error is not detected, the operation is not guaranteed after that.
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".
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 cfg600px*/ #pragma task Task1 /*Refer to note 2*/ void Task1 (VP_INT exinf); /*Refer to note 2*/ void Task1 (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 1 For details about the variable-sized memory pool state packet, refer to "[Variable-sized memory pool state packet: T_RMPL]".