The C Programmer’s Guide to the QVGA ControllerTable of ContentsPART 1 GETTING STARTED Introduction. How to Use This Manual Chapter 1: Getting to Know Your QVGA PART 2 PROGRAMMING THE QVGA CONTROLLER Chapter 3: The IDE: Writing, Compiling, Downloading and Debugging Programs Chapter 4: Making Effective Use of Memory Chapter 5: Programming the Graphical User Interface Chapter 6: Real Time Programming Chapter 7: Failure and Run-Time Error Recovery PART 3 COMMUNICATIONS, MEASUREMENT, AND CONTROL Chapter 8: Digital and Timer-Controlled I/O Chapter 9: Data Acquisition Using the QVGA Controller Chapter 10: Outputting Voltages with Digital to Analog Conversion PART 4: PUTTING IT ALL TOGETHER Chapter 13: A Turnkeyed Application PART 5: REFERENCE DATA Appendix A: QVGA Electrical Specifications |
Chapter 12 Chapter 12: The Battery-Backed Real-Time ClockThe battery backed real time clock is set and read using the Control-C functions ReadWatch() and SetWatch(). In C, these two routines access a fixed pre-allocated structure in the 68HC11's on-chip RAM using structure macros defined in the WATCH.H header file. For example, the following code reads the watch and stores the current minute (after the hour) in the variable named current_minute:
static int current_minute; ReadWatch(); current_minute = WATCH_MINUTE; Because the structure that is written to by ReadWatch() is at a fixed location, this code is not re-entrant. This is not a problem in single-task applications or applications where only one task uses the watch. But it can cause problems if multiple tasks are executing ReadWatch(). For example, assume that task #1 calls ReadWatch(), but before it can access the contents of the structure using the assignment statement, the timeslice interrupt occurs and task#2 proceeds to call ReadWatch(), then the contents of WATCH_MINUTE could be changed before task#1 is able to execute its assignment statement. To avoid this situation, the multitasking application can be configured so that only one task calls ReadWatch() and SetWatch() and shares the data with other tasks. Another option is to define a resource variable to mediate access to the watch. The routines needed to accomplish this are declared in the MTASKER.H file and described in detail in the Control-C Glossary. The following brief example illustrates how to design a re-entrant function that returns the current WATCH_MINUTE:
RESOURCE watch_resource; // declare resource variable: controls // watch access _Q int CurrentMinute(void) // reads watch, returns current minute { int minute; GET(watch_resource); // get access to watch; Pause() if // another task has it ReadWatch(); // updates contents of watch structure minute = WATCH_MINUTE; // you can also transfer other contents // from the watch structure to // "task-private" variables here RELEASE(watch_resource); // release access to watch so other // tasks can use it return minute; } The CurrentMinute() function can be simultaneously called from multiple tasks without causing any conflicts. The GET() and RELEASE() macros automatically mediate access to the watch, ensuring that only one task has access at a time. Interrupts are disabled during the entire operation of the functions ReadWatch() and SetWatch() for approximately 0.5 and 0.45 msec respectively.
The words that access the watch use the top 16 bytes of the 68HC11F1’s on-chip RAM (at addresses 0xB3F0-0xB3FF) as a buffer to hold intermediate results during the data transfers. You may use these locations for other purposes when the watch is not being accessed. |
Home|Site Map|Products|Manuals|Resources|Order|About Us
Copyright (c) 2006 Mosaic Industries, Inc.
Your source for single board computers, embedded controllers, and operator interfaces for instruments and automation