Loading...
Searching...
No Matches
cpu.h
Go to the documentation of this file.
1/*
2 * Copyright (C) 2015 Kaspar Schleiser <kaspar@schleiser.de>
3 * 2014 Freie Universität Berlin, Hinnerk van Bruinehsen
4 * 2018 RWTH Aachen, Josua Arndt <jarndt@ias.rwth-aachen.de>
5 * 2021-2023 Gerson Fernando Budke <nandojve@gmail.com>
6 *
7 * This file is subject to the terms and conditions of the GNU Lesser
8 * General Public License v2.1. See the file LICENSE in the top level
9 * directory for more details.
10 */
11
12#pragma once
13
33
34#include <stdio.h>
35#include <stdint.h>
36
37#include <avr/interrupt.h>
38#include "architecture.h"
39#include "cpu_conf.h"
40#include "cpu_clock.h"
41#include "sched.h"
42#include "thread.h"
43#include "states_internal.h"
44
45#ifdef __cplusplus
46extern "C"
47{
48#endif
49
54#ifndef AVR8_PM_DISABLE_BOD_ON_SLEEP
55#define AVR8_PM_DISABLE_BOD_ON_SLEEP 0
56#endif
58
62#define CPU_CYCLES_PER_LOOP (7)
63
68#define PERIPH_I2C_NEED_READ_REG
69#define PERIPH_I2C_NEED_WRITE_REG
70#define PERIPH_I2C_NEED_READ_REGS
71#define PERIPH_I2C_NEED_WRITE_REGS
73
77static inline void avr8_enter_isr(void)
78{
79 /* This flag is only called from IRQ context, and nested IRQs are not
80 * supported as of now. The flag will be unset before the IRQ context is
81 * left, so no need to use memory barriers or atomics here
82 */
84}
85
91#define AVR8_STATE_FLAG_UART_TX(uart) (0x01U << uart)
92
98static inline void avr8_uart_tx_set_pending(unsigned uart)
99{
101}
102
108static inline void avr8_uart_tx_clear_pending(unsigned uart)
109{
111}
112
119static inline int avr8_is_uart_tx_pending(void)
120{
121 return avr8_state_uart;
122}
123
127void avr8_exit_isr(void);
128
132void avr8_clk_init(void);
133
140static inline uinttxtptr_t __attribute__((always_inline)) cpu_get_caller_pc(void)
141{
142 uinttxtptr_t addr;
143 __asm__ volatile(
144 "ldi %D[dest], 0" "\n\t"
145#if __AVR_3_BYTE_PC__
146 "pop %C[dest] " "\n\t"
147#else
148 "ldi %C[dest], 0" "\n\t"
149#endif
150 "pop %B[dest]" "\n\t"
151 "pop %A[dest]" "\n\t"
152 "push %A[dest]" "\n\t"
153 "push %B[dest]" "\n\t"
154#if __AVR_3_BYTE_PC__
155 "push %C[dest] " "\n\t"
156#endif
157 : [dest] "=r"(addr)
158 : /* no inputs */
159 : "memory"
160 );
161
162 /* addr now contains instruction to return to, subtract one to get
163 * the instruction that called this function. Also multiply by two to get
164 * the byte position, rather than the (16 bit) instruction position */
165 addr = (addr - 1 ) * 2;
166 return addr;
167}
168
173
178
179#ifdef __cplusplus
180}
181#endif
182
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:108
static void avr8_enter_isr(void)
Run this code on entering interrupt routines.
Definition cpu.h:77
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:140
static void avr8_uart_tx_set_pending(unsigned uart)
Set UART TX channel as pending.
Definition cpu.h:98
#define AVR8_STATE_FLAG_UART_TX(uart)
Compute UART TX channel.
Definition cpu.h:91
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:119
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.