RTC auf true

Committer:
kevman
Date:
Wed Mar 13 11:03:24 2019 +0000
Revision:
2:7aab896b1a3b
Parent:
0:38ceb79fef03
2019-03-13

Who changed what in which revision?

UserRevisionLine numberNew contents of line
kevman 0:38ceb79fef03 1 /* mbed Microcontroller Library
kevman 0:38ceb79fef03 2 * Copyright (c) 2006-2017 ARM Limited
kevman 0:38ceb79fef03 3 *
kevman 0:38ceb79fef03 4 * Permission is hereby granted, free of charge, to any person obtaining a copy
kevman 0:38ceb79fef03 5 * of this software and associated documentation files (the "Software"), to deal
kevman 0:38ceb79fef03 6 * in the Software without restriction, including without limitation the rights
kevman 0:38ceb79fef03 7 * to use, copy, modify, merge, publish, distribute, sublicense, and/or sell
kevman 0:38ceb79fef03 8 * copies of the Software, and to permit persons to whom the Software is
kevman 0:38ceb79fef03 9 * furnished to do so, subject to the following conditions:
kevman 0:38ceb79fef03 10 *
kevman 0:38ceb79fef03 11 * The above copyright notice and this permission notice shall be included in
kevman 0:38ceb79fef03 12 * all copies or substantial portions of the Software.
kevman 0:38ceb79fef03 13 *
kevman 0:38ceb79fef03 14 * THE SOFTWARE IS PROVIDED "AS IS", WITHOUT WARRANTY OF ANY KIND, EXPRESS OR
kevman 0:38ceb79fef03 15 * IMPLIED, INCLUDING BUT NOT LIMITED TO THE WARRANTIES OF MERCHANTABILITY,
kevman 0:38ceb79fef03 16 * FITNESS FOR A PARTICULAR PURPOSE AND NONINFRINGEMENT. IN NO EVENT SHALL THE
kevman 0:38ceb79fef03 17 * AUTHORS OR COPYRIGHT HOLDERS BE LIABLE FOR ANY CLAIM, DAMAGES OR OTHER
kevman 0:38ceb79fef03 18 * LIABILITY, WHETHER IN AN ACTION OF CONTRACT, TORT OR OTHERWISE, ARISING FROM,
kevman 0:38ceb79fef03 19 * OUT OF OR IN CONNECTION WITH THE SOFTWARE OR THE USE OR OTHER DEALINGS IN THE
kevman 0:38ceb79fef03 20 * SOFTWARE.
kevman 0:38ceb79fef03 21 */
kevman 0:38ceb79fef03 22 #ifndef MAIL_H
kevman 0:38ceb79fef03 23 #define MAIL_H
kevman 0:38ceb79fef03 24
kevman 0:38ceb79fef03 25 #include <stdint.h>
kevman 0:38ceb79fef03 26 #include <string.h>
kevman 0:38ceb79fef03 27
kevman 0:38ceb79fef03 28 #include "Queue.h"
kevman 0:38ceb79fef03 29 #include "MemoryPool.h"
kevman 0:38ceb79fef03 30 #include "cmsis_os2.h"
kevman 0:38ceb79fef03 31 #include "mbed_rtos_storage.h"
kevman 0:38ceb79fef03 32 #include "mbed_rtos1_types.h"
kevman 0:38ceb79fef03 33
kevman 0:38ceb79fef03 34 #include "platform/NonCopyable.h"
kevman 0:38ceb79fef03 35
kevman 0:38ceb79fef03 36 using namespace rtos;
kevman 0:38ceb79fef03 37
kevman 0:38ceb79fef03 38 namespace rtos {
kevman 0:38ceb79fef03 39 /** \addtogroup rtos */
kevman 0:38ceb79fef03 40 /** @{*/
kevman 0:38ceb79fef03 41 /**
kevman 0:38ceb79fef03 42 * \defgroup rtos_Mail Mail class
kevman 0:38ceb79fef03 43 * @{
kevman 0:38ceb79fef03 44 */
kevman 0:38ceb79fef03 45
kevman 0:38ceb79fef03 46 /** The Mail class allow to control, send, receive, or wait for mail.
kevman 0:38ceb79fef03 47 A mail is a memory block that is send to a thread or interrupt service routine.
kevman 0:38ceb79fef03 48 @tparam T data type of a single message element.
kevman 0:38ceb79fef03 49 @tparam queue_sz maximum number of messages in queue.
kevman 0:38ceb79fef03 50
kevman 0:38ceb79fef03 51 @note
kevman 0:38ceb79fef03 52 Memory considerations: The mail data store and control structures will be created on current thread's stack,
kevman 0:38ceb79fef03 53 both for the mbed OS and underlying RTOS objects (static or dynamic RTOS memory pools are not being used).
kevman 0:38ceb79fef03 54 */
kevman 0:38ceb79fef03 55 template<typename T, uint32_t queue_sz>
kevman 0:38ceb79fef03 56 class Mail : private mbed::NonCopyable<Mail<T, queue_sz> > {
kevman 0:38ceb79fef03 57 public:
kevman 0:38ceb79fef03 58 /** Create and Initialize Mail queue.
kevman 0:38ceb79fef03 59 *
kevman 0:38ceb79fef03 60 * @note You cannot call this function from ISR context.
kevman 0:38ceb79fef03 61 */
kevman 0:38ceb79fef03 62 Mail() { };
kevman 0:38ceb79fef03 63
kevman 0:38ceb79fef03 64 /** Check if the mail queue is empty
kevman 0:38ceb79fef03 65 *
kevman 0:38ceb79fef03 66 * @return True if the mail queue is empty, false if not
kevman 0:38ceb79fef03 67 *
kevman 0:38ceb79fef03 68 * @note You may call this function from ISR context.
kevman 0:38ceb79fef03 69 */
kevman 0:38ceb79fef03 70 bool empty() const {
kevman 0:38ceb79fef03 71 return _queue.empty();
kevman 0:38ceb79fef03 72 }
kevman 0:38ceb79fef03 73
kevman 0:38ceb79fef03 74 /** Check if the mail queue is full
kevman 0:38ceb79fef03 75 *
kevman 0:38ceb79fef03 76 * @return True if the mail queue is full, false if not
kevman 0:38ceb79fef03 77 *
kevman 0:38ceb79fef03 78 * @note You may call this function from ISR context.
kevman 0:38ceb79fef03 79 */
kevman 0:38ceb79fef03 80 bool full() const {
kevman 0:38ceb79fef03 81 return _queue.full();
kevman 0:38ceb79fef03 82 }
kevman 0:38ceb79fef03 83
kevman 0:38ceb79fef03 84 /** Allocate a memory block of type T
kevman 0:38ceb79fef03 85 @param millisec timeout value or 0 in case of no time-out. (default: 0).
kevman 0:38ceb79fef03 86 @return pointer to memory block that can be filled with mail or NULL in case error.
kevman 0:38ceb79fef03 87
kevman 0:38ceb79fef03 88 @note You may call this function from ISR context if the millisec parameter is set to 0.
kevman 0:38ceb79fef03 89 */
kevman 0:38ceb79fef03 90 T* alloc(uint32_t millisec=0) {
kevman 0:38ceb79fef03 91 return _pool.alloc();
kevman 0:38ceb79fef03 92 }
kevman 0:38ceb79fef03 93
kevman 0:38ceb79fef03 94 /** Allocate a memory block of type T and set memory block to zero.
kevman 0:38ceb79fef03 95 @param millisec timeout value or 0 in case of no time-out. (default: 0).
kevman 0:38ceb79fef03 96 @return pointer to memory block that can be filled with mail or NULL in case error.
kevman 0:38ceb79fef03 97
kevman 0:38ceb79fef03 98 @note You may call this function from ISR context if the millisec parameter is set to 0.
kevman 0:38ceb79fef03 99 */
kevman 0:38ceb79fef03 100 T* calloc(uint32_t millisec=0) {
kevman 0:38ceb79fef03 101 return _pool.calloc();
kevman 0:38ceb79fef03 102 }
kevman 0:38ceb79fef03 103
kevman 0:38ceb79fef03 104 /** Put a mail in the queue.
kevman 0:38ceb79fef03 105 @param mptr memory block previously allocated with Mail::alloc or Mail::calloc.
kevman 0:38ceb79fef03 106 @return status code that indicates the execution status of the function.
kevman 0:38ceb79fef03 107
kevman 0:38ceb79fef03 108 @note You may call this function from ISR context.
kevman 0:38ceb79fef03 109 */
kevman 0:38ceb79fef03 110 osStatus put(T *mptr) {
kevman 0:38ceb79fef03 111 return _queue.put(mptr);
kevman 0:38ceb79fef03 112 }
kevman 0:38ceb79fef03 113
kevman 0:38ceb79fef03 114 /** Get a mail from a queue.
kevman 0:38ceb79fef03 115 @param millisec timeout value or 0 in case of no time-out. (default: osWaitForever).
kevman 0:38ceb79fef03 116 @return event that contains mail information or error code.
kevman 0:38ceb79fef03 117
kevman 0:38ceb79fef03 118 @note You may call this function from ISR context if the millisec parameter is set to 0.
kevman 0:38ceb79fef03 119 */
kevman 0:38ceb79fef03 120 osEvent get(uint32_t millisec=osWaitForever) {
kevman 0:38ceb79fef03 121 osEvent evt = _queue.get(millisec);
kevman 0:38ceb79fef03 122 if (evt.status == osEventMessage) {
kevman 0:38ceb79fef03 123 evt.status = osEventMail;
kevman 0:38ceb79fef03 124 }
kevman 0:38ceb79fef03 125 return evt;
kevman 0:38ceb79fef03 126 }
kevman 0:38ceb79fef03 127
kevman 0:38ceb79fef03 128 /** Free a memory block from a mail.
kevman 0:38ceb79fef03 129 @param mptr pointer to the memory block that was obtained with Mail::get.
kevman 0:38ceb79fef03 130 @return status code that indicates the execution status of the function.
kevman 0:38ceb79fef03 131
kevman 0:38ceb79fef03 132 @note You may call this function from ISR context.
kevman 0:38ceb79fef03 133 */
kevman 0:38ceb79fef03 134 osStatus free(T *mptr) {
kevman 0:38ceb79fef03 135 return _pool.free(mptr);
kevman 0:38ceb79fef03 136 }
kevman 0:38ceb79fef03 137
kevman 0:38ceb79fef03 138 private:
kevman 0:38ceb79fef03 139 Queue<T, queue_sz> _queue;
kevman 0:38ceb79fef03 140 MemoryPool<T, queue_sz> _pool;
kevman 0:38ceb79fef03 141 };
kevman 0:38ceb79fef03 142
kevman 0:38ceb79fef03 143 /** @}*/
kevman 0:38ceb79fef03 144 /** @}*/
kevman 0:38ceb79fef03 145
kevman 0:38ceb79fef03 146 }
kevman 0:38ceb79fef03 147
kevman 0:38ceb79fef03 148 #endif
kevman 0:38ceb79fef03 149
kevman 0:38ceb79fef03 150
kevman 0:38ceb79fef03 151