查看: 3434|回复: 0

[S12] MC9S12G系列芯片,FLASH擦写时能开总中断吗?

[复制链接]
  • TA的每日心情
    慵懒
    2018-11-15 16:18
  • 签到天数: 39 天

    连续签到: 1 天

    [LV.5]常住居民I

    16

    主题

    259

    帖子

    3

    高级会员

    Rank: 4

    积分
    993
    最后登录
    2023-1-6
    发表于 2016-4-22 09:27:56 | 显示全部楼层 |阅读模式
    本帖最后由 小华-415468 于 2016-4-22 09:29 编辑

    求助线上FAE FLASH擦写可以开中断吗(所用芯片是MC9S12G48)?因为擦(PFLASH)FLASH Sector时有好几十毫秒延时,关了总中断,定时器的定时时间就会有偏差,还有CallFnCmdInRam这个函数,为什么擦FLASH时要放到RAM执行,顺便发送一份擦FLASH的函数代码给予那些FLASH擦写没函数的学友们。

    byte IFsh1_EraseSector(IFsh1_TAddress Addr)
    {
      if (BlockOutOfRange(Addr, Addr)) {   /* Check range of address */
        return(ERR_RANGE);
      }
      EnterCritical();                     /* Enter critical section */
      ClearFlags();                        /* Clear all flags */
      if (FSTAT_CCIF == 0U) {              /* Is command buffer full ? */
        ExitCritical();                    /* Exit critical section */
        return ERR_BUSY;                   /* If yes then error */
      }
      FCCOBIX = 0U;                        /* Clear index register */
      FCCOBHI = 0x0AU;                     /* Erase P-Flash sector command */
      FCCOBLO = (byte)(Addr >> 16U);       /* High address word */
      FCCOBIX++;                           /* Shift index register */
      FCCOB = (word)(Addr & 0xFFFFFFF8UL); /* Low address word aligned to 8 byte phrase*/
      CallFnCmdInRam();                    /* Copy Wait in RAM routine to stack and launch the flash process */
      if (FSTAT_FPVIOL == 1U) {            /* Is protection violation detected ? */
        ExitCritical();                    /* Exit critical section */
        return ERR_NOTAVAIL;               /* If yes then error */
      }
      if (FSTAT_ACCERR == 1U) {            /* Is acces error detected ? */
        ExitCritical();                    /* Exit critical section */
        return ERR_NOTAVAIL;               /* If yes then error */
      }
      if (FSTAT_MGSTAT) {                  /* Was attempt to erase the sector errorneous? */
        ExitCritical();                    /* Exit critical section */
        return ERR_VALUE;                  /* If yes then error */
      }
      ExitCritical();                      /* Exit critical section */
      return ERR_OK;                       /* OK */
    }

    /*部分调用函数*/
    #define EnterCritical() \
    /*lint -save  -e950 -esym(960,14.3) Disable MISRA rule (1.1,14.3) checking. */\
        { __asm(pshc); __asm(sei); __asm(movb 1,SP+,CCR_reg); } /* This macro is used by Processor Expert. It saves CCR register and disable global interrupts. */ \


    #define ExitCritical() \
    /*lint -save  -e950 -esym(960,14.3) Disable MISRA rule (1.1,14.3) checking. */\
        { __asm(movb CCR_reg, 1,-SP); __asm(pulc); } /* This macro is used by Processor Expert. It restores CCR register saved in SaveStatusReg(). */ \


    #define ClearFlags()  (FSTAT = 0x30U)

    static void FnCmdInRam_(void)
    {
      FSTAT = 0x80U;                       /* Clear flag command buffer empty */
      while (FSTAT_CCIF == 0U) {}          /* Wait to command complete */
      return;
    }
    #pragma MESSAGE DISABLE C12056         /* Disable warning C12056 "SP debug info incorrect becouse of optimization or inline assembler" */

    /* Types definitions */

    typedef struct {
       uint8_t code[15];             /* Structure required to copy code to ram memory */
      /* Size of this structure needs to be at least (but best) the size of the FnCmdInRam_ */
    } FnCmdInRamStruct;

    typedef void (* near pFnCmdInRam)(void);


    #pragma MESSAGE DISABLE C1805          /* Disable warning C1805 "Non-standard conversion used" */
    /*lint -save  -e740 -e931 Disable MISRA rule (1.2) checking. */
    static void CallFnCmdInRam()
    {
      FnCmdInRamStruct FnCmdInRam = *(FnCmdInRamStruct *)(FnCmdInRam_); /* Create a copy of Wait in RAM routine on stack */

      ((pFnCmdInRam)&FnCmdInRam)();        /* Call code in RAM */
      return;
    }

    我知道答案 目前已有0人回答
    回复

    使用道具 举报

    您需要登录后才可以回帖 注册/登录

    本版积分规则

    关闭

    站长推荐上一条 /3 下一条

    Archiver|手机版|小黑屋|恩智浦技术社区

    GMT+8, 2025-7-22 19:23 , Processed in 0.082748 second(s), 20 queries , MemCache On.

    Powered by Discuz! X3.4

    Copyright © 2001-2024, Tencent Cloud.

    快速回复 返回顶部 返回列表