diff options
Diffstat (limited to 'platforms/avr')
-rw-r--r-- | platforms/avr/_wait.h | 2 | ||||
-rw-r--r-- | platforms/avr/drivers/i2c_master.c | 2 | ||||
-rw-r--r-- | platforms/avr/drivers/i2c_master.h | 51 | ||||
-rw-r--r-- | platforms/avr/drivers/i2c_slave.h | 4 | ||||
-rw-r--r-- | platforms/avr/drivers/spi_master.h | 68 | ||||
-rw-r--r-- | platforms/avr/drivers/uart.h | 39 | ||||
-rw-r--r-- | platforms/avr/gpio.h | 6 | ||||
-rw-r--r-- | platforms/avr/platform.mk | 13 | ||||
-rw-r--r-- | platforms/avr/timer.c | 28 |
9 files changed, 18 insertions, 195 deletions
diff --git a/platforms/avr/_wait.h b/platforms/avr/_wait.h index 39cbf618d2..54f578ace0 100644 --- a/platforms/avr/_wait.h +++ b/platforms/avr/_wait.h @@ -21,6 +21,8 @@ #include <util/delay.h> #pragma GCC diagnostic pop +extern void __builtin_avr_delay_cycles(uint32_t); + // http://ww1.microchip.com/downloads/en/devicedoc/atmel-0856-avr-instruction-set-manual.pdf // page 22: Table 4-2. Arithmetic and Logic Instructions /* diff --git a/platforms/avr/drivers/i2c_master.c b/platforms/avr/drivers/i2c_master.c index 64083d862a..9136f4a7b9 100644 --- a/platforms/avr/drivers/i2c_master.c +++ b/platforms/avr/drivers/i2c_master.c @@ -315,4 +315,4 @@ __attribute__((weak)) i2c_status_t i2c_ping_address(uint8_t address, uint16_t ti i2c_status_t status = i2c_start(address, timeout); i2c_stop(); return status; -}
\ No newline at end of file +} diff --git a/platforms/avr/drivers/i2c_master.h b/platforms/avr/drivers/i2c_master.h deleted file mode 100644 index b797997619..0000000000 --- a/platforms/avr/drivers/i2c_master.h +++ /dev/null @@ -1,51 +0,0 @@ -/* Copyright (C) 2019 Elia Ritterbusch - + - * 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 3 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 <https://www.gnu.org/licenses/>. - */ -/* Library made by: g4lvanix - * GitHub repository: https://github.com/g4lvanix/I2C-master-lib - */ - -#pragma once - -#include <stdint.h> - -// ### DEPRECATED - DO NOT USE ### -#define i2c_writeReg(devaddr, regaddr, data, length, timeout) i2c_write_register(devaddr, regaddr, data, length, timeout) -#define i2c_writeReg16(devaddr, regaddr, data, length, timeout) i2c_write_register16(devaddr, regaddr, data, length, timeout) -#define i2c_readReg(devaddr, regaddr, data, length, timeout) i2c_read_register(devaddr, regaddr, data, length, timeout) -#define i2c_readReg16(devaddr, regaddr, data, length, timeout) i2c_read_register16(devaddr, regaddr, data, length, timeout) -// ############################### - -#define I2C_READ 0x01 -#define I2C_WRITE 0x00 - -typedef int16_t i2c_status_t; - -#define I2C_STATUS_SUCCESS (0) -#define I2C_STATUS_ERROR (-1) -#define I2C_STATUS_TIMEOUT (-2) - -#define I2C_TIMEOUT_IMMEDIATE (0) -#define I2C_TIMEOUT_INFINITE (0xFFFF) - -void i2c_init(void); -i2c_status_t i2c_transmit(uint8_t address, const uint8_t* data, uint16_t length, uint16_t timeout); -i2c_status_t i2c_transmit_P(uint8_t address, const uint8_t* data, uint16_t length, uint16_t timeout); -i2c_status_t i2c_receive(uint8_t address, uint8_t* data, uint16_t length, uint16_t timeout); -i2c_status_t i2c_write_register(uint8_t devaddr, uint8_t regaddr, const uint8_t* data, uint16_t length, uint16_t timeout); -i2c_status_t i2c_write_register16(uint8_t devaddr, uint16_t regaddr, const uint8_t* data, uint16_t length, uint16_t timeout); -i2c_status_t i2c_read_register(uint8_t devaddr, uint8_t regaddr, uint8_t* data, uint16_t length, uint16_t timeout); -i2c_status_t i2c_read_register16(uint8_t devaddr, uint16_t regaddr, uint8_t* data, uint16_t length, uint16_t timeout); -i2c_status_t i2c_ping_address(uint8_t address, uint16_t timeout); diff --git a/platforms/avr/drivers/i2c_slave.h b/platforms/avr/drivers/i2c_slave.h index 178b6a29df..8614bd865a 100644 --- a/platforms/avr/drivers/i2c_slave.h +++ b/platforms/avr/drivers/i2c_slave.h @@ -22,6 +22,8 @@ #pragma once +#include "compiler_support.h" + #ifndef I2C_SLAVE_REG_COUNT # if defined(USE_I2C) && defined(SPLIT_COMMON_TRANSACTIONS) @@ -33,7 +35,7 @@ #endif // I2C_SLAVE_REG_COUNT -_Static_assert(I2C_SLAVE_REG_COUNT < 256, "I2C target registers must be single byte"); +STATIC_ASSERT(I2C_SLAVE_REG_COUNT < 256, "I2C target registers must be single byte"); extern volatile uint8_t i2c_slave_reg[I2C_SLAVE_REG_COUNT]; diff --git a/platforms/avr/drivers/spi_master.h b/platforms/avr/drivers/spi_master.h deleted file mode 100644 index ebbf7ddeab..0000000000 --- a/platforms/avr/drivers/spi_master.h +++ /dev/null @@ -1,68 +0,0 @@ -/* Copyright 2020 - * - * 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 3 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 <https://www.gnu.org/licenses/>. - */ - -#pragma once - -#include <stdbool.h> - -#include "gpio.h" - -typedef int16_t spi_status_t; - -// Hardware SS pin is defined in the header so that user code can refer to it -#if defined(__AVR_AT90USB162__) || defined(__AVR_ATmega16U2__) || defined(__AVR_ATmega32U2__) || defined(__AVR_ATmega16U4__) || defined(__AVR_ATmega32U4__) || defined(__AVR_AT90USB646__) || defined(__AVR_AT90USB647__) || defined(__AVR_AT90USB1286__) || defined(__AVR_AT90USB1287__) -# define SPI_SS_PIN B0 -#elif defined(__AVR_ATmega32A__) -# define SPI_SS_PIN B4 -#elif defined(__AVR_ATmega328P__) || defined(__AVR_ATmega328__) -# define SPI_SS_PIN B2 -#endif - -#define SPI_STATUS_SUCCESS (0) -#define SPI_STATUS_ERROR (-1) -#define SPI_STATUS_TIMEOUT (-2) - -#define SPI_TIMEOUT_IMMEDIATE (0) -#define SPI_TIMEOUT_INFINITE (0xFFFF) - -#ifdef __cplusplus -extern "C" { -#endif -typedef struct spi_start_config_t { - pin_t slave_pin; - bool lsb_first; - uint8_t mode; - uint16_t divisor; - bool cs_active_low; -} spi_start_config_t; - -void spi_init(void); - -bool spi_start(pin_t slavePin, bool lsbFirst, uint8_t mode, uint16_t divisor); -bool spi_start_extended(spi_start_config_t *start_config); - -spi_status_t spi_write(uint8_t data); - -spi_status_t spi_read(void); - -spi_status_t spi_transmit(const uint8_t *data, uint16_t length); - -spi_status_t spi_receive(uint8_t *data, uint16_t length); - -void spi_stop(void); -#ifdef __cplusplus -} -#endif diff --git a/platforms/avr/drivers/uart.h b/platforms/avr/drivers/uart.h deleted file mode 100644 index e2dc664eda..0000000000 --- a/platforms/avr/drivers/uart.h +++ /dev/null @@ -1,39 +0,0 @@ -/* UART Example for Teensy USB Development Board - * http://www.pjrc.com/teensy/ - * Copyright (c) 2009 PJRC.COM, LLC - * - * Permission is hereby granted, free of charge, to any person obtaining a copy - * of this software and associated documentation files (the "Software"), to deal - * in the Software without restriction, including without limitation the rights - * to use, copy, modify, merge, publish, distribute, sublicense, and/or sell - * copies of the Software, and to permit persons to whom the Software is - * furnished to do so, subject to the following conditions: - * - * The above copyright notice and this permission notice shall be included in - * all copies or substantial portions of the Software. - * - * THE SOFTWARE IS PROVIDED "AS IS", WITHOUT WARRANTY OF ANY KIND, EXPRESS OR - * IMPLIED, INCLUDING BUT NOT LIMITED TO THE WARRANTIES OF MERCHANTABILITY, - * FITNESS FOR A PARTICULAR PURPOSE AND NONINFRINGEMENT. IN NO EVENT SHALL THE - * AUTHORS OR COPYRIGHT HOLDERS BE LIABLE FOR ANY CLAIM, DAMAGES OR OTHER - * LIABILITY, WHETHER IN AN ACTION OF CONTRACT, TORT OR OTHERWISE, ARISING FROM, - * OUT OF OR IN CONNECTION WITH THE SOFTWARE OR THE USE OR OTHER DEALINGS IN - * THE SOFTWARE. - */ - -#pragma once - -#include <stdint.h> -#include <stdbool.h> - -void uart_init(uint32_t baud); - -void uart_write(uint8_t data); - -uint8_t uart_read(void); - -void uart_transmit(const uint8_t *data, uint16_t length); - -void uart_receive(uint8_t *data, uint16_t length); - -bool uart_available(void); diff --git a/platforms/avr/gpio.h b/platforms/avr/gpio.h index 6f089bc663..4c09619772 100644 --- a/platforms/avr/gpio.h +++ b/platforms/avr/gpio.h @@ -16,6 +16,8 @@ #pragma once #include <avr/io.h> + +#include "compiler_support.h" #include "pin_defs.h" typedef uint8_t pin_t; @@ -24,9 +26,9 @@ typedef uint8_t pin_t; #define gpio_set_pin_input(pin) (DDRx_ADDRESS(pin) &= ~_BV((pin)&0xF), PORTx_ADDRESS(pin) &= ~_BV((pin)&0xF)) #define gpio_set_pin_input_high(pin) (DDRx_ADDRESS(pin) &= ~_BV((pin)&0xF), PORTx_ADDRESS(pin) |= _BV((pin)&0xF)) -#define gpio_set_pin_input_low(pin) _Static_assert(0, "GPIO pulldowns in input mode are not available on AVR") +#define gpio_set_pin_input_low(pin) STATIC_ASSERT(0, "GPIO pulldowns in input mode are not available on AVR") #define gpio_set_pin_output_push_pull(pin) (DDRx_ADDRESS(pin) |= _BV((pin)&0xF)) -#define gpio_set_pin_output_open_drain(pin) _Static_assert(0, "Open-drain outputs are not available on AVR") +#define gpio_set_pin_output_open_drain(pin) STATIC_ASSERT(0, "Open-drain outputs are not available on AVR") #define gpio_set_pin_output(pin) gpio_set_pin_output_push_pull(pin) #define gpio_write_pin_high(pin) (PORTx_ADDRESS(pin) |= _BV((pin)&0xF)) diff --git a/platforms/avr/platform.mk b/platforms/avr/platform.mk index a625f2e5d0..f0187457b3 100644 --- a/platforms/avr/platform.mk +++ b/platforms/avr/platform.mk @@ -12,9 +12,10 @@ HEX = $(OBJCOPY) -O $(FORMAT) -R .eeprom -R .fuse -R .lock -R .signature EEP = $(OBJCOPY) -j .eeprom --set-section-flags=.eeprom="alloc,load" --change-section-lma .eeprom=0 --no-change-warnings -O $(FORMAT) BIN = -ifeq ("$(shell echo "int main(){}" | $(CC) --param=min-pagesize=0 -x c - -o /dev/null 2>&1)", "") -COMPILEFLAGS += --param=min-pagesize=0 -endif +COMPILEFLAGS += $(call cc-option,--param=min-pagesize=0) + +# Fix ICE's: https://gcc.gnu.org/bugzilla/show_bug.cgi?id=116389 +COMPILEFLAGS += $(call cc-option,-mlra) COMPILEFLAGS += -funsigned-char COMPILEFLAGS += -funsigned-bitfields @@ -25,10 +26,12 @@ COMPILEFLAGS += -fshort-enums COMPILEFLAGS += -mcall-prologues COMPILEFLAGS += -fno-builtin-printf -# Linker relaxation is only possible if -# link time optimizations are not enabled. +# On older compilers, linker relaxation is only possible if link time optimizations are not enabled. ifeq ($(strip $(LTO_ENABLE)), no) COMPILEFLAGS += -mrelax +else + # Newer compilers may support both, so quickly check before adding `-mrelax`. + COMPILEFLAGS += $(call cc-option,-mrelax,,-flto=auto) endif ASFLAGS += $(AVR_ASFLAGS) diff --git a/platforms/avr/timer.c b/platforms/avr/timer.c index 26ba0e29fa..b2230ad84b 100644 --- a/platforms/avr/timer.c +++ b/platforms/avr/timer.c @@ -125,34 +125,6 @@ inline uint32_t timer_read32(void) { return t; } -/** \brief timer elapsed - * - * FIXME: needs doc - */ -inline uint16_t timer_elapsed(uint16_t last) { - uint32_t t; - - ATOMIC_BLOCK(ATOMIC_RESTORESTATE) { - t = timer_count; - } - - return TIMER_DIFF_16((t & 0xFFFF), last); -} - -/** \brief timer elapsed32 - * - * FIXME: needs doc - */ -inline uint32_t timer_elapsed32(uint32_t last) { - uint32_t t; - - ATOMIC_BLOCK(ATOMIC_RESTORESTATE) { - t = timer_count; - } - - return TIMER_DIFF_32(t, last); -} - // excecuted once per 1ms.(excess for just timer count?) #ifndef __AVR_ATmega32A__ # define TIMER_INTERRUPT_VECTOR TIMER0_COMPA_vect |