gpt4 book ai didi

C - 在闪存中存储全局变量?

转载 作者:太空宇宙 更新时间:2023-11-04 01:25:08 24 4
gpt4 key购买 nike

正如标题所暗示的,我目前在我的程序中缺少 SRAM,而且我找不到减少全局变量的方法。是否可以将全局变量带到闪存中?由于这些变量是频繁读写的,是否会因为nand flash的读写次数有限而对它们不利?

如果闪存不能处理这个问题,EEPROM 会是一个不错的选择吗?

编辑:对不起,模棱两可的家伙。我正在使用 Atmel AVR ATmega32HVB,它具有: 2K字节的SRAM, 1K字节的EEPROM 32K字节的FLASH

编译器:AVR C/C++

平台:IAR 嵌入式 AVR

我想去掉的全局变量是:

uint32_t capacityInCCAccumulated[TOTAL_CELL];

int32_t AccumulatedCCADCvalue[TOTAL_CELL]; 

代码片段:

  int32_t AccumulatedCCADCvalue[TOTAL_CELL];
void CCGASG_AccumulateCCADCMeasurements(int32_t ccadcMeasurement, uint16_t slowRCperiod)
{
uint8_t cellIndex;
// Sampling period dependant on configuration of CCADC sampling..
int32_t temp = ccadcMeasurement * (int32_t)slowRCperiod;

bool polChange = false;
if(temp < 0) {
temp = -temp;
polChange = true;
}

// Add 0.5*divisor to get proper rounding
temp += (1<<(CCGASG_ACC_SCALING-1));
temp >>= CCGASG_ACC_SCALING;

if(polChange) {
temp = -temp;
}
for (cellIndex = 0; cellIndex < TOTAL_CELL; cellIndex++)
{
AccumulatedCCADCvalue[cellIndex] += temp;
}

// If it was a charge, update the charge cycle counter
if(ccadcMeasurement <= 0) {
// If it was a discharge, AccumulatedCADCvalue can be negative, and that
// is "impossible", so set it to zero
for (cellIndex = 0; cellIndex < TOTAL_CELL; cellIndex++)
{
if(AccumulatedCCADCvalue[cellIndex] < 0)
{
AccumulatedCCADCvalue[cellIndex] = 0;
}
}
}
}

还有这个

uint32_t capacityInCCAccumulated[TOTAL_CELL];
void BATTPARAM_InitSramParameters() {
uint8_t cellIndex;
// Active current threshold in ticks
battParams_sram.activeCurrentThresholdInTicks = (uint16_t) BATTCUR_mA2Ticks(battParams.activeCurrentThreshold);

for (cellIndex = 0; cellIndex < TOTAL_CELL; cellIndex++)
{
// Full charge capacity in CC accumulated
battParams_sram.capacityInCCAccumulated[cellIndex] = (uint32_t) CCGASG_mAh2Acc(battParams.fullChargeCapacity);
}
// Terminate discharge limit in CC accumulated
battParams_sram.terminateDischargeLimit = CCGASG_mAh2Acc(battParams.terminateDischargeLimit);

// Values for remaining capacity calibration
GASG_CalculateRemainingCapacityValues();
}

最佳答案

would it be bad for the nand flash because they have limited number of read/write cycle?

是的,频繁修改数据时使用闪存不是一个好主意。只读闪存不会减少闪存的使用生命周期。删除和写入会缩短闪存生命周期。

与传统内存相比,从闪存读取和写入速度要慢得多。

要写入一个字节,必须删除整个 block 并重新写入闪存。

关于C - 在闪存中存储全局变量?,我们在Stack Overflow上找到一个类似的问题: https://stackoverflow.com/questions/32712167/

24 4 0
Copyright 2021 - 2024 cfsdn All Rights Reserved 蜀ICP备2022000587号
广告合作:1813099741@qq.com 6ren.com