d

Dependencies:   AX12_final MX106_not_working comunication_1 mbed-dev

Fork of MX106-finaltest by Team DIANA

Committer:
clynamen
Date:
Thu Nov 24 15:29:50 2016 +0000
Revision:
12:6ac3cac5677c
Parent:
1:946c65496383
dynamixel

Who changed what in which revision?

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