First off just want to say I've learned a lot by lurking here - this is a great forum with very helpful posters - keep up the good work.
My question is about flash operations and the PIT on the S12XDP512. I'm writing a bootloader which must periodically toggle a port connected to an external watchdog, and flash new product code to locations in the flash memory. I've set up a timer interrupt using the PIT, and the ISR for this interrupt toggles the port (period required for watchdog is once every second).
I've set up the flash routines and the timer ISR to be allocated to RAM, so they are not run from flash, and interrupts are disabled when a flash write command is initiated. My issue is that I would like to keep toggling the watchdog port inside the flash routines, if the timer has expired. I set up a check for the PTF flag for the appropriate channel, and a routine which toggles the port is called if it is set (timer has expired):
I have not included the erase routine, as it is very similar to the write routine. All code and data above are allocated to RAM.
The timer ISR works correctly. The flash write routine does not work (processor jumps to random address and halts, etc.) when interrupts are disabled and ExtWdToggle_PseudoIsr() is called. The timings for a max-delay flash write and sector erase are ~75 us and 27 ms, respectively, so I think I may be fine if the timer expires while inside the flash routines, and it is not serviced until interrupts are re-enabled (watchdog period is 1 sec). However, I'd still like to get this to work. Any ideas?
Ok, asked the reigning S12X / Codewarrior expert at my work, and he fixed my problem.
FYI, turns out that while I had a line, #pragma CODE_SEG __NEAR_SEG IntReqHndlr_Code_Seg, before my definition of ExtWdToggle_PseudoIsr(), to allocate it to RAM, I also needed a similar #pragma before the function prototype to make sure the compiler uses the right function call paradigm for calling code in RAM.