Index: Common.h =================================================================== diff -u -rd352b607eeb20a7f06c32d776e5db2e35932ede2 -r62f81f0f9649926feae18dc09da001690dbcd26e --- Common.h (.../Common.h) (revision d352b607eeb20a7f06c32d776e5db2e35932ede2) +++ Common.h (.../Common.h) (revision 62f81f0f9649926feae18dc09da001690dbcd26e) @@ -27,7 +27,7 @@ #define DEBUG_ENABLED 1 #define UF_TEST_ENABLED 1 // #define DISABLE_CRC_ERROR 1 - #define DISABLE_MOTOR_CURRENT_ERRORS 1 +// #define DISABLE_MOTOR_CURRENT_ERRORS 1 #define SHOW_RAW_FLOW_VALUES 1 // #define CAN_TEST 1 Index: Timers.c =================================================================== diff -u --- Timers.c (revision 0) +++ Timers.c (revision 62f81f0f9649926feae18dc09da001690dbcd26e) @@ -0,0 +1,160 @@ +/************************************************************************** + * + * Copyright (c) 2019-2020 Diality Inc. - All Rights Reserved. + * + * THIS CODE MAY NOT BE COPIED OR REPRODUCED IN ANY FORM, IN PART OR IN + * WHOLE, WITHOUT THE EXPLICIT PERMISSION OF THE COPYRIGHT OWNER. + * + * @file Timers.c + * + * @date 25-Sep-2019 + * @author S. Nash + * + * @brief Timers service module. Provides miscellaneous timer functions. + * + **************************************************************************/ + +#include "Timers.h" + +// ********** private definitions ********** + +// ********** private data ********** + +static U32 msTimerCount = 0; + +/************************************************************************* + * @brief + * The initTimers function initializes the Timers module. + * @details + * Inputs : none + * Outputs : Timers module initialized. + * @param none + * @return none + *************************************************************************/ +void initTimers( void ) +{ + msTimerCount = 0; +} + +/************************************************************************* + * @brief + * The incMSTimerCount function increments the ms timer count. + * @details + * Inputs : none + * Outputs : msTimerCount incremented + * @param none + * @return none + *************************************************************************/ +void incMSTimerCount( void ) +{ + msTimerCount++; +} + +/************************************************************************* + * @brief + * The getMSTimerCount function returns the current ms timer count. + * @details + * Inputs : msTimerCount + * Outputs : none + * @param none + * @return msTimerCount + *************************************************************************/ +U32 getMSTimerCount( void ) +{ + return msTimerCount; +} + +/************************************************************************* + * @brief + * The didTimeout function determines whether a timeout has occurred between \n + * a given start count and a given timeout period (in ms). + * @details + * Inputs : msTimerCount + * Outputs : none + * @param startMSCount : the ms count at the start of the timeout period + * @param timeoutPeriod : the period for the timeout (in ms) + * @return TRUE if a timeout has occurred, FALSE if not + *************************************************************************/ +BOOL didTimeout( U32 startMSCount, U32 timeoutPeriod ) +{ + BOOL result = FALSE; + U32 currMSCount = msTimerCount; + + // no wrap + if ( currMSCount >= startMSCount ) + { + if ( ( currMSCount - startMSCount ) >= timeoutPeriod ) + { + result = TRUE; + } + } + // counter wrapped + else + { + U32 deltaMSCount = ( 0xFFFFFFFF - startMSCount ) + currMSCount + 1; + + if ( deltaMSCount >= timeoutPeriod ) + { + result = TRUE; + } + } + + return result; +} + +/************************************************************************* + * @brief + * The calcTimeSince function calculates the time (in ms) from a given start \n + * time until now. + * @details + * Inputs : msTimerCount + * Outputs : none + * @param startMSCount : the ms count at the start of the period + * @return ms since given start time + *************************************************************************/ +U32 calcTimeSince( U32 startMSCount ) +{ + U32 result; + U32 currMSCount = msTimerCount; + + // no wrap + if ( currMSCount >= startMSCount ) + { + result = currMSCount - startMSCount; + } + else + { + result = ( 0xFFFFFFFF - startMSCount ) + currMSCount + 1; + } + + return result; +} + +/************************************************************************* + * @brief + * The calcTimeBetween function calculates the time (in ms) from a given start \n + * time until a given end time. + * @details + * Inputs : none + * Outputs : none + * @param startMSCount : the ms count at the start of the period + * @param endMSCount : the ms count at the end of the period + * @return ms between two given times + *************************************************************************/ +U32 calcTimeBetween( U32 startMSCount, U32 endMSCount ) +{ + U32 result; + + // no wrap + if ( endMSCount >= startMSCount ) + { + result = endMSCount - startMSCount; + } + else + { + result = ( 0xFFFFFFFF - startMSCount ) + endMSCount + 1; + } + + return result; +} + Index: Timers.h =================================================================== diff -u --- Timers.h (revision 0) +++ Timers.h (revision 62f81f0f9649926feae18dc09da001690dbcd26e) @@ -0,0 +1,31 @@ +/************************************************************************** + * + * Copyright (c) 2019-2020 Diality Inc. - All Rights Reserved. + * + * THIS CODE MAY NOT BE COPIED OR REPRODUCED IN ANY FORM, IN PART OR IN + * WHOLE, WITHOUT THE EXPLICIT PERMISSION OF THE COPYRIGHT OWNER. + * + * @file Timers.h + * + * @date 25-Sep-2019 + * @author S. Nash + * + * @brief header file for Timers service . + * + **************************************************************************/ + +#ifndef __TIMERS_H__ +#define __TIMERS_H__ + +#include "Common.h" + +// ********** public function prototypes ********** + +void initTimers( void ); +void incMSTimerCount( void ); +U32 getMSTimerCount( void ); +BOOL didTimeout( U32 startMSCount, U32 timeoutPeriod ); +U32 calcTimeSince( U32 startMSCount ); +U32 calcTimeBetween( U32 startMSCount, U32 endMSCount ); + +#endif Index: Utilities.c =================================================================== diff -u --- Utilities.c (revision 0) +++ Utilities.c (revision 62f81f0f9649926feae18dc09da001690dbcd26e) @@ -0,0 +1,130 @@ +/************************************************************************** + * + * Copyright (c) 2019-2020 Diality Inc. - All Rights Reserved. + * + * THIS CODE MAY NOT BE COPIED OR REPRODUCED IN ANY FORM, IN PART OR IN + * WHOLE, WITHOUT THE EXPLICIT PERMISSION OF THE COPYRIGHT OWNER. + * + * @file Utilities.c + * + * @date 23-Oct-2019 + * @author S. Nash + * + * @brief Utilities service module. Provides miscellaneous utility \n + * functions. + * + **************************************************************************/ + +#include "Common.h" +#include "Utilities.h" + +// ********** private definitions ********** + +#define INITIAL_CRC16_VAL 0xFFFF +#define INITIAL_CRC08_VAL 0x00 + +// ********** private data ********** + +const U16 crc16_table[] = +{ + 0x0000, 0x1021, 0x2042, 0x3063, 0x4084, 0x50a5, 0x60c6, 0x70e7, + 0x8108, 0x9129, 0xa14a, 0xb16b, 0xc18c, 0xd1ad, 0xe1ce, 0xf1ef, + 0x1231, 0x0210, 0x3273, 0x2252, 0x52b5, 0x4294, 0x72f7, 0x62d6, + 0x9339, 0x8318, 0xb37b, 0xa35a, 0xd3bd, 0xc39c, 0xf3ff, 0xe3de, + 0x2462, 0x3443, 0x0420, 0x1401, 0x64e6, 0x74c7, 0x44a4, 0x5485, + 0xa56a, 0xb54b, 0x8528, 0x9509, 0xe5ee, 0xf5cf, 0xc5ac, 0xd58d, + 0x3653, 0x2672, 0x1611, 0x0630, 0x76d7, 0x66f6, 0x5695, 0x46b4, + 0xb75b, 0xa77a, 0x9719, 0x8738, 0xf7df, 0xe7fe, 0xd79d, 0xc7bc, + 0x48c4, 0x58e5, 0x6886, 0x78a7, 0x0840, 0x1861, 0x2802, 0x3823, + 0xc9cc, 0xd9ed, 0xe98e, 0xf9af, 0x8948, 0x9969, 0xa90a, 0xb92b, + 0x5af5, 0x4ad4, 0x7ab7, 0x6a96, 0x1a71, 0x0a50, 0x3a33, 0x2a12, + 0xdbfd, 0xcbdc, 0xfbbf, 0xeb9e, 0x9b79, 0x8b58, 0xbb3b, 0xab1a, + 0x6ca6, 0x7c87, 0x4ce4, 0x5cc5, 0x2c22, 0x3c03, 0x0c60, 0x1c41, + 0xedae, 0xfd8f, 0xcdec, 0xddcd, 0xad2a, 0xbd0b, 0x8d68, 0x9d49, + 0x7e97, 0x6eb6, 0x5ed5, 0x4ef4, 0x3e13, 0x2e32, 0x1e51, 0x0e70, + 0xff9f, 0xefbe, 0xdfdd, 0xcffc, 0xbf1b, 0xaf3a, 0x9f59, 0x8f78, + 0x9188, 0x81a9, 0xb1ca, 0xa1eb, 0xd10c, 0xc12d, 0xf14e, 0xe16f, + 0x1080, 0x00a1, 0x30c2, 0x20e3, 0x5004, 0x4025, 0x7046, 0x6067, + 0x83b9, 0x9398, 0xa3fb, 0xb3da, 0xc33d, 0xd31c, 0xe37f, 0xf35e, + 0x02b1, 0x1290, 0x22f3, 0x32d2, 0x4235, 0x5214, 0x6277, 0x7256, + 0xb5ea, 0xa5cb, 0x95a8, 0x8589, 0xf56e, 0xe54f, 0xd52c, 0xc50d, + 0x34e2, 0x24c3, 0x14a0, 0x0481, 0x7466, 0x6447, 0x5424, 0x4405, + 0xa7db, 0xb7fa, 0x8799, 0x97b8, 0xe75f, 0xf77e, 0xc71d, 0xd73c, + 0x26d3, 0x36f2, 0x0691, 0x16b0, 0x6657, 0x7676, 0x4615, 0x5634, + 0xd94c, 0xc96d, 0xf90e, 0xe92f, 0x99c8, 0x89e9, 0xb98a, 0xa9ab, + 0x5844, 0x4865, 0x7806, 0x6827, 0x18c0, 0x08e1, 0x3882, 0x28a3, + 0xcb7d, 0xdb5c, 0xeb3f, 0xfb1e, 0x8bf9, 0x9bd8, 0xabbb, 0xbb9a, + 0x4a75, 0x5a54, 0x6a37, 0x7a16, 0x0af1, 0x1ad0, 0x2ab3, 0x3a92, + 0xfd2e, 0xed0f, 0xdd6c, 0xcd4d, 0xbdaa, 0xad8b, 0x9de8, 0x8dc9, + 0x7c26, 0x6c07, 0x5c64, 0x4c45, 0x3ca2, 0x2c83, 0x1ce0, 0x0cc1, + 0xef1f, 0xff3e, 0xcf5d, 0xdf7c, 0xaf9b, 0xbfba, 0x8fd9, 0x9ff8, + 0x6e17, 0x7e36, 0x4e55, 0x5e74, 0x2e93, 0x3eb2, 0x0ed1, 0x1ef0 +}; + +const U08 crc8_table[] = { + 0, 49, 98, 83, 196, 245, 166, 151, 185, 136, 219, 234, 125, 76, 31, 46, + 67, 114, 33, 16, 135, 182, 229, 212, 250, 203, 152, 169, 62, 15, 92, 109, + 134, 183, 228, 213, 66, 115, 32, 17, 63, 14, 93, 108, 251, 202, 153, 168, + 197, 244, 167, 150, 1, 48, 99, 82, 124, 77, 30, 47, 184, 137, 218, 235, + 61, 12, 95, 110, 249, 200, 155, 170, 132, 181, 230, 215, 64, 113, 34, 19, + 126, 79, 28, 45, 186, 139, 216, 233, 199, 246, 165, 148, 3, 50, 97, 80, + 187, 138, 217, 232, 127, 78, 29, 44, 2, 51, 96, 81, 198, 247, 164, 149, + 248, 201, 154, 171, 60, 13, 94, 111, 65, 112, 35, 18, 133, 180, 231, 214, + 122, 75, 24, 41, 190, 143, 220, 237, 195, 242, 161, 144, 7, 54, 101, 84, + 57, 8, 91, 106, 253, 204, 159, 174, 128, 177, 226, 211, 68, 117, 38, 23, + 252, 205, 158, 175, 56, 9, 90, 107, 69, 116, 39, 22, 129, 176, 227, 210, + 191, 142, 221, 236, 123, 74, 25, 40, 6, 55, 100, 85, 194, 243, 160, 145, + 71, 118, 37, 20, 131, 178, 225, 208, 254, 207, 156, 173, 58, 11, 88, 105, + 4, 53, 102, 87, 192, 241, 162, 147, 189, 140, 223, 238, 121, 72, 27, 42, + 193, 240, 163, 146, 5, 52, 103, 86, 120, 73, 26, 43, 188, 141, 222, 239, + 130, 179, 224, 209, 70, 119, 36, 21, 59, 10, 89, 104, 255, 206, 157, 172 +}; + +/************************************************************************* + * @brief crc16 + * The crc16 function calculates a 16-bit CRC for a given range of bytes \n + * in memory. Poly = 0x1021. Not reflected. Initial value = 0xFFFF. + * @details + * Inputs : none + * Outputs : none + * @param address : pointer to start address of memory range to calculate CRC for + * @param len : # of bytes in the memory range to calculate CRC for + * @return CRC + *************************************************************************/ +U16 crc16( const U08 *address, U32 len ) +{ + U16 crc = INITIAL_CRC16_VAL; + + while ( len-- > 0 ) + { + crc = ( crc << SHIFT_8_BITS_FOR_BYTE_SHIFT ) ^ crc16_table[ *address ^ ( ( crc >> SHIFT_8_BITS_FOR_BYTE_SHIFT ) & MASK_OFF_MSB ) ]; + address++; + } + + return crc; +} + +/************************************************************************* + * @brief crc8 + * The crc8 function calculates a 8-bit CRC for a given range of bytes \n + * in memory. + * @details + * Inputs : none + * Outputs : none + * @param address : pointer to start address of memory range to calculate CRC for + * @param len : # of bytes in the memory range to calculate CRC for + * @return CRC + *************************************************************************/ +U08 crc8( const U08 *address, U32 len ) +{ + U08 crc = INITIAL_CRC08_VAL; + + while ( len-- > 0 ) + { + crc = crc8_table[ (*address) ^ crc ]; + address++; + } + + return crc; +} + Index: Utilities.h =================================================================== diff -u --- Utilities.h (revision 0) +++ Utilities.h (revision 62f81f0f9649926feae18dc09da001690dbcd26e) @@ -0,0 +1,28 @@ +/************************************************************************** + * + * Copyright (c) 2019-2020 Diality Inc. - All Rights Reserved. + * + * THIS CODE MAY NOT BE COPIED OR REPRODUCED IN ANY FORM, IN PART OR IN + * WHOLE, WITHOUT THE EXPLICIT PERMISSION OF THE COPYRIGHT OWNER. + * + * @file Utilities.h + * + * @date 23-Oct-2019 + * @author S. Nash + * + * @brief header file for utilities service module. + * + **************************************************************************/ + +#ifndef __UTILITIES_H__ +#define __UTILITIES_H__ + +// ********** public definitions ********** + + +// ********** public function prototypes ********** + +U16 crc16( const U08 *address, U32 len ); +U08 crc8( const U08 *address, U32 len ); + +#endif Index: irqDispatch_a.asm =================================================================== diff -u --- irqDispatch_a.asm (revision 0) +++ irqDispatch_a.asm (revision 62f81f0f9649926feae18dc09da001690dbcd26e) @@ -0,0 +1,74 @@ +;------------------------------------------------------------------------------- +; irqDispatch_a.asm +; +; (c) Texas Instruments 2009-2012, All rights reserved. +; + + ; Export Symbols + .def _irqDispatch + + ; Import Symbols + .ref C_irqDispatch + + ; The following should be placed in the .text section + .text + + ; Function: _irqDispatch + .align 4 + .armfunc _irqDispatch + + ; Use ARM mode assembly + .arm + + ; Note: This implementation is for ARMv7-R (Cortex-R4) in ARM mode only. + +_irqDispatch: .asmfunc + ; TI ASM Step 1: + SUB LR, LR, #4 ; construct the return address + SRSDB #31! ; Save LR_irq and SPSR_irq to System mode stack + + ; TI ASM Step 2: + CPS #31 ; Switch to System mode + + ; TI ASM Step 3: + PUSH {R0-R3, R12} ; Store AAPCS registers + + .if __TI_VFPV3D16_SUPPORT__ = 1 ; If VFPV3D16 is used + FMRX R12, FPSCR + STMFD SP!, {R12} + FMRX R12, FPEXC + STMFD SP!, {R12} + FSTMDBD SP!, {D0-D7} + .endif + + ; TI ASM Step 4 + ; Align stack to a 64 Bit boundary + AND R3, SP, #4 ; Calculate Stack adjustment to 64bit boundary + SUB SP, SP, R3 ; Adjust System Stack + PUSH {R3, LR} ; Put Stack adjustment and System Mode LR on Stack + + ; TI ASM Step 5 + BL C_irqDispatch ; Call Second Level IRQ Dispatcher C routine + + ; TI ASM Step 6 + ; Undo stack alignment + POP {R3, LR} ; Get Stack adjustment and System Mode LR from Stack + ADD SP, SP, R3 ; Undo System Stack adjustment + + ; TI ASM Step 7 + .if __TI_VFPV3D16_SUPPORT__ = 1 ; If VFPV3D16 is used + FLDMIAD SP!, {D0-D7} + LDMFD SP!, {R12} + FMXR FPEXC, R12 + LDMFD SP!, {R12} + FMXR FPSCR, R12 + .endif + + POP {R0-R3, R12} ; Restore AAPCS registers + + ; TI ASM Step 7 + RFEIA SP! ; Return using RFE from System mode stack + .endasmfunc + + .end +;------------------------------------------------------------------------------- Index: irqDispatch_c.c =================================================================== diff -u --- irqDispatch_c.c (revision 0) +++ irqDispatch_c.c (revision 62f81f0f9649926feae18dc09da001690dbcd26e) @@ -0,0 +1,222 @@ +/************************************************************************** + * + * Copyright (c) 2019-2020 Diality Inc. - All Rights Reserved. + * + * THIS CODE MAY NOT BE COPIED OR REPRODUCED IN ANY FORM, IN PART OR IN + * WHOLE, WITHOUT THE EXPLICIT PERMISSION OF THE COPYRIGHT OWNER. + * + * @file irqDispatch_c.c + * + * @date 30-Sep-2019 + * @author S. Nash (Modified example from Texas Instruments - 5/13/2014) + * + * @brief Contains Second Level IRQ Dispatcher C routine + * + **************************************************************************/ + +#if defined(__TI_VIM_128CH__) +#include "sys_common.h" +#include "sys_vim.h" +#elif defined(__TI_VIM_96CH__) +#include "sys_common.h" +#include "sys_vim.h" +#else +#error File irqDispatcher.c requires either __TI_VIM_96CH__ or __TI_VIM_128CH__ to be defined. +#endif + + +/** @typedef vimRAM_t + * @brief Vim Ram Definition + * + * This type is used to access the VIM RAM. + */ + +typedef volatile struct vimRam +{ + t_isrFuncPTR ISR[VIM_CHANNELS + 1]; +} vimRAM_t; + + +/** @var vimRAM_t * const vimRAM + * @brief vimRAM definition + * + * This variable is used to access the VIM RAM. + */ + +static const vimRAM_t * const vimRAM = ((vimRAM_t *)0xFFF82000U); + + +/** @var sint32 s32NestingLevel; + * @brief Variable to store the current level of nesting + * + */ + +static sint32 s32NestingLevel = 0; + + +/** @def MAX_NESTING_LEVEL + * @brief Defines max nesting deep + * + */ + +#define MAX_NESTING_LEVEL 8 + + +/** @fn void C_irqDispatch(void) + * @brief Second Level IRQ Dispatcher C routine + * @note This implementation is limited to the use of the first 96 interrupt priority's. + * + */ + +/* Ensure that the function is coded with ARM mode instructions. */ +#pragma CODE_STATE(C_irqDispatch, 32); +/* Inform the Compiler that the function is called externally, and thus should not be removed. */ +#pragma FUNC_EXT_CALLED(C_irqDispatch); +void C_irqDispatch(void) +{ + /* TI C Step 1 */ + uint32 u32IrqIndex = vimREG->IRQINDEX; /* Read IRQ Index Offset Vector */ + + /* TI C Step 2 */ + t_isrFuncPTR irq_func_pnt = vimRAM->ISR[u32IrqIndex]; /* Read IRQ Interrupt Vector */ + /** Note: + * Do not use the IRQVECREG to readout the vector address, as this could change between Step 1 and 2. + * As an alternative you could read out the vector from the constant table which was used to initialize the VIM RAM. + * This method should be faster than reading the vector address from the VIM RAM, as Flash accesses are faster than peripheral accesses. + */ + + /* IRQIVEC is zero if no interrupt is pending */ + if (0U == u32IrqIndex) + { + /* Phantom Interrupt */ + + /** @todo + * Add custom fault handler, if necessary. + */ + + // while(1); + // TODO - understand why we might get here and decide what we want to do + } + else + { + /* Increment Nesting Level indicator */ + s32NestingLevel++; + + /* If Nesting Level indicator is less than the max level, enable IRQ to allow further preemption */ + if ((MAX_NESTING_LEVEL) > s32NestingLevel) + { + /* TI C Step 3 */ + /* Save VIM REQENASET[0,1,2] Registers for later restore */ + uint32 SaveREQMASKSET0 = vimREG->REQMASKSET0; + uint32 SaveREQMASKSET1 = vimREG->REQMASKSET1; + uint32 SaveREQMASKSET2 = vimREG->REQMASKSET2; +#if defined(__TI_VIM_128CH__) + uint32 SaveREQMASKSET3 = vimREG->REQMASKSET3; +#endif + + /* TI C Step 4 */ + /* Mask out lower priority IRQ's and the current IRQ itself, keep FIQ's enabled */ + if (96U < u32IrqIndex) /* 96-...*/ + { +#if defined(__TI_VIM_128CH__) + /* REG->REQMASKCLR0 = ( 0xFFFFFFFCU & (~vimREG->FIRQPR0)); Higher priority */ + /* REG->REQMASKCLR1 = ( 0xFFFFFFFFU & (~vimREG->FIRQPR1)); Higher priority */ + /* REG->REQMASKCLR2 = ( 0xFFFFFFFFU & (~vimREG->FIRQPR2)); Higher priority */ + vimREG->REQMASKCLR3 = ((0xFFFFFFFFU << (u32IrqIndex - 97U)) & (~vimREG->FIRQPR3)); + vimREG->REQMASKCLR3; /* Readback Mask to ensure that the previous write was finished before enabling interrupts again */ +#elif defined(__TI_VIM_96CH__) + /** @todo + * Add custom fault handler, if necessary. + */ + while (1); /* Fault */ +#else +#error File irqDispatcher.c requires either __TI_VIM_96CH__ or __TI_VIM_128CH__ to be defined. +#endif + } + else if (64U < u32IrqIndex) /* 64-96 */ + { + /* REG->REQMASKCLR0 = ( 0xFFFFFFFCU & (~vimREG->FIRQPR0)); Higher priority */ + /* REG->REQMASKCLR1 = ( 0xFFFFFFFFU & (~vimREG->FIRQPR1)); Higher priority */ + vimREG->REQMASKCLR2 = ((0xFFFFFFFFU << (u32IrqIndex - 65U)) & (~vimREG->FIRQPR2)); +#if defined(__TI_VIM_128CH__) + vimREG->REQMASKCLR3 = ( 0xFFFFFFFFU & (~vimREG->FIRQPR3)); + vimREG->REQMASKCLR3; /* Readback Mask to ensure that the previous write was finished before enabling interrupts again */ +#elif defined(__TI_VIM_96CH__) + vimREG->REQMASKCLR2; /* Readback Mask to ensure that the previous write was finished before enabling interrupts again */ +#else +#error File irqDispatcher.c requires either __TI_VIM_96CH__ or __TI_VIM_128CH__ to be defined. +#endif + } + else if (32U < u32IrqIndex) /* 32-63 */ + { + /* REG->REQMASKCLR0 = ( 0xFFFFFFFCU & (~vimREG->FIRQPR0)); Higher priority */ + vimREG->REQMASKCLR1 = ((0xFFFFFFFFU << (u32IrqIndex - 33U)) & (~vimREG->FIRQPR1)); + vimREG->REQMASKCLR2 = ( 0xFFFFFFFFU & (~vimREG->FIRQPR2)); +#if defined(__TI_VIM_128CH__) + vimREG->REQMASKCLR3 = ( 0xFFFFFFFFU & (~vimREG->FIRQPR3)); + vimREG->REQMASKCLR3; /* Readback Mask to ensure that the previous write was finished before enabling interrupts again */ +#elif defined(__TI_VIM_96CH__) + vimREG->REQMASKCLR2; /* Readback Mask to ensure that the previous write was finished before enabling interrupts again */ +#else +#error File irqDispatcher.c requires either __TI_VIM_96CH__ or __TI_VIM_128CH__ to be defined. +#endif + } + else if ( 2U < u32IrqIndex) /* 2-31 */ + { + + vimREG->REQMASKCLR0 = ((0xFFFFFFFFU << (u32IrqIndex - 1U)) & (~vimREG->FIRQPR0)); + vimREG->REQMASKCLR1 = ( 0xFFFFFFFFU & (~vimREG->FIRQPR1)); + vimREG->REQMASKCLR2 = ( 0xFFFFFFFFU & (~vimREG->FIRQPR2)); +#if defined(__TI_VIM_128CH__) + vimREG->REQMASKCLR3 = ( 0xFFFFFFFFU & (~vimREG->FIRQPR3)); + vimREG->REQMASKCLR3; /* Readback Mask to ensure that the previous write was finished before enabling interrupts again */ +#elif defined(__TI_VIM_96CH__) + vimREG->REQMASKCLR2; /* Readback Mask to ensure that the previous write was finished before enabling interrupts again */ +#else +#error File irqDispatcher.c requires either __TI_VIM_96CH__ or __TI_VIM_128CH__ to be defined. +#endif + } + else /* if (0U < u32IrqIndex) */ /* 0 and 1 */ + { + /* Vectors 0 and 1 are tied to FIQ and this code is thus dead for IRQ. */ + + /** @todo + * Add custom fault handler, if necessary. + */ + + while (1); /* Fault */ + } + + /* TI C Step 5 */ + _enable_IRQ(); /* Enable IRQ, to allow preemption of IRQ routine */ + + /* TI C Step 6 */ + (*irq_func_pnt)(); /* Execute interrupt routine */ + + /* TI C Step 7 */ + _disable_IRQ(); /* Disable IRQ, to protect the remainder of the dispatcher from preemption */ + + /* TI C Step 8 */ + /* Restore VIM REQENASET[0,1,2] Registers */ + vimREG->REQMASKSET0 = SaveREQMASKSET0; + vimREG->REQMASKSET1 = SaveREQMASKSET1; + vimREG->REQMASKSET2 = SaveREQMASKSET2; +#if defined(__TI_VIM_128CH__) + vimREG->REQMASKSET3 = SaveREQMASKSET3; +#endif + } + else + { + /* Do not enable IRQ, because max nesting level was reached */ + (*irq_func_pnt)(); /* Execute interrupt routine */ + } + + if (0 < s32NestingLevel) + { + s32NestingLevel--; + } + } + + /* TI C Step 9 */ + return; /* Return to First Level IRQ Dispatcher Assembly routine */ +}