原创 msp430在程序初始将常量写入FLASH信息段中

2012-5-16 11:47 4400 7 5 分类: MCU/ 嵌入式

该程序参考TI的电量方案程序ESP文件:

在ESP430.h文件中申明结构体

struct ts_parameters{
          float VRatio;
          float IRatio;
          float EnergyRatio;
          int pSET_PHASECORR1;
          int pSET_PHASECORR2;
          unsigned int pSET_GAINCORR1;
          unsigned int pSET_GAINCORR2;
          int pSET_V1OFFSET;
          int pSET_I1OFFSET;
          int pSET_I2OFFSET;
          unsigned int pSET_ADAPTI1;
          unsigned int pSET_ADAPTI2;
          unsigned int pSET_STARTCURR_INT;
          unsigned int pSET_STARTCURR_FRAC;
          union tu_ulong_word pSET_INTRPTLEVL;
          unsigned long ulTempGain;
          unsigned long ulTempOffset;
          union ts_long_word pSET_POFFSET1;
          union ts_long_word pSET_POFFSET2;
#ifdef ESP_V2
          unsigned int pSET_CORRCOMP;
#endif
          };

 

在ESP430.C文件中定义结构体变量


struct ts_parameters s_parameters;


#ifdef __IAR_SYSTEMS_ICC__
#if __VER__ < 200
#pragma memory=constseg(INFOA)
#else
#pragma constseg=INFOA
#endif
#endif


#ifdef __CROSSWORKS_MSP430
#pragma constseg("INFO")
#endif

#ifdef __TI_COMPILER_VERSION__
#pragma DATA_SECTION(s_parameters_flash, ".infoA")
#endif
/**********************将参数信息放置到FLASH中***************/
//---------说明:以下参数如defSET_V1OFFSET,其实是实数值
const struct ts_parameters s_parameters_flash =
           {
              defVRatio,
              defIRatio,
              defEnergyRatio,
              defSET_PHASECORR1,
              defSET_PHASECORR2,
              defSET_GAINCORR1,
              defSET_GAINCORR2,
              defSET_V1OFFSET,
              defSET_I1OFFSET,
              defSET_I2OFFSET,
              defSET_ADAPTI1,
              defSET_ADAPTI2,
              defSET_STARTCURR_INT,
              defSET_STARTCURR_FRAC,
              {defSET_INTRPTLEVL_LO,
               defSET_INTRPTLEVL_HI},
              defTempGain,
              defTempOffset,
              0,  // P1Offset
              0,  // P2Offset
#ifdef ESP_V2
              0   // CORRCOMP CMRR
#endif
           };

上述程序是对该结构体变量s_parameters_flash 直接附初值,该变量时存储在FLASH 信息段A中的

如图所示:

1f8fc338-62ed-4c28-8940-80cefe429142.jpgd682bd39-79c5-4a86-9016-fb50c08489ba.jpg

当我们需要赋值给变量s_parameters

 if (flashvars) s_parameters = s_parameters_flash;

结果如图:

938ab59d-25ea-4808-9be2-d8b100b650d5.jpg


9ed272b0-6d50-42dd-85ef-cf8cf77096d7.jpg

科技成就生活,创新源自智拓

www.ourjcdz.com

7e696431hbfaf3da94bd7&690

 


 



 

PARTNER CONTENT

文章评论0条评论)

登录后参与讨论
EE直播间
更多
我要评论
0
7
关闭 站长推荐上一条 /3 下一条