source: soft/giet_vm/giet_drivers/tim_driver.c @ 445

Last change on this file since 445 was 437, checked in by alain, 10 years ago

Introducing dynamic allocation of peripheral channel(TTY, NIC, TIM, CMA)
Removint the ICU driver : ICU component not supported anymore.
Removing the FBF driver.

File size: 4.7 KB
Line 
1//////////////////////////////////////////////////////////////////////////////////////
2// File     : tim_driver.c
3// Date     : 23/05/2013
4// Author   : alain greiner
5// Copyright (c) UPMC-LIP6
6//////////////////////////////////////////////////////////////////////////////////////
7
8#include <giet_config.h>
9#include <hard_config.h>
10#include <tim_driver.h>
11#include <utils.h>
12
13#if !defined(SEG_TIM_BASE)
14# error: You must define SEG_TIM_BASE in the hard_config.h file
15#endif
16
17#if !defined(PERI_CLUSTER_INCREMENT)
18# error: You must define PERI_CLUSTER_INCREMENT in the hard_config.h file
19#endif
20
21#if !defined(X_SIZE)
22# error: You must define X_SIZE in the hard_config.h file
23#endif
24
25#if !defined(Y_SIZE)
26# error: You must define X_SIZE in the hard_config.h file
27#endif
28
29#if !defined(X_WIDTH)
30# error: You must define X_WIDTH in the hard_config.h file
31#endif
32
33#if !defined(Y_WIDTH)
34# error: You must define X_WIDTH in the hard_config.h file
35#endif
36
37#if !defined(NB_PROCS_MAX)
38# error: You must define NB_PROCS_MAX in the hard_config.h file
39#endif
40
41#if !defined(NB_TIM_CHANNELS)
42#define NB_TIM_CHANNELS 0
43#endif
44
45#if ( (NB_TIM_CHANNELS + NB_PROC_MAX) > 32 )
46# error: NB_TIM_CHANNELS + NB_PROCS_MAX cannot be larger than 32
47#endif
48
49/////////////////////////////////////////////////////////////////////////////////
50//                      global variables
51/////////////////////////////////////////////////////////////////////////////////
52
53#define in_unckdata __attribute__((section (".unckdata")))
54
55#if (NB_TIM_CHANNELS > 0)
56in_unckdata volatile unsigned char _user_timer_event[NB_TIM_CHANNELS]
57                        = { [0 ... ((1<<NB_TIM_CHANNELS) - 1)] = 0 };
58#endif
59
60/////////////////////////////////////////////////////////////////////////////////
61//                      access functions
62/////////////////////////////////////////////////////////////////////////////////
63
64//////////////////////////////////////////////////////////////
65unsigned int _timer_get_register( unsigned int channel,
66                                  unsigned int index )
67{
68    unsigned int* vaddr = (unsigned int*)SEG_TIM_BASE + channel*TIMER_SPAN + index;
69    return _io_extended_read( vaddr );
70}
71
72//////////////////////////////////////////////////////
73void _timer_set_register( unsigned int channel,
74                          unsigned int index,
75                          unsigned int value )
76{
77    unsigned int* vaddr = (unsigned int*)SEG_TIM_BASE + channel*TIMER_SPAN + index;
78    _io_extended_write( vaddr, value );
79}
80
81///////////////////////////////////////
82int _timer_start( unsigned int channel, 
83                  unsigned int period ) 
84{
85#if NB_TIM_CHANNELS
86
87    if ( channel >= NB_TIM_CHANNELS )
88    {
89        _puts("[GIET ERROR] in _timer_start()\n");
90        return -1;
91    }
92
93    _timer_set_register( channel, TIMER_PERIOD, period );
94    _timer_set_register( channel, TIMER_MODE  , 0x3 );
95   
96    return 0;
97
98#else
99
100    _puts("[GIET ERROR] _timer_start() should not be called when NB_TIM_CHANNELS is 0\n");
101    return -1;
102
103#endif
104}
105
106///////////////////////////////////////
107int _timer_stop( unsigned int channel ) 
108{
109#if NB_TIM_CHANNELS
110
111    if ( channel >= NB_TIM_CHANNELS )
112    {
113        _puts("[GIET ERROR] in _timer_stop()\n");
114        return -1;
115    }
116
117    _timer_set_register( channel, TIMER_MODE  , 0 );
118
119    return 0;
120
121#else
122
123    _puts("[GIET ERROR] _timer_stop() should not be called when NB_TIM_CHANNELS is 0\n");
124    return -1;
125
126#endif
127}
128
129////////////////////////////////////////////
130int _timer_reset_cpt( unsigned int channel ) 
131{
132#if NB_TIM_CHANNELS
133
134    if ( channel >= NB_TIM_CHANNELS )
135    {
136        _puts("[GIET ERROR in _timer_reset_cpt()\n");
137        return -1;
138    }
139
140    unsigned int period = _timer_get_register( channel, TIMER_PERIOD );
141    _timer_set_register( channel, TIMER_PERIOD, period );
142
143    return 0;
144
145#else
146
147    _puts("[GIET ERROR] _timer_reset_cpt should not be called when NB_TIM_CHANNELS is 0\n");
148    return -1;
149
150#endif
151}
152
153///////////////////////////////////////
154void _timer_isr( unsigned int irq_type,   // HWI / PTI
155                 unsigned int irq_id,     // index returned by XCU
156                 unsigned int channel )   // user timer index
157{
158#if NB_TIM_CHANNELS
159
160    // acknowledge IRQ
161    _timer_set_register( channel, TIMER_RESETIRQ, 0 ); 
162
163    // register the event
164    _user_timer_event[channel] = 1;
165
166    // display a message on TTY 0
167    _puts("\n[GIET WARNING] User Timer IRQ at cycle %d for channel = %d\n",
168            _get_proctime(), channel );
169
170#else
171
172    _puts("[GIET ERROR] _timer_isr() should not be called when NB_TIM_CHANNELS == 0\n");
173    _exit();
174
175#endif
176}
177
178
179
180// Local Variables:
181// tab-width: 4
182// c-basic-offset: 4
183// c-file-offsets:((innamespace . 0)(inline-open . 0))
184// indent-tabs-mode: nil
185// End:
186// vim: filetype=c:expandtab:shiftwidth=4:tabstop=4:softtabstop=4
187
Note: See TracBrowser for help on using the repository browser.