sched: major refactor
This commit is contained in:
parent
f4e321932f
commit
f49a6643d7
4 changed files with 72 additions and 43 deletions
|
@ -3,16 +3,14 @@
|
|||
|
||||
#include <arch/sched.h>
|
||||
#include <arch/at91sam3x8e/hardware.h>
|
||||
#include <arch/at91sam3x8e/interrupt.h>
|
||||
|
||||
#include <ardix/string.h>
|
||||
#include <ardix/sched.h>
|
||||
|
||||
#include <stdbool.h>
|
||||
#include <toolchain.h>
|
||||
|
||||
#ifdef __cplusplus
|
||||
extern "C"
|
||||
{
|
||||
#endif /* __cplusplus */
|
||||
|
||||
/**
|
||||
* Set the PENDSV bit in the system control block.
|
||||
*/
|
||||
|
@ -30,7 +28,7 @@ void irq_sys_tick(void)
|
|||
sched_pendsv_req();
|
||||
}
|
||||
|
||||
void sched_init_process_regs(struct reg_snapshot *reg_snap, void (*entry)(void))
|
||||
void sched_init_process_regs(struct reg_snapshot *reg_snap, int (*entry)(void))
|
||||
{
|
||||
memset(reg_snap, 0, sizeof(*reg_snap));
|
||||
|
||||
|
@ -57,7 +55,7 @@ static inline void sched_nvic_set_prio_group(uint32_t prio_group)
|
|||
REG_SCB_AIRCR = reg_val;
|
||||
}
|
||||
|
||||
int sched_hwtimer_init(unsigned int freq)
|
||||
int arch_sched_hwtimer_init(unsigned int freq)
|
||||
{
|
||||
uint32_t ticks = sys_core_clock / freq;
|
||||
if (ticks > REG_SYSTICK_LOAD_RELOAD_MASK)
|
||||
|
@ -75,14 +73,13 @@ int sched_hwtimer_init(unsigned int freq)
|
|||
return 0;
|
||||
}
|
||||
|
||||
inline void sched_atomic_enter(void)
|
||||
void arch_sched_process_init(struct process *process, void (*entry)(void))
|
||||
{
|
||||
REG_SYSTICK_CTRL &= ~REG_SYSTICK_CTRL_ENABLE_BIT;
|
||||
}
|
||||
struct reg_snapshot *regs = process->stack_bottom - sizeof(*regs);
|
||||
process->sp = regs;
|
||||
|
||||
inline void sched_atomic_leave(bool resched)
|
||||
{
|
||||
REG_SYSTICK_CTRL |= REG_SYSTICK_CTRL_ENABLE_BIT;
|
||||
memset(regs, 0, sizeof(*regs));
|
||||
regs->hw.pc = (void *)((uint32_t)entry | 1U); /* thumb instruction set flag */
|
||||
}
|
||||
|
||||
void sched_exec_early(void)
|
||||
|
@ -91,10 +88,6 @@ void sched_exec_early(void)
|
|||
sched_pendsv_req();
|
||||
}
|
||||
|
||||
#ifdef __cplusplus
|
||||
} /* extern "C" */
|
||||
#endif /* __cplusplus */
|
||||
|
||||
/*
|
||||
* Copyright (c) 2020 Felix Kopp <sandtler@sandtler.club>
|
||||
*
|
||||
|
|
|
@ -20,7 +20,7 @@ void irq_svc(void);
|
|||
/** Debug handler (reserved) */
|
||||
void irq_debug_mon(void);
|
||||
/** Pending SV interrupt handler */
|
||||
extern void irq_pend_sv(void);
|
||||
void irq_pend_sv(void);
|
||||
/** SysTick interrupt handler */
|
||||
void irq_sys_tick(void);
|
||||
|
||||
|
|
45
include/arch/at91sam3x8e/sched.h
Normal file
45
include/arch/at91sam3x8e/sched.h
Normal file
|
@ -0,0 +1,45 @@
|
|||
/* SPDX-License-Identifier: BSD-3-Clause */
|
||||
/* See the end of this file for copyright, licensing, and warranty information. */
|
||||
|
||||
#pragma once
|
||||
|
||||
#include <arch/at91sam3x8e/interrupt.h>
|
||||
#include <ardix/sched.h>
|
||||
#include <toolchain.h>
|
||||
|
||||
/** Enter atomic context, i.e. disable preemption */
|
||||
__always_inline void sched_atomic_enter(void)
|
||||
{
|
||||
arch_irq_disable(IRQNO_PEND_SV);
|
||||
}
|
||||
|
||||
/** Leave atomic context, i.e. re-enable preemption */
|
||||
__always_inline void sched_atomic_leave(void)
|
||||
{
|
||||
arch_irq_enable(IRQNO_PEND_SV);
|
||||
}
|
||||
|
||||
/*
|
||||
* Copyright (c) 2020 Felix Kopp <sandtler@sandtler.club>
|
||||
*
|
||||
* Redistribution and use in source and binary forms, with or without modification, are permitted
|
||||
* provided that the following conditions are met:
|
||||
*
|
||||
* 1. Redistributions of source code must retain the above copyright notice, this list of
|
||||
* conditions and the following disclaimer.
|
||||
* 2. Redistributions in binary form must reproduce the above copyright notice, this list of
|
||||
* conditions and the following disclaimer in the documentation and/or other materials
|
||||
* provided with the distribution.
|
||||
* 3. Neither the name of the copyright holder nor the names of its contributors may be
|
||||
* used to endorse or promote products derived from this software without specific prior
|
||||
* written permission.
|
||||
*
|
||||
* THIS SOFTWARE IS PROVIDED BY THE COPYRIGHT HOLDERS AND CONTRIBUTORS "AS IS" AND ANY EXPRESS OR
|
||||
* IMPLIED WARRANTIES, INCLUDING, BUT NOT LIMITED TO, THE IMPLIED WARRANTIES OF MERCHANTABILITY AND
|
||||
* FITNESS FOR A PARTICULAR PURPOSE ARE DISCLAIMED. IN NO EVENT SHALL THE COPYRIGHT HOLDER OR
|
||||
* CONTRIBUTORS BE LIABLE FOR ANY DIRECT, INDIRECT, INCIDENTAL, SPECIAL, EXEMPLARY, OR CONSEQUENTIAL
|
||||
* DAMAGES (INCLUDING, BUT NOT LIMITED TO, PROCUREMENT OF SUBSTITUTE GOODS OR SERVICES; LOSS OF USE,
|
||||
* DATA, OR PROFITS; OR BUSINESS INTERRUPTION) HOWEVER CAUSED AND ON ANY THEORY OF LIABILITY,
|
||||
* WHETHER IN CONTRACT, STRICT LIABILITY, OR TORT (INCLUDING NEGLIGENCE OR OTHERWISE) ARISING IN ANY
|
||||
* WAY OUT OF THE USE OF THIS SOFTWARE, EVEN IF ADVISED OF THE POSSIBILITY OF SUCH DAMAGE.
|
||||
*/
|
|
@ -4,43 +4,34 @@
|
|||
#pragma once
|
||||
|
||||
#include <arch/hardware.h>
|
||||
|
||||
#include <stdbool.h>
|
||||
#include <toolchain.h>
|
||||
|
||||
struct process; /* see include/ardix/sched.h */
|
||||
|
||||
/**
|
||||
* Initialize a hardware timer for schduling.
|
||||
*
|
||||
* @param freq: The timer frequency in Hertz.
|
||||
*/
|
||||
int sched_hwtimer_init(unsigned int freq);
|
||||
int arch_sched_hwtimer_init(unsigned int freq);
|
||||
|
||||
/**
|
||||
* Disable all scheduling interrupts in order to enter atomic context.
|
||||
*/
|
||||
void sched_atomic_enter(void);
|
||||
|
||||
/**
|
||||
* Re-enable scheduling interrupts, i.e. leave atomic context.
|
||||
* Initialize a new process.
|
||||
* This requires the process' `stack_base` field to be initialized as the
|
||||
* initial register values are written to the stack.
|
||||
*
|
||||
* @param resched: If `true`, request the scheduler to proceed to the next
|
||||
* process ASAP. Until then, put the CPU to sleep if required.
|
||||
*/
|
||||
void sched_atomic_leave(bool resched);
|
||||
|
||||
/**
|
||||
* Infinite loop of sleep instructions.
|
||||
*/
|
||||
void sched_idle_process_loop(void);
|
||||
|
||||
/**
|
||||
* Initialize the register values of a newly allocated process image.
|
||||
* Called by the scheduling subsystem when a process is being created.
|
||||
*
|
||||
* @param reg_snap: The stack memory location where the initial register values
|
||||
* are to be loaded from.
|
||||
* @param process: The process.
|
||||
* @param entry: The process entry point.
|
||||
*/
|
||||
void sched_init_process_regs(struct reg_snapshot *reg_snap,
|
||||
void (*entry)(void));
|
||||
void arch_sched_process_init(struct process *process, void (*entry)(void));
|
||||
|
||||
#ifdef ARCH_AT91SAM3X8E
|
||||
#include <arch/at91sam3x8e/sched.h>
|
||||
#else
|
||||
#error "Unsupported architecture"
|
||||
#endif
|
||||
|
||||
/*
|
||||
* Copyright (c) 2020 Felix Kopp <sandtler@sandtler.club>
|
||||
|
|
Loading…
Reference in a new issue