Control a robot over the internet using UDP and a Wifly module (WiFi).

Dependencies:   Motor TextLCD WiflyInterface mbed-rtos mbed

Committer:
apatel336
Date:
Thu Oct 17 13:27:56 2013 +0000
Revision:
0:c0dc3a76f3d4
Initial Release

Who changed what in which revision?

UserRevisionLine numberNew contents of line
apatel336 0:c0dc3a76f3d4 1 /* mbed Microcontroller Library
apatel336 0:c0dc3a76f3d4 2 * Copyright (c) 2006-2012 ARM Limited
apatel336 0:c0dc3a76f3d4 3 *
apatel336 0:c0dc3a76f3d4 4 * Permission is hereby granted, free of charge, to any person obtaining a copy
apatel336 0:c0dc3a76f3d4 5 * of this software and associated documentation files (the "Software"), to deal
apatel336 0:c0dc3a76f3d4 6 * in the Software without restriction, including without limitation the rights
apatel336 0:c0dc3a76f3d4 7 * to use, copy, modify, merge, publish, distribute, sublicense, and/or sell
apatel336 0:c0dc3a76f3d4 8 * copies of the Software, and to permit persons to whom the Software is
apatel336 0:c0dc3a76f3d4 9 * furnished to do so, subject to the following conditions:
apatel336 0:c0dc3a76f3d4 10 *
apatel336 0:c0dc3a76f3d4 11 * The above copyright notice and this permission notice shall be included in
apatel336 0:c0dc3a76f3d4 12 * all copies or substantial portions of the Software.
apatel336 0:c0dc3a76f3d4 13 *
apatel336 0:c0dc3a76f3d4 14 * THE SOFTWARE IS PROVIDED "AS IS", WITHOUT WARRANTY OF ANY KIND, EXPRESS OR
apatel336 0:c0dc3a76f3d4 15 * IMPLIED, INCLUDING BUT NOT LIMITED TO THE WARRANTIES OF MERCHANTABILITY,
apatel336 0:c0dc3a76f3d4 16 * FITNESS FOR A PARTICULAR PURPOSE AND NONINFRINGEMENT. IN NO EVENT SHALL THE
apatel336 0:c0dc3a76f3d4 17 * AUTHORS OR COPYRIGHT HOLDERS BE LIABLE FOR ANY CLAIM, DAMAGES OR OTHER
apatel336 0:c0dc3a76f3d4 18 * LIABILITY, WHETHER IN AN ACTION OF CONTRACT, TORT OR OTHERWISE, ARISING FROM,
apatel336 0:c0dc3a76f3d4 19 * OUT OF OR IN CONNECTION WITH THE SOFTWARE OR THE USE OR OTHER DEALINGS IN THE
apatel336 0:c0dc3a76f3d4 20 * SOFTWARE.
apatel336 0:c0dc3a76f3d4 21 */
apatel336 0:c0dc3a76f3d4 22 #ifndef THREAD_H
apatel336 0:c0dc3a76f3d4 23 #define THREAD_H
apatel336 0:c0dc3a76f3d4 24
apatel336 0:c0dc3a76f3d4 25 #include <stdint.h>
apatel336 0:c0dc3a76f3d4 26 #include "cmsis_os.h"
apatel336 0:c0dc3a76f3d4 27
apatel336 0:c0dc3a76f3d4 28 namespace rtos {
apatel336 0:c0dc3a76f3d4 29
apatel336 0:c0dc3a76f3d4 30 /** The Thread class allow defining, creating, and controlling thread functions in the system. */
apatel336 0:c0dc3a76f3d4 31 class Thread {
apatel336 0:c0dc3a76f3d4 32 public:
apatel336 0:c0dc3a76f3d4 33 /** Create a new thread, and start it executing the specified function.
apatel336 0:c0dc3a76f3d4 34 @param task function to be executed by this thread.
apatel336 0:c0dc3a76f3d4 35 @param argument pointer that is passed to the thread function as start argument. (default: NULL).
apatel336 0:c0dc3a76f3d4 36 @param priority initial priority of the thread function. (default: osPriorityNormal).
apatel336 0:c0dc3a76f3d4 37 @param stack_size stack size (in bytes) requirements for the thread function. (default: DEFAULT_STACK_SIZE).
apatel336 0:c0dc3a76f3d4 38 @param stack_pointer pointer to the stack area to be used by this thread (default: NULL).
apatel336 0:c0dc3a76f3d4 39 */
apatel336 0:c0dc3a76f3d4 40 Thread(void (*task)(void const *argument), void *argument=NULL,
apatel336 0:c0dc3a76f3d4 41 osPriority priority=osPriorityNormal,
apatel336 0:c0dc3a76f3d4 42 uint32_t stack_size=DEFAULT_STACK_SIZE,
apatel336 0:c0dc3a76f3d4 43 unsigned char *stack_pointer=NULL);
apatel336 0:c0dc3a76f3d4 44
apatel336 0:c0dc3a76f3d4 45 /** Terminate execution of a thread and remove it from Active Threads
apatel336 0:c0dc3a76f3d4 46 @return status code that indicates the execution status of the function.
apatel336 0:c0dc3a76f3d4 47 */
apatel336 0:c0dc3a76f3d4 48 osStatus terminate();
apatel336 0:c0dc3a76f3d4 49
apatel336 0:c0dc3a76f3d4 50 /** Set priority of an active thread
apatel336 0:c0dc3a76f3d4 51 @param priority new priority value for the thread function.
apatel336 0:c0dc3a76f3d4 52 @return status code that indicates the execution status of the function.
apatel336 0:c0dc3a76f3d4 53 */
apatel336 0:c0dc3a76f3d4 54 osStatus set_priority(osPriority priority);
apatel336 0:c0dc3a76f3d4 55
apatel336 0:c0dc3a76f3d4 56 /** Get priority of an active thread
apatel336 0:c0dc3a76f3d4 57 @return current priority value of the thread function.
apatel336 0:c0dc3a76f3d4 58 */
apatel336 0:c0dc3a76f3d4 59 osPriority get_priority();
apatel336 0:c0dc3a76f3d4 60
apatel336 0:c0dc3a76f3d4 61 /** Set the specified Signal Flags of an active thread.
apatel336 0:c0dc3a76f3d4 62 @param signals specifies the signal flags of the thread that should be set.
apatel336 0:c0dc3a76f3d4 63 @return previous signal flags of the specified thread or 0x80000000 in case of incorrect parameters.
apatel336 0:c0dc3a76f3d4 64 */
apatel336 0:c0dc3a76f3d4 65 int32_t signal_set(int32_t signals);
apatel336 0:c0dc3a76f3d4 66
apatel336 0:c0dc3a76f3d4 67 /** State of the Thread */
apatel336 0:c0dc3a76f3d4 68 enum State {
apatel336 0:c0dc3a76f3d4 69 Inactive, /**< Not created or terminated */
apatel336 0:c0dc3a76f3d4 70 Ready, /**< Ready to run */
apatel336 0:c0dc3a76f3d4 71 Running, /**< Running */
apatel336 0:c0dc3a76f3d4 72 WaitingDelay, /**< Waiting for a delay to occur */
apatel336 0:c0dc3a76f3d4 73 WaitingInterval, /**< Waiting for an interval to occur */
apatel336 0:c0dc3a76f3d4 74 WaitingOr, /**< Waiting for one event in a set to occur */
apatel336 0:c0dc3a76f3d4 75 WaitingAnd, /**< Waiting for multiple events in a set to occur */
apatel336 0:c0dc3a76f3d4 76 WaitingSemaphore, /**< Waiting for a semaphore event to occur */
apatel336 0:c0dc3a76f3d4 77 WaitingMailbox, /**< Waiting for a mailbox event to occur */
apatel336 0:c0dc3a76f3d4 78 WaitingMutex, /**< Waiting for a mutex event to occur */
apatel336 0:c0dc3a76f3d4 79 };
apatel336 0:c0dc3a76f3d4 80
apatel336 0:c0dc3a76f3d4 81 /** State of this Thread
apatel336 0:c0dc3a76f3d4 82 @return the State of this Thread
apatel336 0:c0dc3a76f3d4 83 */
apatel336 0:c0dc3a76f3d4 84 State get_state();
apatel336 0:c0dc3a76f3d4 85
apatel336 0:c0dc3a76f3d4 86 /** Wait for one or more Signal Flags to become signaled for the current RUNNING thread.
apatel336 0:c0dc3a76f3d4 87 @param signals wait until all specified signal flags set or 0 for any single signal flag.
apatel336 0:c0dc3a76f3d4 88 @param millisec timeout value or 0 in case of no time-out. (default: osWaitForever).
apatel336 0:c0dc3a76f3d4 89 @return event flag information or error code.
apatel336 0:c0dc3a76f3d4 90 */
apatel336 0:c0dc3a76f3d4 91 static osEvent signal_wait(int32_t signals, uint32_t millisec=osWaitForever);
apatel336 0:c0dc3a76f3d4 92
apatel336 0:c0dc3a76f3d4 93 /** Wait for a specified time period in millisec:
apatel336 0:c0dc3a76f3d4 94 @param millisec time delay value
apatel336 0:c0dc3a76f3d4 95 @return status code that indicates the execution status of the function.
apatel336 0:c0dc3a76f3d4 96 */
apatel336 0:c0dc3a76f3d4 97 static osStatus wait(uint32_t millisec);
apatel336 0:c0dc3a76f3d4 98
apatel336 0:c0dc3a76f3d4 99 /** Pass control to next thread that is in state READY.
apatel336 0:c0dc3a76f3d4 100 @return status code that indicates the execution status of the function.
apatel336 0:c0dc3a76f3d4 101 */
apatel336 0:c0dc3a76f3d4 102 static osStatus yield();
apatel336 0:c0dc3a76f3d4 103
apatel336 0:c0dc3a76f3d4 104 /** Get the thread id of the current running thread.
apatel336 0:c0dc3a76f3d4 105 @return thread ID for reference by other functions or NULL in case of error.
apatel336 0:c0dc3a76f3d4 106 */
apatel336 0:c0dc3a76f3d4 107 static osThreadId gettid();
apatel336 0:c0dc3a76f3d4 108
apatel336 0:c0dc3a76f3d4 109 virtual ~Thread();
apatel336 0:c0dc3a76f3d4 110
apatel336 0:c0dc3a76f3d4 111 private:
apatel336 0:c0dc3a76f3d4 112 osThreadId _tid;
apatel336 0:c0dc3a76f3d4 113 osThreadDef_t _thread_def;
apatel336 0:c0dc3a76f3d4 114 bool _dynamic_stack;
apatel336 0:c0dc3a76f3d4 115 };
apatel336 0:c0dc3a76f3d4 116
apatel336 0:c0dc3a76f3d4 117 }
apatel336 0:c0dc3a76f3d4 118 #endif