S32K148 SysTick_Handler

キャンセル
次の結果を表示 
表示  限定  | 次の代わりに検索 
もしかして: 

S32K148 SysTick_Handler

1,225件の閲覧回数
347996379
Contributor III

//====================================================================================
//函数名称 : u8 BSPSysTickInit(u32 time, u8 busClock)
//输入参数 : time:配置时间[1,200000](0.001ms即1us) busClock:总线时钟≥1(M)
//输出参数 : 初始化结果 TRUE:成功 FALSE:失败
//函数功能 : 系统闹钟定时中断驱动模块初始化
//注意事项 : BSP调用,系统us级定时
//===================================================================================
u8 BSPSysTickInit(u32 time, u8 busClock)
{
      //u32 clkTime = 0;

      //参数错误
      if((0 == time) || (time > 200000) || (0 == busClock))
      {
           return(FALSE);
        }

      S32_SysTick->RVR = 0xFFFFFF;//350ms
      //S32_SysTick->RVR = 0xBB3F;//1ms
      S32_SysTick->CVR = S32_SysTick_CVR_CURRENT(0);
      S32_SysTick->CVR = 0;
      S32_SysTick->CSR = S32_SysTick_CSR_TICKINT(1) | S32_SysTick_CSR_ENABLE(1);

      return(TRUE);
}

//====================================================================================
//函数名称 :void SysTick_Handler(void)
//输入参数 : void
//输出参数 : void
//函数功能 : 系统闹钟定时中断程序
//注意事项 : 底层调用,用于系统1ms定时
//====================================================================================
void SysTick_Handler(void)

{

      BSPCosRefur();

}

//====================================================================================
//函数名称 : void BSP_ENTER_CRITICAL(void)
//输入参数 : void
//输出参数 : void
//函数功能 : 进入临界区域(禁止中断)
//注意事项 :
//====================================================================================
void BSP_ENTER_CRITICAL(void)
{
      INT_SYS_DisableIRQGlobal();
}

//====================================================================================
//函数名称 : void BSP_EXIT_CRITICAL(void)
//输入参数 : void
//输出参数 : void
//函数功能 : 切换出临界区域(使能中断)
//注意事项 :
//====================================================================================
void BSP_EXIT_CRITICAL(void)
{
      INT_SYS_EnableIRQGlobal();
}

//====================================================================================
//函数名称 : void BSPCosRefur(void)
//输入参数 : void
//输出参数 : void
//函数功能 : 中断执行函数,设定COS任务标志
//注意事项 : 1ms定时中断调用
//====================================================================================
void BSPCosRefur(void)
{
      u8 i = 0;
      t_COS *pcos;

      sCOSTimer++;
   
      pcos = &sCosTbl[0];

      if(sCOSTimer >= COS_MAX_USEABLE_TIME)
      {
            for(i = 0; i < COS_MAX_NUM; i++)
            {
                  if(pcos->CosCtr != 0x0ffffffff)
                  {
                        pcos->CosCtr -= COS_MAX_USEABLE_TIME;
                  }
                  pcos++;
               }

         sCOSTimer -= COS_MAX_USEABLE_TIME;
         }

      pcos = &sCosTbl[0];
      for(i = 0; i < COS_MAX_NUM; i++)
      {
            if(pcos->CosEn == 1)
            {
                  if(pcos->CosCtr <= sCOSTimer)
                  {
                        pcos->CosRdy = 1;
                  }
            }
      pcos++;
      }
}

u32 watchcounter = 0;
//===================================================================================
//函数名称 : int main(void)
//输入参数 : void
//输出参数 : void
//函数功能 : 主函数,自动执行
//注意事项 :
//====================================================================================
int main(void)
{
      BSPSystemInit(); //初始化

      for(;;)
      {
            BSPCosTask((void *)0); //执行COS任务
            //watchcounter++;
      }
}

hello !

I have a question now.

When I use the system timer to interrupt, the interrupt works, the main function works, and the "watchcounter" variable counts normally.

But when I switch to my g task, the interrupt gets stuck and my "BSPCosTask((void *)0)" task doesn't work properly. Why?Is my Systick_Handler configuration abnormal?

0 件の賞賛
1 返信

1,050件の閲覧回数
victorjimenez
NXP TechSupport
NXP TechSupport

Hello,

Sorry for the late response. Could you please clarify where does your interrupt gets stuck? I took a look at your Systick_Handler, and it's not the best implementation. It's recommended to keep the interrupt handlers as short as possible, and in your case, you have a for loop.

I think you are trying to make a 1ms delay, is this correct? If this is the case, I would recommend you to use the function OSIF_TimeDelay, this function generates any delay in miliseconds. You can find it within the SDK in the files osif_baremetal.c and osif_baremetal.h. If you import the lin_master example provided in the SDK, you will find these files on the following path: lin_master_s32k148 > SDK > rtos > osif.

pastedImage_24.png

Best regards,

Victor

0 件の賞賛