I had a problem getting the H8/S port to run on an H8S/2212 – it kept crashing, with even the simplest of tasks (flashing an LED). Working through the FreeRTOS code, I finally discovered that as distributed, it supports only Interrupt Control Mode 0. We’re using Interrupt Control Mode 2 (prioritized interrupts) in our project. Here’s the fix, if anyone else needs it:
In portmacro.h, I added a new #define portINTERRUPT_MODE_2 and then changed the critical section macros as follows:
/* define the following if Interrupt Control Mode 2 is used */
#define portINTERRUPT_MODE_2
/*-----------------------------------------------------------*/
#ifdef portINTERRUPT_MODE_2
/* Critical section handling. */
#define portENABLE_INTERRUPTS() asm volatile( "ANDC #0xF8, EXR" );
#define portDISABLE_INTERRUPTS() asm volatile( "ORC #0x07, EXR" );
/* Push the EXR then disable interrupts. */
#define portENTER_CRITICAL() asm volatile( "STC EXR, @-ER7" );
portDISABLE_INTERRUPTS();
/* Pop the EXR to set the interrupt masking back to its previous state. */
#define portEXIT_CRITICAL() asm volatile( "LDC @ER7+, EXR" );
#else
/* Critical section handling. */
#define portENABLE_INTERRUPTS() asm volatile( "ANDC #0x7F, CCR" );
#define portDISABLE_INTERRUPTS() asm volatile( "ORC #0x80, CCR" );
/* Push the CCR then disable interrupts. */
#define portENTER_CRITICAL() asm volatile( "STC CCR, @-ER7" );
portDISABLE_INTERRUPTS();
/* Pop the CCR to set the interrupt masking back to its previous state. */
#define portEXIT_CRITICAL() asm volatile( "LDC @ER7+, CCR" );
#endif
/*-----------------------------------------------------------*/
In function pxPortInitialiseStack, in file port.c, I changed the CCR initialization as follows:
/* Followed by the CCR. */
pxTopOfStack--;
*pxTopOfStack = portINITIAL_CCR;
/* If H8S interrupt mode 2 is used, we also need to push EXR */
#ifdef portINTERRUPT_MODE_2
pxTopOfStack--;
*pxTopOfStack = 0;
pxTopOfStack--;
*pxTopOfStack = portINITIAL_EXR;
#endif
with this at the top of the file:
/* If interrupt control mode 2 is used, the interrupt stack is different */
#define portINITIAL_EXR ( ( portSTACK_TYPE ) 0x00 )