Rahul Dahiya / Mbed OS STM32F7 Ethernet
Committer:
rahul_dahiya
Date:
Wed Jan 15 15:57:15 2020 +0530
Revision:
0:fb8047b156bb
STM32F7 LWIP

Who changed what in which revision?

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