FreeRTOS - Hardware-dependent

Created:2018-11-15  Last modified:2018-11-15


  1. Port

    Hardware-dependent code is defined in the port.c source file.

  2. Function

    1. disable/enable interrupt

      By disabling and enabling interrupts, we can create a hard critical section

      This is imp

                              taskENTER_CRITICAL();
                              #define taskENTER_CRITICAL()		portENTER_CRITICAL() // task.h
                              #define portENTER_CRITICAL()		vPortEnterCritical() // portmacro.h
      
                              void vPortEnterCritical( void ) // port.c
                              {
                                  portDISABLE_INTERRUPTS();
                                  uxCriticalNesting++;
      
                                  /* This is not the interrupt safe version of the enter critical function so
                                  assert() if it is being called from an interrupt context.  Only API
                                  functions that end in "FromISR" can be used in an interrupt.  Only assert if
                                  the critical nesting count is 1 to protect against recursive calls if the
                                  assert function also uses a critical section. */
                                  if( uxCriticalNesting == 1 )
                                  {
                                      configASSERT( ( portNVIC_INT_CTRL_REG & portVECTACTIVE_MASK ) == 0 );
                                  }
                              }
                              #define portDISABLE_INTERRUPTS()				vPortRaiseBASEPRI() // portmacro.h
      
                              static portFORCE_INLINE void vPortRaiseBASEPRI( void )  // portmacro.h
                              {
                                  uint32_t ulNewBASEPRI = configMAX_SYSCALL_INTERRUPT_PRIORITY; // which is  5 << (8-4) = 0b01010000 = 0x50
      
                                  __asm
                                  {
                                      /* Set BASEPRI to the max syscall priority to effect a critical
                                      section. */
                                      msr basepri, ulNewBASEPRI
                                      dsb
                                      isb
                                  }
                              }
                              #define configPRIO_BITS         4   // FreeRTOSConfig.h
                              #define configLIBRARY_MAX_SYSCALL_INTERRUPT_PRIORITY 5
                              #define configMAX_SYSCALL_INTERRUPT_PRIORITY 	( configLIBRARY_MAX_SYSCALL_INTERRUPT_PRIORITY << (8 - configPRIO_BITS) ) 
                              
      
      
                          
  3. References