mbed client lightswitch demo

Dependencies:   mbed Socket lwip-eth lwip-sys lwip

Fork of mbed-client-classic-example-lwip by Austin Blackstone

Committer:
mbedAustin
Date:
Thu Jun 09 17:08:36 2016 +0000
Revision:
11:cada08fc8a70
Commit for public Consumption

Who changed what in which revision?

UserRevisionLine numberNew contents of line
mbedAustin 11:cada08fc8a70 1 /*----------------------------------------------------------------------------
mbedAustin 11:cada08fc8a70 2 * RL-ARM - RTX
mbedAustin 11:cada08fc8a70 3 *----------------------------------------------------------------------------
mbedAustin 11:cada08fc8a70 4 * Name: RT_TIME.C
mbedAustin 11:cada08fc8a70 5 * Purpose: Delay and interval wait functions
mbedAustin 11:cada08fc8a70 6 * Rev.: V4.70
mbedAustin 11:cada08fc8a70 7 *----------------------------------------------------------------------------
mbedAustin 11:cada08fc8a70 8 *
mbedAustin 11:cada08fc8a70 9 * Copyright (c) 1999-2009 KEIL, 2009-2013 ARM Germany GmbH
mbedAustin 11:cada08fc8a70 10 * All rights reserved.
mbedAustin 11:cada08fc8a70 11 * Redistribution and use in source and binary forms, with or without
mbedAustin 11:cada08fc8a70 12 * modification, are permitted provided that the following conditions are met:
mbedAustin 11:cada08fc8a70 13 * - Redistributions of source code must retain the above copyright
mbedAustin 11:cada08fc8a70 14 * notice, this list of conditions and the following disclaimer.
mbedAustin 11:cada08fc8a70 15 * - Redistributions in binary form must reproduce the above copyright
mbedAustin 11:cada08fc8a70 16 * notice, this list of conditions and the following disclaimer in the
mbedAustin 11:cada08fc8a70 17 * documentation and/or other materials provided with the distribution.
mbedAustin 11:cada08fc8a70 18 * - Neither the name of ARM nor the names of its contributors may be used
mbedAustin 11:cada08fc8a70 19 * to endorse or promote products derived from this software without
mbedAustin 11:cada08fc8a70 20 * specific prior written permission.
mbedAustin 11:cada08fc8a70 21 *
mbedAustin 11:cada08fc8a70 22 * THIS SOFTWARE IS PROVIDED BY THE COPYRIGHT HOLDERS AND CONTRIBUTORS "AS IS"
mbedAustin 11:cada08fc8a70 23 * AND ANY EXPRESS OR IMPLIED WARRANTIES, INCLUDING, BUT NOT LIMITED TO, THE
mbedAustin 11:cada08fc8a70 24 * IMPLIED WARRANTIES OF MERCHANTABILITY AND FITNESS FOR A PARTICULAR PURPOSE
mbedAustin 11:cada08fc8a70 25 * ARE DISCLAIMED. IN NO EVENT SHALL COPYRIGHT HOLDERS AND CONTRIBUTORS BE
mbedAustin 11:cada08fc8a70 26 * LIABLE FOR ANY DIRECT, INDIRECT, INCIDENTAL, SPECIAL, EXEMPLARY, OR
mbedAustin 11:cada08fc8a70 27 * CONSEQUENTIAL DAMAGES (INCLUDING, BUT NOT LIMITED TO, PROCUREMENT OF
mbedAustin 11:cada08fc8a70 28 * SUBSTITUTE GOODS OR SERVICES; LOSS OF USE, DATA, OR PROFITS; OR BUSINESS
mbedAustin 11:cada08fc8a70 29 * INTERRUPTION) HOWEVER CAUSED AND ON ANY THEORY OF LIABILITY, WHETHER IN
mbedAustin 11:cada08fc8a70 30 * CONTRACT, STRICT LIABILITY, OR TORT (INCLUDING NEGLIGENCE OR OTHERWISE)
mbedAustin 11:cada08fc8a70 31 * ARISING IN ANY WAY OUT OF THE USE OF THIS SOFTWARE, EVEN IF ADVISED OF THE
mbedAustin 11:cada08fc8a70 32 * POSSIBILITY OF SUCH DAMAGE.
mbedAustin 11:cada08fc8a70 33 *---------------------------------------------------------------------------*/
mbedAustin 11:cada08fc8a70 34
mbedAustin 11:cada08fc8a70 35 #include "rt_TypeDef.h"
mbedAustin 11:cada08fc8a70 36 #include "RTX_Config.h"
mbedAustin 11:cada08fc8a70 37 #include "rt_Task.h"
mbedAustin 11:cada08fc8a70 38 #include "rt_Time.h"
mbedAustin 11:cada08fc8a70 39
mbedAustin 11:cada08fc8a70 40 /*----------------------------------------------------------------------------
mbedAustin 11:cada08fc8a70 41 * Global Variables
mbedAustin 11:cada08fc8a70 42 *---------------------------------------------------------------------------*/
mbedAustin 11:cada08fc8a70 43
mbedAustin 11:cada08fc8a70 44 /* Free running system tick counter */
mbedAustin 11:cada08fc8a70 45 U32 os_time;
mbedAustin 11:cada08fc8a70 46
mbedAustin 11:cada08fc8a70 47
mbedAustin 11:cada08fc8a70 48 /*----------------------------------------------------------------------------
mbedAustin 11:cada08fc8a70 49 * Functions
mbedAustin 11:cada08fc8a70 50 *---------------------------------------------------------------------------*/
mbedAustin 11:cada08fc8a70 51
mbedAustin 11:cada08fc8a70 52
mbedAustin 11:cada08fc8a70 53 /*--------------------------- rt_time_get -----------------------------------*/
mbedAustin 11:cada08fc8a70 54
mbedAustin 11:cada08fc8a70 55 U32 rt_time_get (void) {
mbedAustin 11:cada08fc8a70 56 /* Get system time tick */
mbedAustin 11:cada08fc8a70 57 return (os_time);
mbedAustin 11:cada08fc8a70 58 }
mbedAustin 11:cada08fc8a70 59
mbedAustin 11:cada08fc8a70 60
mbedAustin 11:cada08fc8a70 61 /*--------------------------- rt_dly_wait -----------------------------------*/
mbedAustin 11:cada08fc8a70 62
mbedAustin 11:cada08fc8a70 63 void rt_dly_wait (U16 delay_time) {
mbedAustin 11:cada08fc8a70 64 /* Delay task by "delay_time" */
mbedAustin 11:cada08fc8a70 65 rt_block (delay_time, WAIT_DLY);
mbedAustin 11:cada08fc8a70 66 }
mbedAustin 11:cada08fc8a70 67
mbedAustin 11:cada08fc8a70 68
mbedAustin 11:cada08fc8a70 69 /*--------------------------- rt_itv_set ------------------------------------*/
mbedAustin 11:cada08fc8a70 70
mbedAustin 11:cada08fc8a70 71 void rt_itv_set (U16 interval_time) {
mbedAustin 11:cada08fc8a70 72 /* Set interval length and define start of first interval */
mbedAustin 11:cada08fc8a70 73 os_tsk.run->interval_time = interval_time;
mbedAustin 11:cada08fc8a70 74 os_tsk.run->delta_time = interval_time + (U16)os_time;
mbedAustin 11:cada08fc8a70 75 }
mbedAustin 11:cada08fc8a70 76
mbedAustin 11:cada08fc8a70 77
mbedAustin 11:cada08fc8a70 78 /*--------------------------- rt_itv_wait -----------------------------------*/
mbedAustin 11:cada08fc8a70 79
mbedAustin 11:cada08fc8a70 80 void rt_itv_wait (void) {
mbedAustin 11:cada08fc8a70 81 /* Wait for interval end and define start of next one */
mbedAustin 11:cada08fc8a70 82 U16 delta;
mbedAustin 11:cada08fc8a70 83
mbedAustin 11:cada08fc8a70 84 delta = os_tsk.run->delta_time - (U16)os_time;
mbedAustin 11:cada08fc8a70 85 os_tsk.run->delta_time += os_tsk.run->interval_time;
mbedAustin 11:cada08fc8a70 86 if ((delta & 0x8000) == 0) {
mbedAustin 11:cada08fc8a70 87 rt_block (delta, WAIT_ITV);
mbedAustin 11:cada08fc8a70 88 }
mbedAustin 11:cada08fc8a70 89 }
mbedAustin 11:cada08fc8a70 90
mbedAustin 11:cada08fc8a70 91 /*----------------------------------------------------------------------------
mbedAustin 11:cada08fc8a70 92 * end of file
mbedAustin 11:cada08fc8a70 93 *---------------------------------------------------------------------------*/
mbedAustin 11:cada08fc8a70 94