13716e7ca25f6bf68f422ab5d559f244b3b4471f
[aversive.git] / modules / base / scheduler / scheduler.c
1 /*  
2  *  Copyright Droids Corporation, Microb Technology, Eirbot (2005)
3  * 
4  *  This program is free software; you can redistribute it and/or modify
5  *  it under the terms of the GNU General Public License as published by
6  *  the Free Software Foundation; either version 2 of the License, or
7  *  (at your option) any later version.
8  *
9  *  This program is distributed in the hope that it will be useful,
10  *  but WITHOUT ANY WARRANTY; without even the implied warranty of
11  *  MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE.  See the
12  *  GNU General Public License for more details.
13  *
14  *  You should have received a copy of the GNU General Public License
15  *  along with this program; if not, write to the Free Software
16  *  Foundation, Inc., 59 Temple Place, Suite 330, Boston, MA  02111-1307  USA
17  *
18  *  Revision : $Id: scheduler.c,v 1.9.4.6 2009-11-08 17:33:14 zer0 Exp $
19  *
20  */
21
22 #include <string.h>
23 #include <stdio.h>
24 #include <inttypes.h>
25
26 #include <aversive/parts.h>
27 #include <aversive/pgmspace.h>
28 #include <aversive.h>
29
30 #include <scheduler.h>
31 #include <scheduler_private.h>
32 #include <scheduler_stats.h>
33 #include <scheduler_config.h>
34
35
36 /* this file is compiled for AVR version only */
37
38 /** declared in scheduler_host.c in case of host version */
39 struct event_t g_tab_event[SCHEDULER_NB_MAX_EVENT];
40
41 #ifdef CONFIG_MODULE_SCHEDULER_STATS
42 struct scheduler_stats sched_stats;
43 #endif
44
45 void scheduler_init(void)
46 {
47         memset(g_tab_event, 0, sizeof(g_tab_event));
48
49 #ifdef CONFIG_MODULE_SCHEDULER_USE_TIMERS
50         SCHEDULER_TIMER_REGISTER();
51 #endif
52
53 #ifdef CONFIG_MODULE_SCHEDULER_TIMER0
54         /* activation of corresponding interrupt */
55         TOIE0_REG |= (1<<TOIE0); /* TIMSK */
56
57         TCNT0 = 0; 
58         CS00_REG = SCHEDULER_CK; /* TCCR0 */
59 #endif
60 }
61
62
63 #ifdef CONFIG_MODULE_SCHEDULER_TIMER0
64 #if defined(SIG_OVERFLOW0)
65 SIGNAL(SIG_OVERFLOW0)
66 #else
67 SIGNAL(TIMER0_OVF_vect)
68 #endif
69 {
70         scheduler_interrupt();
71 }
72 #endif /* CONFIG_MODULE_SCHEDULER_USE_TIMERS */