1
0
mirror of https://github.com/RIOT-OS/RIOT.git synced 2024-12-29 04:50:03 +01:00
Commit Graph

94 Commits

Author SHA1 Message Date
Marian Buschsieweke
36e8526046
drivers/periph_gpio_ll: change API to access GPIO ports
The API was based on the assumption that GPIO ports are mapped in memory
sanely, so that a `GPIO_PORT(num)` macro would work allow for constant
folding when `num` is known and still be efficient when it is not.

Some MCUs, however, will need a look up tables to efficiently translate
GPIO port numbers to the port's base address. This will prevent the use
of such a `GPIO_PORT(num)` macro in constant initializers.

As a result, we rather provide `GPIO_PORT_0`, `GPIO_PORT_1`, etc. macros
for each GPIO port present (regardless of MCU naming scheme), as well as
`GPIO_PORT_A`, `GPIO_PORT_B`, etc. macros if (and only if) the MCU port
naming scheme uses letters rather than numbers.

These can be defined as macros to the peripheral base address even when
those are randomly mapped into the address space. In addition, a C
function `gpio_port()` replaces the role of the `GPIO_PORT()` and
`gpio_port_num()` the `GPIO_PORT_NUM()` macro. Those functions will
still be implemented as efficient as possible and will allow constant
folding where it was formerly possible. Hence, there is no downside for
MCUs with sane peripheral memory mapping, but it is highly beneficial
for the crazy ones.

There are also two benefits for the non-crazy MCUs:
1. We can now test for valid port numbers with `#ifdef GPIO_PORT_<NUM>`
    - This directly benefits the test in `tests/periph/gpio_ll`, which
      can now provide a valid GPIO port for each and every board
    - Writing to invalid memory mapped I/O addresses was treated as
      triggering undefined behavior by the compiler and used as a
      optimization opportunity
2. We can now detect at compile time if the naming scheme of the MCU
   uses letters or numbers, and produce more user friendly output.
    - This is directly applied in the test app
2024-08-02 09:55:24 +02:00
Marian Buschsieweke
c011764022
cpu/atmega_common: implement gpio_ll_switch_dir 2024-02-05 10:56:16 +01:00
Marian Buschsieweke
f3bd3476ee
cpu/atmega_common: Make GPIO_DISCONNECT alias for GPIO_INPUT
Since on ATmega GPIOs cannot be disconnected and the reset state is
them being an input, this may help making code more portable.
2024-01-23 15:03:34 +01:00
Marian Buschsieweke
2a00ec13e5
drivers/periph/gpio_ll: shrink gpio_conf_t
This commit optimizes the `gpio_conf_t` type in the following
regards:

- The "base" `gpio_conf_t` is stripped from members that only some
  platforms support, e.g. drive strength, slew rate, and disabling of
  the Schmitt Trigger are no longer universally available but
  platform-specific extensions
- The `gpio_conf_t` is now crammed into a bit-field that is 8 bit or
  16 bit wide. This allows for storing lots of them e.g. in
  `driver_foo_params_t` or `uart_conf_t` etc.
- A `union` of the `struct` with bit-field members and a `bits` is used
  to allow accessing all bits in a simple C statement and to ensure
  alignment for efficient handling of the type

Co-authored-by: Gunar Schorcht <gunar@schorcht.net>
2024-01-21 08:38:40 +01:00
Gerson Fernando Budke
c64a64f549
cpu/atmega_common: Increase stack a little bit
This is necessary to allow run the thread_duel example.

