LPC_RTC gen purpose registers

09 Oct 2011

can these be used to store floating point numbers between resets?

easily save integers but haven't discovered how to stash fp...

09 Oct 2011

digging a bit I see that the gen purpose registers are uint_32 which i think means 32-bit integer only what needs to happen then (i think) is converting a fp number to uint_32 on storage and back again when I pop the register.

can anyone confirm that i'm on the right track? each register is 4 bytes so should be sufficient to hold an fp number (right?)

would not mind some pointers on effecting that...

09 Oct 2011

Hi Gary,

I think you'd want to do something like:

#include "mbed.h"

void set_float(float value) {
    LPC_RTC->GPREG0 = *((uint32_t*)&value);
}

float get_float() {
    return *((float*)&(LPC_RTC->GPREG0));
}

int main() {
    set_float(2.0);
    float v = get_float();
}

You can read set_float from right to left as get the address of the float value (&value), cast that to be an address of an int value (uint32_t*), and then read the value of the int at that address (*). So instead of casting the value itself (which would do a conversion), you cast a pointer to it.

...assuming i haven't made a mistake!

Simon

09 Oct 2011

Simon,

TNX! works a charm. Still learning how the compiler manipulates memory (as you can tell...). One last pesky question then. How to expand this to utilize all of the registers gpreg0-4 ?

gmb