HomeCore 0.1.3 (07b5544)
Bare-metal personal computer firmware for Cortex-M
Loading...
Searching...
No Matches
arch.h
Go to the documentation of this file.
1/*
2 * MIT License
3 *
4 * Copyright (c) 2026 Grzegorz Grzęda
5 *
6 * Permission is hereby granted, free of charge, to any person obtaining a copy
7 * of this software and associated documentation files (the "Software"), to deal
8 * in the Software without restriction, including without limitation the rights
9 * to use, copy, modify, merge, publish, distribute, sublicense, and/or sell
10 * copies of the Software, and to permit persons to whom the Software is
11 * furnished to do so, subject to the following conditions:
12 *
13 * The above copyright notice and this permission notice shall be included in all
14 * copies or substantial portions of the Software.
15 *
16 * THE SOFTWARE IS PROVIDED "AS IS", WITHOUT WARRANTY OF ANY KIND, EXPRESS OR
17 * IMPLIED, INCLUDING BUT NOT LIMITED TO THE WARRANTIES OF MERCHANTABILITY,
18 * FITNESS FOR A PARTICULAR PURPOSE AND NONINFRINGEMENT. IN NO EVENT SHALL THE
19 * AUTHORS OR COPYRIGHT HOLDERS BE LIABLE FOR ANY CLAIM, DAMAGES OR OTHER
20 * LIABILITY, WHETHER IN AN ACTION OF CONTRACT, TORT OR OTHERWISE, ARISING FROM,
21 * OUT OF OR IN CONNECTION WITH THE SOFTWARE OR THE USE OR OTHER DEALINGS IN THE
22 * SOFTWARE.
23 */
24/*---------------------------------------------------------------------------*/
30/*---------------------------------------------------------------------------*/
31#ifndef HOME_CORE_ARCH_H
32#define HOME_CORE_ARCH_H
33/*---------------------------------------------------------------------------*/
34#if defined(__cplusplus)
35extern "C" {
36#endif
37/*---------------------------------------------------------------------------*/
38#include <stdint.h>
39#include <stddef.h>
40#include <stdbool.h>
41/*---------------------------------------------------------------------------*/
52/*---------------------------------------------------------------------------*/
64void arch_init(void);
65/*---------------------------------------------------------------------------*/
72void arch_cpu_idle(void);
73/*---------------------------------------------------------------------------*/
81void arch_cpu_halt(void);
82/*---------------------------------------------------------------------------*/
84void arch_cpu_reset(void);
85/*---------------------------------------------------------------------------*/
92void arch_panic(void) __attribute__((noreturn));
94/*---------------------------------------------------------------------------*/
99typedef uintptr_t arch_irq_key_t;
100/*---------------------------------------------------------------------------*/
110/*---------------------------------------------------------------------------*/
119/*---------------------------------------------------------------------------*/
128/*---------------------------------------------------------------------------*/
137void arch_irq_entry(void);
138/*---------------------------------------------------------------------------*/
145void arch_irq_enable(int irq);
146/*---------------------------------------------------------------------------*/
153void arch_irq_disable(int irq);
154/*---------------------------------------------------------------------------*/
163void arch_irq_set_priority(int irq, int priority);
164/*---------------------------------------------------------------------------*/
171/*---------------------------------------------------------------------------*/
179/*---------------------------------------------------------------------------*/
195int arch_cpu_timer_init(uint32_t cpu_hz, uint32_t tick_hz);
196/*---------------------------------------------------------------------------*/
200/*---------------------------------------------------------------------------*/
215typedef void (*arch_thread_entry_t)(void *arg);
216/*---------------------------------------------------------------------------*/
218typedef void (*arch_thread_exit_t)(void);
219/*---------------------------------------------------------------------------*/
236void *arch_stack_init(void *stack_mem,
237 size_t stack_size,
239 void *arg,
240 arch_thread_exit_t exit);
241/*---------------------------------------------------------------------------*/
250void arch_context_switch(void **old_sp, void *new_sp);
251/*---------------------------------------------------------------------------*/
257void arch_context_switch_to(void *new_sp) __attribute__((noreturn));
258/*---------------------------------------------------------------------------*/
260void arch_yield(void);
262/*---------------------------------------------------------------------------*/
264/*---------------------------------------------------------------------------*/
265#if defined(__cplusplus)
266}
267#endif
268/*---------------------------------------------------------------------------*/
269#endif // HOME_CORE_ARCH_H
270/*---------------------------------------------------------------------------*/
void arch_yield(void)
Set PendSV pending to request rescheduling.
void * arch_stack_init(void *stack_mem, size_t stack_size, arch_thread_entry_t entry, void *arg, arch_thread_exit_t exit)
Build the initial stack frame for a new thread.
uintptr_t arch_irq_key_t
Saved interrupt mask state returned by arch_irq_lock().
Definition arch.h:99
arch_irq_key_t arch_irq_lock(void)
Mask all configurable-priority interrupts.
void arch_init(void)
Point the vector table at the linked image and set core exception priorities.
void arch_irq_set_priority(int irq, int priority)
Set the priority of an interrupt or core exception.
void arch_cpu_idle(void)
Wait for an interrupt.
void arch_irq_set_pending(int irq)
Set a peripheral interrupt pending.
void arch_context_switch_to(void *new_sp)
Start the first thread through a supervisor call.
void(* arch_thread_exit_t)(void)
Function the thread runs if its entry point returns.
Definition arch.h:218
void arch_irq_entry(void)
Common entry for every peripheral interrupt.
void arch_context_switch(void **old_sp, void *new_sp)
Request a switch from the current thread to another one.
bool arch_irq_is_locked(void)
Report whether interrupts are masked.
int arch_cpu_timer_init(uint32_t cpu_hz, uint32_t tick_hz)
Start the periodic system timer.
void arch_cpu_timer_stop(void)
Stop the system timer and its interrupt.
void arch_irq_clear_pending(int irq)
Clear a pending peripheral interrupt.
void arch_cpu_halt(void)
Mask interrupts and stop permanently.
void arch_irq_disable(int irq)
Disable a peripheral interrupt in the interrupt controller.
void arch_cpu_reset(void)
Request a system reset.
void arch_irq_enable(int irq)
Enable a peripheral interrupt in the interrupt controller.
void arch_panic(void)
Halt permanently after a fatal error, without reporting a message.
void arch_irq_unlock(arch_irq_key_t key)
Restore the interrupt mask saved by arch_irq_lock().
void(* arch_thread_entry_t)(void *arg)
Thread entry point.
Definition arch.h:215