From 776f90ff2c3701abc15ef246716cae186a53e7d4 Mon Sep 17 00:00:00 2001 From: Markus Hitter Date: Sun, 12 Jul 2015 16:07:51 +0200 Subject: [PATCH] ARM: simplify serial and get rid of mbed-pinmap_common.c. We have only one UART, we use only one UART, so it's pointless to do pin mapping calculations at runtime. Binary size down by 268 bytes: SIZES ARM... lpc1114 FLASH : 1724 bytes 6% RAM : 156 bytes 4% EEPROM : 0 bytes 0% --- Makefile-ARM | 2 +- mbed-pinmap.h | 5 --- mbed-pinmap_common.c | 81 -------------------------------------------- mbed-serial_api.c | 41 ++++------------------ mbed-serial_api.h | 2 -- 5 files changed, 7 insertions(+), 124 deletions(-) delete mode 100644 mbed-pinmap_common.c diff --git a/Makefile-ARM b/Makefile-ARM index e2d6c41..a88b45a 100644 --- a/Makefile-ARM +++ b/Makefile-ARM @@ -98,7 +98,7 @@ TARGET = $(PROGRAM).hex # Until the generic ARM port is completed, we'd have to wrap all sources # in #ifdef __AVR__. To avoid this, build only a selection for now: SOURCES = mendel.c cpu.c serial.c -SOURCES += mbed-serial_api.c mbed-pinmap.c mbed-pinmap_common.c +SOURCES += mbed-serial_api.c mbed-pinmap.c ifeq ($(MCU), lpc1114) SOURCES += mbed-system_LPC11xx.c endif diff --git a/mbed-pinmap.h b/mbed-pinmap.h index f141e3b..eadb962 100644 --- a/mbed-pinmap.h +++ b/mbed-pinmap.h @@ -43,11 +43,6 @@ typedef struct { void pin_function(PinName pin, int function); void pin_mode (PinName pin, PinMode mode); -uint32_t pinmap_peripheral(PinName pin, const PinMap* map); -uint32_t pinmap_merge (uint32_t a, uint32_t b); -void pinmap_pinout (PinName pin, const PinMap *map); -uint32_t pinmap_find_peripheral(PinName pin, const PinMap* map); - #ifdef __cplusplus } #endif diff --git a/mbed-pinmap_common.c b/mbed-pinmap_common.c deleted file mode 100644 index a2cf35d..0000000 --- a/mbed-pinmap_common.c +++ /dev/null @@ -1,81 +0,0 @@ -/* mbed Microcontroller Library - * Copyright (c) 2006-2013 ARM Limited - * - * Licensed under the Apache License, Version 2.0 (the "License"); - * you may not use this file except in compliance with the License. - * You may obtain a copy of the License at - * - * http://www.apache.org/licenses/LICENSE-2.0 - * - * Unless required by applicable law or agreed to in writing, software - * distributed under the License is distributed on an "AS IS" BASIS, - * WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied. - * See the License for the specific language governing permissions and - * limitations under the License. - */ -/* - Notes for Teacup: - - Copied from $(MBED)/libraries/mbed/common/pinmap_common.c. - - Used only to get things running quickly. Without serial it's almost - impossible to see wether code changes work. Should go away soon, because - all this MBED stuff is too bloated for Teacup's purposes. - - - Prefixed names of #include files with mbed- to match the names of the - copies in the Teacup repo. - - Wrapped the whole file in #ifdef __ARMEL__ to not cause conflicts with - AVR builds. -*/ -#ifdef __ARMEL__ -#include "mbed-pinmap.h" - -void pinmap_pinout(PinName pin, const PinMap *map) { - if (pin == NC) - return; - - while (map->pin != NC) { - if (map->pin == pin) { - pin_function(pin, map->function); - - pin_mode(pin, PullNone); - return; - } - map++; - } -} - -uint32_t pinmap_merge(uint32_t a, uint32_t b) { - // both are the same (inc both NC) - if (a == b) - return a; - - // one (or both) is not connected - if (a == (uint32_t)NC) - return b; - if (b == (uint32_t)NC) - return a; - - // mis-match error case - return (uint32_t)NC; -} - -uint32_t pinmap_find_peripheral(PinName pin, const PinMap* map) { - while (map->pin != NC) { - if (map->pin == pin) - return map->peripheral; - map++; - } - return (uint32_t)NC; -} - -uint32_t pinmap_peripheral(PinName pin, const PinMap* map) { - uint32_t peripheral = (uint32_t)NC; - - if (pin == (PinName)NC) - return (uint32_t)NC; - peripheral = pinmap_find_peripheral(pin, map); - - return peripheral; -} -#endif /* __ARMEL__ */ diff --git a/mbed-serial_api.c b/mbed-serial_api.c index fb8f812..d356464 100644 --- a/mbed-serial_api.c +++ b/mbed-serial_api.c @@ -44,22 +44,6 @@ ******************************************************************************/ #define UART_NUM 1 -static const PinMap PinMap_UART_TX[] = { - {P2_8 , UART_0, 0x02}, - {P3_5 , UART_0, 0x02}, - {P3_0 , UART_0, 0x03}, - {P1_7 , UART_0, 0x01}, - {NC , NC , 0x00} -}; - -static const PinMap PinMap_UART_RX[] = { - {P2_7 , UART_0, 0x02}, - {P3_4 , UART_0, 0x02}, - {P3_1 , UART_0, 0x03}, - {P1_6 , UART_0, 0x01}, - {NC , NC , 0x00} -}; - static uint32_t serial_irq_ids[UART_NUM] = {0}; static uart_irq_handler irq_handler; @@ -69,10 +53,7 @@ serial_t stdio_uart; void mbed_serial_init(serial_t *obj, PinName tx, PinName rx) { int is_stdio_uart = 0; - // determine the UART to use - UARTName uart_tx = (UARTName)pinmap_peripheral(tx, PinMap_UART_TX); - UARTName uart_rx = (UARTName)pinmap_peripheral(rx, PinMap_UART_RX); - UARTName uart = (UARTName)pinmap_merge(uart_tx, uart_rx); + UARTName uart = UART_0; obj->uart = (LPC_UART_TypeDef *)uart; LPC_SYSCON->SYSAHBCLKCTRL |= (1<<12); @@ -93,17 +74,11 @@ void mbed_serial_init(serial_t *obj, PinName tx, PinName rx) { mbed_serial_format(obj, 8, ParityNone, 1); // pinout the chosen uart - pinmap_pinout(tx, PinMap_UART_TX); - pinmap_pinout(rx, PinMap_UART_RX); - - // set rx/tx pins in PullUp mode - if (tx != NC) { - pin_mode(tx, PullUp); - } - if (rx != NC) { - pin_mode(rx, PullUp); - } - + pin_function(tx, 0x01); + pin_mode(tx, PullUp); + pin_function(rx, 0x01); + pin_mode(rx, PullUp); + switch (uart) { case UART_0: obj->index = 0; break; } @@ -299,10 +274,6 @@ void mbed_serial_clear(serial_t *obj) { | 0 << 6; // interrupt depth } -void mbed_serial_pinout_tx(PinName tx) { - pinmap_pinout(tx, PinMap_UART_TX); -} - void mbed_serial_break_clear(serial_t *obj) { obj->uart->LCR &= ~(1 << 6); } diff --git a/mbed-serial_api.h b/mbed-serial_api.h index 777fe25..2a1834e 100644 --- a/mbed-serial_api.h +++ b/mbed-serial_api.h @@ -78,8 +78,6 @@ void mbed_serial_clear (serial_t *obj); void mbed_serial_break_set (serial_t *obj); void mbed_serial_break_clear(serial_t *obj); -void mbed_serial_pinout_tx(PinName tx); - void mbed_serial_set_flow_control(serial_t *obj, FlowControl type, PinName rxflow, PinName txflow); #ifdef __cplusplus