From: Nathael Pajani Date: Sun, 7 Dec 2014 22:00:07 +0000 (+0100) Subject: Use const structs for the pio definitions Move the weak definitions outside of the... X-Git-Url: http://git.techno-innov.fr/?a=commitdiff_plain;h=bc58fdef09cc323ea1e9d87cdd9a1fbf76abe77a;p=soft%2Flpc122x%2Fcore Use const structs for the pio definitions Move the weak definitions outside of the driver file, so that the compiler cannot optimise and use the empty "weak" definitions. Next step is to merge all definitions in a single table, and call a single pio config function. --- diff --git a/drivers/adc.c b/drivers/adc.c index fce8721..0868688 100644 --- a/drivers/adc.c +++ b/drivers/adc.c @@ -173,9 +173,7 @@ void adc_prepare_conversion_on_event(uint8_t channels, uint8_t event, int use_in /***************************************************************************** */ /* ADC Setup : private part : Clocks, Pins, Power and Mode */ -struct pio adc_pins[] __attribute__ ((weak)) = { - ARRAY_LAST_PIN, -}; +extern const struct pio adc_pins[]; static void set_adc_pins(void) { diff --git a/drivers/gpio.c b/drivers/gpio.c index be0da15..5c98697 100644 --- a/drivers/gpio.c +++ b/drivers/gpio.c @@ -37,9 +37,7 @@ /* GPIO setup */ /* Set all GPIO used in a default state */ -struct pio gpio_pins[] __attribute__ ((weak)) = { - ARRAY_LAST_PIN, -}; +extern const struct pio gpio_pins[]; static void set_gpio_pins(void) { diff --git a/drivers/i2c.c b/drivers/i2c.c index 3934500..93daec5 100644 --- a/drivers/i2c.c +++ b/drivers/i2c.c @@ -454,9 +454,7 @@ static void i2c_clock_on(uint32_t i2c_clk_freq) } /* I2C Pins configuration */ -struct pio i2c0_pins[] __attribute__ ((weak)) = { - ARRAY_LAST_PIN, -}; +extern const struct pio i2c0_pins[]; static void set_i2c_pins(void) diff --git a/drivers/serial.c b/drivers/serial.c index 24c7d9b..2d1603a 100644 --- a/drivers/serial.c +++ b/drivers/serial.c @@ -235,12 +235,8 @@ static uint32_t uart_setup(uint32_t uart_num) /* Note : We MUST set LPC_IO_DIGITAL for Rx even if the bit is marked as "Reserved" in * the datasheet ! */ -struct pio uart0_pins[] __attribute__ ((weak)) = { - ARRAY_LAST_PIN, -}; -struct pio uart1_pins[] __attribute__ ((weak)) = { - ARRAY_LAST_PIN, -}; +extern const struct pio uart0_pins[]; +extern const struct pio uart1_pins[]; static void uart_set_pin_func(uint32_t uart_num) { diff --git a/drivers/ssp.c b/drivers/ssp.c index cb323dd..8ca73ba 100644 --- a/drivers/ssp.c +++ b/drivers/ssp.c @@ -305,9 +305,7 @@ void ssp_clk_update(void) } /* Configure all SPI pins. */ -struct pio ssp0_pins[] __attribute__ ((weak)) = { - ARRAY_LAST_PIN, -}; +extern const struct pio ssp0_pins[]; static void ssp_set_pin_func(uint32_t ssp_num) { int i = 0; diff --git a/drivers/timers.c b/drivers/timers.c index c66cee2..d00f915 100644 --- a/drivers/timers.c +++ b/drivers/timers.c @@ -220,24 +220,16 @@ int timer_setup(uint32_t timer_num, struct timer_config* conf) /* Setup timer pins to be used as match or capture pin */ -struct pio timer0_pins[] __attribute__ ((weak)) = { - ARRAY_LAST_PIN, -}; -struct pio timer1_pins[] __attribute__ ((weak)) = { - ARRAY_LAST_PIN, -}; -struct pio timer2_pins[] __attribute__ ((weak)) = { - ARRAY_LAST_PIN, -}; -struct pio timer3_pins[] __attribute__ ((weak)) = { - ARRAY_LAST_PIN, -}; +extern const struct pio timer0_pins[]; +extern const struct pio timer1_pins[]; +extern const struct pio timer2_pins[]; +extern const struct pio timer3_pins[]; #define LPC_TIMER_PIN_CONFIG (LPC_IO_MODE_PULL_UP | LPC_IO_DIGITAL | LPC_IO_DRIVE_HIGHCURENT) static void timer_pins_setup(uint32_t timer_num) { int i = 0; - struct pio* timer_pins = NULL; + const struct pio* timer_pins = NULL; switch (timer_num) { case LPC_TIMER_16B0: timer_pins = timer0_pins; diff --git a/drivers/weak_pinout.c b/drivers/weak_pinout.c new file mode 100644 index 0000000..b6bd258 --- /dev/null +++ b/drivers/weak_pinout.c @@ -0,0 +1,68 @@ +/**************************************************************************** + * driver/weak_pinout.c + * + * Copyright 2013-2014 Nathael Pajani + * + * + * This program is free software: you can redistribute it and/or modify + * it under the terms of the GNU General Public License as published by + * the Free Software Foundation, either version 2 of the License, or + * (at your option) any later version. + * + * This program is distributed in the hope that it will be useful, + * but WITHOUT ANY WARRANTY; without even the implied warranty of + * MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the + * GNU General Public License for more details. + * + * You should have received a copy of the GNU General Public License + * along with this program. If not, see . + * + *************************************************************************** */ + + +#include "core/pio.h" + +/***************************************************************************** */ +/* Pins configuration */ +/* List of available pin blocks : + * clkout_pin, uart0_pins, uart1_pins, i2c0_pins, ssp0_pins, + * timer0_pins, timer1_pins, timer2_pins, timer3_pins, + * adc_pins, gpio_pins + * + * This files defines "weak" "empty" pio structures for all of the drivers so + * that the drivers can compile even if the user does not define empty pio + * structures for unused drivers. + * + * These will be overridden by the user definitions. + * + */ +const struct pio uart0_pins[] __attribute__ ((weak)) = { + ARRAY_LAST_PIN, +}; +const struct pio uart1_pins[] __attribute__ ((weak)) = { + ARRAY_LAST_PIN, +}; +const struct pio i2c0_pins[] __attribute__ ((weak)) = { + ARRAY_LAST_PIN, +}; +const struct pio ssp0_pins[] __attribute__ ((weak)) = { + ARRAY_LAST_PIN, +}; +const struct pio timer0_pins[] __attribute__ ((weak)) = { + ARRAY_LAST_PIN, +}; +const struct pio timer1_pins[] __attribute__ ((weak)) = { + ARRAY_LAST_PIN, +}; +const struct pio timer2_pins[] __attribute__ ((weak)) = { + ARRAY_LAST_PIN, +}; +const struct pio timer3_pins[] __attribute__ ((weak)) = { + ARRAY_LAST_PIN, +}; +const struct pio adc_pins[] __attribute__ ((weak)) = { + ARRAY_LAST_PIN, +}; +const struct pio gpio_pins[] __attribute__ ((weak)) = { + ARRAY_LAST_PIN, +};