Jim Flynn
/
aws-iot-device-sdk-mbed-c
Changes to enabled on-line compiler
platform/ezconnect/wnc14a2a-driver/WNC14A2AInterface/WNCIO.h@0:082731ede69f, 2018-05-30 (annotated)
- Committer:
- JMF
- Date:
- Wed May 30 20:59:51 2018 +0000
- Revision:
- 0:082731ede69f
Initial commit
Who changed what in which revision?
User | Revision | Line number | New contents of line |
---|---|---|---|
JMF | 0:082731ede69f | 1 | /** |
JMF | 0:082731ede69f | 2 | * copyright (c) 2017-2018, James Flynn |
JMF | 0:082731ede69f | 3 | * SPDX-License-Identifier: Apache-2.0 |
JMF | 0:082731ede69f | 4 | */ |
JMF | 0:082731ede69f | 5 | |
JMF | 0:082731ede69f | 6 | /* |
JMF | 0:082731ede69f | 7 | * Licensed under the Apache License, Version 2.0 (the "License"); |
JMF | 0:082731ede69f | 8 | * you may not use this file except in compliance with the License. |
JMF | 0:082731ede69f | 9 | * You may obtain a copy of the License at |
JMF | 0:082731ede69f | 10 | * |
JMF | 0:082731ede69f | 11 | * http://www.apache.org/licenses/LICENSE-2.0 |
JMF | 0:082731ede69f | 12 | * |
JMF | 0:082731ede69f | 13 | * Unless required by applicable law or agreed to in writing, software |
JMF | 0:082731ede69f | 14 | * distributed under the License is distributed on an "AS IS" BASIS, |
JMF | 0:082731ede69f | 15 | * WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied. |
JMF | 0:082731ede69f | 16 | * |
JMF | 0:082731ede69f | 17 | * See the License for the specific language governing permissions and |
JMF | 0:082731ede69f | 18 | * limitations under the License. |
JMF | 0:082731ede69f | 19 | */ |
JMF | 0:082731ede69f | 20 | |
JMF | 0:082731ede69f | 21 | /** |
JMF | 0:082731ede69f | 22 | * @file WNCIO.h |
JMF | 0:082731ede69f | 23 | * @brief A class that WNCInterface uses for input/output |
JMF | 0:082731ede69f | 24 | * |
JMF | 0:082731ede69f | 25 | * @author James Flynn |
JMF | 0:082731ede69f | 26 | * |
JMF | 0:082731ede69f | 27 | * @date 1-Feb-2018 |
JMF | 0:082731ede69f | 28 | * |
JMF | 0:082731ede69f | 29 | */ |
JMF | 0:082731ede69f | 30 | |
JMF | 0:082731ede69f | 31 | #ifndef __WNCIO__ |
JMF | 0:082731ede69f | 32 | #define __WNCIO__ |
JMF | 0:082731ede69f | 33 | #include <stdio.h> |
JMF | 0:082731ede69f | 34 | #include "mbed.h" |
JMF | 0:082731ede69f | 35 | |
JMF | 0:082731ede69f | 36 | /** WncIO class |
JMF | 0:082731ede69f | 37 | * Used to read/write the WNC UART using FILE I/O. |
JMF | 0:082731ede69f | 38 | */ |
JMF | 0:082731ede69f | 39 | |
JMF | 0:082731ede69f | 40 | class WncIO |
JMF | 0:082731ede69f | 41 | { |
JMF | 0:082731ede69f | 42 | public: |
JMF | 0:082731ede69f | 43 | //! Create class with either stdio or a pointer to a uart |
JMF | 0:082731ede69f | 44 | WncIO( UARTSerial * uart): m_puart(uart) {;} |
JMF | 0:082731ede69f | 45 | ~WncIO() {}; |
JMF | 0:082731ede69f | 46 | |
JMF | 0:082731ede69f | 47 | //! standard printf() functionallity |
JMF | 0:082731ede69f | 48 | int printf( char * fmt, ...) { |
JMF | 0:082731ede69f | 49 | char buffer[256]; |
JMF | 0:082731ede69f | 50 | int ret=0; |
JMF | 0:082731ede69f | 51 | va_list args; |
JMF | 0:082731ede69f | 52 | va_start (args, fmt); |
JMF | 0:082731ede69f | 53 | vsnprintf(buffer, sizeof(buffer), fmt, args); |
JMF | 0:082731ede69f | 54 | prt.lock(); |
JMF | 0:082731ede69f | 55 | ret=m_puart->write(buffer,strlen(buffer)); |
JMF | 0:082731ede69f | 56 | prt.unlock(); |
JMF | 0:082731ede69f | 57 | va_end (args); |
JMF | 0:082731ede69f | 58 | return ret; |
JMF | 0:082731ede69f | 59 | } |
JMF | 0:082731ede69f | 60 | |
JMF | 0:082731ede69f | 61 | //! standard putc() functionallity |
JMF | 0:082731ede69f | 62 | int putc( int c ) { |
JMF | 0:082731ede69f | 63 | int ret=0; |
JMF | 0:082731ede69f | 64 | prt.lock(); |
JMF | 0:082731ede69f | 65 | ret=m_puart->write((const void*)&c,1); |
JMF | 0:082731ede69f | 66 | prt.unlock(); |
JMF | 0:082731ede69f | 67 | return ret; |
JMF | 0:082731ede69f | 68 | } |
JMF | 0:082731ede69f | 69 | |
JMF | 0:082731ede69f | 70 | //! standard puts() functionallity |
JMF | 0:082731ede69f | 71 | int puts( const char * str ) { |
JMF | 0:082731ede69f | 72 | int ret=0; |
JMF | 0:082731ede69f | 73 | prt.lock(); |
JMF | 0:082731ede69f | 74 | ret=m_puart->write(str,strlen(str)); |
JMF | 0:082731ede69f | 75 | prt.unlock(); |
JMF | 0:082731ede69f | 76 | return ret; |
JMF | 0:082731ede69f | 77 | } |
JMF | 0:082731ede69f | 78 | |
JMF | 0:082731ede69f | 79 | //! return true when data is available, false otherwise |
JMF | 0:082731ede69f | 80 | bool readable( void ) { |
JMF | 0:082731ede69f | 81 | return m_puart->readable(); |
JMF | 0:082731ede69f | 82 | } |
JMF | 0:082731ede69f | 83 | |
JMF | 0:082731ede69f | 84 | //! get the next character available from the uart |
JMF | 0:082731ede69f | 85 | int getc( void ) { |
JMF | 0:082731ede69f | 86 | char c; |
JMF | 0:082731ede69f | 87 | m_puart->read( &c, 1 ); |
JMF | 0:082731ede69f | 88 | return c; |
JMF | 0:082731ede69f | 89 | } |
JMF | 0:082731ede69f | 90 | |
JMF | 0:082731ede69f | 91 | //! set the uart baud rate |
JMF | 0:082731ede69f | 92 | void baud( int baud ) { |
JMF | 0:082731ede69f | 93 | m_puart->set_baud(baud); |
JMF | 0:082731ede69f | 94 | } |
JMF | 0:082731ede69f | 95 | |
JMF | 0:082731ede69f | 96 | private: |
JMF | 0:082731ede69f | 97 | UARTSerial *m_puart; |
JMF | 0:082731ede69f | 98 | Mutex prt; |
JMF | 0:082731ede69f | 99 | }; |
JMF | 0:082731ede69f | 100 | |
JMF | 0:082731ede69f | 101 | #endif |
JMF | 0:082731ede69f | 102 |