NRF: receive, ntp, Data to Sd-card working

Dependencies:   F7_Ethernet mbed BSP_DISCO_F746NG Test_Mainboard SDFileSystem RF24

Committer:
lowlowry
Date:
Sun Jun 20 13:48:06 2021 +0000
Revision:
4:5ecb71f149bf
Parent:
0:d984976f1f1c
NRF: receive, ntp, Data to Sd-card working

Who changed what in which revision?

UserRevisionLine numberNew contents of line
leo44 0:d984976f1f1c 1 /* mbed Microcontroller Library
leo44 0:d984976f1f1c 2 * Copyright (c) 2006-2012 ARM Limited
leo44 0:d984976f1f1c 3 *
leo44 0:d984976f1f1c 4 * Permission is hereby granted, free of charge, to any person obtaining a copy
leo44 0:d984976f1f1c 5 * of this software and associated documentation files (the "Software"), to deal
leo44 0:d984976f1f1c 6 * in the Software without restriction, including without limitation the rights
leo44 0:d984976f1f1c 7 * to use, copy, modify, merge, publish, distribute, sublicense, and/or sell
leo44 0:d984976f1f1c 8 * copies of the Software, and to permit persons to whom the Software is
leo44 0:d984976f1f1c 9 * furnished to do so, subject to the following conditions:
leo44 0:d984976f1f1c 10 *
leo44 0:d984976f1f1c 11 * The above copyright notice and this permission notice shall be included in
leo44 0:d984976f1f1c 12 * all copies or substantial portions of the Software.
leo44 0:d984976f1f1c 13 *
leo44 0:d984976f1f1c 14 * THE SOFTWARE IS PROVIDED "AS IS", WITHOUT WARRANTY OF ANY KIND, EXPRESS OR
leo44 0:d984976f1f1c 15 * IMPLIED, INCLUDING BUT NOT LIMITED TO THE WARRANTIES OF MERCHANTABILITY,
leo44 0:d984976f1f1c 16 * FITNESS FOR A PARTICULAR PURPOSE AND NONINFRINGEMENT. IN NO EVENT SHALL THE
leo44 0:d984976f1f1c 17 * AUTHORS OR COPYRIGHT HOLDERS BE LIABLE FOR ANY CLAIM, DAMAGES OR OTHER
leo44 0:d984976f1f1c 18 * LIABILITY, WHETHER IN AN ACTION OF CONTRACT, TORT OR OTHERWISE, ARISING FROM,
leo44 0:d984976f1f1c 19 * OUT OF OR IN CONNECTION WITH THE SOFTWARE OR THE USE OR OTHER DEALINGS IN THE
leo44 0:d984976f1f1c 20 * SOFTWARE.
leo44 0:d984976f1f1c 21 */
leo44 0:d984976f1f1c 22 #ifndef MAIL_H
leo44 0:d984976f1f1c 23 #define MAIL_H
leo44 0:d984976f1f1c 24
leo44 0:d984976f1f1c 25 #include <stdint.h>
leo44 0:d984976f1f1c 26 #include <string.h>
leo44 0:d984976f1f1c 27
leo44 0:d984976f1f1c 28 #include "cmsis_os.h"
leo44 0:d984976f1f1c 29
leo44 0:d984976f1f1c 30 namespace rtos {
leo44 0:d984976f1f1c 31
leo44 0:d984976f1f1c 32 /** The Mail class allow to control, send, receive, or wait for mail.
leo44 0:d984976f1f1c 33 A mail is a memory block that is send to a thread or interrupt service routine.
leo44 0:d984976f1f1c 34 @tparam T data type of a single message element.
leo44 0:d984976f1f1c 35 @tparam queue_sz maximum number of messages in queue.
leo44 0:d984976f1f1c 36 */
leo44 0:d984976f1f1c 37 template<typename T, uint32_t queue_sz>
leo44 0:d984976f1f1c 38 class Mail {
leo44 0:d984976f1f1c 39 public:
leo44 0:d984976f1f1c 40 /** Create and Initialise Mail queue. */
leo44 0:d984976f1f1c 41 Mail() {
leo44 0:d984976f1f1c 42 #ifdef CMSIS_OS_RTX
leo44 0:d984976f1f1c 43 memset(_mail_q, 0, sizeof(_mail_q));
leo44 0:d984976f1f1c 44 _mail_p[0] = _mail_q;
leo44 0:d984976f1f1c 45
leo44 0:d984976f1f1c 46 memset(_mail_m, 0, sizeof(_mail_m));
leo44 0:d984976f1f1c 47 _mail_p[1] = _mail_m;
leo44 0:d984976f1f1c 48
leo44 0:d984976f1f1c 49 _mail_def.pool = _mail_p;
leo44 0:d984976f1f1c 50 _mail_def.queue_sz = queue_sz;
leo44 0:d984976f1f1c 51 _mail_def.item_sz = sizeof(T);
leo44 0:d984976f1f1c 52 #endif
leo44 0:d984976f1f1c 53 _mail_id = osMailCreate(&_mail_def, NULL);
leo44 0:d984976f1f1c 54 }
leo44 0:d984976f1f1c 55
leo44 0:d984976f1f1c 56 /** Allocate a memory block of type T
leo44 0:d984976f1f1c 57 @param millisec timeout value or 0 in case of no time-out. (default: 0).
leo44 0:d984976f1f1c 58 @return pointer to memory block that can be filled with mail or NULL in case error.
leo44 0:d984976f1f1c 59 */
leo44 0:d984976f1f1c 60 T* alloc(uint32_t millisec=0) {
leo44 0:d984976f1f1c 61 return (T*)osMailAlloc(_mail_id, millisec);
leo44 0:d984976f1f1c 62 }
leo44 0:d984976f1f1c 63
leo44 0:d984976f1f1c 64 /** Allocate a memory block of type T and set memory block to zero.
leo44 0:d984976f1f1c 65 @param millisec timeout value or 0 in case of no time-out. (default: 0).
leo44 0:d984976f1f1c 66 @return pointer to memory block that can be filled with mail or NULL in case error.
leo44 0:d984976f1f1c 67 */
leo44 0:d984976f1f1c 68 T* calloc(uint32_t millisec=0) {
leo44 0:d984976f1f1c 69 return (T*)osMailCAlloc(_mail_id, millisec);
leo44 0:d984976f1f1c 70 }
leo44 0:d984976f1f1c 71
leo44 0:d984976f1f1c 72 /** Put a mail in the queue.
leo44 0:d984976f1f1c 73 @param mptr memory block previously allocated with Mail::alloc or Mail::calloc.
leo44 0:d984976f1f1c 74 @return status code that indicates the execution status of the function.
leo44 0:d984976f1f1c 75 */
leo44 0:d984976f1f1c 76 osStatus put(T *mptr) {
leo44 0:d984976f1f1c 77 return osMailPut(_mail_id, (void*)mptr);
leo44 0:d984976f1f1c 78 }
leo44 0:d984976f1f1c 79
leo44 0:d984976f1f1c 80 /** Get a mail from a queue.
leo44 0:d984976f1f1c 81 @param millisec timeout value or 0 in case of no time-out. (default: osWaitForever).
leo44 0:d984976f1f1c 82 @return event that contains mail information or error code.
leo44 0:d984976f1f1c 83 */
leo44 0:d984976f1f1c 84 osEvent get(uint32_t millisec=osWaitForever) {
leo44 0:d984976f1f1c 85 return osMailGet(_mail_id, millisec);
leo44 0:d984976f1f1c 86 }
leo44 0:d984976f1f1c 87
leo44 0:d984976f1f1c 88 /** Free a memory block from a mail.
leo44 0:d984976f1f1c 89 @param mptr pointer to the memory block that was obtained with Mail::get.
leo44 0:d984976f1f1c 90 @return status code that indicates the execution status of the function.
leo44 0:d984976f1f1c 91 */
leo44 0:d984976f1f1c 92 osStatus free(T *mptr) {
leo44 0:d984976f1f1c 93 return osMailFree(_mail_id, (void*)mptr);
leo44 0:d984976f1f1c 94 }
leo44 0:d984976f1f1c 95
leo44 0:d984976f1f1c 96 private:
leo44 0:d984976f1f1c 97 osMailQId _mail_id;
leo44 0:d984976f1f1c 98 osMailQDef_t _mail_def;
leo44 0:d984976f1f1c 99 #ifdef CMSIS_OS_RTX
leo44 0:d984976f1f1c 100 uint32_t _mail_q[4+(queue_sz)];
leo44 0:d984976f1f1c 101 uint32_t _mail_m[3+((sizeof(T)+3)/4)*(queue_sz)];
leo44 0:d984976f1f1c 102 void *_mail_p[2];
leo44 0:d984976f1f1c 103 #endif
leo44 0:d984976f1f1c 104 };
leo44 0:d984976f1f1c 105
leo44 0:d984976f1f1c 106 }
leo44 0:d984976f1f1c 107
leo44 0:d984976f1f1c 108 #endif
leo44 0:d984976f1f1c 109