Skip to content
New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

Cortex-M: NVIC and SCB code duplication cleanup #576

Merged
merged 1 commit into from
Sep 25, 2024
Merged
Show file tree
Hide file tree
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
10 changes: 10 additions & 0 deletions hal/arm/Makefile
Original file line number Diff line number Diff line change
@@ -0,0 +1,10 @@
#
# Makefile for HAL ARM common functions
#
# Copyright 2023 Phoenix Systems
#

# TODO handle other common ARM stuff (e.g GIC) and
# select relevant components here

OBJS += $(addprefix $(PREFIX_O)hal/arm/, nvic.o scb.o)
7 changes: 4 additions & 3 deletions hal/armv7m/armv7m.h → hal/arm/barriers.h
Original file line number Diff line number Diff line change
Expand Up @@ -3,7 +3,7 @@
*
* Operating system kernel
*
* ARMv7 Cortex-M related routines
* ARM barriers
*
* Copyright 2021 Phoenix Systems
* Author: Hubert Buczynski
Expand All @@ -13,8 +13,8 @@
* %LICENSE%
*/

#ifndef _HAL_ARMV7M_H_
#define _HAL_ARMV7M_H_
#ifndef HAL_ARM_BARRIERS_H_
#define HAL_ARM_BARRIERS_H_


static inline void hal_cpuDataMemoryBarrier(void)
Expand All @@ -34,4 +34,5 @@ static inline void hal_cpuInstrBarrier(void)
__asm__ volatile ("isb");
}


#endif
77 changes: 77 additions & 0 deletions hal/arm/nvic.c
Original file line number Diff line number Diff line change
@@ -0,0 +1,77 @@
/*
* Phoenix-RTOS
*
* Operating system kernel
*
* Nested Vector Interrupt Controller
*
* Copyright 2017, 2020, 2022, 2024 Phoenix Systems
* Author: Pawel Pisarczyk, Hubert Buczynski, Damian Loewnau, Aleksander Kaminski
*
* This file is part of Phoenix-RTOS.
*
* %LICENSE%
*/


#include <arch/cpu.h>
#include "nvic.h"


struct nvic_s {
volatile u32 iser;
u32 _res0[31];
volatile u32 icer;
u32 _res1[31];
volatile u32 ispr;
u32 _res2[31];
volatile u32 icpr;
u32 _res3[31];
volatile u32 iabr;
u32 _res4[63];
volatile u32 ip;
};


static struct {
struct nvic_s *nvic;
} nvic_common;


void _hal_nvicSetIRQ(s8 irqn, u8 state)
{
volatile u32 *ptr = (state != 0) ? &nvic_common.nvic->iser : &nvic_common.nvic->icer;

*(ptr + ((u8)irqn >> 5)) = 1u << (irqn & 0x1f);

hal_cpuDataSyncBarrier();
hal_cpuInstrBarrier();
}


void _hal_nvicSetPriority(s8 irqn, u32 priority)
{
volatile u8 *ptr = (volatile u8 *)&nvic_common.nvic->ip;

*(ptr + irqn) = (priority << 4) & 0xff;

hal_cpuDataSyncBarrier();
hal_cpuInstrBarrier();
}


void _hal_nvicSetPending(s8 irqn)
{
volatile u32 *ptr = &nvic_common.nvic->ispr;

*(ptr + ((u8)irqn >> 5)) = 1u << (irqn & 0x1f);

hal_cpuDataSyncBarrier();
hal_cpuInstrBarrier();
}


void _hal_nvicInit(void)
{
nvic_common.nvic = (void *)0xe000e100;
}
36 changes: 36 additions & 0 deletions hal/arm/nvic.h
Original file line number Diff line number Diff line change
@@ -0,0 +1,36 @@
/*
* Phoenix-RTOS
*
* Operating system kernel
*
* Nested Vector Interrupt Controller
*
* Copyright 2017, 2020, 2022, 2024 Phoenix Systems
* Author: Pawel Pisarczyk, Hubert Buczynski, Damian Loewnau, Aleksander Kaminski
*
* This file is part of Phoenix-RTOS.
*
* %LICENSE%
*/


#ifndef HAL_ARMV_NVIC_H_
#define HAL_ARMV_NVIC_H_


#include "hal/types.h"


void _hal_nvicSetIRQ(s8 irqn, u8 state);


void _hal_nvicSetPriority(s8 irqn, u32 priority);


void _hal_nvicSetPending(s8 irqn);


void _hal_nvicInit(void);


#endif
Loading
Loading