This library is stripped down version of NetServices library. HTTP server and client function is NOT supported.

Dependents:   imu-daq-eth

Committer:
idinor
Date:
Wed Jul 20 11:45:39 2011 +0000
Revision:
0:dcf3c92487ca

        

Who changed what in which revision?

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