Port to C027 (using AppShield and Ethernet)

Dependencies:   C12832 EthernetInterface LM75B MMA7660 MQTT mbed-rtos mbed

Fork of IBMIoTClientEthernetExample by IBM Watson IoT

Committer:
samdanbury
Date:
Wed Aug 20 12:45:14 2014 +0000
Revision:
6:37b6d0d56190
Code completely changed to improve the structure, flow and memory usage of the application

Who changed what in which revision?

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