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_MEMBOX.C
sam_grove 5:3f93dd1d4cb3 5 * Purpose: Interface functions for fixed memory block management system
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_System.h"
sam_grove 5:3f93dd1d4cb3 38 #include "rt_MemBox.h"
sam_grove 5:3f93dd1d4cb3 39 #include "rt_HAL_CM.h"
sam_grove 5:3f93dd1d4cb3 40
sam_grove 5:3f93dd1d4cb3 41 /*----------------------------------------------------------------------------
sam_grove 5:3f93dd1d4cb3 42 * Global Functions
sam_grove 5:3f93dd1d4cb3 43 *---------------------------------------------------------------------------*/
sam_grove 5:3f93dd1d4cb3 44
sam_grove 5:3f93dd1d4cb3 45
sam_grove 5:3f93dd1d4cb3 46 /*--------------------------- _init_box -------------------------------------*/
sam_grove 5:3f93dd1d4cb3 47
sam_grove 5:3f93dd1d4cb3 48 int _init_box (void *box_mem, U32 box_size, U32 blk_size) {
sam_grove 5:3f93dd1d4cb3 49 /* Initialize memory block system, returns 0 if OK, 1 if fails. */
sam_grove 5:3f93dd1d4cb3 50 void *end;
sam_grove 5:3f93dd1d4cb3 51 void *blk;
sam_grove 5:3f93dd1d4cb3 52 void *next;
sam_grove 5:3f93dd1d4cb3 53 U32 sizeof_bm;
sam_grove 5:3f93dd1d4cb3 54
sam_grove 5:3f93dd1d4cb3 55 /* Create memory structure. */
sam_grove 5:3f93dd1d4cb3 56 if (blk_size & BOX_ALIGN_8) {
sam_grove 5:3f93dd1d4cb3 57 /* Memory blocks 8-byte aligned. */
sam_grove 5:3f93dd1d4cb3 58 blk_size = ((blk_size & ~BOX_ALIGN_8) + 7) & ~7;
sam_grove 5:3f93dd1d4cb3 59 sizeof_bm = (sizeof (struct OS_BM) + 7) & ~7;
sam_grove 5:3f93dd1d4cb3 60 }
sam_grove 5:3f93dd1d4cb3 61 else {
sam_grove 5:3f93dd1d4cb3 62 /* Memory blocks 4-byte aligned. */
sam_grove 5:3f93dd1d4cb3 63 blk_size = (blk_size + 3) & ~3;
sam_grove 5:3f93dd1d4cb3 64 sizeof_bm = sizeof (struct OS_BM);
sam_grove 5:3f93dd1d4cb3 65 }
sam_grove 5:3f93dd1d4cb3 66 if (blk_size == 0) {
sam_grove 5:3f93dd1d4cb3 67 return (1);
sam_grove 5:3f93dd1d4cb3 68 }
sam_grove 5:3f93dd1d4cb3 69 if ((blk_size + sizeof_bm) > box_size) {
sam_grove 5:3f93dd1d4cb3 70 return (1);
sam_grove 5:3f93dd1d4cb3 71 }
sam_grove 5:3f93dd1d4cb3 72 /* Create a Memory structure. */
sam_grove 5:3f93dd1d4cb3 73 blk = ((U8 *) box_mem) + sizeof_bm;
sam_grove 5:3f93dd1d4cb3 74 ((P_BM) box_mem)->free = blk;
sam_grove 5:3f93dd1d4cb3 75 end = ((U8 *) box_mem) + box_size;
sam_grove 5:3f93dd1d4cb3 76 ((P_BM) box_mem)->end = end;
sam_grove 5:3f93dd1d4cb3 77 ((P_BM) box_mem)->blk_size = blk_size;
sam_grove 5:3f93dd1d4cb3 78
sam_grove 5:3f93dd1d4cb3 79 /* Link all free blocks using offsets. */
sam_grove 5:3f93dd1d4cb3 80 end = ((U8 *) end) - blk_size;
sam_grove 5:3f93dd1d4cb3 81 while (1) {
sam_grove 5:3f93dd1d4cb3 82 next = ((U8 *) blk) + blk_size;
sam_grove 5:3f93dd1d4cb3 83 if (next > end) break;
sam_grove 5:3f93dd1d4cb3 84 *((void **)blk) = next;
sam_grove 5:3f93dd1d4cb3 85 blk = next;
sam_grove 5:3f93dd1d4cb3 86 }
sam_grove 5:3f93dd1d4cb3 87 /* end marker */
sam_grove 5:3f93dd1d4cb3 88 *((void **)blk) = 0;
sam_grove 5:3f93dd1d4cb3 89 return (0);
sam_grove 5:3f93dd1d4cb3 90 }
sam_grove 5:3f93dd1d4cb3 91
sam_grove 5:3f93dd1d4cb3 92 /*--------------------------- rt_alloc_box ----------------------------------*/
sam_grove 5:3f93dd1d4cb3 93
sam_grove 5:3f93dd1d4cb3 94 void *rt_alloc_box (void *box_mem) {
sam_grove 5:3f93dd1d4cb3 95 /* Allocate a memory block and return start address. */
sam_grove 5:3f93dd1d4cb3 96 void **free;
sam_grove 5:3f93dd1d4cb3 97 #ifndef __USE_EXCLUSIVE_ACCESS
sam_grove 5:3f93dd1d4cb3 98 int irq_dis;
sam_grove 5:3f93dd1d4cb3 99
sam_grove 5:3f93dd1d4cb3 100 irq_dis = __disable_irq ();
sam_grove 5:3f93dd1d4cb3 101 free = ((P_BM) box_mem)->free;
sam_grove 5:3f93dd1d4cb3 102 if (free) {
sam_grove 5:3f93dd1d4cb3 103 ((P_BM) box_mem)->free = *free;
sam_grove 5:3f93dd1d4cb3 104 }
sam_grove 5:3f93dd1d4cb3 105 if (!irq_dis) __enable_irq ();
sam_grove 5:3f93dd1d4cb3 106 #else
sam_grove 5:3f93dd1d4cb3 107 do {
sam_grove 5:3f93dd1d4cb3 108 if ((free = (void **)__ldrex(&((P_BM) box_mem)->free)) == 0) {
sam_grove 5:3f93dd1d4cb3 109 __clrex();
sam_grove 5:3f93dd1d4cb3 110 break;
sam_grove 5:3f93dd1d4cb3 111 }
sam_grove 5:3f93dd1d4cb3 112 } while (__strex((U32)*free, &((P_BM) box_mem)->free));
sam_grove 5:3f93dd1d4cb3 113 #endif
sam_grove 5:3f93dd1d4cb3 114 return (free);
sam_grove 5:3f93dd1d4cb3 115 }
sam_grove 5:3f93dd1d4cb3 116
sam_grove 5:3f93dd1d4cb3 117
sam_grove 5:3f93dd1d4cb3 118 /*--------------------------- _calloc_box -----------------------------------*/
sam_grove 5:3f93dd1d4cb3 119
sam_grove 5:3f93dd1d4cb3 120 void *_calloc_box (void *box_mem) {
sam_grove 5:3f93dd1d4cb3 121 /* Allocate a 0-initialized memory block and return start address. */
sam_grove 5:3f93dd1d4cb3 122 void *free;
sam_grove 5:3f93dd1d4cb3 123 U32 *p;
sam_grove 5:3f93dd1d4cb3 124 U32 i;
sam_grove 5:3f93dd1d4cb3 125
sam_grove 5:3f93dd1d4cb3 126 free = _alloc_box (box_mem);
sam_grove 5:3f93dd1d4cb3 127 if (free) {
sam_grove 5:3f93dd1d4cb3 128 p = free;
sam_grove 5:3f93dd1d4cb3 129 for (i = ((P_BM) box_mem)->blk_size; i; i -= 4) {
sam_grove 5:3f93dd1d4cb3 130 *p = 0;
sam_grove 5:3f93dd1d4cb3 131 p++;
sam_grove 5:3f93dd1d4cb3 132 }
sam_grove 5:3f93dd1d4cb3 133 }
sam_grove 5:3f93dd1d4cb3 134 return (free);
sam_grove 5:3f93dd1d4cb3 135 }
sam_grove 5:3f93dd1d4cb3 136
sam_grove 5:3f93dd1d4cb3 137
sam_grove 5:3f93dd1d4cb3 138 /*--------------------------- rt_free_box -----------------------------------*/
sam_grove 5:3f93dd1d4cb3 139
sam_grove 5:3f93dd1d4cb3 140 int rt_free_box (void *box_mem, void *box) {
sam_grove 5:3f93dd1d4cb3 141 /* Free a memory block, returns 0 if OK, 1 if box does not belong to box_mem */
sam_grove 5:3f93dd1d4cb3 142 #ifndef __USE_EXCLUSIVE_ACCESS
sam_grove 5:3f93dd1d4cb3 143 int irq_dis;
sam_grove 5:3f93dd1d4cb3 144 #endif
sam_grove 5:3f93dd1d4cb3 145
sam_grove 5:3f93dd1d4cb3 146 if (box < box_mem || box >= ((P_BM) box_mem)->end) {
sam_grove 5:3f93dd1d4cb3 147 return (1);
sam_grove 5:3f93dd1d4cb3 148 }
sam_grove 5:3f93dd1d4cb3 149
sam_grove 5:3f93dd1d4cb3 150 #ifndef __USE_EXCLUSIVE_ACCESS
sam_grove 5:3f93dd1d4cb3 151 irq_dis = __disable_irq ();
sam_grove 5:3f93dd1d4cb3 152 *((void **)box) = ((P_BM) box_mem)->free;
sam_grove 5:3f93dd1d4cb3 153 ((P_BM) box_mem)->free = box;
sam_grove 5:3f93dd1d4cb3 154 if (!irq_dis) __enable_irq ();
sam_grove 5:3f93dd1d4cb3 155 #else
sam_grove 5:3f93dd1d4cb3 156 do {
sam_grove 5:3f93dd1d4cb3 157 *((void **)box) = (void *)__ldrex(&((P_BM) box_mem)->free);
sam_grove 5:3f93dd1d4cb3 158 } while (__strex ((U32)box, &((P_BM) box_mem)->free));
sam_grove 5:3f93dd1d4cb3 159 #endif
sam_grove 5:3f93dd1d4cb3 160 return (0);
sam_grove 5:3f93dd1d4cb3 161 }
sam_grove 5:3f93dd1d4cb3 162
sam_grove 5:3f93dd1d4cb3 163 /*----------------------------------------------------------------------------
sam_grove 5:3f93dd1d4cb3 164 * end of file
sam_grove 5:3f93dd1d4cb3 165 *---------------------------------------------------------------------------*/
sam_grove 5:3f93dd1d4cb3 166