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
32#ifndef CPU_H
33#define CPU_H
34
35#include <stdio.h>
36#include <stdint.h>
37
38#include <avr/interrupt.h>
39#include "architecture.h"
40#include "cpu_conf.h"
41#include "cpu_clock.h"
42#include "sched.h"
43#include "thread.h"
44#include "states_internal.h"
45
46#ifdef __cplusplus
47extern "C"
48{
49#endif
50
55#ifndef AVR8_PM_DISABLE_BOD_ON_SLEEP
56#define AVR8_PM_DISABLE_BOD_ON_SLEEP 0
57#endif
63#define CPU_CYCLES_PER_LOOP (7)
64
69#define PERIPH_I2C_NEED_READ_REG
70#define PERIPH_I2C_NEED_WRITE_REG
71#define PERIPH_I2C_NEED_READ_REGS
72#define PERIPH_I2C_NEED_WRITE_REGS
78static inline void avr8_enter_isr(void)
79{
80 /* This flag is only called from IRQ context, and nested IRQs are not
81 * supported as of now. The flag will be unset before the IRQ context is
82 * left, so no need to use memory barriers or atomics here
83 */
85}
86
92#define AVR8_STATE_FLAG_UART_TX(uart) (0x01U << uart)
93
99static inline void avr8_uart_tx_set_pending(unsigned uart)
100{
102}
103
109static inline void avr8_uart_tx_clear_pending(unsigned uart)
110{
111 avr8_state_uart &= ~AVR8_STATE_FLAG_UART_TX(uart);
112}
113
120static inline int avr8_is_uart_tx_pending(void)
121{
122 return avr8_state_uart;
123}
124
128void avr8_exit_isr(void);
129
133void avr8_clk_init(void);
134
141static inline uinttxtptr_t __attribute__((always_inline)) cpu_get_caller_pc(void)
142{
143 uinttxtptr_t addr;
144 __asm__ volatile(
145 "ldi %D[dest], 0" "\n\t"
146#if __AVR_3_BYTE_PC__
147 "pop %C[dest] " "\n\t"
148#else
149 "ldi %C[dest], 0" "\n\t"
150#endif
151 "pop %B[dest]" "\n\t"
152 "pop %A[dest]" "\n\t"
153 "push %A[dest]" "\n\t"
154 "push %B[dest]" "\n\t"
155#if __AVR_3_BYTE_PC__
156 "push %C[dest] " "\n\t"
157#endif
158 : [dest] "=r"(addr)
159 : /* no inputs */
160 : "memory"
161 );
162
163 /* addr now contains instruction to return to, subtract one to get
164 * the instruction that called this function. Also multiply by two to get
165 * the byte position, rather than the (16 bit) instruction position */
166 addr = (addr - 1 ) * 2;
167 return addr;
168}
169
174
179
180#ifdef __cplusplus
181}
182#endif
183
184#endif /* CPU_H */
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:109
static void avr8_enter_isr(void)
Run this code on entering interrupt routines.
Definition cpu.h:78
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:141
static void avr8_uart_tx_set_pending(unsigned uart)
Set UART TX channel as pending.
Definition cpu.h:99
#define AVR8_STATE_FLAG_UART_TX(uart)
Compute UART TX channel.
Definition cpu.h:92
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:120
void avr8_stdio_init(void)
Initializes avrlibc 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.
stdio wrapper to extend the C libs stdio