123456789101112131415161718192021222324252627282930313233343536373839404142434445464748495051525354555657585960616263646566676869707172737475767778798081828384858687888990919293949596979899100101102103104105106107108109110111112113114115116117118119120121122123124125126127128129130131132133134135136137138139140141142143144145146147148149150151152153154155156157158159160161162163164165166167168169170171172173174175176177178179180181182183184185186187188189190191192193194195196197198199200201202203204205206207208209210211212213214215216217218219220221222223224225226227228229230231232233234235236237238239240241242243244245246247248249250251252253254255256257258259260261262263264265266267268269270271272273274275276277278279280281282283284285286287288289290291292293294295296297298299300301302303304305306307308309310311312313314315316317318319320321322323324325326327328329330331332333334335336337338339340341342343344345346347348349350351352353354355356357358359360361362363364365366367368369370371372373374375376377378379380381382383384385386387388389390391392393394395396397398399400401402403404405406407408409410411412413414415416417418419420421422423424425426427428429430431432433434435436437438439440441442443444445446447448449450451452453454455456457458459460461462463464465466467468469470471472473474475476477478479480481482483484485486487488489490491492493494495496497498499500501502503504505506507508509510511512513514515516517518519520521522523524525526527528529530531532533534535536537538539540541542543544545546547548549550551552553554555556557558559560561562563564565566567568569570571572573574575576577578579580581582583584585586587588589590591592593594595596597598599600601602603604605606607608609610611612613614615616617618619620621622623624625626627628629630631632633634635636637638639640641642643644645646647648649650651652653654655656657658659660661662663664665666667668669670671672673674675676677678679680681682683684685686687688689690691692693694695696697698699700701702703704705706707708709710711712713714715716717718719720721722723724725726727728729730731732733734735736737738739740741742743744745746747748749750751752753754755756757758759760761762763764765766767768769770771772773774775776777778779780781782783784785786787788789790791792793794795796797798799800801802803804805806807808809810811812813814815816817818819820821822823824825826827828829 |
- #include "hw_ints.h"
- #include "hw_nvic.h"
- #include "hw_sys_ctrl.h"
- #include "cpu.h"
- #include "debug.h"
- #include "interrupt.h"
- static const uint32_t g_pui32Priority[] =
- {
- NVIC_APINT_PRIGROUP_0_8, NVIC_APINT_PRIGROUP_1_7, NVIC_APINT_PRIGROUP_2_6,
- NVIC_APINT_PRIGROUP_3_5, NVIC_APINT_PRIGROUP_4_4, NVIC_APINT_PRIGROUP_5_3,
- NVIC_APINT_PRIGROUP_6_2, NVIC_APINT_PRIGROUP_7_1
- };
- static const uint32_t g_pui32Regs[] =
- {
- 0, NVIC_SYS_PRI1, NVIC_SYS_PRI2, NVIC_SYS_PRI3, NVIC_PRI0, NVIC_PRI1,
- NVIC_PRI2, NVIC_PRI3, NVIC_PRI4, NVIC_PRI5, NVIC_PRI6, NVIC_PRI7,
- NVIC_PRI8, NVIC_PRI9, NVIC_PRI10, NVIC_PRI11, NVIC_PRI12, NVIC_PRI13,
- NVIC_PRI14, NVIC_PRI15, NVIC_PRI16, NVIC_PRI17, NVIC_PRI18, NVIC_PRI19,
- NVIC_PRI20, NVIC_PRI21, NVIC_PRI22, NVIC_PRI23, NVIC_PRI24, NVIC_PRI25,
- NVIC_PRI26, NVIC_PRI27, NVIC_PRI28, NVIC_PRI29, NVIC_PRI30, NVIC_PRI31,
- NVIC_PRI32, NVIC_PRI33, NVIC_PRI34, NVIC_PRI35, NVIC_PRI36
- };
- static const uint32_t g_pui32EnRegs[] =
- {
- NVIC_EN0, NVIC_EN1, NVIC_EN2, NVIC_EN3, NVIC_EN4
- };
- static const uint32_t g_pui32DisRegs[] =
- {
- NVIC_DIS0, NVIC_DIS1, NVIC_DIS2, NVIC_DIS3, NVIC_DIS4
- };
- static const uint32_t g_pui32PendRegs[] =
- {
- NVIC_PEND0, NVIC_PEND1, NVIC_PEND2, NVIC_PEND3, NVIC_PEND4
- };
- static const uint32_t g_pui32UnpendRegs[] =
- {
- NVIC_UNPEND0, NVIC_UNPEND1, NVIC_UNPEND2, NVIC_UNPEND3, NVIC_UNPEND4
- };
- static void
- IntDefaultHandler(void)
- {
-
-
-
- while(1)
- {
- }
- }
- #if defined(__ICCARM__)
- #pragma data_alignment=1024
- static __no_init void (*g_pfnRAMVectors[NUM_INTERRUPTS])(void) @ "VTABLE";
- #elif defined(__TI_COMPILER_VERSION__) || defined(DOXYGEN)
- #pragma DATA_ALIGN(g_pfnRAMVectors, 1024)
- #pragma DATA_SECTION(g_pfnRAMVectors, ".vtable")
- void (*g_pfnRAMVectors[NUM_INTERRUPTS])(void);
- #else
- static __attribute__((section("vtable")))
- void (*g_pfnRAMVectors[NUM_INTERRUPTS])(void) __attribute__((aligned(1024)));
- #endif
- bool
- IntMasterEnable(void)
- {
-
-
-
- return(CPUcpsie());
- }
- bool
- IntMasterDisable(void)
- {
-
-
-
- return(CPUcpsid());
- }
- void
- IntRegister(uint32_t ui32Interrupt, void (*pfnHandler)(void))
- {
- uint32_t ui32Idx, ui32Value;
-
-
-
- ASSERT(ui32Interrupt < NUM_INTERRUPTS);
-
- #ifdef CC2538_USE_ALTERNATE_INTERRUPT_MAP
- ASSERT(IntAltMapIsEnabled());
- #else
- ASSERT(~IntAltMapIsEnabled());
- #endif
-
-
-
- ASSERT(((uint32_t)g_pfnRAMVectors & 0x000003ff) == 0);
-
-
-
- if(HWREG(NVIC_VTABLE) != (uint32_t)g_pfnRAMVectors)
- {
-
-
-
-
- ui32Value = HWREG(NVIC_VTABLE);
- for(ui32Idx = 0; ui32Idx < NUM_INTERRUPTS; ui32Idx++)
- {
- g_pfnRAMVectors[ui32Idx] = (void (*)(void))HWREG((ui32Idx * 4) +
- ui32Value);
- }
-
-
-
- HWREG(NVIC_VTABLE) = (uint32_t)g_pfnRAMVectors;
- }
-
-
-
- g_pfnRAMVectors[ui32Interrupt] = pfnHandler;
- }
- void
- IntUnregister(uint32_t ui32Interrupt)
- {
-
-
-
- ASSERT(ui32Interrupt < NUM_INTERRUPTS);
-
-
-
-
- ASSERT(HWREG(NVIC_VTABLE) == (uint32_t)g_pfnRAMVectors);
-
- #ifdef CC2538_USE_ALTERNATE_INTERRUPT_MAP
- ASSERT(IntAltMapIsEnabled());
- #else
- ASSERT(~IntAltMapIsEnabled());
- #endif
-
-
-
- g_pfnRAMVectors[ui32Interrupt] = IntDefaultHandler;
- }
- void
- IntPriorityGroupingSet(uint32_t ui32Bits)
- {
-
-
-
- ASSERT(ui32Bits < NUM_PRIORITY);
-
-
-
- HWREG(NVIC_APINT) = NVIC_APINT_VECTKEY | g_pui32Priority[ui32Bits];
- }
- uint32_t
- IntPriorityGroupingGet(void)
- {
- uint32_t ui32Loop, ui32Value;
-
-
-
- ui32Value = HWREG(NVIC_APINT) & NVIC_APINT_PRIGROUP_M;
-
-
-
- for(ui32Loop = 0; ui32Loop < NUM_PRIORITY; ui32Loop++)
- {
-
-
-
- if(ui32Value == g_pui32Priority[ui32Loop])
- {
- break;
- }
- }
-
-
-
- return(ui32Loop);
- }
- void
- IntPrioritySet(uint32_t ui32Interrupt, uint8_t ui8Priority)
- {
- uint32_t ui32Temp;
-
-
-
- ASSERT((ui32Interrupt >= 4) && (ui32Interrupt < NUM_INTERRUPTS));
-
-
-
- ui32Temp = HWREG(g_pui32Regs[ui32Interrupt >> 2]);
- ui32Temp &= ~(0xFF << (8 * (ui32Interrupt & 3)));
- ui32Temp |= ui8Priority << (8 * (ui32Interrupt & 3));
- HWREG(g_pui32Regs[ui32Interrupt >> 2]) = ui32Temp;
- }
- int32_t
- IntPriorityGet(uint32_t ui32Interrupt)
- {
-
-
-
- ASSERT((ui32Interrupt >= 4) && (ui32Interrupt < NUM_INTERRUPTS));
-
-
-
- return((HWREG(g_pui32Regs[ui32Interrupt >> 2]) >> (8 * (ui32Interrupt & 3))) &
- 0xFF);
- }
- void
- IntEnable(uint32_t ui32Interrupt)
- {
-
-
-
- ASSERT(ui32Interrupt < NUM_INTERRUPTS);
-
-
-
- if(ui32Interrupt == FAULT_MPU)
- {
-
-
-
- HWREG(NVIC_SYS_HND_CTRL) |= NVIC_SYS_HND_CTRL_MEM;
- }
- else if(ui32Interrupt == FAULT_BUS)
- {
-
-
-
- HWREG(NVIC_SYS_HND_CTRL) |= NVIC_SYS_HND_CTRL_BUS;
- }
- else if(ui32Interrupt == FAULT_USAGE)
- {
-
-
-
- HWREG(NVIC_SYS_HND_CTRL) |= NVIC_SYS_HND_CTRL_USAGE;
- }
- else if(ui32Interrupt == FAULT_SYSTICK)
- {
-
-
-
- HWREG(NVIC_ST_CTRL) |= NVIC_ST_CTRL_INTEN;
- }
- else if(ui32Interrupt >= 16)
- {
-
-
-
- HWREG(g_pui32EnRegs[(ui32Interrupt - 16) / 32]) =
- 1 << ((ui32Interrupt - 16) & 31);
- }
- }
- void
- IntDisable(uint32_t ui32Interrupt)
- {
-
-
-
- ASSERT(ui32Interrupt < NUM_INTERRUPTS);
-
-
-
- if(ui32Interrupt == FAULT_MPU)
- {
-
-
-
- HWREG(NVIC_SYS_HND_CTRL) &= ~(NVIC_SYS_HND_CTRL_MEM);
- }
- else if(ui32Interrupt == FAULT_BUS)
- {
-
-
-
- HWREG(NVIC_SYS_HND_CTRL) &= ~(NVIC_SYS_HND_CTRL_BUS);
- }
- else if(ui32Interrupt == FAULT_USAGE)
- {
-
-
-
- HWREG(NVIC_SYS_HND_CTRL) &= ~(NVIC_SYS_HND_CTRL_USAGE);
- }
- else if(ui32Interrupt == FAULT_SYSTICK)
- {
-
-
-
- HWREG(NVIC_ST_CTRL) &= ~(NVIC_ST_CTRL_INTEN);
- }
- else if(ui32Interrupt >= 16)
- {
-
-
-
- HWREG(g_pui32DisRegs[(ui32Interrupt - 16) / 32]) =
- 1 << ((ui32Interrupt - 16) & 31);
- }
- }
- void
- IntPendSet(uint32_t ui32Interrupt)
- {
-
-
-
- ASSERT(ui32Interrupt < NUM_INTERRUPTS);
-
-
-
- if(ui32Interrupt == FAULT_NMI)
- {
-
-
-
- HWREG(NVIC_INT_CTRL) |= NVIC_INT_CTRL_NMI_SET;
- }
- else if(ui32Interrupt == FAULT_PENDSV)
- {
-
-
-
- HWREG(NVIC_INT_CTRL) |= NVIC_INT_CTRL_PEND_SV;
- }
- else if(ui32Interrupt == FAULT_SYSTICK)
- {
-
-
-
- HWREG(NVIC_INT_CTRL) |= NVIC_INT_CTRL_PENDSTSET;
- }
- else if(ui32Interrupt >= 16)
- {
-
-
-
- HWREG(g_pui32PendRegs[(ui32Interrupt - 16) / 32]) =
- 1 << ((ui32Interrupt - 16) & 31);
- }
- }
- void
- IntPendClear(uint32_t ui32Interrupt)
- {
-
-
-
- ASSERT(ui32Interrupt < NUM_INTERRUPTS);
-
-
-
- if(ui32Interrupt == FAULT_PENDSV)
- {
-
-
-
- HWREG(NVIC_INT_CTRL) |= NVIC_INT_CTRL_UNPEND_SV;
- }
- else if(ui32Interrupt == FAULT_SYSTICK)
- {
-
-
-
- HWREG(NVIC_INT_CTRL) |= NVIC_INT_CTRL_PENDSTCLR;
- }
- else if(ui32Interrupt >= 16)
- {
-
-
-
- HWREG(g_pui32UnpendRegs[(ui32Interrupt - 16) / 32]) =
- 1 << ((ui32Interrupt - 16) & 31);
- }
- }
- void
- IntPriorityMaskSet(uint32_t ui32PriorityMask)
- {
- CPUbasepriSet(ui32PriorityMask);
- }
- uint32_t
- IntPriorityMaskGet(void)
- {
- return(CPUbasepriGet());
- }
- void IntAltMapEnable(void)
- {
- HWREG(SYS_CTRL_I_MAP) |= SYS_CTRL_I_MAP_ALTMAP;
- }
- void IntAltMapDisable(void)
- {
- HWREG(SYS_CTRL_I_MAP) &= ~SYS_CTRL_I_MAP_ALTMAP;
- }
- bool IntAltMapIsEnabled(void)
- {
- if(HWREG(SYS_CTRL_I_MAP) & SYS_CTRL_I_MAP_ALTMAP)
- {
- return (true);
- }
- else
- {
- return (false);
- }
- }
|