Contains example code to connect the mbed LPC1768 or FRDM-K64F devices to the IBM Internet of Things Cloud service via ethernet.

Dependencies:   C12832 MQTT LM75B MMA7660

Dependents:   MFT_IoT_demo_USB400 IBM_RFID

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 #include "Thread.h"
samdanbury 6:37b6d0d56190 23
samdanbury 6:37b6d0d56190 24 #include "error.h"
samdanbury 6:37b6d0d56190 25
samdanbury 6:37b6d0d56190 26 namespace rtos {
samdanbury 6:37b6d0d56190 27
samdanbury 6:37b6d0d56190 28 Thread::Thread(void (*task)(void const *argument), void *argument,
samdanbury 6:37b6d0d56190 29 osPriority priority, uint32_t stack_size, unsigned char *stack_pointer) {
samdanbury 6:37b6d0d56190 30 #ifdef CMSIS_OS_RTX
samdanbury 6:37b6d0d56190 31 _thread_def.pthread = task;
samdanbury 6:37b6d0d56190 32 _thread_def.tpriority = priority;
samdanbury 6:37b6d0d56190 33 _thread_def.stacksize = stack_size;
samdanbury 6:37b6d0d56190 34 if (stack_pointer != NULL) {
samdanbury 6:37b6d0d56190 35 _thread_def.stack_pointer = stack_pointer;
samdanbury 6:37b6d0d56190 36 _dynamic_stack = false;
samdanbury 6:37b6d0d56190 37 } else {
samdanbury 6:37b6d0d56190 38 _thread_def.stack_pointer = new unsigned char[stack_size];
samdanbury 6:37b6d0d56190 39 if (_thread_def.stack_pointer == NULL)
samdanbury 6:37b6d0d56190 40 error("Error allocating the stack memory\n");
samdanbury 6:37b6d0d56190 41 _dynamic_stack = true;
samdanbury 6:37b6d0d56190 42 }
samdanbury 6:37b6d0d56190 43 #endif
samdanbury 6:37b6d0d56190 44 _tid = osThreadCreate(&_thread_def, argument);
samdanbury 6:37b6d0d56190 45 }
samdanbury 6:37b6d0d56190 46
samdanbury 6:37b6d0d56190 47 osStatus Thread::terminate() {
samdanbury 6:37b6d0d56190 48 return osThreadTerminate(_tid);
samdanbury 6:37b6d0d56190 49 }
samdanbury 6:37b6d0d56190 50
samdanbury 6:37b6d0d56190 51 osStatus Thread::set_priority(osPriority priority) {
samdanbury 6:37b6d0d56190 52 return osThreadSetPriority(_tid, priority);
samdanbury 6:37b6d0d56190 53 }
samdanbury 6:37b6d0d56190 54
samdanbury 6:37b6d0d56190 55 osPriority Thread::get_priority() {
samdanbury 6:37b6d0d56190 56 return osThreadGetPriority(_tid);
samdanbury 6:37b6d0d56190 57 }
samdanbury 6:37b6d0d56190 58
samdanbury 6:37b6d0d56190 59 int32_t Thread::signal_set(int32_t signals) {
samdanbury 6:37b6d0d56190 60 return osSignalSet(_tid, signals);
samdanbury 6:37b6d0d56190 61 }
samdanbury 6:37b6d0d56190 62
samdanbury 6:37b6d0d56190 63 Thread::State Thread::get_state() {
samdanbury 6:37b6d0d56190 64 return ((State)_thread_def.tcb.state);
samdanbury 6:37b6d0d56190 65 }
samdanbury 6:37b6d0d56190 66
samdanbury 6:37b6d0d56190 67 osEvent Thread::signal_wait(int32_t signals, uint32_t millisec) {
samdanbury 6:37b6d0d56190 68 return osSignalWait(signals, millisec);
samdanbury 6:37b6d0d56190 69 }
samdanbury 6:37b6d0d56190 70
samdanbury 6:37b6d0d56190 71 osStatus Thread::wait(uint32_t millisec) {
samdanbury 6:37b6d0d56190 72 return osDelay(millisec);
samdanbury 6:37b6d0d56190 73 }
samdanbury 6:37b6d0d56190 74
samdanbury 6:37b6d0d56190 75 osStatus Thread::yield() {
samdanbury 6:37b6d0d56190 76 return osThreadYield();
samdanbury 6:37b6d0d56190 77 }
samdanbury 6:37b6d0d56190 78
samdanbury 6:37b6d0d56190 79 osThreadId Thread::gettid() {
samdanbury 6:37b6d0d56190 80 return osThreadGetId();
samdanbury 6:37b6d0d56190 81 }
samdanbury 6:37b6d0d56190 82
samdanbury 6:37b6d0d56190 83 Thread::~Thread() {
samdanbury 6:37b6d0d56190 84 terminate();
samdanbury 6:37b6d0d56190 85 if (_dynamic_stack) {
samdanbury 6:37b6d0d56190 86 delete[] (_thread_def.stack_pointer);
samdanbury 6:37b6d0d56190 87 }
samdanbury 6:37b6d0d56190 88 }
samdanbury 6:37b6d0d56190 89
samdanbury 6:37b6d0d56190 90 }