Signed-off-by: Gerson Fernando Budke <nandojve@gmail.com>
2023-12-01 14:12:24 +01:00
Hugues Larrive
6336672c08 cpu/atmega_common: checking features instead of CPU models 2023-07-04 23:17:21 +02:00
chudov
c52f6e71c2 drivers/at86rf2xx: rx timestamp generation for ATmegaRFR2
Signed-off-by: chudov <chudov@gmail.com>
2023-05-19 15:33:15 +02:00
Marian Buschsieweke
4e3c0777fc
sys/flash_utils: add helpers for placing variables in flash
This adds a layer of convenience abstraction over classical Harvard
architectures (like most AVRs) that do not map the flash memory into
the data address space and modern Harvard architectures or von-Neumann
architectures that do so. The motivation is to safe a lot of RAM for
AVR by storing constant strings into flash.
2023-02-27 12:31:03 +01:00
benpicco
a1ee44e114
Merge pull request #18263 from maribu/cpu/avr8/idle_stack
cpu/{atmega_common,atxmega}: increase idle thread stack size
2022-06-29 00:57:57 +02:00
Marian Buschsieweke
b72cafb169
cpu/atmega_common: Fix atmega_port_addr()
In 04ab5a74f3 a bug was introduced in
the calculation of the GPIO port address by refactoring code. This
fixes the issue by extracting the GPIO port first from the pin.
2022-06-27 22:15:52 +02:00
Marian Buschsieweke
8cc0199437
cpu/{atmega_common,atxmega}: increase idle thread stack size
Our AVR port doesn't make use of an ISR stack and just victimizes the
stack of whatever thread happens to be running, which in most cases is
the idle thread. Hence, the idle stack has to be large enough to
support the ztimer ISR.
2022-06-27 14:39:57 +02:00
Marian Buschsieweke
04ab5a74f3
cpu/atmega_common: implement periph/gpio_ll{,_irq}
Co-authored-by: Gunar Schorcht <gunar@schorcht.net>
Co-authored-by: Alexandre Abadie <alexandre.abadie@inria.fr>
2022-05-02 14:44:55 +02:00
b7e9d4fad2 cpu/atmega_common: also enlarge idle stack for ztimer64 2021-12-08 13:49:25 +01:00
Jan Romann
4384795cb9
treewide: Remove excessive newlines 2021-08-13 19:50:38 +02:00
Gerson Fernando Budke
4cbd311196 cpu: Refact atmega_common into avr8_common
Split atmega_common code into avr8_common folder.  This moves common
avr8 code to be used for all avr8 variants: tiny, mega and xmega.

Signed-off-by: Gerson Fernando Budke <nandojve@gmail.com>
2021-01-07 16:29:22 -03:00
Gerson Fernando Budke
a0028a9ff8 cpu/atmega_common: Split cpu.c into atmega_cpu/cpu.c
Split cpu.c file into cpu.c and atmega_cpu.c files.  This extract mega
specific code from common code.

Signed-off-by: Gerson Fernando Budke <nandojve@gmail.com>
2021-01-07 16:17:05 -03:00
Gerson Fernando Budke
4d68dd5aea cpu/atmega_common: Extract clock definitions
Refactor clock definitions from cpu.h to clock.h.

