Skip to content

Commit 2e13eab

Browse files
Add an assert to catch register overflow (#1265)
1 parent 03db672 commit 2e13eab

1 file changed

Lines changed: 5 additions & 0 deletions

File tree

portable/MPLAB/PIC32MZ/port.c

Lines changed: 5 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -234,6 +234,11 @@ __attribute__(( weak )) void vApplicationSetupTickTimerInterrupt( void )
234234
{
235235
const uint32_t ulCompareMatch = ( (configPERIPHERAL_CLOCK_HZ / portTIMER_PRESCALE) / configTICK_RATE_HZ ) - 1UL;
236236

237+
/* PR1 is 16-bit. Ensure that the configPERIPHERAL_CLOCK_HZ and
238+
* configTICK_RATE_HZ are defined such that ulCompareMatch value would fit
239+
* in 16-bits. */
240+
configASSERT( ( ulCompareMatch & 0xFFFF0000 ) == 0 );
241+
237242
T1CON = 0x0000;
238243
T1CONbits.TCKPS = portPRESCALE_BITS;
239244
PR1 = ulCompareMatch;

0 commit comments

Comments
 (0)