Timer functions, GetSystemTime() based (msec resolution), callbacks can't be NULL.
hTimer SetTimerAfter(int delay, (*good_cb)(int, int), (*bad_cb)(int, int), int whatever);
return: bit0 = 1 when error, handle otherwise
callback arguments: a = current time value, b = 'whatever'
bad_cb() gets called when 'delay' is zero
good_cb() gets called after 'delay' msecs
hTimer SetTimerWhen(int time, (*good_cb)(int, int), (*bad_cb)(int, int), int whatever);
return: bit0 = 1 when error, handle otherwise
callback arguments: a = current time value, b = 'whatever'
bad_cb() gets called when the desired time has already passed
good_cb() gets called when GetSystemTime() reaches 'time'
int CancelTimer(hTimer);
HP timer functions, they use a 20 bit hw counter, retrieved by GetCurrentMachineTime() aka *(int*)0xc0242014
The callbacks can't be NULL.
hHPTimer SetHPTimerAfterNow(int delay, (*good_cb)(int, int), (*bad_cb)(int, int), int whatever);
return: bit0 = 1 when error, handle otherwise
hHPTimer SetHPTimerAfterTimeout(int time_base, int delay, (*good_cb)(int, int), (*bad_cb)(int, int), int whatever)
return: bit0 = 1 when error, handle otherwise
bad_cb(int a, int b);
gets called when the desired time has already passed, a=time_base+delay, b='whatever'
int CancelHPTimer(hHPTimer);
The two callbacks probably get the same kind of params in not noted cases, since they are usually the same in firmware code.
Since the callbacks probably run in interrupt context, they should be as lightweight as possible. They can probably be thumb on DryOS, but most probably need to be ARM on VxWorks.
Here's a demonstration:
Index: core/main.c
===================================================================
--- core/main.c (revision 3343)
+++ core/main.c (working copy)
@@ -189,6 +189,8 @@
}
shooting_init();
+ extern void init_timer_demo();
+ init_timer_demo();
while (1)
{
@@ -249,10 +251,11 @@
i = 0;
-#ifdef DEBUG_PRINT_TO_LCD
- sprintf(osd_buf, "%d", cnt ); // modify cnt to what you want to display
+//#ifdef DEBUG_PRINT_TO_LCD
+ extern int hmmm, hmmmm;
+ sprintf(osd_buf, "%x, %x", hmmm, hmmmm ); // modify cnt to what you want to display
draw_txt_string(1, i++, osd_buf, conf.osd_color);
-#endif
+//#endif
if (camera_info.perf.md_af_tuning)
{
Index: platform/a3200/sub/100d/stubs_entry_2.S
===================================================================
--- platform/a3200/sub/100d/stubs_entry_2.S (revision 3343)
+++ platform/a3200/sub/100d/stubs_entry_2.S (working copy)
@@ -12,3 +12,10 @@
NHSTUB(TurnOnMic, 0xFF8608E8)
NHSTUB(TurnOffMic, 0xFF860914)
NHSTUB(TurnOffE1, 0xff83bc20)
+
+NHSTUB(SetTimerAfter, 0xff83aa4c)
+NHSTUB(SetTimerWhen, 0xff83aacc)
+NHSTUB(CancelTimer, 0xff83ab30)
+NHSTUB(SetHPTimerAfterNow, 0xff888770)
+NHSTUB(SetHPTimerAfterTimeout, 0xff8887f0)
+NHSTUB(CancelHPTimer, 0xff888878)
Index: platform/generic/lib.c
===================================================================
--- platform/generic/lib.c (revision 3343)
+++ platform/generic/lib.c (working copy)
@@ -1 +1,2 @@
#include "platform.h"
+
Index: platform/generic/wrappers.c
===================================================================
--- platform/generic/wrappers.c (revision 3343)
+++ platform/generic/wrappers.c (working copy)
@@ -1677,3 +1677,37 @@
return (conf.remote_enable == 0 && get_usb_bit());
}
+// timer demo
+
+extern int _SetTimerAfter(int delay, int(*good_cb)(int, int), int(*bad_cb)(int, int), int whatever);
+extern int _SetTimerWhen(int time, int(*good_cb)(int, int), int(*bad_cb)(int, int), int whatever);
+extern int _CancelTimer(int);
+
+static int blinkcnt = 0;
+static int blinkdly = 4096;
+static int demostate = 1;
+int hmmm = 0;
+int hmmmm = 0;
+
+int mytimerfunc(int a, int b) {
+ hmmmm = a;
+ hmmm = b;
+ blinkcnt--;
+ if (blinkcnt>0) {
+ _SetTimerAfter(blinkdly,mytimerfunc,mytimerfunc,(int)&hmmm);
+ }
+ else {
+ void init_timer_demo();
+ init_timer_demo();
+ }
+ blinkdly>>=1;
+ debug_led(demostate);
+ demostate = !demostate;
+ return 0;
+}
+void init_timer_demo() {
+ blinkcnt = 8;
+ blinkdly = 1024;
+ _SetTimerWhen(get_tick_count()+10000,mytimerfunc,mytimerfunc,(int)&hmmm);
+}
+