RKH
 All Data Structures Files Functions Variables Typedefs Enumerations Enumerator Macros Groups Pages
rkhmp.h
Go to the documentation of this file.
1 /*
2  * --------------------------------------------------------------------------
3  *
4  * Framework RKH
5  * -------------
6  *
7  * State-machine framework for reactive embedded systems
8  *
9  * Copyright (C) 2010 Leandro Francucci.
10  * All rights reserved. Protected by international copyright laws.
11  *
12  *
13  * RKH is free software: you can redistribute it and/or modify it under the
14  * terms of the GNU General Public License as published by the Free Software
15  * Foundation, either version 3 of the License, or (at your option) any
16  * later version.
17  *
18  * RKH is distributed in the hope that it will be useful, but WITHOUT ANY
19  * WARRANTY; without even the implied warranty of MERCHANTABILITY or
20  * FITNESS FOR A PARTICULAR PURPOSE. See the GNU General Public License for
21  * more details.
22  *
23  * You should have received a copy of the GNU General Public License along
24  * with RKH, see copying.txt file.
25  *
26  * Contact information:
27  * RKH web site: http://sourceforge.net/projects/rkh-reactivesys/
28  * e-mail: francuccilea@gmail.com
29  * ---------------------------------------------------------------------------
30  */
31 
46 /* -------------------------- Development history -------------------------- */
47 /*
48  * 2015.10.24 LeFr v2.4.05 Initial version
49  */
50 
51 /* -------------------------------- Authors -------------------------------- */
52 /*
53  * LeFr Leandro Francucci francuccilea@gmail.com
54  */
55 
56 /* --------------------------------- Notes --------------------------------- */
57 /* --------------------------------- Module -------------------------------- */
58 #ifndef __RKHMP_H__
59 #define __RKHMP_H__
60 
61 /* ----------------------------- Include files ----------------------------- */
62 #include "rkhtype.h"
63 #include "rkhcfg.h"
64 
65 /* ---------------------- External C language linkage ---------------------- */
66 #ifdef __cplusplus
67 extern "C" {
68 #endif
69 
70 /* --------------------------------- Macros -------------------------------- */
71 /* -------------------------------- Constants ------------------------------ */
72 /* ------------------------------- Data types ------------------------------ */
78 #if RKH_CFG_MP_SIZEOF_NBLOCK == 8
79 typedef rui8_t RKH_MPNB_T;
80 #elif RKH_CFG_MP_SIZEOF_NBLOCK == 16
81 typedef rui16_t RKH_MPNB_T;
82 #elif RKH_CFG_MP_SIZEOF_NBLOCK == 32
83 typedef rui32_t RKH_MPNB_T;
84 #else
85 typedef rui8_t RKH_MPNB_T;
86 #endif
87 
93 #if RKH_CFG_MP_SIZEOF_BSIZE == 8
94 typedef rui8_t RKH_MPBS_T;
95 #elif RKH_CFG_MP_SIZEOF_BSIZE == 16
96 typedef rui16_t RKH_MPBS_T;
97 #elif RKH_CFG_MP_SIZEOF_BSIZE == 32
98 typedef rui32_t RKH_MPBS_T;
99 #else
100 typedef rui8_t RKH_MPBS_T;
101 #endif
102 
108 typedef struct
109 {
114  rui8_t inits;
115 
120  rui8_t gets;
121 
126  rui8_t puts;
127 
132  rui8_t free;
133 
138  rui8_t full;
139 } RKH_MPI_T;
140 
189 typedef struct RKH_MP_T
190 {
198  void *free;
199 
204  RKH_MPNB_T nfree;
205 
216  RKH_MPNB_T nblocks;
217 
228  RKH_MPBS_T bsize;
229 
230 #if RKH_CFG_MP_REDUCED_EN == RKH_DISABLED
231 
238  void *start;
239 
244  void *end;
245 
254 #if RKH_CFG_MP_GET_LWM_EN == RKH_ENABLED
255  RKH_MPNB_T nmin;
256 #endif
257 
258 #endif
259 
264 #if RKH_CFG_MP_GET_INFO_EN == RKH_ENABLED
266 #endif
267 } RKH_MP_T;
268 
269 /* -------------------------- External variables --------------------------- */
270 /* -------------------------- Function prototypes -------------------------- */
305 void rkh_mp_init(RKH_MP_T *mp, void *sstart, rui16_t ssize,
306  RKH_MPBS_T bsize);
307 
319 void *rkh_mp_get(RKH_MP_T *mp);
320 
332 void rkh_mp_put(RKH_MP_T *mp, void *blk);
333 
349 RKH_MPBS_T rkh_mp_get_bsize(RKH_MP_T *mp);
350 
366 RKH_MPNB_T rkh_mp_get_nfree(RKH_MP_T *mp);
367 
385 RKH_MPNB_T rkh_mp_get_low_wmark(RKH_MP_T *mp);
386 
406 void rkh_mp_get_info(RKH_MP_T *mp, RKH_MPI_T *mpi);
407 
420 void rkh_mp_clear_info(RKH_MP_T *mp);
421 
422 /* -------------------- External C language linkage end -------------------- */
423 #ifdef __cplusplus
424 }
425 #endif
426 
427 /* ------------------------------ Module end ------------------------------- */
428 #endif
429 
430 /* ------------------------------ End of file ------------------------------ */
rui8_t inits
Number of pool create requests.
Definition: rkhmp.h:114
rui8_t gets
Number of get memory block requests.
Definition: rkhmp.h:120
void rkh_mp_clear_info(RKH_MP_T *mp)
Clear performance information for a particular memory pool.
void * end
The last block in this pool.
Definition: rkhmp.h:244
RKH_MPI_T mpi
Definition: rkhmp.h:265
RKH_MPNB_T nblocks
Total number of blocks in bytes.
Definition: rkhmp.h:216
RKH_MPNB_T rkh_mp_get_low_wmark(RKH_MP_T *mp)
Retrieves the lowest number of free blocks ever present in the pool. This number provides valuable em...
Defines the data structure into which the performance information for memory pools is stored...
Definition: rkhmp.h:108
rui8_t full
Number of full retrieves.
Definition: rkhmp.h:138
RKH_MPBS_T bsize
Maximum block size in bytes.
Definition: rkhmp.h:228
RKH_MPBS_T rkh_mp_get_bsize(RKH_MP_T *mp)
Retrieves the size of memory block in bytes.
void * free
The head of the linked list of free blocks.
Definition: rkhmp.h:198
RKH_MPNB_T nfree
Number of free blocks remaining.
Definition: rkhmp.h:204
RKH_MPNB_T rkh_mp_get_nfree(RKH_MP_T *mp)
Retrieves the current number of free memory blocks in the pool.
void rkh_mp_get_info(RKH_MP_T *mp, RKH_MPI_T *mpi)
Retrieves performance information for a particular memory pool.
RKH user configurations.
rui8_t RKH_MPNB_T
Definition: rkhmp.h:79
void rkh_mp_put(RKH_MP_T *mp, void *blk)
When the application is done with the memory block, it must be returned to the appropiate memory pool...
rui8_t RKH_MPBS_T
Definition: rkhmp.h:94
void * start
The start of the original pool buffer.
Definition: rkhmp.h:238
void * rkh_mp_get(RKH_MP_T *mp)
Get a memory block from one of the previously allocated memory pool.
void rkh_mp_init(RKH_MP_T *mp, void *sstart, rui16_t ssize, RKH_MPBS_T bsize)
Initializes the previously allocated memory pool data strcuture RKH_MP_T.
Defines the data structure used to memory block pool facility.
Definition: rkhmp.h:189
rui8_t puts
Number of put memory block requests.
Definition: rkhmp.h:126
RKH_MPNB_T nmin
Minimum number of free blocks ever in this pool, i.e. holds the lowest number of free blocks ever pre...
Definition: rkhmp.h:255
rui8_t free
Number of no free retrieves.
Definition: rkhmp.h:132
Defines the data types that uses RKH.