This is a fork due to permission issues

Dependencies:   mbed Socket lwip-eth lwip-sys lwip

Fork of 6_songs-from-the-cloud by MakingMusicWorkshop

Committer:
timbeight
Date:
Thu May 19 16:02:10 2016 +0000
Revision:
1:0ddbe2d3319c
Parent:
0:f7c60d3e7b8a
This is my first commit while in the class.

Who changed what in which revision?

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