Signed-off-by: Gerson Fernando Budke <nandojve@gmail.com>
2021-01-07 16:17:05 -03:00
Marian Buschsieweke
dd48ced151
cpu/*/atomic_utils_arch.h: Add volatile qualifier 2020-11-24 14:00:52 +01:00
792e031a95
Merge pull request #14331 from maribu/atomic_utils
sys/atomic_utils: Functions for atomic access
2020-11-12 21:44:53 +01:00
Marian Buschsieweke
a892c1aa23
cpu/atmega_common: Add atomic_utils_arch.h 2020-11-10 10:55:14 +01:00
Marian Buschsieweke
4abbda5b3e
cpu/atmega_common: Add architecture_arch.h 2020-09-29 12:33:59 +02:00
Marian Buschsieweke
040bad0425
cpu/atmega_common: increase stack size with xtimer
If a timer triggers while the idle thread is running, previously a stack
overflow was triggered. This commit increases the idle threads stack size if
xtimer is used.
2020-07-27 16:52:36 +02:00
benpicco
8a2b089cd5
Merge pull request #14098 from maribu/atmega-timer
cpu/atmega_common: Fix periph_timer
2020-05-28 13:23:22 +02:00
Marian Buschsieweke
99bd1c318c
cpu/atmega_common/periph_timer: Add timer_set
Added a low level implementation of timer_set() that allows setting relative
timeouts as short as 0. This results in tests/periph_timer_short_relative_set
no passing.
2020-05-28 11:46:02 +02:00
Marian Buschsieweke
9e566370bf
cpu/atmega_common: Fixed irq_arch implementation
The inline assembly implementation was badly in need of improvement.

- irq_disable() took 2 CPU cycles more than needed
    - The current interrupt state was stored in a temporary register and
      afterwards copied to the target register, rather than storing it in the
      target register right away
    - The lower bits of the state were cleared (as they have no meaning for the
      interrupt status), but the API purposely never required such things from
      implementations.
- irq_restore() took 5 CPU cycles. This was reduced to 3 CPU cycles (or 2 CPU
  cycles in the best case)
2020-05-26 15:19:14 +02:00
Marian Buschsieweke
ba5844098d
cpu/atmega_common: Make irq_arch inline-able
- Moved irq_arch.c to irq_arch.h and marked all functions as
  `__attribute__((always_inline)) static inline`
2020-05-17 18:41:11 +02:00
Marian Buschsieweke
4d1a5b9256
cpu/atmega_common: Drop legacy include
Drop `#include "irq.h"` in `cpu.h`, which was there for a legacy work around.
A bunch of missing includes of `irq.h` materialized due to this and were
fixed.
2020-05-15 11:24:28 +02:00
84745365fd cpu: atmega_common: make THREAD_STACKSIZE_IDLE configurable 2020-03-12 13:01:13 +01:00
Marian Buschsieweke
1879f58512
cpu/atmega_common: Cleanup state flags
- Use one byte of RAM to track both IRQ and UART TX state
- Fix incorrect use of volatile
2020-02-06 15:41:41 +01:00
Sebastian Meiling
91cff05a15 doc: use @name for doxygen groups 2020-01-28 15:46:09 +01:00
Sebastian Meiling
2eae1952f7 doc: fix doxygen groups for atmega cpus 2020-01-28 15:44:29 +01:00
chudov
efa9bb88a2 cpu/atmega256rfr2: symbol counter based RTT support 2019-12-05 22:53:05 +01:00
Matthew Blue
fb211c7c0c cpu/atmega_common: initial RTT support 2019-12-01 17:26:24 +01:00
41e29e3fda
Merge pull request #12790 from maribu/atmega_isr_thread
cpu/atmega_common
2019-11-24 11:10:10 +01:00
Marian Buschsieweke
606d72f64b
cpu/atmega_common: Clean up & fix IRQ handling
At the end of an ISR, the ATmega code was doing an `thread_yield()` instead of
 a `thread_yield_higher()`. This resulted in tests/isr_yield_higher failing.
 Fixing this saves a few lines of code, some ROM, and solves the issue.
2019-11-23 11:57:11 +01:00
Marian Buschsieweke
2b1bee750a
cpu/atmega_common: Stop using reserved names
Names with two leading underscores are reserved in any context of the c
 standard, and thus must not be used. This ATmega platform used it however for
 defining internal stuff. This commit fixes this.
2019-11-23 11:56:11 +01:00
benpicco
09f647eee2
Merge pull request #12693 from maribu/neopixel-atmega
drivers: Added WS281x RGB LED driver for ATmega platform
2019-11-22 22:36:36 +01:00
Yegor Yefremov
cf65070b06 doxygen/GPIO: don't include overridden typedefs
Add missing #ifndefs to overridden GPIO typedefs.

Signed-off-by: Yegor Yefremov <yegorslists@googlemail.com>
2019-11-15 10:35:33 +01:00
Yegor Yefremov
fa3b0ff04b doxygen/SPI: don't include overridden typedefs
Add missing #ifndefs to overridden SPI typedefs.

Signed-off-by: Yegor Yefremov <yegorslists@googlemail.com>
2019-11-15 10:35:32 +01:00
Marian Buschsieweke
ba26aed107
cpu/atmega_common: Restructured code
Moved macros and static inline helper functions needed to access ATmega GPIOs
to cpu/atmega_common/include/atmega_gpio.h in order to reuse them for the
platform specific low level part of the Neopixel driver.
2019-11-12 20:15:59 +01:00
Benjamin Valentin
5b6d56efd5 atmega_common: provide CPU ID for every device
ATmega128RFA1/ATmega256RFR2 do not have a unique CPU ID.

Use the RC oscillator callibration byte as an impromptu CPU ID and rely
on bootlader constants present on all ATmega families for the remaining
bytes.

This way we can provide a faux CPU ID on all ATmega MCUs and typical hobbyists
with no access to JTAG adapters or high voltage programmer capable of writing
the user signature have a good chance that the CPU IDs of their device do not collide.
2019-11-08 16:58:03 +01:00
d22404b8b7
cpu/atmega_common: add implementation for watchdog 2019-11-07 11:35:29 +01:00
Marian Buschsieweke
314184adb5
cpu: Platform specific C11 atomics compat headers
Added headers to define platform specific sizes and types for the C11 atomics
compatibility module for C++.
2019-10-24 23:08:36 +02:00
Gunar Schorcht
4b009649c6 cpu/atmega_common: changes for common heap command 2019-09-05 09:20:55 +02:00
Thomas Perrot
44803ea4fd
cpu/atmega32u4: add support for ATmega32U4 2019-05-24 15:12:47 +02:00
Sebastian Meiling
0edf76d362
Merge pull request #9984 from kaspar030/refactor_atmega_libc
cpu/atmega_common: refactor AVR libc code into module
2019-01-22 08:41:37 +01:00
7313525035 atmega_common: refactor avr-libc-extra into avr_libc_extra module 2019-01-21 14:37:08 +01:00
c97bedcd8b cpu/atmega_common: define eeprom clear byte value 2018-12-04 11:24:57 +01:00
Victor Arino
2ebb187ca9 cpu/atmega-common: PWM implementation
Implementation of PWM with 8-bit timers
2018-11-28 16:00:54 +01:00
Victor Arino
01420152de cpu/atmega-common: add maps for 8-bit timers 2018-11-28 15:58:58 +01:00