普通学生,最近在做东西的时候对fram的读写的C语言程序很迷糊,请问应该学习些什么?
This thread has been locked.
If you have a related question, please click the "Ask a related question" button in the top right corner. The newly created question will be automatically linked to this question.
#if defined(__TI_COMPILER_VERSION__)
#pragma PERSISTENT(FRAM_write)
unsigned long FRAM_write[WRITE_SIZE] = {0};
#elif defined(__IAR_SYSTEMS_ICC__)
__persistent unsigned long FRAM_write[WRITE_SIZE] = {0};
#elif defined(__GNUC__)
unsigned long __attribute__((persistent)) FRAM_write[WRITE_SIZE] = {0}; //???????
#else
#error Compiler not supported!
#endif
请问例程代码这段宏定义中的__((persistent)) FRAM_write[WRITE_SIZE] = {0}; 有什么意义,不太理解,查阅数据手册说的很模糊
Here is example code which should show you how to use data in FRAM.
#include <msp430.h>
#define WRITE_SIZE 128
void FRAMWrite(void);
unsigned char count = 0;
unsigned long data;
#if defined(__TI_COMPILER_VERSION__)
#pragma PERSISTENT(FRAM_write)
unsigned long FRAM_write[WRITE_SIZE] = {0};
#elif defined(__IAR_SYSTEMS_ICC__)
__persistent unsigned long FRAM_write[WRITE_SIZE] = {0};
#elif defined(__GNUC__)
unsigned long __attribute__((persistent)) FRAM_write[WRITE_SIZE] = {0};
#else
#error Compiler not supported!
#endif
int main(void)
{
WDTCTL = WDTPW | WDTHOLD; // Stop WDT
// Configure GPIO
P1OUT &= ~BIT0; // Clear P1.0 output latch for a defined power-on state
P1DIR |= BIT0; // Set P1.0 to output direction
// Disable the GPIO power-on default high-impedance mode to activate
// previously configured port settings
PM5CTL0 &= ~LOCKLPM5;
// Initialize dummy data
data = 0x00010001;
while(1)
{
data += 0x00010001;
FRAMWrite();
count++;
if (count > 100)
{
P1OUT ^= 0x01; // Toggle LED to show 512K bytes
count = 0; // ..have been written
data = 0x00010001;
}
}
}
void FRAMWrite(void)
{
unsigned int i = 0;
for (i = 0; i < WRITE_SIZE; i++)
{
FRAM_write[i] = data;
}
}
你看到前面的#if defined没? 一般编译器如CCS,运行你这段程序时只会执行这句#pragma PERSISTENT(FRAM_write) 在FRAM中生成地址的。同理unsigned long __attribute__((persistent)) FRAM_write[WRITE_SIZE] = {0}; 的作用同#pragma PERSISTENT(FRAM_write) 只是编译器不同罢了。