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

Last change on this file since 702 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
RevLine 
[529]1/////////////////////////////////////////////////////////////////////////////
[437]2// File     : tim_driver.c
[258]3// Date     : 23/05/2013
4// Author   : alain greiner
5// Copyright (c) UPMC-LIP6
[529]6/////////////////////////////////////////////////////////////////////////////
[258]7
8#include <giet_config.h>
[437]9#include <hard_config.h>
[258]10#include <tim_driver.h>
11#include <utils.h>
[456]12#include <tty0.h>
[258]13
[320]14#if !defined(SEG_TIM_BASE)
15# error: You must define SEG_TIM_BASE in the hard_config.h file
16#endif
17
[333]18#if !defined(PERI_CLUSTER_INCREMENT)
19# error: You must define PERI_CLUSTER_INCREMENT in the hard_config.h file
[320]20#endif
21
[263]22#if !defined(X_SIZE)
23# error: You must define X_SIZE in the hard_config.h file
[258]24#endif
25
[263]26#if !defined(Y_SIZE)
27# error: You must define X_SIZE in the hard_config.h file
[258]28#endif
29
[263]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
[258]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
[529]50/////////////////////////////////////////////////////////////////////////////
[437]51//                      global variables
[529]52/////////////////////////////////////////////////////////////////////////////
[258]53
54#define in_unckdata __attribute__((section (".unckdata")))
55
56#if (NB_TIM_CHANNELS > 0)
[437]57in_unckdata volatile unsigned char _user_timer_event[NB_TIM_CHANNELS]
58                        = { [0 ... ((1<<NB_TIM_CHANNELS) - 1)] = 0 };
[258]59#endif
60
[529]61/////////////////////////////////////////////////////////////////////////////
[437]62//                      access functions
[529]63/////////////////////////////////////////////////////////////////////////////
[437]64
[529]65///////////////////////////////////////////////////////
[437]66unsigned int _timer_get_register( unsigned int channel,
67                                  unsigned int index )
[258]68{
[437]69    unsigned int* vaddr = (unsigned int*)SEG_TIM_BASE + channel*TIMER_SPAN + index;
70    return _io_extended_read( vaddr );
71}
[295]72
[437]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 );
[258]80}
81
[437]82///////////////////////////////////////
83int _timer_start( unsigned int channel, 
84                  unsigned int period ) 
[258]85{
[295]86#if NB_TIM_CHANNELS
87
[437]88    if ( channel >= NB_TIM_CHANNELS )
[295]89    {
[437]90        _puts("[GIET ERROR] in _timer_start()\n");
91        return -1;
[295]92    }
[258]93
[437]94    _timer_set_register( channel, TIMER_PERIOD, period );
95    _timer_set_register( channel, TIMER_MODE  , 0x3 );
96   
97    return 0;
[258]98
[437]99#else
[295]100
[437]101    _puts("[GIET ERROR] _timer_start() should not be called when NB_TIM_CHANNELS is 0\n");
102    return -1;
103
[295]104#endif
[258]105}
106
[437]107///////////////////////////////////////
108int _timer_stop( unsigned int channel ) 
[258]109{
[295]110#if NB_TIM_CHANNELS
111
[437]112    if ( channel >= NB_TIM_CHANNELS )
[295]113    {
[437]114        _puts("[GIET ERROR] in _timer_stop()\n");
115        return -1;
[295]116    }
[258]117
[437]118    _timer_set_register( channel, TIMER_MODE  , 0 );
[258]119
[437]120    return 0;
[295]121
122#else
[437]123
124    _puts("[GIET ERROR] _timer_stop() should not be called when NB_TIM_CHANNELS is 0\n");
125    return -1;
126
[295]127#endif
[258]128}
129
[437]130////////////////////////////////////////////
131int _timer_reset_cpt( unsigned int channel ) 
[258]132{
[295]133#if NB_TIM_CHANNELS
134
[437]135    if ( channel >= NB_TIM_CHANNELS )
[295]136    {
[437]137        _puts("[GIET ERROR in _timer_reset_cpt()\n");
138        return -1;
[295]139    }
[258]140
[437]141    unsigned int period = _timer_get_register( channel, TIMER_PERIOD );
142    _timer_set_register( channel, TIMER_PERIOD, period );
[258]143
[437]144    return 0;
[295]145
146#else
[437]147
148    _puts("[GIET ERROR] _timer_reset_cpt should not be called when NB_TIM_CHANNELS is 0\n");
149    return -1;
150
[295]151#endif
[258]152}
153
[437]154///////////////////////////////////////
[295]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
[258]160
[437]161    // acknowledge IRQ
162    _timer_set_register( channel, TIMER_RESETIRQ, 0 ); 
[295]163
164    // register the event
[437]165    _user_timer_event[channel] = 1;
[295]166
167    // display a message on TTY 0
[437]168    _puts("\n[GIET WARNING] User Timer IRQ at cycle %d for channel = %d\n",
169            _get_proctime(), channel );
[295]170
171#else
[437]172
173    _puts("[GIET ERROR] _timer_isr() should not be called when NB_TIM_CHANNELS == 0\n");
[295]174    _exit();
[437]175
[295]176#endif
177}
178
179
180
[258]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.