HomeCore 0.1.3 (07b5544)
Bare-metal personal computer firmware for Cortex-M
Loading...
Searching...
No Matches
arch.h File Reference

Architecture interface: CPU control, interrupts, system timer, and thread-switch primitives. More...

#include <stdint.h>
#include <stddef.h>
#include <stdbool.h>
Include dependency graph for arch.h:

Go to the source code of this file.

Functions

CPU control
void arch_init (void)
 Point the vector table at the linked image and set core exception priorities.
 
void arch_cpu_idle (void)
 Wait for an interrupt.
 
void arch_cpu_halt (void)
 Mask interrupts and stop permanently.
 
void arch_cpu_reset (void)
 Request a system reset.
 
void arch_panic (void)
 Halt permanently after a fatal error, without reporting a message.
 
System timer
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.
 

Interrupt control

typedef uintptr_t arch_irq_key_t
 Saved interrupt mask state returned by arch_irq_lock().
 
arch_irq_key_t arch_irq_lock (void)
 Mask all configurable-priority interrupts.
 
void arch_irq_unlock (arch_irq_key_t key)
 Restore the interrupt mask saved by arch_irq_lock().
 
bool arch_irq_is_locked (void)
 Report whether interrupts are masked.
 
void arch_irq_entry (void)
 Common entry for every peripheral interrupt.
 
void arch_irq_enable (int irq)
 Enable a peripheral interrupt in the interrupt controller.
 
void arch_irq_disable (int irq)
 Disable a peripheral interrupt in the interrupt controller.
 
void arch_irq_set_priority (int irq, int priority)
 Set the priority of an interrupt or core exception.
 
void arch_irq_clear_pending (int irq)
 Clear a pending peripheral interrupt.
 
void arch_irq_set_pending (int irq)
 Set a peripheral interrupt pending.
 

Thread primitives

Scaffolding for a future scheduler.

No code calls these functions yet. The SVC and PendSV handlers they rely on currently call board_panic(), so arch_context_switch(), arch_context_switch_to(), and arch_yield() end in a fatal halt. Floating-point context is not preserved.

typedef void(* arch_thread_entry_t) (void *arg)
 Thread entry point.
 
typedef void(* arch_thread_exit_t) (void)
 Function the thread runs if its entry point returns.
 
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.
 
void arch_context_switch (void **old_sp, void *new_sp)
 Request a switch from the current thread to another one.
 
void arch_context_switch_to (void *new_sp)
 Start the first thread through a supervisor call.
 
void arch_yield (void)
 Set PendSV pending to request rescheduling.
 

Detailed Description

Architecture interface: CPU control, interrupts, system timer, and thread-switch primitives.