need to use Dynamixel

Dependents:   YOZAKURA_ARM YOZAKURA_ARM_USB YOZAKURA_ARM_USB_Keyboard YOZAKURA_ARM_Keyboard0424 ... more

Fork of SerialHalfDuplex by Aimen Al-Refai

Committer:
mbed_unsupported
Date:
Thu Dec 06 12:46:52 2012 +0000
Revision:
0:7802a25daf3b
Child:
1:8fd1fa67565e
Serial Half-Duplex

Who changed what in which revision?

UserRevisionLine numberNew contents of line
mbed_unsupported 0:7802a25daf3b 1 /* mbed Microcontroller Library
mbed_unsupported 0:7802a25daf3b 2 * Copyright (c) 2006-2012 ARM Limited
mbed_unsupported 0:7802a25daf3b 3 *
mbed_unsupported 0:7802a25daf3b 4 * Permission is hereby granted, free of charge, to any person obtaining a copy
mbed_unsupported 0:7802a25daf3b 5 * of this software and associated documentation files (the "Software"), to deal
mbed_unsupported 0:7802a25daf3b 6 * in the Software without restriction, including without limitation the rights
mbed_unsupported 0:7802a25daf3b 7 * to use, copy, modify, merge, publish, distribute, sublicense, and/or sell
mbed_unsupported 0:7802a25daf3b 8 * copies of the Software, and to permit persons to whom the Software is
mbed_unsupported 0:7802a25daf3b 9 * furnished to do so, subject to the following conditions:
mbed_unsupported 0:7802a25daf3b 10 *
mbed_unsupported 0:7802a25daf3b 11 * The above copyright notice and this permission notice shall be included in
mbed_unsupported 0:7802a25daf3b 12 * all copies or substantial portions of the Software.
mbed_unsupported 0:7802a25daf3b 13 *
mbed_unsupported 0:7802a25daf3b 14 * THE SOFTWARE IS PROVIDED "AS IS", WITHOUT WARRANTY OF ANY KIND, EXPRESS OR
mbed_unsupported 0:7802a25daf3b 15 * IMPLIED, INCLUDING BUT NOT LIMITED TO THE WARRANTIES OF MERCHANTABILITY,
mbed_unsupported 0:7802a25daf3b 16 * FITNESS FOR A PARTICULAR PURPOSE AND NONINFRINGEMENT. IN NO EVENT SHALL THE
mbed_unsupported 0:7802a25daf3b 17 * AUTHORS OR COPYRIGHT HOLDERS BE LIABLE FOR ANY CLAIM, DAMAGES OR OTHER
mbed_unsupported 0:7802a25daf3b 18 * LIABILITY, WHETHER IN AN ACTION OF CONTRACT, TORT OR OTHERWISE, ARISING FROM,
mbed_unsupported 0:7802a25daf3b 19 * OUT OF OR IN CONNECTION WITH THE SOFTWARE OR THE USE OR OTHER DEALINGS IN THE
mbed_unsupported 0:7802a25daf3b 20 * SOFTWARE.
mbed_unsupported 0:7802a25daf3b 21 *
mbed_unsupported 0:7802a25daf3b 22 * NOTE: This is an unsupported legacy untested library.
mbed_unsupported 0:7802a25daf3b 23 */
mbed_unsupported 0:7802a25daf3b 24 #include "SerialHalfDuplex.h"
mbed_unsupported 0:7802a25daf3b 25
mbed_unsupported 0:7802a25daf3b 26 #if DEVICE_SERIAL
mbed_unsupported 0:7802a25daf3b 27
mbed_unsupported 0:7802a25daf3b 28 #include "pinmap.h"
mbed_unsupported 0:7802a25daf3b 29 #include "serial_api.h"
mbed_unsupported 0:7802a25daf3b 30 #include "gpio_api.h"
mbed_unsupported 0:7802a25daf3b 31
mbed_unsupported 0:7802a25daf3b 32 namespace mbed {
mbed_unsupported 0:7802a25daf3b 33
mbed_unsupported 0:7802a25daf3b 34 SerialHalfDuplex::SerialHalfDuplex(PinName tx, PinName rx, const char *name)
mbed_unsupported 0:7802a25daf3b 35 : Serial(tx, rx, name) {
mbed_unsupported 0:7802a25daf3b 36 _txpin = tx;
mbed_unsupported 0:7802a25daf3b 37
mbed_unsupported 0:7802a25daf3b 38 gpio_input(_txpin); // set as input
mbed_unsupported 0:7802a25daf3b 39 pin_mode(_txpin, PullNone); // no pull
mbed_unsupported 0:7802a25daf3b 40 pin_function(_txpin, 0); // set as gpio
mbed_unsupported 0:7802a25daf3b 41 }
mbed_unsupported 0:7802a25daf3b 42
mbed_unsupported 0:7802a25daf3b 43 // To transmit a byte in half duplex mode:
mbed_unsupported 0:7802a25daf3b 44 // 1. Disable interrupts, so we don't trigger on loopback byte
mbed_unsupported 0:7802a25daf3b 45 // 2. Set tx pin to UART out
mbed_unsupported 0:7802a25daf3b 46 // 3. Transmit byte as normal
mbed_unsupported 0:7802a25daf3b 47 // 4. Read back byte from looped back tx pin - this both confirms that the
mbed_unsupported 0:7802a25daf3b 48 // transmit has occurred, and also clears the byte from the buffer.
mbed_unsupported 0:7802a25daf3b 49 // 5. Return pin to input mode
mbed_unsupported 0:7802a25daf3b 50 // 6. Re-enable interrupts
mbed_unsupported 0:7802a25daf3b 51
mbed_unsupported 0:7802a25daf3b 52 int SerialHalfDuplex::_putc(int c) {
mbed_unsupported 0:7802a25daf3b 53 int retc;
mbed_unsupported 0:7802a25daf3b 54
mbed_unsupported 0:7802a25daf3b 55 // TODO: We should not disable all interrupts
mbed_unsupported 0:7802a25daf3b 56 __disable_irq();
mbed_unsupported 0:7802a25daf3b 57
mbed_unsupported 0:7802a25daf3b 58 serial_pinout_tx(_txpin);
mbed_unsupported 0:7802a25daf3b 59
mbed_unsupported 0:7802a25daf3b 60 Serial::_putc(c);
mbed_unsupported 0:7802a25daf3b 61 retc = Serial::getc(); // reading also clears any interrupt
mbed_unsupported 0:7802a25daf3b 62
mbed_unsupported 0:7802a25daf3b 63 pin_function(_txpin, 0);
mbed_unsupported 0:7802a25daf3b 64
mbed_unsupported 0:7802a25daf3b 65 __enable_irq();
mbed_unsupported 0:7802a25daf3b 66
mbed_unsupported 0:7802a25daf3b 67 return retc;
mbed_unsupported 0:7802a25daf3b 68 }
mbed_unsupported 0:7802a25daf3b 69
mbed_unsupported 0:7802a25daf3b 70 int SerialHalfDuplex::_getc(void) {
mbed_unsupported 0:7802a25daf3b 71 return Serial::_getc();
mbed_unsupported 0:7802a25daf3b 72 }
mbed_unsupported 0:7802a25daf3b 73
mbed_unsupported 0:7802a25daf3b 74 } // End namespace
mbed_unsupported 0:7802a25daf3b 75
mbed_unsupported 0:7802a25daf3b 76 #endif