summaryrefslogtreecommitdiff
path: root/cesar/hal/timer/test/src/timer_date_past.c
blob: 68045e5d72de04545f8b619d8c99e343632805a1 (plain)
1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
22
23
24
25
26
27
28
29
30
31
32
33
34
35
36
37
38
39
40
41
42
43
44
45
46
47
48
49
50
51
52
53
54
55
56
57
58
59
60
61
62
63
64
65
66
67
68
69
70
71
72
73
74
75
76
77
78
79
80
81
82
83
84
85
86
87
88
89
90
91
92
/* Cesar project {{{
 *
 * Copyright (C) 2009 Spidcom
 *
 * <<<Licence>>>
 *
 * }}} */
/**
 * \file    hal/timer/test/src/timer_date_past.c
 * \brief   « brief description »
 * \ingroup « module »
 *
 * « long description »
 */
#include "common/std.h"
#include "lib/test.h"
#include "lib/blk.h"

#include "hal/timer/timer.h"
#include "hal/timer/inc/context.h"
#include "hal/phy/phy.h"
#include <cyg/kernel/kapi.h>
#include <cyg/infra/diag.h>

#include <string.h>

#define THREAD_PRIO 10

static test_t test;
static hal_timer_t *hal_timer;

/* Thread 1. */
u8 thread1_stack[CYGNUM_HAL_STACK_SIZE_TYPICAL];
cyg_handle_t handle_thread1;
cyg_thread thread1;
hal_timer_instance_t t1_instance;

void
timer_cb (void *nothing)
{
    diag_printf ("Called back.\n");
}

void
thread1_entry_function(cyg_addrword_t data)
{
    hal_timer_instance_init (hal_timer, &t1_instance, NULL, &timer_cb);

    hal_timer_instance_program (hal_timer, &t1_instance,
                                phy_date () - 10);

    diag_printf ("Current instance prgmed : %p\n",
                 hal_timer->current_instance);
    diag_printf ("This instance : %p\n", &t1_instance);
    diag_printf ("Going to a rest\n");
    cyg_thread_delay (2);
    diag_printf ("Test ended\n");
    cyg_thread_suspend (handle_thread1);
    hal_timer_uninit (hal_timer);
    test_result (test);

#ifndef __sparc__
    HAL_PLATFORM_EXIT (test_nb_failed (test) == 0 ? 0 : 1);
#endif
}

int
cyg_user_start (void)
{
    test_init (test, 0, NULL);

    hal_timer = hal_timer_init ();

    diag_printf ("Current phy date : %x\n", phy_date ());

    cyg_thread_create(THREAD_PRIO, &thread1_entry_function,
                      0, "Thread 1", thread1_stack,
                      CYGNUM_HAL_STACK_SIZE_TYPICAL,
                      &handle_thread1, &thread1);

    cyg_thread_resume (handle_thread1);

    return 0;
}

#ifndef __sparc__
u32
phy_date (void)
{
    return cyg_current_time ();
}
#endif