Loading...
Searching...
No Matches
cpu.h
Go to the documentation of this file.
1/*
2 * SPDX-FileCopyrightText: 2015 Kaspar Schleiser <kaspar@schleiser.de>
3 * SPDX-FileCopyrightText: 2014 Freie Universität Berlin, Hinnerk van Bruinehsen
4 * SPDX-FileCopyrightText: 2018 RWTH Aachen, Josua Arndt <jarndt@ias.rwth-aachen.de>
5 * SPDX-FileCopyrightText: 2021-2023 Gerson Fernando Budke <nandojve@gmail.com>
6 * SPDX-License-Identifier: LGPL-2.1-only
7 */
8
9#pragma once
10
30
31#include <stdio.h>
32#include <stdint.h>
33
34#include <avr/interrupt.h>
35#include "architecture.h"
36#include "cpu_conf.h"
37#include "cpu_clock.h"
38#include "sched.h"
39#include "thread.h"
40#include "states_internal.h"
41
42#ifdef __cplusplus
43extern "C"
44{
45#endif
46
51#ifndef AVR8_PM_DISABLE_BOD_ON_SLEEP
52#define AVR8_PM_DISABLE_BOD_ON_SLEEP 0
53#endif
55
59#define CPU_CYCLES_PER_LOOP (7)
60
65#define PERIPH_I2C_NEED_READ_REG
66#define PERIPH_I2C_NEED_WRITE_REG
67#define PERIPH_I2C_NEED_READ_REGS
68#define PERIPH_I2C_NEED_WRITE_REGS
70
74static inline void avr8_enter_isr(void)
75{
76 /* This flag is only called from IRQ context, and nested IRQs are not
77 * supported as of now. The flag will be unset before the IRQ context is
78 * left, so no need to use memory barriers or atomics here
79 */
81}
82
88#define AVR8_STATE_FLAG_UART_TX(uart) (0x01U << uart)
89
95static inline void avr8_uart_tx_set_pending(unsigned uart)
96{
98}
99
105static inline void avr8_uart_tx_clear_pending(unsigned uart)
106{
108}
109
116static inline int avr8_is_uart_tx_pending(void)
117{
118 return avr8_state_uart;
119}
120
124void avr8_exit_isr(void);
125
129void avr8_clk_init(void);
130
137static inline uinttxtptr_t __attribute__((always_inline)) cpu_get_caller_pc(void)
138{
139 uinttxtptr_t addr;
140 __asm__ volatile(
141 "ldi %D[dest], 0" "\n\t"
142#if __AVR_3_BYTE_PC__
143 "pop %C[dest] " "\n\t"
144#else
145 "ldi %C[dest], 0" "\n\t"
146#endif
147 "pop %B[dest]" "\n\t"
148 "pop %A[dest]" "\n\t"
149 "push %A[dest]" "\n\t"
150 "push %B[dest]" "\n\t"
151#if __AVR_3_BYTE_PC__
152 "push %C[dest] " "\n\t"
153#endif
154 : [dest] "=r"(addr)
155 : /* no inputs */
156 : "memory"
157 );
158
159 /* addr now contains instruction to return to, subtract one to get
160 * the instruction that called this function. Also multiply by two to get
161 * the byte position, rather than the (16 bit) instruction position */
162 addr = (addr - 1 ) * 2;
163 return addr;
164}
165
170
175
176#ifdef __cplusplus
177}
178#endif
179
Platform-independent access to architecture details.
void avr8_reset_cause(void)
Print reset cause.
static void avr8_uart_tx_clear_pending(unsigned uart)
Clear UART TX channel pending state.
Definition cpu.h:105
static void avr8_enter_isr(void)
Run this code on entering interrupt routines.
Definition cpu.h:74
void avr8_clk_init(void)
Initialization of the CPU clock.
static uinttxtptr_t cpu_get_caller_pc(void)
Get the last instruction's address.
Definition cpu.h:137
static void avr8_uart_tx_set_pending(unsigned uart)
Set UART TX channel as pending.
Definition cpu.h:95
#define AVR8_STATE_FLAG_UART_TX(uart)
Compute UART TX channel.
Definition cpu.h:88
void avr8_exit_isr(void)
Run this code on exiting interrupt routines.
static int avr8_is_uart_tx_pending(void)
Check if TX on any present UART device is still pending.
Definition cpu.h:116
void avr8_stdio_init(void)
Initializes avrlibc stdio.
stdio wrapper to extend the C libs stdio
uintptr_t uinttxtptr_t
Pointer type to point anywhere in the .text section.
Scheduler API definition.
States internal interface.
#define avr8_state_irq_count
Definition for GPIOR1.
#define avr8_state_uart
Definition for GPIOR0.