Dynamixel controller with CAN interface
Dependencies: AX12_final MX106_not_working comunication_1
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 #include "mbed.h" 00028 #include "pinmap.h" 00029 #include "serial_api.h" 00030 #include "gpio_api.h" 00031 00032 namespace mbed { 00033 00034 SerialHalfDuplex::SerialHalfDuplex(PinName tx, PinName rx, const char *name) 00035 : Serial(tx, rx, name) { 00036 _txpin = tx; 00037 00038 DigitalIn TXPIN(_txpin); // set as input 00039 pin_mode(_txpin, PullNone); // no pull 00040 pin_function(_txpin, 0); // set as gpio 00041 } 00042 00043 // To transmit a byte in half duplex mode: 00044 // 1. Disable interrupts, so we don't trigger on loopback byte 00045 // 2. Set tx pin to UART out 00046 // 3. Transmit byte as normal 00047 // 4. Read back byte from looped back tx pin - this both confirms that the 00048 // transmit has occurred, and also clears the byte from the buffer. 00049 // 5. Return pin to input mode 00050 // 6. Re-enable interrupts 00051 00052 int SerialHalfDuplex::_putc(int c) { 00053 int retc; 00054 00055 // TODO: We should not disable all interrupts 00056 __disable_irq(); 00057 00058 serial_pinout_tx(_txpin); 00059 00060 Serial::_putc(c); 00061 retc = Serial::getc(); // reading also clears any interrupt 00062 00063 pin_function(_txpin, 0); 00064 00065 __enable_irq(); 00066 00067 return retc; 00068 } 00069 00070 int SerialHalfDuplex::_getc(void) { 00071 return Serial::_getc(); 00072 } 00073 00074 } // End namespace 00075 00076 #endif
Generated on Wed Jul 13 2022 20:13:56 by 1.7.2