HTTPClient using static IP

Dependencies:   mbed

Committer:
mr_q
Date:
Mon May 30 11:53:37 2011 +0000
Revision:
0:d8f2f7d5f31b
v0.01 Draft

Who changed what in which revision?

UserRevisionLine numberNew contents of line
mr_q 0:d8f2f7d5f31b 1
mr_q 0:d8f2f7d5f31b 2 /*
mr_q 0:d8f2f7d5f31b 3 Copyright (c) 2010 Donatien Garnier (donatiengar [at] gmail [dot] com)
mr_q 0:d8f2f7d5f31b 4
mr_q 0:d8f2f7d5f31b 5 Permission is hereby granted, free of charge, to any person obtaining a copy
mr_q 0:d8f2f7d5f31b 6 of this software and associated documentation files (the "Software"), to deal
mr_q 0:d8f2f7d5f31b 7 in the Software without restriction, including without limitation the rights
mr_q 0:d8f2f7d5f31b 8 to use, copy, modify, merge, publish, distribute, sublicense, and/or sell
mr_q 0:d8f2f7d5f31b 9 copies of the Software, and to permit persons to whom the Software is
mr_q 0:d8f2f7d5f31b 10 furnished to do so, subject to the following conditions:
mr_q 0:d8f2f7d5f31b 11
mr_q 0:d8f2f7d5f31b 12 The above copyright notice and this permission notice shall be included in
mr_q 0:d8f2f7d5f31b 13 all copies or substantial portions of the Software.
mr_q 0:d8f2f7d5f31b 14
mr_q 0:d8f2f7d5f31b 15 THE SOFTWARE IS PROVIDED "AS IS", WITHOUT WARRANTY OF ANY KIND, EXPRESS OR
mr_q 0:d8f2f7d5f31b 16 IMPLIED, INCLUDING BUT NOT LIMITED TO THE WARRANTIES OF MERCHANTABILITY,
mr_q 0:d8f2f7d5f31b 17 FITNESS FOR A PARTICULAR PURPOSE AND NONINFRINGEMENT. IN NO EVENT SHALL THE
mr_q 0:d8f2f7d5f31b 18 AUTHORS OR COPYRIGHT HOLDERS BE LIABLE FOR ANY CLAIM, DAMAGES OR OTHER
mr_q 0:d8f2f7d5f31b 19 LIABILITY, WHETHER IN AN ACTION OF CONTRACT, TORT OR OTHERWISE, ARISING FROM,
mr_q 0:d8f2f7d5f31b 20 OUT OF OR IN CONNECTION WITH THE SOFTWARE OR THE USE OR OTHER DEALINGS IN
mr_q 0:d8f2f7d5f31b 21 THE SOFTWARE.
mr_q 0:d8f2f7d5f31b 22 */
mr_q 0:d8f2f7d5f31b 23
mr_q 0:d8f2f7d5f31b 24 #include "usb_mem.h"
mr_q 0:d8f2f7d5f31b 25
mr_q 0:d8f2f7d5f31b 26 #include "string.h" //For memcpy, memmove, memset
mr_q 0:d8f2f7d5f31b 27
mr_q 0:d8f2f7d5f31b 28 #include "netCfg.h"
mr_q 0:d8f2f7d5f31b 29 #if NET_USB
mr_q 0:d8f2f7d5f31b 30
mr_q 0:d8f2f7d5f31b 31 #define EDS_COUNT 4
mr_q 0:d8f2f7d5f31b 32 #define TDS_COUNT 8
mr_q 0:d8f2f7d5f31b 33
mr_q 0:d8f2f7d5f31b 34 #define HCCA_SIZE 0x100
mr_q 0:d8f2f7d5f31b 35 #define ED_SIZE 0x10
mr_q 0:d8f2f7d5f31b 36 #define TD_SIZE 0x10
mr_q 0:d8f2f7d5f31b 37
mr_q 0:d8f2f7d5f31b 38 #define TOTAL_SIZE (HCCA_SIZE + (EDS_COUNT*ED_SIZE) + (TDS_COUNT*TD_SIZE))
mr_q 0:d8f2f7d5f31b 39
mr_q 0:d8f2f7d5f31b 40
mr_q 0:d8f2f7d5f31b 41 static volatile __align(256) byte usb_buf[TOTAL_SIZE] __attribute((section("AHBSRAM1"),aligned)); //256 bytes aligned!
mr_q 0:d8f2f7d5f31b 42
mr_q 0:d8f2f7d5f31b 43 static volatile byte* usb_hcca; //256 bytes aligned!
mr_q 0:d8f2f7d5f31b 44
mr_q 0:d8f2f7d5f31b 45 static volatile byte* usb_edBuf; //4 bytes aligned!
mr_q 0:d8f2f7d5f31b 46 static volatile byte* usb_tdBuf; //4 bytes aligned!
mr_q 0:d8f2f7d5f31b 47
mr_q 0:d8f2f7d5f31b 48 static byte usb_edBufAlloc[EDS_COUNT] __attribute((section("AHBSRAM1"),aligned));
mr_q 0:d8f2f7d5f31b 49 static byte usb_tdBufAlloc[TDS_COUNT] __attribute((section("AHBSRAM1"),aligned));
mr_q 0:d8f2f7d5f31b 50
mr_q 0:d8f2f7d5f31b 51 void usb_mem_init()
mr_q 0:d8f2f7d5f31b 52 {
mr_q 0:d8f2f7d5f31b 53 usb_hcca = usb_buf;
mr_q 0:d8f2f7d5f31b 54 usb_edBuf = usb_buf + HCCA_SIZE;
mr_q 0:d8f2f7d5f31b 55 usb_tdBuf = usb_buf + HCCA_SIZE + (EDS_COUNT*ED_SIZE);
mr_q 0:d8f2f7d5f31b 56 memset(usb_edBufAlloc, 0, EDS_COUNT);
mr_q 0:d8f2f7d5f31b 57 memset(usb_tdBufAlloc, 0, TDS_COUNT);
mr_q 0:d8f2f7d5f31b 58 }
mr_q 0:d8f2f7d5f31b 59
mr_q 0:d8f2f7d5f31b 60 volatile byte* usb_get_hcca()
mr_q 0:d8f2f7d5f31b 61 {
mr_q 0:d8f2f7d5f31b 62 return usb_hcca;
mr_q 0:d8f2f7d5f31b 63 }
mr_q 0:d8f2f7d5f31b 64
mr_q 0:d8f2f7d5f31b 65 volatile byte* usb_get_ed()
mr_q 0:d8f2f7d5f31b 66 {
mr_q 0:d8f2f7d5f31b 67 int i;
mr_q 0:d8f2f7d5f31b 68 for(i = 0; i < EDS_COUNT; i++)
mr_q 0:d8f2f7d5f31b 69 {
mr_q 0:d8f2f7d5f31b 70 if( !usb_edBufAlloc[i] )
mr_q 0:d8f2f7d5f31b 71 {
mr_q 0:d8f2f7d5f31b 72 usb_edBufAlloc[i] = 1;
mr_q 0:d8f2f7d5f31b 73 return usb_edBuf + i*ED_SIZE;
mr_q 0:d8f2f7d5f31b 74 }
mr_q 0:d8f2f7d5f31b 75 }
mr_q 0:d8f2f7d5f31b 76 return NULL; //Could not alloc ED
mr_q 0:d8f2f7d5f31b 77 }
mr_q 0:d8f2f7d5f31b 78
mr_q 0:d8f2f7d5f31b 79 volatile byte* usb_get_td()
mr_q 0:d8f2f7d5f31b 80 {
mr_q 0:d8f2f7d5f31b 81 int i;
mr_q 0:d8f2f7d5f31b 82 for(i = 0; i < TDS_COUNT; i++)
mr_q 0:d8f2f7d5f31b 83 {
mr_q 0:d8f2f7d5f31b 84 if( !usb_tdBufAlloc[i] )
mr_q 0:d8f2f7d5f31b 85 {
mr_q 0:d8f2f7d5f31b 86 usb_tdBufAlloc[i] = 1;
mr_q 0:d8f2f7d5f31b 87 return usb_tdBuf + i*TD_SIZE;
mr_q 0:d8f2f7d5f31b 88 }
mr_q 0:d8f2f7d5f31b 89 }
mr_q 0:d8f2f7d5f31b 90 return NULL; //Could not alloc TD
mr_q 0:d8f2f7d5f31b 91 }
mr_q 0:d8f2f7d5f31b 92
mr_q 0:d8f2f7d5f31b 93 void usb_free_ed(volatile byte* ed)
mr_q 0:d8f2f7d5f31b 94 {
mr_q 0:d8f2f7d5f31b 95 int i;
mr_q 0:d8f2f7d5f31b 96 i = (ed - usb_edBuf) / ED_SIZE;
mr_q 0:d8f2f7d5f31b 97 usb_edBufAlloc[i] = 0;
mr_q 0:d8f2f7d5f31b 98 }
mr_q 0:d8f2f7d5f31b 99
mr_q 0:d8f2f7d5f31b 100 void usb_free_td(volatile byte* td)
mr_q 0:d8f2f7d5f31b 101 {
mr_q 0:d8f2f7d5f31b 102 int i;
mr_q 0:d8f2f7d5f31b 103 i = (td - usb_tdBuf) / TD_SIZE;
mr_q 0:d8f2f7d5f31b 104 usb_tdBufAlloc[i] = 0;
mr_q 0:d8f2f7d5f31b 105 }
mr_q 0:d8f2f7d5f31b 106
mr_q 0:d8f2f7d5f31b 107
mr_q 0:d8f2f7d5f31b 108 #endif