Skip to content

Commit

Permalink
Cortex-M: NVIC and SCB code duplication cleanup
Browse files Browse the repository at this point in the history
JIRA: RTOS-886
  • Loading branch information
agkaminski committed Aug 9, 2024
1 parent fa2cb46 commit 2040e21
Show file tree
Hide file tree
Showing 42 changed files with 571 additions and 1,221 deletions.
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
65 changes: 65 additions & 0 deletions hal/arm/nvic.c
Original file line number Diff line number Diff line change
@@ -0,0 +1,65 @@
/*
* 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"


static struct {
volatile u32 *nvic;
} nvic_common;


/* clang-format off */
enum { nvic_iser = 0, nvic_icer = 32, nvic_ispr = 64, nvic_icpr = 96, nvic_iabr = 128,
nvic_ip = 192 };
/* clang-format on */


void _hal_nvicSetIRQ(s8 irqn, u8 state)
{
volatile u32 *ptr = nvic_common.nvic + ((u8)irqn >> 5) + ((state != 0) ? nvic_iser : nvic_icer);
*ptr = 1u << (irqn & 0x1f);

hal_cpuDataSyncBarrier();
hal_cpuInstrBarrier();
}


void _hal_nvicSetPriority(s8 irqn, u32 priority)
{
volatile u8 *ptr;

ptr = ((u8*)(nvic_common.nvic + nvic_ip)) + irqn;

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


void _hal_nvicSetPending(s8 irqn)
{
volatile u32 *ptr = nvic_common.nvic + ((u8)irqn >> 5) + nvic_ispr;

*ptr = 1u << (irqn & 0x1f);

hal_cpuDataSyncBarrier();
}


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

0 comments on commit 2040e21

Please sign in to comment.