summaryrefslogtreecommitdiffstats
path: root/mig_test/software/main.c
blob: 535abf2d0e31cc5ae4b1b8950edf7ce4ed6eec3d (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
135
136
137
138
139
140
141
142
143
144
145
146
147
148
149
150
151
152
153
154
155
156
157
158
159
160
161
162
163
164
165
166
167
168
169
170
171
172
173
174
175
176
177
178
179
180
181
182
183
184
185
186
187
188
189
190
191
192
193
194
195
196
197
198
199
200
201
202
203
204
205
206
207
208
209
210
211
212
213
214
215
216
217
218
219
220
221
222
223
224
225
226
227
228
229
230
231
232
233
234
235
236
237
238
239
240
241
242
243
244
245
246
247
248
249
250
251
252
253
254
255
256
257
258
259
260
261
262
263
264
265
266
267
268
269
270
271
272
273
274
275
276
277
278
279
280
281
282
283
284
285
286
287
288
289
290
291
292
293
294
295
296
/*
 * $Date$
 * $Author$
 * $Revision$
 */

//#include <stdio.h>

#define BOARD_GIGABEE

#include "../include/peripherie.h"
#include <common.h>
#include <timer.h>             // sleep
#include <uart.h>
#include "schedule.h"          // scheduler_init, scheduler_task_*
#include "monitor.h"           // monitor_init, monitor_add_command, monitor_mainloop
#include "monitor_functions.h" // x_function, wmem_function, clear_function, quit_function


////////////////////////////////////////
// named IOs
// input
#define MAC_DATA                          (1<<  4)
#define SIMULATION_ACTIVE                 (1<< 31)
// output
#define LED0                              (1<<  0)
#define LED1                              (1<<  1)
#define LED2                              (1<<  2)
#define LED3                              (1<<  3)
#define LED_USER                          (1<<  5)







////////////////////////////////////////////////////////////

uint32_t         simulation_active;
volatile uint8_t timer_tick;
uint8_t          end_simulation = FALSE;


////////////////////////////////////////
// prototypes

void running_light( uint32_t simulation_active);

uint32_t run_light_function( void);




////////////////////////////////////////
// combined print functions

/*
char uart_lcd_putchar( char c, FILE *stream)
{
    uart_putchar( c, stream);
    lcd_putc( c, stream);
}
*/




// helper functions ////////////////////////////////////////
////////////////////////////////////////////////////////////

// monitor functions ///////////////////////////////////////
////////////////////////////////////////////////////////////

////////////////////////////////////////////////////////////
////////////////////////////////////////////////////////////

void running_light( uint32_t simulation_active)
{
	unsigned int pattern = 0x80300700;
            
    while (1)
    {
    
        gpio0->ioout = 0x0000000f & pattern;
        pattern = (pattern << 1) | (pattern >> 31);


        if ( simulation_active)
        {
            // do only limited runs
            if ( timer_tick) 
            {
                timer_tick = FALSE;
                scheduler_task_check();
                
                if ( end_simulation) break;
            }
        } 
        else
        {
            msleep( 125);
        }
    }

}


////////////////////////////////////////////////////////////


////////////////////////////////////////////////////////////

////////////////////////////////////////////////////////////
// functions for scheduler

void end_simulation_task( void)
{
    end_simulation = TRUE;
}



void running_light_task( void)
{
    static unsigned int pattern = 0x80300700;
            
    gpio0->ioout = 0x0000000f & pattern;
    pattern = (pattern << 1) | (pattern >> 31);

    scheduler_task_add( running_light_task, SECONDS( 0.125));
}



////////////////////////////////////////////////////////////
// start running light
uint32_t run_light_function( void)
{
    scheduler_task_add( running_light_task, 1); 
    return 0;
}



//
//  process serial commands
//
void uart_monitor( void)
{
    uint8_t  c;
    uint8_t  key_time_out = 250;
    uint32_t key_state;

    putchar( '\n');

    monitor_init();


//  monitor_add_command("reset",   "system reset",                          reset_function);
    monitor_add_command("sysinfo", "show system info <verbose>",            system_info_function);

    monitor_add_command("run",     "running light",                         run_light_function);

    monitor_add_command("wmem",    "write word <addr> <length> <value(s)>", wmem_function);
    monitor_add_command("x",       "eXamine memory <addr> <length>",        x_function);
    monitor_add_command("task",    "print tasklist",                        scheduler_tasklist);
                   
    monitor_add_command("help",    "",               help_function);


    // initial help
    help_function();

    monitor_prompt();

    monitor_run = TRUE;

    while( monitor_run)
    {
        // process scheduler
        if ( timer_tick)
        {
            timer_tick = FALSE;
            scheduler_task_check();
        }
    
        // process uart
        if ( uart_check_receiver() ) 
        {
            monitor_input( uart_getchar() );
        }

        // process commands
        monitor_mainloop();
    }
}



////////////////////////////////////////////////////////////

void banner( void)
{
    putstr("\n\n");
    putstr("BSP Trenz Gigabee");

    char     *hw_revision  =    (char *)0x80000000;
    char     *svn_revision =    (char *)0x80000020;
    int32_t  *hw_frequency = (int32_t *)0x80000040;

    if (simulation_active) 
    {
        putstr(" (on sim)\n");
    }
    else
    {
        putstr("\nSVN revision  : "); putstr( svn_revision);
        putstr("\nHW synthesized: "); putstr( hw_revision);
        putstr("\nHW frequency  : "); putint( *hw_frequency/1000000);   putstr(" MHz");
        putstr("\nSW compiled   : " __DATE__ "  " __TIME__ );
        putstr("\nSW frequency  : "); putint( F_CPU/1000000);           putstr(" MHz");
        putchar('\n');
    }
}


////////////////////////////////////////////////////////////
////////////////////////////////////////////////////////////
void _zpu_interrupt( void)
{
    uint32_t reg_val;

    // check for timer 0.0 interrupt
    reg_val = timer0->e[0].ctrl;
    if bit_is_set( reg_val, TIMER_INT_PENDING)
    {
        // clear interrupt pending bit
        clear_bit( reg_val, TIMER_INT_PENDING);
        timer0->e[0].ctrl = reg_val;

        timer_tick = TRUE;
    }
    return;
}

////////////////////////////////////////////////////////////
////////////////////////////////////////////////////////////

int main(void)
{
    
    // check if on simulator or on hardware
    simulation_active = bit_is_set( gpio0->iodata, (1<<31));

    //////////////////////////////////////////////////////////// 
    // init stuff
    timer_init();
    uart_init();
    scheduler_init();
    
        
    // enable timer interrupt, for scheduler
    set_bit( timer0->e[0].ctrl, TIMER_INT_ENABLE);    


    if (!simulation_active) 
    {
        stdout = uart_putchar;
    }
    else
    {
        // debug_putchar is for simulator
        stdout = debug_putchar;
    }

    //////////////////////////////////////////////////////////// 
    banner();

    //////////////////////////////////////////////////////////// 
    // decide which main function to use
    
    if ( !simulation_active) 
    {
		uart_monitor();
    }
   
    // test of scheduler
    scheduler_task_add( end_simulation_task, 1);
    running_light( simulation_active);
    
    //////////////////////////////////////////////////////////// 
    // end simulation
    abort();
    
}
OpenPOWER on IntegriCloud