update the timer callback test for the new timer API

This commit is contained in:
Lephe 2020-07-20 20:34:20 +02:00
parent 6ebec472c5
commit c52327e061
Signed by: Lephenixnoir
GPG Key ID: 1BBA026E13FC0495
1 changed files with 45 additions and 12 deletions

View File

@ -2,11 +2,14 @@
#include <gint/keyboard.h>
#include <gint/timer.h>
#include <gint/clock.h>
#include <gint/defs/util.h>
#include <gintctl/gint.h>
#include <gintctl/util.h>
static int tests = 0;
/* Auxiliary timer for tests than need an interrupt during the callback */
static int auxiliary_timer = -1;
static int callback_simple(volatile void *arg)
{
@ -18,6 +21,8 @@ static int callback_simple(volatile void *arg)
static int callback_sleep(GUNUSED volatile void *arg)
{
/* Start the aux. timer to have a guaranteed non-masked interrupt */
timer_start(auxiliary_timer);
sleep();
tests++;
return TIMER_STOP;
@ -25,12 +30,9 @@ static int callback_sleep(GUNUSED volatile void *arg)
static int callback_timer(GUNUSED volatile void *arg)
{
volatile int timeout = 0;
timer_setup(1, timer_delay(1, 10000, TIMER_Pphi_4), timer_timeout,
&timeout);
timer_start(1);
timer_wait(1);
/* Wait specifically on the auxiliary timer */
timer_start(auxiliary_timer);
timer_wait(auxiliary_timer);
tests++;
return TIMER_STOP;
}
@ -39,6 +41,7 @@ static int callback_timer(GUNUSED volatile void *arg)
void gintctl_gint_timer_callbacks(void)
{
int key=0, base=0;
int status=0;
while(key != KEY_EXIT)
{
@ -51,6 +54,9 @@ void gintctl_gint_timer_callbacks(void)
row_print(4, 1, "F2:Wait with sleep()");
row_print(5, 1, "F3:Start timer!");
if(status == 1) row_print(7, 1, "Success!");
if(status == 2) row_print(7, 1, "Not enough timers!");
extern bopti_image_t img_opt_gint_timer_callbacks;
dimage(0, 56, &img_opt_gint_timer_callbacks);
dprint(69, 56, C_BLACK, "Done:%d", tests);
@ -64,7 +70,7 @@ void gintctl_gint_timer_callbacks(void)
row_print(2, 1,
"registers.");
row_print(4, 1,
"SLEEP transitions to standby mode, forcing an");
"SLEEP transitions to sleep mode, forcing an");
row_print(5, 1,
"interrupt within the callback.");
row_print(7, 1,
@ -74,6 +80,9 @@ void gintctl_gint_timer_callbacks(void)
row_print(10, 1, "Tests run: %d", tests);
if(status == 1) row_print(12, 1, "Success!");
if(status == 2) row_print(12, 1, "Not enough timers!");
fkey_action(1, "SIMPLE");
fkey_action(2, "SLEEP");
fkey_action(3, "TIMER");
@ -82,20 +91,44 @@ void gintctl_gint_timer_callbacks(void)
dupdate();
key = getkey().key;
status = 0;
int (*callback)(volatile void *arg) = NULL;
volatile void *arg = NULL;
auxiliary_timer = -1;
if(key == KEY_F1) callback = callback_simple, arg = &base;
if(key == KEY_F2) callback = callback_sleep;
if(key == KEY_F3) callback = callback_timer;
if(callback)
if(!callback) continue;
/* Allocate a first timer to run the callback */
int t = timer_setup(TIMER_ANY, 40000, callback, arg);
if(t < 0)
{
timer_setup(0, timer_delay(0, 10000, TIMER_Pphi_4),
callback, arg);
timer_start(0);
timer_wait(0);
status = 2;
continue;
}
/* Now allocate a second timer for tests 2 and 3 */
if(key == KEY_F2 || key == KEY_F3)
{
/* Request a TMU (higher priority) */
auxiliary_timer = timer_setup(TIMER_TMU, 10000, NULL);
if(auxiliary_timer < 0)
{
status = 2;
timer_stop(t);
continue;
}
/* The auxiliary timer must have a higher priority */
if(auxiliary_timer > t) swap(t, auxiliary_timer);
}
status = 1;
timer_start(t);
timer_wait(t);
}
}