Changes to allow hardware camera trigger
Fork of GPS_Incremental by
MODSERIAL/PUTC.cpp@10:078891935385, 2013-04-18 (annotated)
- Committer:
- dannyman939
- Date:
- Thu Apr 18 00:59:49 2013 +0000
- Revision:
- 10:078891935385
- Parent:
- 0:c746ee34feae
Hardware trigger camera using the DigitalOut of Pin 2
Who changed what in which revision?
User | Revision | Line number | New contents of line |
---|---|---|---|
dannyman939 | 0:c746ee34feae | 1 | /* |
dannyman939 | 0:c746ee34feae | 2 | Copyright (c) 2010 Andy Kirkham |
dannyman939 | 0:c746ee34feae | 3 | |
dannyman939 | 0:c746ee34feae | 4 | Permission is hereby granted, free of charge, to any person obtaining a copy |
dannyman939 | 0:c746ee34feae | 5 | of this software and associated documentation files (the "Software"), to deal |
dannyman939 | 0:c746ee34feae | 6 | in the Software without restriction, including without limitation the rights |
dannyman939 | 0:c746ee34feae | 7 | to use, copy, modify, merge, publish, distribute, sublicense, and/or sell |
dannyman939 | 0:c746ee34feae | 8 | copies of the Software, and to permit persons to whom the Software is |
dannyman939 | 0:c746ee34feae | 9 | furnished to do so, subject to the following conditions: |
dannyman939 | 0:c746ee34feae | 10 | |
dannyman939 | 0:c746ee34feae | 11 | The above copyright notice and this permission notice shall be included in |
dannyman939 | 0:c746ee34feae | 12 | all copies or substantial portions of the Software. |
dannyman939 | 0:c746ee34feae | 13 | |
dannyman939 | 0:c746ee34feae | 14 | THE SOFTWARE IS PROVIDED "AS IS", WITHOUT WARRANTY OF ANY KIND, EXPRESS OR |
dannyman939 | 0:c746ee34feae | 15 | IMPLIED, INCLUDING BUT NOT LIMITED TO THE WARRANTIES OF MERCHANTABILITY, |
dannyman939 | 0:c746ee34feae | 16 | FITNESS FOR A PARTICULAR PURPOSE AND NONINFRINGEMENT. IN NO EVENT SHALL THE |
dannyman939 | 0:c746ee34feae | 17 | AUTHORS OR COPYRIGHT HOLDERS BE LIABLE FOR ANY CLAIM, DAMAGES OR OTHER |
dannyman939 | 0:c746ee34feae | 18 | LIABILITY, WHETHER IN AN ACTION OF CONTRACT, TORT OR OTHERWISE, ARISING FROM, |
dannyman939 | 0:c746ee34feae | 19 | OUT OF OR IN CONNECTION WITH THE SOFTWARE OR THE USE OR OTHER DEALINGS IN |
dannyman939 | 0:c746ee34feae | 20 | THE SOFTWARE. |
dannyman939 | 0:c746ee34feae | 21 | */ |
dannyman939 | 0:c746ee34feae | 22 | |
dannyman939 | 0:c746ee34feae | 23 | #include "MODSERIAL.h" |
dannyman939 | 0:c746ee34feae | 24 | #include "MACROS.h" |
dannyman939 | 0:c746ee34feae | 25 | |
dannyman939 | 0:c746ee34feae | 26 | namespace AjK { |
dannyman939 | 0:c746ee34feae | 27 | |
dannyman939 | 0:c746ee34feae | 28 | int |
dannyman939 | 0:c746ee34feae | 29 | MODSERIAL::__putc(int c, bool block) { |
dannyman939 | 0:c746ee34feae | 30 | |
dannyman939 | 0:c746ee34feae | 31 | // If no buffer is in use fall back to standard TX FIFO usage. |
dannyman939 | 0:c746ee34feae | 32 | // Note, we must block in this case and ignore bool "block" |
dannyman939 | 0:c746ee34feae | 33 | // so as to maintain compat with Mbed Serial. |
dannyman939 | 0:c746ee34feae | 34 | if (buffer[TxIrq] == (char *)NULL || buffer_size[TxIrq] == 0) { |
dannyman939 | 0:c746ee34feae | 35 | while (! MODSERIAL_THR_HAS_SPACE) ; // Wait for space in the TX FIFO. |
dannyman939 | 0:c746ee34feae | 36 | _THR = (uint32_t)c; |
dannyman939 | 0:c746ee34feae | 37 | return 0; |
dannyman939 | 0:c746ee34feae | 38 | } |
dannyman939 | 0:c746ee34feae | 39 | |
dannyman939 | 0:c746ee34feae | 40 | if ( MODSERIAL_THR_HAS_SPACE && MODSERIAL_TX_BUFFER_EMPTY && dmaSendChannel == -1 ) { |
dannyman939 | 0:c746ee34feae | 41 | _THR = (uint32_t)c; |
dannyman939 | 0:c746ee34feae | 42 | } |
dannyman939 | 0:c746ee34feae | 43 | else { |
dannyman939 | 0:c746ee34feae | 44 | if (block) { |
dannyman939 | 0:c746ee34feae | 45 | uint32_t ier = _IER; _IER = 1; |
dannyman939 | 0:c746ee34feae | 46 | while ( MODSERIAL_TX_BUFFER_FULL ) { // Blocks! |
dannyman939 | 0:c746ee34feae | 47 | // If putc() is called from an ISR then we are stuffed |
dannyman939 | 0:c746ee34feae | 48 | // because in an ISR no bytes from the TX buffer will |
dannyman939 | 0:c746ee34feae | 49 | // get transferred to teh TX FIFOs while we block here. |
dannyman939 | 0:c746ee34feae | 50 | // So, to work around this, instead of sitting in a |
dannyman939 | 0:c746ee34feae | 51 | // loop waiting for space in the TX buffer (which will |
dannyman939 | 0:c746ee34feae | 52 | // never happen in IRQ context), check to see if the |
dannyman939 | 0:c746ee34feae | 53 | // TX FIFO has space available to move bytes from the |
dannyman939 | 0:c746ee34feae | 54 | // TX buffer to TX FIFO to make space. The easiest way |
dannyman939 | 0:c746ee34feae | 55 | // to do this is to poll the isr_tx() function while we |
dannyman939 | 0:c746ee34feae | 56 | // are blocking. |
dannyman939 | 0:c746ee34feae | 57 | isr_tx(false); |
dannyman939 | 0:c746ee34feae | 58 | } |
dannyman939 | 0:c746ee34feae | 59 | _IER = ier; |
dannyman939 | 0:c746ee34feae | 60 | } |
dannyman939 | 0:c746ee34feae | 61 | else if( MODSERIAL_TX_BUFFER_FULL ) { |
dannyman939 | 0:c746ee34feae | 62 | buffer_overflow[TxIrq] = c; // Oh dear, no room in buffer. |
dannyman939 | 0:c746ee34feae | 63 | _isr[TxOvIrq].call(&this->callbackInfo); |
dannyman939 | 0:c746ee34feae | 64 | return -1; |
dannyman939 | 0:c746ee34feae | 65 | } |
dannyman939 | 0:c746ee34feae | 66 | _IER &= ~2; |
dannyman939 | 0:c746ee34feae | 67 | buffer[TxIrq][buffer_in[TxIrq]] = c; |
dannyman939 | 0:c746ee34feae | 68 | __disable_irq(); |
dannyman939 | 0:c746ee34feae | 69 | buffer_count[TxIrq]++; |
dannyman939 | 0:c746ee34feae | 70 | __enable_irq(); |
dannyman939 | 0:c746ee34feae | 71 | buffer_in[TxIrq]++; |
dannyman939 | 0:c746ee34feae | 72 | if (buffer_in[TxIrq] >= buffer_size[TxIrq]) { |
dannyman939 | 0:c746ee34feae | 73 | buffer_in[TxIrq] = 0; |
dannyman939 | 0:c746ee34feae | 74 | } |
dannyman939 | 0:c746ee34feae | 75 | _IER |= 2; |
dannyman939 | 0:c746ee34feae | 76 | } |
dannyman939 | 0:c746ee34feae | 77 | |
dannyman939 | 0:c746ee34feae | 78 | return 0; |
dannyman939 | 0:c746ee34feae | 79 | } |
dannyman939 | 0:c746ee34feae | 80 | |
dannyman939 | 0:c746ee34feae | 81 | }; // namespace AjK ends |