From mboxrd@z Thu Jan 1 00:00:00 1970 From: "Chris Sekula" To: Subject: [ECOS] Problems with eCos clocks Date: Wed, 29 Aug 2001 14:19:00 -0000 Message-id: <8669764C0A96B640AE8A6F5BB7C259D972FA@turnpdcf1.home.turnpikeglobal.com> X-SW-Source: 2001-08/msg00919.html 1. The resolution of the real time clock in the default configuration is 10 milliseconds. However, for an application that I am writing, I need a clock with a resolution of about 100 microseconds. I tried to create a clock with a 100 microsecond resolution using the API listed on p.36 of the eCos Reference Manual (September 2000). I created a cyg_resolution_t structure and set the dividend and divisor appropriately (one billion and ten thousand) for a 100 microsecond resolution. I called cyg_counter_create to create a counter and the cyg_clock_create function to create the clock with the desired resolution. I then used the cyg_clock_to_counter function to obtain a handle to the counter (huCounter). I used the following code snippet to test the clock: printf("Starting timing loop \n"); while (!bkill) { t2 = cyg_counter_current_value(huCounter); dt = t2-t1; if (dt >500) { bkill = true; printf("end loop \n"); } } printf("# of clock ticks = %d \n", dt); With a clock resolution of 100 microseconds, I was expecting the while loop to end after 500 clock ticks, or 50 milliseconds. Instead, the program hung. I modified the above code so that the loop would exit after a few seconds (based upon timing from the real time clock) and examined the values of t1, t2 and dt. These values were all zero. 2. What is required to create and run a clock with a finer resolution than that of the real time clock? Is the API for clocks and counters sufficient, or is it necessary to set a microprocessor timer and write an interrupt handler to handle the overflow of the timer and increment a counter appropriately? 3. I tried to modify the resolution of the real time clock in code by obtaining a handle to the RTC with cyg_real_time_clock() and then trying cyg_clock_set_resolution with the appropriate resolution. When I ran my test code, the while loop exited after about 5 seconds, corresponding to 500 ticks of 10 milliseconds per tick. Therefore, the function cyg_clock_set_resolution had no effect on changing the resolution of the real time clock. Is it possible to change the resolution of the RTC in code? 4. Using the eCos Config Tool, Under the option 'ECos Kernel', 'Counters and clocks', I selected the option 'Override default clock settings' and then modified the clock resolution numerator and denominator to one billion and ten thousand respectively (I wasn't sure what to set the Clock Hardware Initialization value to, so I left it). I rebuilt eCos and compiled it with my test program. In my test program, I also checked what the resolution of the RTC was with the function cyg_clock_get_resolution. I obtained the correct values for the dividend and divisor for the new settings (one billion and ten thousand), but my while loop exited after 5 seconds, indicating that the resolution of the RTC was unaffected. 5. I checked two of the include files generated by the Configuration Tool: \install\include\pkconfig\kernel.h and \install\include\pkconfig\hal_i386_pcmb.h. I noticed that the value of CYGNUM_HAL_RTC_DENOMINATOR retained the initial value of 100 as opposed to the new value of 10000 that I had set in the Config Tool. I manually changed the value of the denominator to 10000 and recompiled the code. My code produced the same result: an exit from the loop after 5 seconds. 6. What steps are required to reconfigure the resolution of the Real Time Clock with the Configuration Tool? Regards, CHRIS.