Everything
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.
For details about the static API "variable_memorypool[]", refer to "19.15 Variable-sized Memory Pool Information (variable_memorypool[])"
7.3.2 Size of Variable-sized memory block
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.
Table 7-1 Variation of memory block size
No,
Size of memory block (Hexadecimal)
Example-1
max_memsize = 0x100
Example-1
max_memsize = 0x20000
1
12 (0xC)
Used
-
2
36 (0x24)
Used
-
3
84 (0x54)
Used
Used
4
180 (0xB4)
Used
Used
5
372 (0x174)
-
Used
6
756 (0x2F4)
-
Used
7
1524 (0x5F4)
-
Used
8
3060 (0xBF4)
-
Used
9
6132 (0x17F4)
-
Used
10
12276 (0x2FF4)
-
Used
11
24564 (0x5FF4)
-
Used
12
49140 (0xBFF4)
-
Used
13
98292 (0x17FF4)
-
Used
14
196596 (0x2FFF4)
-
Used
15
393204 (0x5FFF4)
-
-
16
786420 (0xBFFF4)
-
-
17
1572852 (0x17FFF4)
-
-
18
3145716 (0x2FFFF4)
-
-
19
6291444 (0x5FFFF4)
-
-
20
12582900 (0xBFFFF4)
-
-
21
25165812 (0x17FFFF4)
-
-
22
50331636 (0x2FFFFF4)
-
-
23
100663284 (0x5FFFFF4)
-
-
24
201326580 (0xBFFFFF4)
-
-

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.
- get_mpl (Wait)
- pget_mpl, ipget_mpl (Polling)
- tget_mpl (Wait with time-out)
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
Return Value
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.
E_OK
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.
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 variable-sized memory pool is reset as a result of issuing vrst_mpl.
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      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 1 For the size of the memory block, refer to "7.3.2 Size of Variable-sized memory block".
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 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.
 #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 1 For the size of the memory block, refer to "7.3.2 Size of Variable-sized memory block".
Note 2 The contents of the block are undefined.
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.
WAITING State for a Variable-sized Memory Block Cancel Operation
Return Value
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.
E_OK
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.
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 variable-sized memory pool is reset as a result of issuing vrst_mpl.
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      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 1 For the size of the memory block, refer to "7.3.2 Size of Variable-sized memory block".
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 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.
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*/
 
     /* ......... */
 }

Note For details about the variable-sized memory pool state packet, refer to "[Variable-sized memory pool state packet: T_RMPL]".