Important changes to repositories hosted on mbed.com
Mbed hosted mercurial repositories are deprecated and are due to be permanently deleted in July 2026.
To keep a copy of this software download the repository Zip archive or clone locally using Mercurial.
It is also possible to export all your personal repositories from the account settings page.
Dependents: YOZAKURA_ARM YOZAKURA_ARM_USB YOZAKURA_ARM_USB_Keyboard YOZAKURA_ARM_Keyboard0424 ... more
Fork of SerialHalfDuplex by
SerialHalfDuplex.cpp
00001 /* mbed Microcontroller Library 00002 * Copyright (c) 2006-2012 ARM Limited 00003 * 00004 * Permission is hereby granted, free of charge, to any person obtaining a copy 00005 * of this software and associated documentation files (the "Software"), to deal 00006 * in the Software without restriction, including without limitation the rights 00007 * to use, copy, modify, merge, publish, distribute, sublicense, and/or sell 00008 * copies of the Software, and to permit persons to whom the Software is 00009 * furnished to do so, subject to the following conditions: 00010 * 00011 * The above copyright notice and this permission notice shall be included in 00012 * all copies or substantial portions of the Software. 00013 * 00014 * THE SOFTWARE IS PROVIDED "AS IS", WITHOUT WARRANTY OF ANY KIND, EXPRESS OR 00015 * IMPLIED, INCLUDING BUT NOT LIMITED TO THE WARRANTIES OF MERCHANTABILITY, 00016 * FITNESS FOR A PARTICULAR PURPOSE AND NONINFRINGEMENT. IN NO EVENT SHALL THE 00017 * AUTHORS OR COPYRIGHT HOLDERS BE LIABLE FOR ANY CLAIM, DAMAGES OR OTHER 00018 * LIABILITY, WHETHER IN AN ACTION OF CONTRACT, TORT OR OTHERWISE, ARISING FROM, 00019 * OUT OF OR IN CONNECTION WITH THE SOFTWARE OR THE USE OR OTHER DEALINGS IN THE 00020 * SOFTWARE. 00021 * 00022 * NOTE: This is an unsupported legacy untested library. 00023 */ 00024 #include "SerialHalfDuplex.h" 00025 00026 #if DEVICE_SERIAL 00027 00028 #include "pinmap.h" 00029 #include "serial_api.h" 00030 #include "gpio_api.h" 00031 //#include "RawSerial.h" 00032 00033 namespace mbed { 00034 00035 SerialHalfDuplex::SerialHalfDuplex(PinName tx, PinName rx, const char *name) 00036 : Serial(tx, rx, name) { 00037 _txpin = tx; 00038 00039 // set as input 00040 gpio_set(_txpin); 00041 pin_mode(_txpin, PullNone); // no pull 00042 pin_function(_txpin, 0); // set as gpio 00043 } 00044 00045 // To transmit a byte in half duplex mode: 00046 // 1. Disable interrupts, so we don't trigger on loopback byte 00047 // 2. Set tx pin to UART out 00048 // 3. Transmit byte as normal 00049 // 4. Read back byte from looped back tx pin - this both confirms that the 00050 // transmit has occurred, and also clears the byte from the buffer. 00051 // 5. Return pin to input mode 00052 // 6. Re-enable interrupts 00053 00054 int SerialHalfDuplex::_putc(int c) { 00055 int retc; 00056 00057 // TODO: We should not disable all interrupts 00058 __disable_irq(); 00059 00060 serial_pinout_tx(_txpin); 00061 00062 Serial::_putc(c); 00063 retc = Serial::getc(); // reading also clears any interrupt 00064 00065 pin_function(_txpin, 0); 00066 00067 __enable_irq(); 00068 00069 return retc; 00070 } 00071 00072 int SerialHalfDuplex::_getc(void) { 00073 return Serial::_getc(); 00074 } 00075 00076 } // End namespace 00077 00078 #endif
Generated on Thu Jul 21 2022 19:41:08 by
1.7.2
