source: soft/giet_vm/giet_drivers/tim_driver.c

Last change on this file was 529, checked in by alain, 10 years ago

1) Removing the IOC driver (integrated in the FAT library).
2) Simplifying the BDV, HBA, SDC, RDK drivers: they support
only two modes (synchronous => polling / descheduling => IRQ),
and only one access function (for both read/write).

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