Integrating the ublox LISA C200 modem

Fork of SprintUSBModemHTTPClientTest by Donatien Garnier

Committer:
sam_grove
Date:
Thu Sep 26 00:44:20 2013 -0500
Revision:
5:3f93dd1d4cb3
Exported program and replaced contents of the repo with the source
to build and debug using keil mdk. Libs NOT upto date are lwip, lwip-sys
and socket. these have newer versions under mbed_official but were starting
from a know working point

Who changed what in which revision?

UserRevisionLine numberNew contents of line
sam_grove 5:3f93dd1d4cb3 1 /*----------------------------------------------------------------------------
sam_grove 5:3f93dd1d4cb3 2 * RL-ARM - RTX
sam_grove 5:3f93dd1d4cb3 3 *----------------------------------------------------------------------------
sam_grove 5:3f93dd1d4cb3 4 * Name: RT_MUTEX.C
sam_grove 5:3f93dd1d4cb3 5 * Purpose: Implements mutex synchronization objects
sam_grove 5:3f93dd1d4cb3 6 * Rev.: V4.60
sam_grove 5:3f93dd1d4cb3 7 *----------------------------------------------------------------------------
sam_grove 5:3f93dd1d4cb3 8 *
sam_grove 5:3f93dd1d4cb3 9 * Copyright (c) 1999-2009 KEIL, 2009-2012 ARM Germany GmbH
sam_grove 5:3f93dd1d4cb3 10 * All rights reserved.
sam_grove 5:3f93dd1d4cb3 11 * Redistribution and use in source and binary forms, with or without
sam_grove 5:3f93dd1d4cb3 12 * modification, are permitted provided that the following conditions are met:
sam_grove 5:3f93dd1d4cb3 13 * - Redistributions of source code must retain the above copyright
sam_grove 5:3f93dd1d4cb3 14 * notice, this list of conditions and the following disclaimer.
sam_grove 5:3f93dd1d4cb3 15 * - Redistributions in binary form must reproduce the above copyright
sam_grove 5:3f93dd1d4cb3 16 * notice, this list of conditions and the following disclaimer in the
sam_grove 5:3f93dd1d4cb3 17 * documentation and/or other materials provided with the distribution.
sam_grove 5:3f93dd1d4cb3 18 * - Neither the name of ARM nor the names of its contributors may be used
sam_grove 5:3f93dd1d4cb3 19 * to endorse or promote products derived from this software without
sam_grove 5:3f93dd1d4cb3 20 * specific prior written permission.
sam_grove 5:3f93dd1d4cb3 21 *
sam_grove 5:3f93dd1d4cb3 22 * THIS SOFTWARE IS PROVIDED BY THE COPYRIGHT HOLDERS AND CONTRIBUTORS "AS IS"
sam_grove 5:3f93dd1d4cb3 23 * AND ANY EXPRESS OR IMPLIED WARRANTIES, INCLUDING, BUT NOT LIMITED TO, THE
sam_grove 5:3f93dd1d4cb3 24 * IMPLIED WARRANTIES OF MERCHANTABILITY AND FITNESS FOR A PARTICULAR PURPOSE
sam_grove 5:3f93dd1d4cb3 25 * ARE DISCLAIMED. IN NO EVENT SHALL COPYRIGHT HOLDERS AND CONTRIBUTORS BE
sam_grove 5:3f93dd1d4cb3 26 * LIABLE FOR ANY DIRECT, INDIRECT, INCIDENTAL, SPECIAL, EXEMPLARY, OR
sam_grove 5:3f93dd1d4cb3 27 * CONSEQUENTIAL DAMAGES (INCLUDING, BUT NOT LIMITED TO, PROCUREMENT OF
sam_grove 5:3f93dd1d4cb3 28 * SUBSTITUTE GOODS OR SERVICES; LOSS OF USE, DATA, OR PROFITS; OR BUSINESS
sam_grove 5:3f93dd1d4cb3 29 * INTERRUPTION) HOWEVER CAUSED AND ON ANY THEORY OF LIABILITY, WHETHER IN
sam_grove 5:3f93dd1d4cb3 30 * CONTRACT, STRICT LIABILITY, OR TORT (INCLUDING NEGLIGENCE OR OTHERWISE)
sam_grove 5:3f93dd1d4cb3 31 * ARISING IN ANY WAY OUT OF THE USE OF THIS SOFTWARE, EVEN IF ADVISED OF THE
sam_grove 5:3f93dd1d4cb3 32 * POSSIBILITY OF SUCH DAMAGE.
sam_grove 5:3f93dd1d4cb3 33 *---------------------------------------------------------------------------*/
sam_grove 5:3f93dd1d4cb3 34
sam_grove 5:3f93dd1d4cb3 35 #include "rt_TypeDef.h"
sam_grove 5:3f93dd1d4cb3 36 #include "RTX_Conf.h"
sam_grove 5:3f93dd1d4cb3 37 #include "rt_List.h"
sam_grove 5:3f93dd1d4cb3 38 #include "rt_Task.h"
sam_grove 5:3f93dd1d4cb3 39 #include "rt_Mutex.h"
sam_grove 5:3f93dd1d4cb3 40 #include "rt_HAL_CM.h"
sam_grove 5:3f93dd1d4cb3 41
sam_grove 5:3f93dd1d4cb3 42
sam_grove 5:3f93dd1d4cb3 43 /*----------------------------------------------------------------------------
sam_grove 5:3f93dd1d4cb3 44 * Functions
sam_grove 5:3f93dd1d4cb3 45 *---------------------------------------------------------------------------*/
sam_grove 5:3f93dd1d4cb3 46
sam_grove 5:3f93dd1d4cb3 47
sam_grove 5:3f93dd1d4cb3 48 /*--------------------------- rt_mut_init -----------------------------------*/
sam_grove 5:3f93dd1d4cb3 49
sam_grove 5:3f93dd1d4cb3 50 void rt_mut_init (OS_ID mutex) {
sam_grove 5:3f93dd1d4cb3 51 /* Initialize a mutex object */
sam_grove 5:3f93dd1d4cb3 52 P_MUCB p_MCB = mutex;
sam_grove 5:3f93dd1d4cb3 53
sam_grove 5:3f93dd1d4cb3 54 p_MCB->cb_type = MUCB;
sam_grove 5:3f93dd1d4cb3 55 p_MCB->prio = 0;
sam_grove 5:3f93dd1d4cb3 56 p_MCB->level = 0;
sam_grove 5:3f93dd1d4cb3 57 p_MCB->p_lnk = NULL;
sam_grove 5:3f93dd1d4cb3 58 p_MCB->owner = NULL;
sam_grove 5:3f93dd1d4cb3 59 }
sam_grove 5:3f93dd1d4cb3 60
sam_grove 5:3f93dd1d4cb3 61
sam_grove 5:3f93dd1d4cb3 62 /*--------------------------- rt_mut_delete ---------------------------------*/
sam_grove 5:3f93dd1d4cb3 63
sam_grove 5:3f93dd1d4cb3 64 #ifdef __CMSIS_RTOS
sam_grove 5:3f93dd1d4cb3 65 OS_RESULT rt_mut_delete (OS_ID mutex) {
sam_grove 5:3f93dd1d4cb3 66 /* Delete a mutex object */
sam_grove 5:3f93dd1d4cb3 67 P_MUCB p_MCB = mutex;
sam_grove 5:3f93dd1d4cb3 68 P_TCB p_TCB;
sam_grove 5:3f93dd1d4cb3 69
sam_grove 5:3f93dd1d4cb3 70 /* Restore owner task's priority. */
sam_grove 5:3f93dd1d4cb3 71 if (p_MCB->level != 0) {
sam_grove 5:3f93dd1d4cb3 72 p_MCB->owner->prio = p_MCB->prio;
sam_grove 5:3f93dd1d4cb3 73 if (p_MCB->owner != os_tsk.run) {
sam_grove 5:3f93dd1d4cb3 74 rt_resort_prio (p_MCB->owner);
sam_grove 5:3f93dd1d4cb3 75 }
sam_grove 5:3f93dd1d4cb3 76 }
sam_grove 5:3f93dd1d4cb3 77
sam_grove 5:3f93dd1d4cb3 78 while (p_MCB->p_lnk != NULL) {
sam_grove 5:3f93dd1d4cb3 79 /* A task is waiting for mutex. */
sam_grove 5:3f93dd1d4cb3 80 p_TCB = rt_get_first ((P_XCB)p_MCB);
sam_grove 5:3f93dd1d4cb3 81 rt_ret_val(p_TCB, 0/*osOK*/);
sam_grove 5:3f93dd1d4cb3 82 rt_rmv_dly(p_TCB);
sam_grove 5:3f93dd1d4cb3 83 p_TCB->state = READY;
sam_grove 5:3f93dd1d4cb3 84 rt_put_prio (&os_rdy, p_TCB);
sam_grove 5:3f93dd1d4cb3 85 }
sam_grove 5:3f93dd1d4cb3 86
sam_grove 5:3f93dd1d4cb3 87 if (os_rdy.p_lnk && (os_rdy.p_lnk->prio > os_tsk.run->prio)) {
sam_grove 5:3f93dd1d4cb3 88 /* preempt running task */
sam_grove 5:3f93dd1d4cb3 89 rt_put_prio (&os_rdy, os_tsk.run);
sam_grove 5:3f93dd1d4cb3 90 os_tsk.run->state = READY;
sam_grove 5:3f93dd1d4cb3 91 rt_dispatch (NULL);
sam_grove 5:3f93dd1d4cb3 92 }
sam_grove 5:3f93dd1d4cb3 93
sam_grove 5:3f93dd1d4cb3 94 p_MCB->cb_type = 0;
sam_grove 5:3f93dd1d4cb3 95
sam_grove 5:3f93dd1d4cb3 96 return (OS_R_OK);
sam_grove 5:3f93dd1d4cb3 97 }
sam_grove 5:3f93dd1d4cb3 98 #endif
sam_grove 5:3f93dd1d4cb3 99
sam_grove 5:3f93dd1d4cb3 100
sam_grove 5:3f93dd1d4cb3 101 /*--------------------------- rt_mut_release --------------------------------*/
sam_grove 5:3f93dd1d4cb3 102
sam_grove 5:3f93dd1d4cb3 103 OS_RESULT rt_mut_release (OS_ID mutex) {
sam_grove 5:3f93dd1d4cb3 104 /* Release a mutex object */
sam_grove 5:3f93dd1d4cb3 105 P_MUCB p_MCB = mutex;
sam_grove 5:3f93dd1d4cb3 106 P_TCB p_TCB;
sam_grove 5:3f93dd1d4cb3 107
sam_grove 5:3f93dd1d4cb3 108 if (p_MCB->level == 0 || p_MCB->owner != os_tsk.run) {
sam_grove 5:3f93dd1d4cb3 109 /* Unbalanced mutex release or task is not the owner */
sam_grove 5:3f93dd1d4cb3 110 return (OS_R_NOK);
sam_grove 5:3f93dd1d4cb3 111 }
sam_grove 5:3f93dd1d4cb3 112 if (--p_MCB->level != 0) {
sam_grove 5:3f93dd1d4cb3 113 return (OS_R_OK);
sam_grove 5:3f93dd1d4cb3 114 }
sam_grove 5:3f93dd1d4cb3 115 /* Restore owner task's priority. */
sam_grove 5:3f93dd1d4cb3 116 os_tsk.run->prio = p_MCB->prio;
sam_grove 5:3f93dd1d4cb3 117 if (p_MCB->p_lnk != NULL) {
sam_grove 5:3f93dd1d4cb3 118 /* A task is waiting for mutex. */
sam_grove 5:3f93dd1d4cb3 119 p_TCB = rt_get_first ((P_XCB)p_MCB);
sam_grove 5:3f93dd1d4cb3 120 #ifdef __CMSIS_RTOS
sam_grove 5:3f93dd1d4cb3 121 rt_ret_val(p_TCB, 0/*osOK*/);
sam_grove 5:3f93dd1d4cb3 122 #else
sam_grove 5:3f93dd1d4cb3 123 rt_ret_val(p_TCB, OS_R_MUT);
sam_grove 5:3f93dd1d4cb3 124 #endif
sam_grove 5:3f93dd1d4cb3 125 rt_rmv_dly (p_TCB);
sam_grove 5:3f93dd1d4cb3 126 /* A waiting task becomes the owner of this mutex. */
sam_grove 5:3f93dd1d4cb3 127 p_MCB->level = 1;
sam_grove 5:3f93dd1d4cb3 128 p_MCB->owner = p_TCB;
sam_grove 5:3f93dd1d4cb3 129 p_MCB->prio = p_TCB->prio;
sam_grove 5:3f93dd1d4cb3 130 /* Priority inversion, check which task continues. */
sam_grove 5:3f93dd1d4cb3 131 if (os_tsk.run->prio >= rt_rdy_prio()) {
sam_grove 5:3f93dd1d4cb3 132 rt_dispatch (p_TCB);
sam_grove 5:3f93dd1d4cb3 133 }
sam_grove 5:3f93dd1d4cb3 134 else {
sam_grove 5:3f93dd1d4cb3 135 /* Ready task has higher priority than running task. */
sam_grove 5:3f93dd1d4cb3 136 rt_put_prio (&os_rdy, os_tsk.run);
sam_grove 5:3f93dd1d4cb3 137 rt_put_prio (&os_rdy, p_TCB);
sam_grove 5:3f93dd1d4cb3 138 os_tsk.run->state = READY;
sam_grove 5:3f93dd1d4cb3 139 p_TCB->state = READY;
sam_grove 5:3f93dd1d4cb3 140 rt_dispatch (NULL);
sam_grove 5:3f93dd1d4cb3 141 }
sam_grove 5:3f93dd1d4cb3 142 }
sam_grove 5:3f93dd1d4cb3 143 else {
sam_grove 5:3f93dd1d4cb3 144 /* Check if own priority raised by priority inversion. */
sam_grove 5:3f93dd1d4cb3 145 if (rt_rdy_prio() > os_tsk.run->prio) {
sam_grove 5:3f93dd1d4cb3 146 rt_put_prio (&os_rdy, os_tsk.run);
sam_grove 5:3f93dd1d4cb3 147 os_tsk.run->state = READY;
sam_grove 5:3f93dd1d4cb3 148 rt_dispatch (NULL);
sam_grove 5:3f93dd1d4cb3 149 }
sam_grove 5:3f93dd1d4cb3 150 }
sam_grove 5:3f93dd1d4cb3 151 return (OS_R_OK);
sam_grove 5:3f93dd1d4cb3 152 }
sam_grove 5:3f93dd1d4cb3 153
sam_grove 5:3f93dd1d4cb3 154
sam_grove 5:3f93dd1d4cb3 155 /*--------------------------- rt_mut_wait -----------------------------------*/
sam_grove 5:3f93dd1d4cb3 156
sam_grove 5:3f93dd1d4cb3 157 OS_RESULT rt_mut_wait (OS_ID mutex, U16 timeout) {
sam_grove 5:3f93dd1d4cb3 158 /* Wait for a mutex, continue when mutex is free. */
sam_grove 5:3f93dd1d4cb3 159 P_MUCB p_MCB = mutex;
sam_grove 5:3f93dd1d4cb3 160
sam_grove 5:3f93dd1d4cb3 161 if (p_MCB->level == 0) {
sam_grove 5:3f93dd1d4cb3 162 p_MCB->owner = os_tsk.run;
sam_grove 5:3f93dd1d4cb3 163 p_MCB->prio = os_tsk.run->prio;
sam_grove 5:3f93dd1d4cb3 164 goto inc;
sam_grove 5:3f93dd1d4cb3 165 }
sam_grove 5:3f93dd1d4cb3 166 if (p_MCB->owner == os_tsk.run) {
sam_grove 5:3f93dd1d4cb3 167 /* OK, running task is the owner of this mutex. */
sam_grove 5:3f93dd1d4cb3 168 inc:p_MCB->level++;
sam_grove 5:3f93dd1d4cb3 169 return (OS_R_OK);
sam_grove 5:3f93dd1d4cb3 170 }
sam_grove 5:3f93dd1d4cb3 171 /* Mutex owned by another task, wait until released. */
sam_grove 5:3f93dd1d4cb3 172 if (timeout == 0) {
sam_grove 5:3f93dd1d4cb3 173 return (OS_R_TMO);
sam_grove 5:3f93dd1d4cb3 174 }
sam_grove 5:3f93dd1d4cb3 175 /* Raise the owner task priority if lower than current priority. */
sam_grove 5:3f93dd1d4cb3 176 /* This priority inversion is called priority inheritance. */
sam_grove 5:3f93dd1d4cb3 177 if (p_MCB->prio < os_tsk.run->prio) {
sam_grove 5:3f93dd1d4cb3 178 p_MCB->owner->prio = os_tsk.run->prio;
sam_grove 5:3f93dd1d4cb3 179 rt_resort_prio (p_MCB->owner);
sam_grove 5:3f93dd1d4cb3 180 }
sam_grove 5:3f93dd1d4cb3 181 if (p_MCB->p_lnk != NULL) {
sam_grove 5:3f93dd1d4cb3 182 rt_put_prio ((P_XCB)p_MCB, os_tsk.run);
sam_grove 5:3f93dd1d4cb3 183 }
sam_grove 5:3f93dd1d4cb3 184 else {
sam_grove 5:3f93dd1d4cb3 185 p_MCB->p_lnk = os_tsk.run;
sam_grove 5:3f93dd1d4cb3 186 os_tsk.run->p_lnk = NULL;
sam_grove 5:3f93dd1d4cb3 187 os_tsk.run->p_rlnk = (P_TCB)p_MCB;
sam_grove 5:3f93dd1d4cb3 188 }
sam_grove 5:3f93dd1d4cb3 189 rt_block(timeout, WAIT_MUT);
sam_grove 5:3f93dd1d4cb3 190 return (OS_R_TMO);
sam_grove 5:3f93dd1d4cb3 191 }
sam_grove 5:3f93dd1d4cb3 192
sam_grove 5:3f93dd1d4cb3 193
sam_grove 5:3f93dd1d4cb3 194 /*----------------------------------------------------------------------------
sam_grove 5:3f93dd1d4cb3 195 * end of file
sam_grove 5:3f93dd1d4cb3 196 *---------------------------------------------------------------------------*/
sam_grove 5:3f93dd1d4cb3 197