aboutsummaryrefslogtreecommitdiffstats
path: root/src/simulator/main.c
blob: 419fa5314f00e5db678f37f208b11f877ab2b558 (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
93
94
95
96
97
98
99
100
101
102
103
104
105
106
107
108
109
110
111
112
113
114
115
116
117
118
119
120
121
122
123
124
125
126
127
128
129
130
131
132
133
134
// Main starting point for host simulator.
//
// Copyright (C) 2016  Kevin O'Connor <kevin@koconnor.net>
//
// This file may be distributed under the terms of the GNU GPLv3 license.

#include <fcntl.h>
#include <stdio.h>
#include <unistd.h>
#include "board/misc.h" // timer_from_us
#include "board/irq.h" // irq_disable
#include "sched.h" // sched_main


/****************************************************************
 * Interrupts
 ****************************************************************/

uint8_t Interrupt_off;

void irq_disable(void)
{
    Interrupt_off = 1;
    barrier();
}

void irq_enable(void)
{
    barrier();
    Interrupt_off = 0;
}

uint8_t irq_save(void)
{
    uint8_t flag = Interrupt_off;
    irq_disable();
    return flag;
}

void irq_restore(uint8_t flag)
{
    barrier();
    Interrupt_off = flag;
}


/****************************************************************
 * Timers
 ****************************************************************/

uint32_t
timer_from_us(uint32_t us)
{
    return 0; // XXX
}

void
timer_periodic(void)
{
}

uint32_t
timer_read_time(void)
{
    return 0; // XXX
}

uint8_t
timer_set_next(uint32_t next)
{
    return 0;
}

uint8_t
timer_try_set_next(uint32_t next)
{
    return 1;
}


/****************************************************************
 * Turn stdin/stdout into serial console
 ****************************************************************/

// XXX
char *
console_get_input(uint8_t *plen)
{
    *plen = 0;
    return NULL;
}

void
console_pop_input(uint8_t len)
{
}

// Return an output buffer that the caller may fill with transmit messages
char *
console_get_output(uint8_t len)
{
    return NULL;
}

// Accept the given number of bytes added to the transmit buffer
void
console_push_output(uint8_t len)
{
}


/****************************************************************
 * Startup
 ****************************************************************/

// Periodically sleep so we don't consume all CPU
static void
simu_pause(void)
{
    // XXX - should check that no timers are present.
    usleep(1);
}
DECL_TASK(simu_pause);

// Main entry point for simulator.
int
main(void)
{
    // Make stdin non-blocking
    fcntl(STDIN_FILENO, F_SETFL, fcntl(STDIN_FILENO, F_GETFL, 0) | O_NONBLOCK);

    sched_main();
    return 0;
}