mbed client lightswitch demo

Dependencies:   mbed Socket lwip-eth lwip-sys lwip

Fork of mbed-client-classic-example-lwip by Austin Blackstone

Committer:
mbedAustin
Date:
Thu Jun 09 17:08:36 2016 +0000
Revision:
11:cada08fc8a70
Commit for public Consumption

Who changed what in which revision?

UserRevisionLine numberNew contents of line
mbedAustin 11:cada08fc8a70 1 /* mbed Microcontroller Library
mbedAustin 11:cada08fc8a70 2 * Copyright (c) 2006-2012 ARM Limited
mbedAustin 11:cada08fc8a70 3 *
mbedAustin 11:cada08fc8a70 4 * Permission is hereby granted, free of charge, to any person obtaining a copy
mbedAustin 11:cada08fc8a70 5 * of this software and associated documentation files (the "Software"), to deal
mbedAustin 11:cada08fc8a70 6 * in the Software without restriction, including without limitation the rights
mbedAustin 11:cada08fc8a70 7 * to use, copy, modify, merge, publish, distribute, sublicense, and/or sell
mbedAustin 11:cada08fc8a70 8 * copies of the Software, and to permit persons to whom the Software is
mbedAustin 11:cada08fc8a70 9 * furnished to do so, subject to the following conditions:
mbedAustin 11:cada08fc8a70 10 *
mbedAustin 11:cada08fc8a70 11 * The above copyright notice and this permission notice shall be included in
mbedAustin 11:cada08fc8a70 12 * all copies or substantial portions of the Software.
mbedAustin 11:cada08fc8a70 13 *
mbedAustin 11:cada08fc8a70 14 * THE SOFTWARE IS PROVIDED "AS IS", WITHOUT WARRANTY OF ANY KIND, EXPRESS OR
mbedAustin 11:cada08fc8a70 15 * IMPLIED, INCLUDING BUT NOT LIMITED TO THE WARRANTIES OF MERCHANTABILITY,
mbedAustin 11:cada08fc8a70 16 * FITNESS FOR A PARTICULAR PURPOSE AND NONINFRINGEMENT. IN NO EVENT SHALL THE
mbedAustin 11:cada08fc8a70 17 * AUTHORS OR COPYRIGHT HOLDERS BE LIABLE FOR ANY CLAIM, DAMAGES OR OTHER
mbedAustin 11:cada08fc8a70 18 * LIABILITY, WHETHER IN AN ACTION OF CONTRACT, TORT OR OTHERWISE, ARISING FROM,
mbedAustin 11:cada08fc8a70 19 * OUT OF OR IN CONNECTION WITH THE SOFTWARE OR THE USE OR OTHER DEALINGS IN THE
mbedAustin 11:cada08fc8a70 20 * SOFTWARE.
mbedAustin 11:cada08fc8a70 21 */
mbedAustin 11:cada08fc8a70 22 #ifndef QUEUE_H
mbedAustin 11:cada08fc8a70 23 #define QUEUE_H
mbedAustin 11:cada08fc8a70 24
mbedAustin 11:cada08fc8a70 25 #include <stdint.h>
mbedAustin 11:cada08fc8a70 26 #include <string.h>
mbedAustin 11:cada08fc8a70 27
mbedAustin 11:cada08fc8a70 28 #include "cmsis_os.h"
mbedAustin 11:cada08fc8a70 29 #include "mbed_error.h"
mbedAustin 11:cada08fc8a70 30
mbedAustin 11:cada08fc8a70 31 namespace rtos {
mbedAustin 11:cada08fc8a70 32
mbedAustin 11:cada08fc8a70 33 /** The Queue class allow to control, send, receive, or wait for messages.
mbedAustin 11:cada08fc8a70 34 A message can be a integer or pointer value to a certain type T that is send
mbedAustin 11:cada08fc8a70 35 to a thread or interrupt service routine.
mbedAustin 11:cada08fc8a70 36 @tparam T data type of a single message element.
mbedAustin 11:cada08fc8a70 37 @tparam queue_sz maximum number of messages in queue.
mbedAustin 11:cada08fc8a70 38 */
mbedAustin 11:cada08fc8a70 39 template<typename T, uint32_t queue_sz>
mbedAustin 11:cada08fc8a70 40 class Queue {
mbedAustin 11:cada08fc8a70 41 public:
mbedAustin 11:cada08fc8a70 42 /** Create and initialise a message Queue. */
mbedAustin 11:cada08fc8a70 43 Queue() {
mbedAustin 11:cada08fc8a70 44 #ifdef CMSIS_OS_RTX
mbedAustin 11:cada08fc8a70 45 memset(_queue_q, 0, sizeof(_queue_q));
mbedAustin 11:cada08fc8a70 46 _queue_def.pool = _queue_q;
mbedAustin 11:cada08fc8a70 47 _queue_def.queue_sz = queue_sz;
mbedAustin 11:cada08fc8a70 48 #endif
mbedAustin 11:cada08fc8a70 49 _queue_id = osMessageCreate(&_queue_def, NULL);
mbedAustin 11:cada08fc8a70 50 if (_queue_id == NULL) {
mbedAustin 11:cada08fc8a70 51 error("Error initialising the queue object\n");
mbedAustin 11:cada08fc8a70 52 }
mbedAustin 11:cada08fc8a70 53 }
mbedAustin 11:cada08fc8a70 54
mbedAustin 11:cada08fc8a70 55 /** Put a message in a Queue.
mbedAustin 11:cada08fc8a70 56 @param data message pointer.
mbedAustin 11:cada08fc8a70 57 @param millisec timeout value or 0 in case of no time-out. (default: 0)
mbedAustin 11:cada08fc8a70 58 @return status code that indicates the execution status of the function.
mbedAustin 11:cada08fc8a70 59 */
mbedAustin 11:cada08fc8a70 60 osStatus put(T* data, uint32_t millisec=0) {
mbedAustin 11:cada08fc8a70 61 return osMessagePut(_queue_id, (uint32_t)data, millisec);
mbedAustin 11:cada08fc8a70 62 }
mbedAustin 11:cada08fc8a70 63
mbedAustin 11:cada08fc8a70 64 /** Get a message or Wait for a message from a Queue.
mbedAustin 11:cada08fc8a70 65 @param millisec timeout value or 0 in case of no time-out. (default: osWaitForever).
mbedAustin 11:cada08fc8a70 66 @return event information that includes the message and the status code.
mbedAustin 11:cada08fc8a70 67 */
mbedAustin 11:cada08fc8a70 68 osEvent get(uint32_t millisec=osWaitForever) {
mbedAustin 11:cada08fc8a70 69 return osMessageGet(_queue_id, millisec);
mbedAustin 11:cada08fc8a70 70 }
mbedAustin 11:cada08fc8a70 71
mbedAustin 11:cada08fc8a70 72 private:
mbedAustin 11:cada08fc8a70 73 osMessageQId _queue_id;
mbedAustin 11:cada08fc8a70 74 osMessageQDef_t _queue_def;
mbedAustin 11:cada08fc8a70 75 #ifdef CMSIS_OS_RTX
mbedAustin 11:cada08fc8a70 76 uint32_t _queue_q[4+(queue_sz)];
mbedAustin 11:cada08fc8a70 77 #endif
mbedAustin 11:cada08fc8a70 78 };
mbedAustin 11:cada08fc8a70 79
mbedAustin 11:cada08fc8a70 80 }
mbedAustin 11:cada08fc8a70 81 #endif