Home Alert System

Dependencies:   PWM_Tone_Library DHT

Committer:
ethaderu
Date:
Tue Mar 05 02:34:44 2019 +0000
Revision:
3:78f223d34f36
Publish 1

Who changed what in which revision?

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