Safari Books Online is a digital library providing on-demand subscription access to thousands of learning resources.
138 Chapter 7 eight-levels-deep FIFOs, that can truly free up a considerable amount of CPU time. Up to eight words of data (16 bytes) can be written or retrieved from the SPI buffers in short bursts, leaving much more time to the CPU to process the data in between the successive bursts. Tips & Tricks If you store important data in an external non-volatile memory, you might want to put some additional safety measures in place (both hardware and software). From a hardware perspective make sure that: l l l l Adequate power supply decoupling (a capacitor) is provided close to the memory device. A pull-up resistor (10 kohm) is provided on the Chip Select line, to avoid floating during the microcontroller power-up and reset. An additional pull-down resistor (10 kohm) can be provided on the SCK clock line to avoid clocking of the peripheral during boundary scan and other board testing procedures. Clean and fast power-up and down slope are provided to the microcontroller to guarantee reliable Power On Reset operation. If necessary, add an external voltage supervisor (see MCP809 devices for example). A number of software methods can then be employed to prevent even the most remote possibility that a program bug or the proverbial cosmic ray might trigger the write routine. Here are some suggestions: l l l l l Avoid reading and especially updating the NVM content right after power-up. Allow a few milliseconds for the power supply to stabilize (application dependent). Add a software write-enable flag, and demand that the calling application set the flag before calling the write routine, possibly after verifying some essential application- specific entry condition. Add a stack level counter; each function in the stack of calls implemented by the library should increment the counter upon entry and decrement it on exit. The write routine should refuse to perform if the counter is not at the expected level. Some users refuse to use the NVM memory locations corresponding to the first address (0x0000) and/or the last address (0xffff), believing they could be statistically more likely to be the subject to corruption. More seriously, store two copies of each essential piece of data, performing two separate calls to the write routine. If each copy contains even a simple checksum, it will be easy, when reading it back, to discard the corrupted one and recover. Exercises l l l Several functions in the library are performing locking loops that could reduce the overall application performance. By using the SPI port interrupts implement a non-blocking version of the library. Enable the new SPI 16-bit mode to accelerate basic read and write operations. Develop (circular) buffered versions of the read and write functions.