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 THREAD_H
mbedAustin 11:cada08fc8a70 23 #define THREAD_H
mbedAustin 11:cada08fc8a70 24
mbedAustin 11:cada08fc8a70 25 #include <stdint.h>
mbedAustin 11:cada08fc8a70 26 #include "cmsis_os.h"
mbedAustin 11:cada08fc8a70 27
mbedAustin 11:cada08fc8a70 28 namespace rtos {
mbedAustin 11:cada08fc8a70 29
mbedAustin 11:cada08fc8a70 30 /** The Thread class allow defining, creating, and controlling thread functions in the system. */
mbedAustin 11:cada08fc8a70 31 class Thread {
mbedAustin 11:cada08fc8a70 32 public:
mbedAustin 11:cada08fc8a70 33 /** Create a new thread, and start it executing the specified function.
mbedAustin 11:cada08fc8a70 34 @param task function to be executed by this thread.
mbedAustin 11:cada08fc8a70 35 @param argument pointer that is passed to the thread function as start argument. (default: NULL).
mbedAustin 11:cada08fc8a70 36 @param priority initial priority of the thread function. (default: osPriorityNormal).
mbedAustin 11:cada08fc8a70 37 @param stack_size stack size (in bytes) requirements for the thread function. (default: DEFAULT_STACK_SIZE).
mbedAustin 11:cada08fc8a70 38 @param stack_pointer pointer to the stack area to be used by this thread (default: NULL).
mbedAustin 11:cada08fc8a70 39 */
mbedAustin 11:cada08fc8a70 40 Thread(void (*task)(void const *argument), void *argument=NULL,
mbedAustin 11:cada08fc8a70 41 osPriority priority=osPriorityNormal,
mbedAustin 11:cada08fc8a70 42 uint32_t stack_size=DEFAULT_STACK_SIZE,
mbedAustin 11:cada08fc8a70 43 unsigned char *stack_pointer=NULL);
mbedAustin 11:cada08fc8a70 44
mbedAustin 11:cada08fc8a70 45 /** Terminate execution of a thread and remove it from Active Threads
mbedAustin 11:cada08fc8a70 46 @return status code that indicates the execution status of the function.
mbedAustin 11:cada08fc8a70 47 */
mbedAustin 11:cada08fc8a70 48 osStatus terminate();
mbedAustin 11:cada08fc8a70 49
mbedAustin 11:cada08fc8a70 50 /** Set priority of an active thread
mbedAustin 11:cada08fc8a70 51 @param priority new priority value for the thread function.
mbedAustin 11:cada08fc8a70 52 @return status code that indicates the execution status of the function.
mbedAustin 11:cada08fc8a70 53 */
mbedAustin 11:cada08fc8a70 54 osStatus set_priority(osPriority priority);
mbedAustin 11:cada08fc8a70 55
mbedAustin 11:cada08fc8a70 56 /** Get priority of an active thread
mbedAustin 11:cada08fc8a70 57 @return current priority value of the thread function.
mbedAustin 11:cada08fc8a70 58 */
mbedAustin 11:cada08fc8a70 59 osPriority get_priority();
mbedAustin 11:cada08fc8a70 60
mbedAustin 11:cada08fc8a70 61 /** Set the specified Signal Flags of an active thread.
mbedAustin 11:cada08fc8a70 62 @param signals specifies the signal flags of the thread that should be set.
mbedAustin 11:cada08fc8a70 63 @return previous signal flags of the specified thread or 0x80000000 in case of incorrect parameters.
mbedAustin 11:cada08fc8a70 64 */
mbedAustin 11:cada08fc8a70 65 int32_t signal_set(int32_t signals);
mbedAustin 11:cada08fc8a70 66
mbedAustin 11:cada08fc8a70 67 /** Clears the specified Signal Flags of an active thread.
mbedAustin 11:cada08fc8a70 68 @param signals specifies the signal flags of the thread that should be cleared.
mbedAustin 11:cada08fc8a70 69 @return resultant signal flags of the specified thread or 0x80000000 in case of incorrect parameters.
mbedAustin 11:cada08fc8a70 70 */
mbedAustin 11:cada08fc8a70 71 int32_t signal_clr(int32_t signals);
mbedAustin 11:cada08fc8a70 72
mbedAustin 11:cada08fc8a70 73 /** State of the Thread */
mbedAustin 11:cada08fc8a70 74 enum State {
mbedAustin 11:cada08fc8a70 75 Inactive, /**< Not created or terminated */
mbedAustin 11:cada08fc8a70 76 Ready, /**< Ready to run */
mbedAustin 11:cada08fc8a70 77 Running, /**< Running */
mbedAustin 11:cada08fc8a70 78 WaitingDelay, /**< Waiting for a delay to occur */
mbedAustin 11:cada08fc8a70 79 WaitingInterval, /**< Waiting for an interval to occur */
mbedAustin 11:cada08fc8a70 80 WaitingOr, /**< Waiting for one event in a set to occur */
mbedAustin 11:cada08fc8a70 81 WaitingAnd, /**< Waiting for multiple events in a set to occur */
mbedAustin 11:cada08fc8a70 82 WaitingSemaphore, /**< Waiting for a semaphore event to occur */
mbedAustin 11:cada08fc8a70 83 WaitingMailbox, /**< Waiting for a mailbox event to occur */
mbedAustin 11:cada08fc8a70 84 WaitingMutex, /**< Waiting for a mutex event to occur */
mbedAustin 11:cada08fc8a70 85 };
mbedAustin 11:cada08fc8a70 86
mbedAustin 11:cada08fc8a70 87 /** State of this Thread
mbedAustin 11:cada08fc8a70 88 @return the State of this Thread
mbedAustin 11:cada08fc8a70 89 */
mbedAustin 11:cada08fc8a70 90 State get_state();
mbedAustin 11:cada08fc8a70 91
mbedAustin 11:cada08fc8a70 92 /** Get the total stack memory size for this Thread
mbedAustin 11:cada08fc8a70 93 @return the total stack memory size in bytes
mbedAustin 11:cada08fc8a70 94 */
mbedAustin 11:cada08fc8a70 95 uint32_t stack_size();
mbedAustin 11:cada08fc8a70 96
mbedAustin 11:cada08fc8a70 97 /** Get the currently unused stack memory for this Thread
mbedAustin 11:cada08fc8a70 98 @return the currently unused stack memory in bytes
mbedAustin 11:cada08fc8a70 99 */
mbedAustin 11:cada08fc8a70 100 uint32_t free_stack();
mbedAustin 11:cada08fc8a70 101
mbedAustin 11:cada08fc8a70 102 /** Get the currently used stack memory for this Thread
mbedAustin 11:cada08fc8a70 103 @return the currently used stack memory in bytes
mbedAustin 11:cada08fc8a70 104 */
mbedAustin 11:cada08fc8a70 105 uint32_t used_stack();
mbedAustin 11:cada08fc8a70 106
mbedAustin 11:cada08fc8a70 107 /** Get the maximum stack memory usage to date for this Thread
mbedAustin 11:cada08fc8a70 108 @return the maximum stack memory usage to date in bytes
mbedAustin 11:cada08fc8a70 109 */
mbedAustin 11:cada08fc8a70 110 uint32_t max_stack();
mbedAustin 11:cada08fc8a70 111
mbedAustin 11:cada08fc8a70 112 /** Wait for one or more Signal Flags to become signaled for the current RUNNING thread.
mbedAustin 11:cada08fc8a70 113 @param signals wait until all specified signal flags set or 0 for any single signal flag.
mbedAustin 11:cada08fc8a70 114 @param millisec timeout value or 0 in case of no time-out. (default: osWaitForever).
mbedAustin 11:cada08fc8a70 115 @return event flag information or error code.
mbedAustin 11:cada08fc8a70 116 */
mbedAustin 11:cada08fc8a70 117 static osEvent signal_wait(int32_t signals, uint32_t millisec=osWaitForever);
mbedAustin 11:cada08fc8a70 118
mbedAustin 11:cada08fc8a70 119 /** Wait for a specified time period in millisec:
mbedAustin 11:cada08fc8a70 120 @param millisec time delay value
mbedAustin 11:cada08fc8a70 121 @return status code that indicates the execution status of the function.
mbedAustin 11:cada08fc8a70 122 */
mbedAustin 11:cada08fc8a70 123 static osStatus wait(uint32_t millisec);
mbedAustin 11:cada08fc8a70 124
mbedAustin 11:cada08fc8a70 125 /** Pass control to next thread that is in state READY.
mbedAustin 11:cada08fc8a70 126 @return status code that indicates the execution status of the function.
mbedAustin 11:cada08fc8a70 127 */
mbedAustin 11:cada08fc8a70 128 static osStatus yield();
mbedAustin 11:cada08fc8a70 129
mbedAustin 11:cada08fc8a70 130 /** Get the thread id of the current running thread.
mbedAustin 11:cada08fc8a70 131 @return thread ID for reference by other functions or NULL in case of error.
mbedAustin 11:cada08fc8a70 132 */
mbedAustin 11:cada08fc8a70 133 static osThreadId gettid();
mbedAustin 11:cada08fc8a70 134
mbedAustin 11:cada08fc8a70 135 virtual ~Thread();
mbedAustin 11:cada08fc8a70 136
mbedAustin 11:cada08fc8a70 137 private:
mbedAustin 11:cada08fc8a70 138 osThreadId _tid;
mbedAustin 11:cada08fc8a70 139 osThreadDef_t _thread_def;
mbedAustin 11:cada08fc8a70 140 bool _dynamic_stack;
mbedAustin 11:cada08fc8a70 141 };
mbedAustin 11:cada08fc8a70 142
mbedAustin 11:cada08fc8a70 143 }
mbedAustin 11:cada08fc8a70 144 #endif