Code for our FYDP -only one IMU works right now -RTOS is working
mbed/MODSERIAL/GETC.cpp@0:964eb6a2ef00, 2015-03-18 (annotated)
- Committer:
- majik
- Date:
- Wed Mar 18 22:23:48 2015 +0000
- Revision:
- 0:964eb6a2ef00
This is our FYDP code, but only one IMU works with the RTOS.
Who changed what in which revision?
User | Revision | Line number | New contents of line |
---|---|---|---|
majik | 0:964eb6a2ef00 | 1 | /* |
majik | 0:964eb6a2ef00 | 2 | Copyright (c) 2010 Andy Kirkham |
majik | 0:964eb6a2ef00 | 3 | |
majik | 0:964eb6a2ef00 | 4 | Permission is hereby granted, free of charge, to any person obtaining a copy |
majik | 0:964eb6a2ef00 | 5 | of this software and associated documentation files (the "Software"), to deal |
majik | 0:964eb6a2ef00 | 6 | in the Software without restriction, including without limitation the rights |
majik | 0:964eb6a2ef00 | 7 | to use, copy, modify, merge, publish, distribute, sublicense, and/or sell |
majik | 0:964eb6a2ef00 | 8 | copies of the Software, and to permit persons to whom the Software is |
majik | 0:964eb6a2ef00 | 9 | furnished to do so, subject to the following conditions: |
majik | 0:964eb6a2ef00 | 10 | |
majik | 0:964eb6a2ef00 | 11 | The above copyright notice and this permission notice shall be included in |
majik | 0:964eb6a2ef00 | 12 | all copies or substantial portions of the Software. |
majik | 0:964eb6a2ef00 | 13 | |
majik | 0:964eb6a2ef00 | 14 | THE SOFTWARE IS PROVIDED "AS IS", WITHOUT WARRANTY OF ANY KIND, EXPRESS OR |
majik | 0:964eb6a2ef00 | 15 | IMPLIED, INCLUDING BUT NOT LIMITED TO THE WARRANTIES OF MERCHANTABILITY, |
majik | 0:964eb6a2ef00 | 16 | FITNESS FOR A PARTICULAR PURPOSE AND NONINFRINGEMENT. IN NO EVENT SHALL THE |
majik | 0:964eb6a2ef00 | 17 | AUTHORS OR COPYRIGHT HOLDERS BE LIABLE FOR ANY CLAIM, DAMAGES OR OTHER |
majik | 0:964eb6a2ef00 | 18 | LIABILITY, WHETHER IN AN ACTION OF CONTRACT, TORT OR OTHERWISE, ARISING FROM, |
majik | 0:964eb6a2ef00 | 19 | OUT OF OR IN CONNECTION WITH THE SOFTWARE OR THE USE OR OTHER DEALINGS IN |
majik | 0:964eb6a2ef00 | 20 | THE SOFTWARE. |
majik | 0:964eb6a2ef00 | 21 | */ |
majik | 0:964eb6a2ef00 | 22 | |
majik | 0:964eb6a2ef00 | 23 | #include "MODSERIAL.h" |
majik | 0:964eb6a2ef00 | 24 | #include "MACROS.h" |
majik | 0:964eb6a2ef00 | 25 | |
majik | 0:964eb6a2ef00 | 26 | namespace AjK { |
majik | 0:964eb6a2ef00 | 27 | |
majik | 0:964eb6a2ef00 | 28 | int |
majik | 0:964eb6a2ef00 | 29 | MODSERIAL::__getc(bool block) |
majik | 0:964eb6a2ef00 | 30 | { |
majik | 0:964eb6a2ef00 | 31 | // If no buffer is in use fall back to standard RX FIFO usage. |
majik | 0:964eb6a2ef00 | 32 | // Note, we must block in this case and ignore bool "block" |
majik | 0:964eb6a2ef00 | 33 | // so as to maintain compat with Mbed Serial. |
majik | 0:964eb6a2ef00 | 34 | if (buffer_size[RxIrq] == 0 || buffer[RxIrq] == (char *)NULL) { |
majik | 0:964eb6a2ef00 | 35 | while(! MODSERIAL_READABLE ) ; |
majik | 0:964eb6a2ef00 | 36 | return (int)(MODSERIAL_READ_REG & 0xFF); |
majik | 0:964eb6a2ef00 | 37 | } |
majik | 0:964eb6a2ef00 | 38 | |
majik | 0:964eb6a2ef00 | 39 | if (block) { while ( MODSERIAL_RX_BUFFER_EMPTY ) ; } // Blocks. |
majik | 0:964eb6a2ef00 | 40 | else if ( MODSERIAL_RX_BUFFER_EMPTY ) return -1; |
majik | 0:964eb6a2ef00 | 41 | |
majik | 0:964eb6a2ef00 | 42 | int c = buffer[RxIrq][buffer_out[RxIrq]]; |
majik | 0:964eb6a2ef00 | 43 | buffer_out[RxIrq]++; |
majik | 0:964eb6a2ef00 | 44 | if (buffer_out[RxIrq] >= buffer_size[RxIrq]) { |
majik | 0:964eb6a2ef00 | 45 | buffer_out[RxIrq] = 0; |
majik | 0:964eb6a2ef00 | 46 | } |
majik | 0:964eb6a2ef00 | 47 | |
majik | 0:964eb6a2ef00 | 48 | // If we have made space in the RX Buffer then copy over |
majik | 0:964eb6a2ef00 | 49 | // any characters in the RX FIFO that my reside there. |
majik | 0:964eb6a2ef00 | 50 | // Temporarily disable the RX IRQ so that we do not re-enter |
majik | 0:964eb6a2ef00 | 51 | // it under interrupts. |
majik | 0:964eb6a2ef00 | 52 | if ( ! MODSERIAL_RX_BUFFER_FULL ) { |
majik | 0:964eb6a2ef00 | 53 | uint32_t irq_reg = MODSERIAL_IRQ_REG; |
majik | 0:964eb6a2ef00 | 54 | DISABLE_RX_IRQ; |
majik | 0:964eb6a2ef00 | 55 | isr_rx(); |
majik | 0:964eb6a2ef00 | 56 | MODSERIAL_IRQ_REG = irq_reg; |
majik | 0:964eb6a2ef00 | 57 | } |
majik | 0:964eb6a2ef00 | 58 | |
majik | 0:964eb6a2ef00 | 59 | __disable_irq(); |
majik | 0:964eb6a2ef00 | 60 | buffer_count[RxIrq]--; |
majik | 0:964eb6a2ef00 | 61 | __enable_irq(); |
majik | 0:964eb6a2ef00 | 62 | return c; |
majik | 0:964eb6a2ef00 | 63 | } |
majik | 0:964eb6a2ef00 | 64 | |
majik | 0:964eb6a2ef00 | 65 | }; // namespace AjK ends |