1e2ae7563e71c8b1152f9afab96af0325664c06e
[aversive.git] / modules / base / scheduler / test / main.c
1 /*  \r
2  *  Copyright Droids Corporation, Microb Technology, Eirbot (2005)\r
3  * \r
4  *  This program is free software; you can redistribute it and/or modify\r
5  *  it under the terms of the GNU General Public License as published by\r
6  *  the Free Software Foundation; either version 2 of the License, or\r
7  *  (at your option) any later version.\r
8  *\r
9  *  This program is distributed in the hope that it will be useful,\r
10  *  but WITHOUT ANY WARRANTY; without even the implied warranty of\r
11  *  MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE.  See the\r
12  *  GNU General Public License for more details.\r
13  *\r
14  *  You should have received a copy of the GNU General Public License\r
15  *  along with this program; if not, write to the Free Software\r
16  *  Foundation, Inc., 59 Temple Place, Suite 330, Boston, MA  02111-1307  USA\r
17  *\r
18  *  Revision : $Id: main.c,v 1.9.4.5 2007-06-01 09:37:22 zer0 Exp $\r
19  *\r
20  */\r
21 \r
22 #include <scheduler.h>\r
23 #include <aversive/wait.h>\r
24 #include <stdio.h>\r
25 #include <uart.h>\r
26 //#include <timer.h>\r
27 #include <hostsim.h>\r
28 \r
29 uint8_t event_id;\r
30 \r
31 void f1(void * nothing)\r
32 {\r
33         printf("%s\n", __FUNCTION__);\r
34 }\r
35 \r
36 void f2(void * nothing)\r
37 {\r
38         printf("%s\n", __FUNCTION__);\r
39 }\r
40 \r
41 void f3(void * nothing)\r
42 {\r
43         printf("%s START\n", __FUNCTION__);\r
44         wait_ms(1000);\r
45         printf("%s END\n", __FUNCTION__);\r
46 }\r
47 \r
48 void supp(void * nothing)\r
49 {\r
50         scheduler_del_event(event_id);\r
51 }\r
52 \r
53 int main(void)\r
54 {\r
55 #ifdef HOST_VERSION\r
56         hostsim_uart_init();\r
57         hostsim_ittimer_add(scheduler_interrupt, 1 * 1000 * 1000); /* 1ms period */\r
58         hostsim_ittimer_enable(100); /* 100 us */\r
59 #else\r
60         uart_init();\r
61         fdevopen(uart0_dev_send, uart0_dev_recv);\r
62 \r
63 #ifdef CONFIG_MODULE_TIMER\r
64         timer_init();\r
65 #endif\r
66 #endif\r
67 \r
68         scheduler_init();\r
69         printf("init2\n");\r
70         wait_ms(2000);\r
71         printf("init3\n");\r
72 \r
73         sei();\r
74 \r
75         event_id = scheduler_add_periodical_event_priority(f1, NULL,\r
76                 500000l/SCHEDULER_UNIT, 200);\r
77         scheduler_add_periodical_event_priority(f2, NULL,\r
78                 500000l/SCHEDULER_UNIT, 100);\r
79         scheduler_add_periodical_event(f3, NULL, 1000000l/SCHEDULER_UNIT);\r
80 \r
81         scheduler_add_single_event(supp, NULL, 5000000l/SCHEDULER_UNIT);\r
82 \r
83         while (1);\r
84 \r
85         return 0;\r
86 }\r