Base station firmware

Committer:
Perijah
Date:
Tue May 24 13:16:55 2016 +0000
Revision:
0:ecc3925d3f8c
Base station firmware

Who changed what in which revision?

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