/* * Copyright (c) 2020 Raspberry Pi (Trading) Ltd. * * SPDX-License-Identifier: BSD-3-Clause *//* ... */#include"hardware/exception.h"#include"hardware/sync.h"#include"pico/platform/cpu_regs.h"#ifndefexception_is_compile_time_defaultstaticboolexception_is_compile_time_default(exception_handler_thandler){#ifdef__riscvexternchar__unhandled_exception;return(uintptr_t)handler==(uintptr_t)__unhandled_exception;/* ... */#elseexternchar__default_isrs_start;externchar__default_isrs_end;return((uintptr_t)handler)>=(uintptr_t)&__default_isrs_start&&((uintptr_t)handler)<(uintptr_t)&__default_isrs_end;/* ... */#endif}{ ... }/* ... */#endifstaticinlineexception_handler_t*get_exception_table(void){#ifdef__riscvexternuintptr_t__riscv_exception_table;return(exception_handler_t*)&__riscv_exception_table;/* ... */#elsereturn(exception_handler_t*)scb_hw->vtor;#endif}{ ... }staticvoidset_raw_exception_handler_and_restore_interrupts(enumexception_numbernum,exception_handler_thandler,uint32_tsave){// update vtable (vtable_handler may be same or updated depending on cases, but we do it anyway for compactness)get_exception_table()[num]=handler;__dmb();restore_interrupts_from_disabled(save);}{ ... }staticinlinevoidcheck_exception_param(__unusedenumexception_numbernum){invalid_params_if(HARDWARE_EXCEPTION,num<MIN_EXCEPTION_NUM||num>=MAX_EXCEPTION_NUM);}{ ... }exception_handler_texception_get_vtable_handler(enumexception_numbernum){check_exception_param(num);returnget_exception_table()[num];}{ ... }exception_handler_texception_set_exclusive_handler(enumexception_numbernum,exception_handler_thandler){check_exception_param(num);#if!PICO_NO_RAM_VECTOR_TABLEuint32_tsave=save_and_disable_interrupts();exception_handler_tcurrent=exception_get_vtable_handler(num);hard_assert(handler==current||exception_is_compile_time_default(current));set_raw_exception_handler_and_restore_interrupts(num,handler,save);/* ... */#elsepanic_unsupported();#endifreturncurrent;}{ ... }voidexception_restore_handler(enumexception_numbernum,exception_handler_toriginal_handler){hard_assert(exception_is_compile_time_default(original_handler));#if!PICO_NO_RAM_VECTOR_TABLEuint32_tsave=save_and_disable_interrupts();set_raw_exception_handler_and_restore_interrupts(num,original_handler,save);/* ... */#elsepanic_unsupported();#endif}{ ... }#ifndef__riscvstaticio_rw_32*get_shpr0(uintnum){io_rw_32*shpr0=NULL;#if__ARM_ARCH_6M__// only has shpr2-3if(num>=8&&num<16)shpr0=(io_rw_32*)(PPB_BASE+ARM_CPU_PREFIXED(SHPR2_OFFSET)-8);/* ... */#elif__ARM_ARCH_8M_MAIN__// only has shpr1-3if(num>=4&&num<16)shpr0=(io_rw_32*)(PPB_BASE+ARM_CPU_PREFIXED(SHPR1_OFFSET)-4);/* ... */#endifreturnshpr0;}{ ... }boolexception_set_priority(uintnum,uint8_thardware_priority){io_rw_32*shpr0=get_shpr0(num);if(shpr0){// note that only 32 bit writes are supportedshpr0[num/4]=(shpr0[num/4]&~(0xffu<<(8*(num&3u))))|(((uint32_t)hardware_priority)<<(8*(num&3u)));returntrue;}if (shpr0) { ... }returnfalse;}{ ... }uintexception_get_priority(uintnum){io_rw_32*shpr0=get_shpr0(num);if(shpr0){// note that only 32 bit writes are supportedreturn(uint8_t)(shpr0[num/4]>>(8*(num&3)));}if (shpr0) { ... }returnPICO_LOWEST_EXCEPTION_PRIORITY;}{ ... }#endif/* ... */
Details
Show: from
Types: Columns:
All items filtered out
All items filtered out
This file uses the notable symbols shown below. Click anywhere in the file to view more details.