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