|
@@ -41,16 +41,40 @@ float kupa;
|
|
|
|
|
|
static uint32_t copy_array[16];
|
|
|
|
|
|
+static inline uint32_t rdcycle(void)
|
|
|
+{
|
|
|
+ uint32_t cycle;
|
|
|
+ __asm__ volatile ("rdcycle %0" : "=r" (cycle));
|
|
|
+ return cycle;
|
|
|
+}
|
|
|
+
|
|
|
/* Timer fuction */
|
|
|
+#define CYCLES_DIV 24000000.0f
|
|
|
+#define UPDATE_MS 3.0f
|
|
|
+// TODO: integers not floats?
|
|
|
+
|
|
|
+static uint32_t last_rdcycle;
|
|
|
static bool timer_expired()
|
|
|
{
|
|
|
-
|
|
|
+ bool success = false;
|
|
|
+ uint32_t current = rdcycle();
|
|
|
+ uint32_t diff = current - last_rdcycle;
|
|
|
+ //printf(" diff %d last: %d current: %d\n", diff, last_rdcycle, current);
|
|
|
+ // TODO: overflow handling
|
|
|
+ float elapsed_seconds = (float)(diff) / CYCLES_DIV;
|
|
|
+ if (elapsed_seconds > UPDATE_MS)
|
|
|
+ {
|
|
|
+ last_rdcycle = current;
|
|
|
+ printf("Timer expired!\n");
|
|
|
+ success = true;;
|
|
|
+ }
|
|
|
+ return success;
|
|
|
}
|
|
|
|
|
|
/* three signal generation params */
|
|
|
static void update_three_signal_values()
|
|
|
{
|
|
|
-
|
|
|
+ //printf("Updating 3signal values\n");
|
|
|
}
|
|
|
|
|
|
static void print_mailbox_contents()
|
|
@@ -242,6 +266,9 @@ void main()
|
|
|
|
|
|
switch (cmd)
|
|
|
{
|
|
|
+ case 'q':
|
|
|
+ printf("Current rdcycle %d\n", rdcycle());
|
|
|
+ break;
|
|
|
case 'b':
|
|
|
boot_dfu();
|
|
|
break;
|