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

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