A modern Music Player Daemon based on Rockbox open source high quality audio player
libadwaita audio rust zig deno mpris rockbox mpd

arm: add NVIC utility functions

Change-Id: I85567251fb00dec0f38be2a63261ad5509f4ec4f

authored by

Aidan MacDonald and committed by
Solomon Peachy
d68efd33 d14ddcaf

+90
+90
firmware/target/arm/nvic-arm.h
··· 1 + /*************************************************************************** 2 + * __________ __ ___. 3 + * Open \______ \ ____ ____ | | _\_ |__ _______ ___ 4 + * Source | _// _ \_/ ___\| |/ /| __ \ / _ \ \/ / 5 + * Jukebox | | ( <_> ) \___| < | \_\ ( <_> > < < 6 + * Firmware |____|_ /\____/ \___ >__|_ \|___ /\____/__/\_ \ 7 + * \/ \/ \/ \/ \/ 8 + * $Id$ 9 + * 10 + * Copyright (C) 2025 by Aidan MacDonald 11 + * 12 + * This program is free software; you can redistribute it and/or 13 + * modify it under the terms of the GNU General Public License 14 + * as published by the Free Software Foundation; either version 2 15 + * of the License, or (at your option) any later version. 16 + * 17 + * This software is distributed on an "AS IS" basis, WITHOUT WARRANTY OF ANY 18 + * KIND, either express or implied. 19 + * 20 + ****************************************************************************/ 21 + #ifndef __NVIC_ARM_H__ 22 + #define __NVIC_ARM_H__ 23 + 24 + #include "system.h" 25 + #include "cortex-m/nvic.h" 26 + 27 + #define NVIC_MAX_PRIO 0xFF 28 + 29 + static inline void nvic_enable_irq(int nr) 30 + { 31 + int reg = nr / 32; 32 + int bit = nr % 32; 33 + 34 + cm_write(NVIC_ISER(reg), BIT_N(bit)); 35 + } 36 + 37 + static inline void nvic_disable_irq(int nr) 38 + { 39 + int reg = nr / 32; 40 + int bit = nr % 32; 41 + 42 + cm_write(NVIC_ICER(reg), BIT_N(bit)); 43 + } 44 + 45 + static inline void nvic_set_pending_irq(int nr) 46 + { 47 + int reg = nr / 32; 48 + int bit = nr % 32; 49 + 50 + cm_write(NVIC_ISPR(reg), BIT_N(bit)); 51 + } 52 + 53 + static inline void nvic_clear_pending_irq(int nr) 54 + { 55 + int reg = nr / 32; 56 + int bit = nr % 32; 57 + 58 + cm_write(NVIC_ICPR(reg), BIT_N(bit)); 59 + } 60 + 61 + static inline bool nvic_is_active_irq(int nr) 62 + { 63 + int reg = nr / 32; 64 + int bit = nr % 32; 65 + 66 + return cm_read(NVIC_IABR(reg)) & BIT_N(bit); 67 + } 68 + 69 + static inline bool nvic_is_enabled_irq(int nr) 70 + { 71 + int reg = nr / 32; 72 + int bit = nr % 32; 73 + 74 + return cm_read(NVIC_ISER(reg)) & BIT_N(bit); 75 + } 76 + 77 + static inline void nvic_set_irq_priority(int nr, int prio) 78 + { 79 + int reg = nr / 4; 80 + int shift = (nr % 4) * 8; 81 + 82 + uint32_t val = cm_read(NVIC_IPR(reg)); 83 + 84 + val &= NVIC_MAX_PRIO << shift; 85 + val |= (prio & NVIC_MAX_PRIO) << shift; 86 + 87 + cm_write(NVIC_IPR(reg), val); 88 + } 89 + 90 + #endif /* __NVIC_ARM_H__ */