We are running a survey to help us improve the experience for all of our members. If you see the survey appear, please take the time to tell us about your experience if you can.
I'm using RTX51 Tiny on the ADuC845 and i have problems with program crash. The program will freeze or reset and start all over.
The problem occure only sometimes when i'm writing to the dataflash.
Due to an Anomaly of the ADuC845 (see below) i have to disable all interrupts (EA=0) before writing to the dataflash. BUT it is not recommended to disable all interrupts when using RTX51 Tiny. And if you have to, then only for a short time. In my case it is not a short time couse to the long time (~2.4ms) it takes to write to dataflash.
Is there a way to overcome this problem?
Here is my program in a short version (sorry for the loss of indent):
void write (unsigned ee_addr, void const *p_data, size_t size) {
do {
EDATA1 = *((unsigned char*)p_data)++;
if (--size) {
EDATA2 = *((unsigned char*)p_data)++;
EDATA3 = *((unsigned char*)p_data)++;
EDATA4 = *((unsigned char*)p_data)++;
size--;
}
EADRH = HIGHBYTE(ee_addr);
EADRL = LOWBYTE(ee_addr++);
EA = OFF; // Disable all interrupts
ECON = 0x05; // Erase page, 2ms
ECON = 0x02; // Write page, 380us
EA = ON; // Enable all interrupts
} while (size);
.
void sec_process (void) _task_ SEC_PROCESS {
while (1) {
sec++;
if (sec % 3600 == 0) write (SEC_ADR, &sec, sizeof sec);
os_wait2 (K_IVL, 192); // 192 = 1sec
- The sec_process will increment the sec counter every second and write the sec counter to dataflash every 1 hour.
- The write function will write any size and kind of data to the dataflash at the location ee_addr.
Cut from the Anomaly Sheet ADuC845: 1. Interrupts During Reading/Writing to DATAFLASH/EE [er001] Background: There are 4 kB of DATAFLASH/EE that can be used for nonvolatile data storage. Issue: If an interrupt occurs during a DATAFLASH/EE read or write operation, code execution following the ISR may resume at a random program memory address. Workaround: Disable all interrupts prior to a read or write operation. This can be done by setting the EA bit to 0. Related Issues: None.
Regards Peter