Bmag incl gps rettelse
Dependencies: mbed WDT MODSERIAL BME280
USBHost/mbed-rtos/rtos/MemoryPool.h@56:df9052e3808c, 2019-06-20 (annotated)
- Committer:
- gert_lauritsen
- Date:
- Thu Jun 20 07:13:18 2019 +0000
- Revision:
- 56:df9052e3808c
change date stamp from gps, reads serialnumb from file.
Who changed what in which revision?
User | Revision | Line number | New contents of line |
---|---|---|---|
gert_lauritsen | 56:df9052e3808c | 1 | /* mbed Microcontroller Library |
gert_lauritsen | 56:df9052e3808c | 2 | * Copyright (c) 2006-2012 ARM Limited |
gert_lauritsen | 56:df9052e3808c | 3 | * |
gert_lauritsen | 56:df9052e3808c | 4 | * Permission is hereby granted, free of charge, to any person obtaining a copy |
gert_lauritsen | 56:df9052e3808c | 5 | * of this software and associated documentation files (the "Software"), to deal |
gert_lauritsen | 56:df9052e3808c | 6 | * in the Software without restriction, including without limitation the rights |
gert_lauritsen | 56:df9052e3808c | 7 | * to use, copy, modify, merge, publish, distribute, sublicense, and/or sell |
gert_lauritsen | 56:df9052e3808c | 8 | * copies of the Software, and to permit persons to whom the Software is |
gert_lauritsen | 56:df9052e3808c | 9 | * furnished to do so, subject to the following conditions: |
gert_lauritsen | 56:df9052e3808c | 10 | * |
gert_lauritsen | 56:df9052e3808c | 11 | * The above copyright notice and this permission notice shall be included in |
gert_lauritsen | 56:df9052e3808c | 12 | * all copies or substantial portions of the Software. |
gert_lauritsen | 56:df9052e3808c | 13 | * |
gert_lauritsen | 56:df9052e3808c | 14 | * THE SOFTWARE IS PROVIDED "AS IS", WITHOUT WARRANTY OF ANY KIND, EXPRESS OR |
gert_lauritsen | 56:df9052e3808c | 15 | * IMPLIED, INCLUDING BUT NOT LIMITED TO THE WARRANTIES OF MERCHANTABILITY, |
gert_lauritsen | 56:df9052e3808c | 16 | * FITNESS FOR A PARTICULAR PURPOSE AND NONINFRINGEMENT. IN NO EVENT SHALL THE |
gert_lauritsen | 56:df9052e3808c | 17 | * AUTHORS OR COPYRIGHT HOLDERS BE LIABLE FOR ANY CLAIM, DAMAGES OR OTHER |
gert_lauritsen | 56:df9052e3808c | 18 | * LIABILITY, WHETHER IN AN ACTION OF CONTRACT, TORT OR OTHERWISE, ARISING FROM, |
gert_lauritsen | 56:df9052e3808c | 19 | * OUT OF OR IN CONNECTION WITH THE SOFTWARE OR THE USE OR OTHER DEALINGS IN THE |
gert_lauritsen | 56:df9052e3808c | 20 | * SOFTWARE. |
gert_lauritsen | 56:df9052e3808c | 21 | */ |
gert_lauritsen | 56:df9052e3808c | 22 | #ifndef MEMORYPOOL_H |
gert_lauritsen | 56:df9052e3808c | 23 | #define MEMORYPOOL_H |
gert_lauritsen | 56:df9052e3808c | 24 | |
gert_lauritsen | 56:df9052e3808c | 25 | #include <stdint.h> |
gert_lauritsen | 56:df9052e3808c | 26 | #include <string.h> |
gert_lauritsen | 56:df9052e3808c | 27 | |
gert_lauritsen | 56:df9052e3808c | 28 | #include "cmsis_os.h" |
gert_lauritsen | 56:df9052e3808c | 29 | |
gert_lauritsen | 56:df9052e3808c | 30 | namespace rtos { |
gert_lauritsen | 56:df9052e3808c | 31 | /** \addtogroup rtos */ |
gert_lauritsen | 56:df9052e3808c | 32 | /** @{*/ |
gert_lauritsen | 56:df9052e3808c | 33 | |
gert_lauritsen | 56:df9052e3808c | 34 | /** Define and manage fixed-size memory pools of objects of a given type. |
gert_lauritsen | 56:df9052e3808c | 35 | @tparam T data type of a single object (element). |
gert_lauritsen | 56:df9052e3808c | 36 | @tparam queue_sz maximum number of objects (elements) in the memory pool. |
gert_lauritsen | 56:df9052e3808c | 37 | */ |
gert_lauritsen | 56:df9052e3808c | 38 | template<typename T, uint32_t pool_sz> |
gert_lauritsen | 56:df9052e3808c | 39 | class MemoryPool { |
gert_lauritsen | 56:df9052e3808c | 40 | public: |
gert_lauritsen | 56:df9052e3808c | 41 | /** Create and Initialize a memory pool. */ |
gert_lauritsen | 56:df9052e3808c | 42 | MemoryPool() { |
gert_lauritsen | 56:df9052e3808c | 43 | #ifdef CMSIS_OS_RTX |
gert_lauritsen | 56:df9052e3808c | 44 | memset(_pool_m, 0, sizeof(_pool_m)); |
gert_lauritsen | 56:df9052e3808c | 45 | _pool_def.pool = _pool_m; |
gert_lauritsen | 56:df9052e3808c | 46 | |
gert_lauritsen | 56:df9052e3808c | 47 | _pool_def.pool_sz = pool_sz; |
gert_lauritsen | 56:df9052e3808c | 48 | _pool_def.item_sz = sizeof(T); |
gert_lauritsen | 56:df9052e3808c | 49 | #endif |
gert_lauritsen | 56:df9052e3808c | 50 | _pool_id = osPoolCreate(&_pool_def); |
gert_lauritsen | 56:df9052e3808c | 51 | } |
gert_lauritsen | 56:df9052e3808c | 52 | |
gert_lauritsen | 56:df9052e3808c | 53 | /** Allocate a memory block of type T from a memory pool. |
gert_lauritsen | 56:df9052e3808c | 54 | @return address of the allocated memory block or NULL in case of no memory available. |
gert_lauritsen | 56:df9052e3808c | 55 | */ |
gert_lauritsen | 56:df9052e3808c | 56 | T* alloc(void) { |
gert_lauritsen | 56:df9052e3808c | 57 | return (T*)osPoolAlloc(_pool_id); |
gert_lauritsen | 56:df9052e3808c | 58 | } |
gert_lauritsen | 56:df9052e3808c | 59 | |
gert_lauritsen | 56:df9052e3808c | 60 | /** Allocate a memory block of type T from a memory pool and set memory block to zero. |
gert_lauritsen | 56:df9052e3808c | 61 | @return address of the allocated memory block or NULL in case of no memory available. |
gert_lauritsen | 56:df9052e3808c | 62 | */ |
gert_lauritsen | 56:df9052e3808c | 63 | T* calloc(void) { |
gert_lauritsen | 56:df9052e3808c | 64 | return (T*)osPoolCAlloc(_pool_id); |
gert_lauritsen | 56:df9052e3808c | 65 | } |
gert_lauritsen | 56:df9052e3808c | 66 | |
gert_lauritsen | 56:df9052e3808c | 67 | /** Return an allocated memory block back to a specific memory pool. |
gert_lauritsen | 56:df9052e3808c | 68 | @param address of the allocated memory block that is returned to the memory pool. |
gert_lauritsen | 56:df9052e3808c | 69 | @return status code that indicates the execution status of the function. |
gert_lauritsen | 56:df9052e3808c | 70 | */ |
gert_lauritsen | 56:df9052e3808c | 71 | osStatus free(T *block) { |
gert_lauritsen | 56:df9052e3808c | 72 | return osPoolFree(_pool_id, (void*)block); |
gert_lauritsen | 56:df9052e3808c | 73 | } |
gert_lauritsen | 56:df9052e3808c | 74 | |
gert_lauritsen | 56:df9052e3808c | 75 | private: |
gert_lauritsen | 56:df9052e3808c | 76 | osPoolId _pool_id; |
gert_lauritsen | 56:df9052e3808c | 77 | osPoolDef_t _pool_def; |
gert_lauritsen | 56:df9052e3808c | 78 | #ifdef CMSIS_OS_RTX |
gert_lauritsen | 56:df9052e3808c | 79 | uint32_t _pool_m[3+((sizeof(T)+3)/4)*(pool_sz)]; |
gert_lauritsen | 56:df9052e3808c | 80 | #endif |
gert_lauritsen | 56:df9052e3808c | 81 | }; |
gert_lauritsen | 56:df9052e3808c | 82 | |
gert_lauritsen | 56:df9052e3808c | 83 | } |
gert_lauritsen | 56:df9052e3808c | 84 | #endif |
gert_lauritsen | 56:df9052e3808c | 85 | |
gert_lauritsen | 56:df9052e3808c | 86 | /** @}*/ |