tk_cre_mpf
Create Fixed-size Memory Pool
See Also
ID mpfid = tk_cre_mpf ( T_CMPF *pk_cmpf ) ;
T_CMPF* pk_cmpf Information about the memory pool to be created
pk_cmpf detail:
VP exinf Extended information
ATR mpfatr Memory pool attributes
W mpfcnt Memory pool block count
W blfsz Memory block size (in bytes)
UB dsname[8] DS object name
VP bufptr User buffer pointer
(Other implementation-dependent parameters may be added beyond this point.)
ID mpfid Fixed-size memory pool ID
or Error Code
E_NOMEM Insufficient memory (memory for control block or memory pool area cannot be allocated)
E_LIMIT Number of fixed-size memory pools exceeds the system limit
E_RSATR Reserved attribute (mpfatr is invalid or cannot be used)
E_PAR Parameter error (pk_cmpf is invalid; mpfcnt or blfsz is negative or invalid)
Creates a fixed-size memory pool, assigning to it a fixed-size memory pool ID.
This system call allocates a memory space for use as a memory pool based on the information specified in parameters mpfcnt and blfsz, and assigns a control block to the memory pool. A memory block of size blfsz can be allocated from the created memory pool by calling the tk_get_mpf system call.
exinf can be used freely by the user to store miscellaneous information about the created memory pool. The information set in this parameter can be referenced by tk_ref_mpf. If a larger area is needed for indicating user information, or if the information needs to be changed after the memory pool is created, this can be done by allocating separate memory for this purpose and putting the memory packet address in exinf. The OS pays no attention to the contents of exinf.
mpfatr indicates system attributes in its low bits and implementation-dependent information in the high bits. The system attributes part of mpfatr is as follows.
mpfatr:= (TA_TFIFO || TA_TPRI) | TA_USERBUF | TA_DSNAME| (TA_RNG0 || TA_RNG1 || TA_RNG2 || TA_RNG3)
TA_TFIFO Tasks waiting for memory allocation are queued in FIFO order
TA_TPRI Tasks waiting for memory allocation are queued in priority order
TA_RNGn Memory access privilege is set to protection level n
TA_USERBUF Indicates that the task uses an area specified by the user as a buffer
TA_DSNAME Specifies DS object name
#define TA_TFIFO 0x00000000 /* manage task queue by FIFO */
#define TA_TPRI 0x00000001 /* manage task queue by priority */
#define TA_USERBUF 0x00000020 /* User buffer */
#define TA_DSNAME 0x00000040 /* DS object name */
#define TA_RNG0 0x00000000 /* protection level 0 */
#define TA_RNG1 0x00000100 /* protection level 1 */
#define TA_RNG2 0x00000200 /* protection level 2 */
#define TA_RNG3 0x00000300 /* protection level 3 */
The queuing order of tasks waiting for memory block allocation from a memory pool can be specified in TA_TFIFO or TA_TPRI. If the attribute is TA_TFIFO, tasks are ordered by FIFO, whereas TA_TPRI specifies queuing of tasks in order of their priority setting.
For TA_RNGn, a protection level shall be specified to restrict the memory access. However, in µT-Kernel, systems without MMU are assumed. So, all specified protection levels behave the same as protection level 0.
Specification of protection level exists in µT-Kernel only to ensure compatibility with T-Kernel. So, when using only in µT-Kernel, there is no problem if protection level 0 is specified. To create an application available both in µT-Kernel and in T-Kernel, you only need to provide the protection level in T-Kernel.
If TA_USERBUF is specified, bufptr becomes valid, and the memory area of @mpfcnt@*@blfsz@ bytes with bufptr at the head is used as a memory pool area. In this case, the memory pool area is not prepared by the OS. If TA_USERBUF is not specified, bufptr is ignored, and a memory pool area is allocated by the OS.
When TA_DSNAME is specified, dsname is valid and specifies the DS object name. DS object name is used by the debugger to identify objects and is handled only by debugger support functions API, td_ref_dsname and td_set_dsname. For more details, refer to td_ref_dsname and td_set_dsname. If TA_DSNAME is not specified, dsname is ignored. Then td_ref_dsname and td_set_dsname return E_OBJ error.
In the case of a fixed-size memory pool, separate memory pools must be provided for different block sizes. That is, if various memory block sizes are required, memory pools must be created for each block size.
A system without MMU is assumed for µT-Kernel. However, in order to ensure portability to the T-Kernel, TA_RNGn attribute shall be accepted.
It is possible, for example, to treat all TA_RNGn as equivalent to TA_RNG0; but no error must be returned.
TA_NODISWAI does not exist in the attributes for mpfatr. This is because, in µT-Kernel, there is no wait-disabled function.
TA_USERBUF and bufptr have been added.
In µT-Kernel, systems without MMU are assumed. So the functions concerning protection level are not supported. Nevertheless, the reason why TA_RNGn attribute has been retained is to maintain compatibility with the T-Kernel.
mpfcnt and blfsz, the member of T_CMPF, are of W type instead of INT type.
There is neither TA_USERBUF nor bufptr in T-Kernel. So, when using this function, modification is required when porting it to T-Kernel. However, if mpfcnt and blfsz are set correctly, you can port it by simply deleting TA_USERBUF and bufptr.

Comments
Click here to Post a Comment