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 /*----------------------------------------------------------------------------
samdanbury 6:37b6d0d56190 2 * RL-ARM - RTX
samdanbury 6:37b6d0d56190 3 *----------------------------------------------------------------------------
samdanbury 6:37b6d0d56190 4 * Name: RT_EVENT.C
samdanbury 6:37b6d0d56190 5 * Purpose: Implements waits and wake-ups for event flags
samdanbury 6:37b6d0d56190 6 * Rev.: V4.60
samdanbury 6:37b6d0d56190 7 *----------------------------------------------------------------------------
samdanbury 6:37b6d0d56190 8 *
samdanbury 6:37b6d0d56190 9 * Copyright (c) 1999-2009 KEIL, 2009-2012 ARM Germany GmbH
samdanbury 6:37b6d0d56190 10 * All rights reserved.
samdanbury 6:37b6d0d56190 11 * Redistribution and use in source and binary forms, with or without
samdanbury 6:37b6d0d56190 12 * modification, are permitted provided that the following conditions are met:
samdanbury 6:37b6d0d56190 13 * - Redistributions of source code must retain the above copyright
samdanbury 6:37b6d0d56190 14 * notice, this list of conditions and the following disclaimer.
samdanbury 6:37b6d0d56190 15 * - Redistributions in binary form must reproduce the above copyright
samdanbury 6:37b6d0d56190 16 * notice, this list of conditions and the following disclaimer in the
samdanbury 6:37b6d0d56190 17 * documentation and/or other materials provided with the distribution.
samdanbury 6:37b6d0d56190 18 * - Neither the name of ARM nor the names of its contributors may be used
samdanbury 6:37b6d0d56190 19 * to endorse or promote products derived from this software without
samdanbury 6:37b6d0d56190 20 * specific prior written permission.
samdanbury 6:37b6d0d56190 21 *
samdanbury 6:37b6d0d56190 22 * THIS SOFTWARE IS PROVIDED BY THE COPYRIGHT HOLDERS AND CONTRIBUTORS "AS IS"
samdanbury 6:37b6d0d56190 23 * AND ANY EXPRESS OR IMPLIED WARRANTIES, INCLUDING, BUT NOT LIMITED TO, THE
samdanbury 6:37b6d0d56190 24 * IMPLIED WARRANTIES OF MERCHANTABILITY AND FITNESS FOR A PARTICULAR PURPOSE
samdanbury 6:37b6d0d56190 25 * ARE DISCLAIMED. IN NO EVENT SHALL COPYRIGHT HOLDERS AND CONTRIBUTORS BE
samdanbury 6:37b6d0d56190 26 * LIABLE FOR ANY DIRECT, INDIRECT, INCIDENTAL, SPECIAL, EXEMPLARY, OR
samdanbury 6:37b6d0d56190 27 * CONSEQUENTIAL DAMAGES (INCLUDING, BUT NOT LIMITED TO, PROCUREMENT OF
samdanbury 6:37b6d0d56190 28 * SUBSTITUTE GOODS OR SERVICES; LOSS OF USE, DATA, OR PROFITS; OR BUSINESS
samdanbury 6:37b6d0d56190 29 * INTERRUPTION) HOWEVER CAUSED AND ON ANY THEORY OF LIABILITY, WHETHER IN
samdanbury 6:37b6d0d56190 30 * CONTRACT, STRICT LIABILITY, OR TORT (INCLUDING NEGLIGENCE OR OTHERWISE)
samdanbury 6:37b6d0d56190 31 * ARISING IN ANY WAY OUT OF THE USE OF THIS SOFTWARE, EVEN IF ADVISED OF THE
samdanbury 6:37b6d0d56190 32 * POSSIBILITY OF SUCH DAMAGE.
samdanbury 6:37b6d0d56190 33 *---------------------------------------------------------------------------*/
samdanbury 6:37b6d0d56190 34
samdanbury 6:37b6d0d56190 35 #include "rt_TypeDef.h"
samdanbury 6:37b6d0d56190 36 #include "RTX_Conf.h"
samdanbury 6:37b6d0d56190 37 #include "rt_System.h"
samdanbury 6:37b6d0d56190 38 #include "rt_Event.h"
samdanbury 6:37b6d0d56190 39 #include "rt_List.h"
samdanbury 6:37b6d0d56190 40 #include "rt_Task.h"
samdanbury 6:37b6d0d56190 41 #include "rt_HAL_CM.h"
samdanbury 6:37b6d0d56190 42
samdanbury 6:37b6d0d56190 43
samdanbury 6:37b6d0d56190 44 /*----------------------------------------------------------------------------
samdanbury 6:37b6d0d56190 45 * Functions
samdanbury 6:37b6d0d56190 46 *---------------------------------------------------------------------------*/
samdanbury 6:37b6d0d56190 47
samdanbury 6:37b6d0d56190 48
samdanbury 6:37b6d0d56190 49 /*--------------------------- rt_evt_wait -----------------------------------*/
samdanbury 6:37b6d0d56190 50
samdanbury 6:37b6d0d56190 51 OS_RESULT rt_evt_wait (U16 wait_flags, U16 timeout, BOOL and_wait) {
samdanbury 6:37b6d0d56190 52 /* Wait for one or more event flags with optional time-out. */
samdanbury 6:37b6d0d56190 53 /* "wait_flags" identifies the flags to wait for. */
samdanbury 6:37b6d0d56190 54 /* "timeout" is the time-out limit in system ticks (0xffff if no time-out) */
samdanbury 6:37b6d0d56190 55 /* "and_wait" specifies the AND-ing of "wait_flags" as condition to be met */
samdanbury 6:37b6d0d56190 56 /* to complete the wait. (OR-ing if set to 0). */
samdanbury 6:37b6d0d56190 57 U32 block_state;
samdanbury 6:37b6d0d56190 58
samdanbury 6:37b6d0d56190 59 if (and_wait) {
samdanbury 6:37b6d0d56190 60 /* Check for AND-connected events */
samdanbury 6:37b6d0d56190 61 if ((os_tsk.run->events & wait_flags) == wait_flags) {
samdanbury 6:37b6d0d56190 62 os_tsk.run->events &= ~wait_flags;
samdanbury 6:37b6d0d56190 63 return (OS_R_EVT);
samdanbury 6:37b6d0d56190 64 }
samdanbury 6:37b6d0d56190 65 block_state = WAIT_AND;
samdanbury 6:37b6d0d56190 66 }
samdanbury 6:37b6d0d56190 67 else {
samdanbury 6:37b6d0d56190 68 /* Check for OR-connected events */
samdanbury 6:37b6d0d56190 69 if (os_tsk.run->events & wait_flags) {
samdanbury 6:37b6d0d56190 70 os_tsk.run->waits = os_tsk.run->events & wait_flags;
samdanbury 6:37b6d0d56190 71 os_tsk.run->events &= ~wait_flags;
samdanbury 6:37b6d0d56190 72 return (OS_R_EVT);
samdanbury 6:37b6d0d56190 73 }
samdanbury 6:37b6d0d56190 74 block_state = WAIT_OR;
samdanbury 6:37b6d0d56190 75 }
samdanbury 6:37b6d0d56190 76 /* Task has to wait */
samdanbury 6:37b6d0d56190 77 os_tsk.run->waits = wait_flags;
samdanbury 6:37b6d0d56190 78 rt_block (timeout, (U8)block_state);
samdanbury 6:37b6d0d56190 79 return (OS_R_TMO);
samdanbury 6:37b6d0d56190 80 }
samdanbury 6:37b6d0d56190 81
samdanbury 6:37b6d0d56190 82
samdanbury 6:37b6d0d56190 83 /*--------------------------- rt_evt_set ------------------------------------*/
samdanbury 6:37b6d0d56190 84
samdanbury 6:37b6d0d56190 85 void rt_evt_set (U16 event_flags, OS_TID task_id) {
samdanbury 6:37b6d0d56190 86 /* Set one or more event flags of a selectable task. */
samdanbury 6:37b6d0d56190 87 P_TCB p_tcb;
samdanbury 6:37b6d0d56190 88
samdanbury 6:37b6d0d56190 89 p_tcb = os_active_TCB[task_id-1];
samdanbury 6:37b6d0d56190 90 if (p_tcb == NULL) {
samdanbury 6:37b6d0d56190 91 return;
samdanbury 6:37b6d0d56190 92 }
samdanbury 6:37b6d0d56190 93 p_tcb->events |= event_flags;
samdanbury 6:37b6d0d56190 94 event_flags = p_tcb->waits;
samdanbury 6:37b6d0d56190 95 /* If the task is not waiting for an event, it should not be put */
samdanbury 6:37b6d0d56190 96 /* to ready state. */
samdanbury 6:37b6d0d56190 97 if (p_tcb->state == WAIT_AND) {
samdanbury 6:37b6d0d56190 98 /* Check for AND-connected events */
samdanbury 6:37b6d0d56190 99 if ((p_tcb->events & event_flags) == event_flags) {
samdanbury 6:37b6d0d56190 100 goto wkup;
samdanbury 6:37b6d0d56190 101 }
samdanbury 6:37b6d0d56190 102 }
samdanbury 6:37b6d0d56190 103 if (p_tcb->state == WAIT_OR) {
samdanbury 6:37b6d0d56190 104 /* Check for OR-connected events */
samdanbury 6:37b6d0d56190 105 if (p_tcb->events & event_flags) {
samdanbury 6:37b6d0d56190 106 p_tcb->waits &= p_tcb->events;
samdanbury 6:37b6d0d56190 107 wkup: p_tcb->events &= ~event_flags;
samdanbury 6:37b6d0d56190 108 rt_rmv_dly (p_tcb);
samdanbury 6:37b6d0d56190 109 p_tcb->state = READY;
samdanbury 6:37b6d0d56190 110 #ifdef __CMSIS_RTOS
samdanbury 6:37b6d0d56190 111 rt_ret_val2(p_tcb, 0x08/*osEventSignal*/, p_tcb->waits);
samdanbury 6:37b6d0d56190 112 #else
samdanbury 6:37b6d0d56190 113 rt_ret_val (p_tcb, OS_R_EVT);
samdanbury 6:37b6d0d56190 114 #endif
samdanbury 6:37b6d0d56190 115 rt_dispatch (p_tcb);
samdanbury 6:37b6d0d56190 116 }
samdanbury 6:37b6d0d56190 117 }
samdanbury 6:37b6d0d56190 118 }
samdanbury 6:37b6d0d56190 119
samdanbury 6:37b6d0d56190 120
samdanbury 6:37b6d0d56190 121 /*--------------------------- rt_evt_clr ------------------------------------*/
samdanbury 6:37b6d0d56190 122
samdanbury 6:37b6d0d56190 123 void rt_evt_clr (U16 clear_flags, OS_TID task_id) {
samdanbury 6:37b6d0d56190 124 /* Clear one or more event flags (identified by "clear_flags") of a */
samdanbury 6:37b6d0d56190 125 /* selectable task (identified by "task"). */
samdanbury 6:37b6d0d56190 126 P_TCB task = os_active_TCB[task_id-1];
samdanbury 6:37b6d0d56190 127
samdanbury 6:37b6d0d56190 128 if (task == NULL) {
samdanbury 6:37b6d0d56190 129 return;
samdanbury 6:37b6d0d56190 130 }
samdanbury 6:37b6d0d56190 131 task->events &= ~clear_flags;
samdanbury 6:37b6d0d56190 132 }
samdanbury 6:37b6d0d56190 133
samdanbury 6:37b6d0d56190 134
samdanbury 6:37b6d0d56190 135 /*--------------------------- isr_evt_set -----------------------------------*/
samdanbury 6:37b6d0d56190 136
samdanbury 6:37b6d0d56190 137 void isr_evt_set (U16 event_flags, OS_TID task_id) {
samdanbury 6:37b6d0d56190 138 /* Same function as "os_evt_set", but to be called by ISRs. */
samdanbury 6:37b6d0d56190 139 P_TCB p_tcb = os_active_TCB[task_id-1];
samdanbury 6:37b6d0d56190 140
samdanbury 6:37b6d0d56190 141 if (p_tcb == NULL) {
samdanbury 6:37b6d0d56190 142 return;
samdanbury 6:37b6d0d56190 143 }
samdanbury 6:37b6d0d56190 144 rt_psq_enq (p_tcb, event_flags);
samdanbury 6:37b6d0d56190 145 rt_psh_req ();
samdanbury 6:37b6d0d56190 146 }
samdanbury 6:37b6d0d56190 147
samdanbury 6:37b6d0d56190 148
samdanbury 6:37b6d0d56190 149 /*--------------------------- rt_evt_get ------------------------------------*/
samdanbury 6:37b6d0d56190 150
samdanbury 6:37b6d0d56190 151 U16 rt_evt_get (void) {
samdanbury 6:37b6d0d56190 152 /* Get events of a running task after waiting for OR connected events. */
samdanbury 6:37b6d0d56190 153 return (os_tsk.run->waits);
samdanbury 6:37b6d0d56190 154 }
samdanbury 6:37b6d0d56190 155
samdanbury 6:37b6d0d56190 156
samdanbury 6:37b6d0d56190 157 /*--------------------------- rt_evt_psh ------------------------------------*/
samdanbury 6:37b6d0d56190 158
samdanbury 6:37b6d0d56190 159 void rt_evt_psh (P_TCB p_CB, U16 set_flags) {
samdanbury 6:37b6d0d56190 160 /* Check if task has to be waken up */
samdanbury 6:37b6d0d56190 161 U16 event_flags;
samdanbury 6:37b6d0d56190 162
samdanbury 6:37b6d0d56190 163 p_CB->events |= set_flags;
samdanbury 6:37b6d0d56190 164 event_flags = p_CB->waits;
samdanbury 6:37b6d0d56190 165 if (p_CB->state == WAIT_AND) {
samdanbury 6:37b6d0d56190 166 /* Check for AND-connected events */
samdanbury 6:37b6d0d56190 167 if ((p_CB->events & event_flags) == event_flags) {
samdanbury 6:37b6d0d56190 168 goto rdy;
samdanbury 6:37b6d0d56190 169 }
samdanbury 6:37b6d0d56190 170 }
samdanbury 6:37b6d0d56190 171 if (p_CB->state == WAIT_OR) {
samdanbury 6:37b6d0d56190 172 /* Check for OR-connected events */
samdanbury 6:37b6d0d56190 173 if (p_CB->events & event_flags) {
samdanbury 6:37b6d0d56190 174 p_CB->waits &= p_CB->events;
samdanbury 6:37b6d0d56190 175 rdy: p_CB->events &= ~event_flags;
samdanbury 6:37b6d0d56190 176 rt_rmv_dly (p_CB);
samdanbury 6:37b6d0d56190 177 p_CB->state = READY;
samdanbury 6:37b6d0d56190 178 #ifdef __CMSIS_RTOS
samdanbury 6:37b6d0d56190 179 rt_ret_val2(p_CB, 0x08/*osEventSignal*/, p_CB->waits);
samdanbury 6:37b6d0d56190 180 #else
samdanbury 6:37b6d0d56190 181 rt_ret_val (p_CB, OS_R_EVT);
samdanbury 6:37b6d0d56190 182 #endif
samdanbury 6:37b6d0d56190 183 rt_put_prio (&os_rdy, p_CB);
samdanbury 6:37b6d0d56190 184 }
samdanbury 6:37b6d0d56190 185 }
samdanbury 6:37b6d0d56190 186 }
samdanbury 6:37b6d0d56190 187
samdanbury 6:37b6d0d56190 188 /*----------------------------------------------------------------------------
samdanbury 6:37b6d0d56190 189 * end of file
samdanbury 6:37b6d0d56190 190 *---------------------------------------------------------------------------*/