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:
yusuke_kyo
Date:
Thu Apr 16 02:17:54 2015 +0000
Revision:
4:9fdccecae31f
Parent:
3:8eeadefbee4e
pc.getc()

Who changed what in which revision?

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