teste de publish

Dependencies:   DS1820 HighSpeedAnalogIn devices mbed

Committer:
brunofgc
Date:
Fri Mar 24 15:54:41 2017 +0000
Revision:
0:1c0a769988ee
Saidas digitais com pwm ok, entradas analogicas ok

Who changed what in which revision?

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