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