RAMDisk example for the USBFileSystem

Dependencies:   mbed USBFileSystem

Fork of USBFileSystem_RAMDISK_HelloWorld by Erik -

Committer:
Sissors
Date:
Tue Jul 30 18:27:18 2013 +0000
Revision:
1:e1b0157ce547
Memory leaks -_-

Who changed what in which revision?

UserRevisionLine numberNew contents of line
Sissors 1:e1b0157ce547 1 /* Copyright (c) 2010-2011 mbed.org, MIT License
Sissors 1:e1b0157ce547 2 *
Sissors 1:e1b0157ce547 3 * Permission is hereby granted, free of charge, to any person obtaining a copy of this software
Sissors 1:e1b0157ce547 4 * and associated documentation files (the "Software"), to deal in the Software without
Sissors 1:e1b0157ce547 5 * restriction, including without limitation the rights to use, copy, modify, merge, publish,
Sissors 1:e1b0157ce547 6 * distribute, sublicense, and/or sell copies of the Software, and to permit persons to whom the
Sissors 1:e1b0157ce547 7 * Software is furnished to do so, subject to the following conditions:
Sissors 1:e1b0157ce547 8 *
Sissors 1:e1b0157ce547 9 * The above copyright notice and this permission notice shall be included in all copies or
Sissors 1:e1b0157ce547 10 * substantial portions of the Software.
Sissors 1:e1b0157ce547 11 *
Sissors 1:e1b0157ce547 12 * THE SOFTWARE IS PROVIDED "AS IS", WITHOUT WARRANTY OF ANY KIND, EXPRESS OR IMPLIED, INCLUDING
Sissors 1:e1b0157ce547 13 * BUT NOT LIMITED TO THE WARRANTIES OF MERCHANTABILITY, FITNESS FOR A PARTICULAR PURPOSE AND
Sissors 1:e1b0157ce547 14 * NONINFRINGEMENT. IN NO EVENT SHALL THE AUTHORS OR COPYRIGHT HOLDERS BE LIABLE FOR ANY CLAIM,
Sissors 1:e1b0157ce547 15 * DAMAGES OR OTHER LIABILITY, WHETHER IN AN ACTION OF CONTRACT, TORT OR OTHERWISE, ARISING FROM,
Sissors 1:e1b0157ce547 16 * OUT OF OR IN CONNECTION WITH THE SOFTWARE OR THE USE OR OTHER DEALINGS IN THE SOFTWARE.
Sissors 1:e1b0157ce547 17 */
Sissors 1:e1b0157ce547 18
Sissors 1:e1b0157ce547 19 #include "stdint.h"
Sissors 1:e1b0157ce547 20 #include "USBSerial.h"
Sissors 1:e1b0157ce547 21
Sissors 1:e1b0157ce547 22 int USBSerial::_putc(int c) {
Sissors 1:e1b0157ce547 23 if (!terminal_connected)
Sissors 1:e1b0157ce547 24 return 0;
Sissors 1:e1b0157ce547 25 send((uint8_t *)&c, 1);
Sissors 1:e1b0157ce547 26 return 1;
Sissors 1:e1b0157ce547 27 }
Sissors 1:e1b0157ce547 28
Sissors 1:e1b0157ce547 29 int USBSerial::_getc() {
Sissors 1:e1b0157ce547 30 uint8_t c;
Sissors 1:e1b0157ce547 31 while (buf.isEmpty());
Sissors 1:e1b0157ce547 32 buf.dequeue(&c);
Sissors 1:e1b0157ce547 33 return c;
Sissors 1:e1b0157ce547 34 }
Sissors 1:e1b0157ce547 35
Sissors 1:e1b0157ce547 36
Sissors 1:e1b0157ce547 37 bool USBSerial::writeBlock(uint8_t * buf, uint16_t size) {
Sissors 1:e1b0157ce547 38 if(size > MAX_PACKET_SIZE_EPBULK) {
Sissors 1:e1b0157ce547 39 return false;
Sissors 1:e1b0157ce547 40 }
Sissors 1:e1b0157ce547 41 if(!send(buf, size)) {
Sissors 1:e1b0157ce547 42 return false;
Sissors 1:e1b0157ce547 43 }
Sissors 1:e1b0157ce547 44 return true;
Sissors 1:e1b0157ce547 45 }
Sissors 1:e1b0157ce547 46
Sissors 1:e1b0157ce547 47
Sissors 1:e1b0157ce547 48
Sissors 1:e1b0157ce547 49 bool USBSerial::EP2_OUT_callback() {
Sissors 1:e1b0157ce547 50 uint8_t c[65];
Sissors 1:e1b0157ce547 51 uint32_t size = 0;
Sissors 1:e1b0157ce547 52
Sissors 1:e1b0157ce547 53 //we read the packet received and put it on the circular buffer
Sissors 1:e1b0157ce547 54 readEP(c, &size);
Sissors 1:e1b0157ce547 55 for (int i = 0; i < size; i++) {
Sissors 1:e1b0157ce547 56 buf.queue(c[i]);
Sissors 1:e1b0157ce547 57 }
Sissors 1:e1b0157ce547 58
Sissors 1:e1b0157ce547 59 //call a potential handler
Sissors 1:e1b0157ce547 60 rx.call();
Sissors 1:e1b0157ce547 61
Sissors 1:e1b0157ce547 62 // We reactivate the endpoint to receive next characters
Sissors 1:e1b0157ce547 63 readStart(EPBULK_OUT, MAX_PACKET_SIZE_EPBULK);
Sissors 1:e1b0157ce547 64 return true;
Sissors 1:e1b0157ce547 65 }
Sissors 1:e1b0157ce547 66
Sissors 1:e1b0157ce547 67 uint8_t USBSerial::available() {
Sissors 1:e1b0157ce547 68 return buf.available();
Sissors 1:e1b0157ce547 69 }