[437] | 1 | ////////////////////////////////////////////////////////////////////////////////////// |
---|
[258] | 2 | // File : tim_driver.h |
---|
| 3 | // Date : 01/11/2013 |
---|
| 4 | // Author : alain greiner |
---|
| 5 | // Copyright (c) UPMC-LIP6 |
---|
| 6 | /////////////////////////////////////////////////////////////////////////////////// |
---|
[437] | 7 | // The tim_driver.c and tim_driver.h files are part ot the GIET-VM nano-kernel. |
---|
| 8 | // This driver supports the SoCLib vci_multi_timer component. |
---|
| 9 | // |
---|
| 10 | // It can exist several multi_timers in the architecture (at most one per cluster), |
---|
| 11 | // and each one can contain several timers (called channels). |
---|
| 12 | // |
---|
| 13 | // There is two types of timers: |
---|
| 14 | // - "system" timers : one per processor, used for context switch. |
---|
| 15 | // local_id in [0, NB_PROCS_MAX-1], |
---|
| 16 | // - "user" timers : requested by the task in the mapping_info data structure. |
---|
| 17 | // For each user timer, the timer_id is stored in the context of the task. |
---|
| 18 | // The global index is cluster_xy * (NB_PROCS_MAX + NB_TIM_CHANNELS) + local_id |
---|
| 19 | // |
---|
| 20 | // The NB_PROCS_MAX and NB_TIM_CHANNELS values must be defined in hard_config.h file. |
---|
| 21 | // |
---|
| 22 | // The virtual base address of the segment associated to a channel is: |
---|
| 23 | // SEG_TIM_BASE + cluster_xy * PERI_CLUSTER_INCREMENT + TIMER_SPAN * timer_id |
---|
| 24 | // |
---|
| 25 | // The SEG_TIM_BASE and PERI_CLUSTER_INCREMENT must be defined in hard_config.h. |
---|
| 26 | ///////////////////////////////////////////////////////////////////////////////////// |
---|
[258] | 27 | |
---|
[295] | 28 | #ifndef _GIET_TIM_DRIVER_H_ |
---|
| 29 | #define _GIET_TIM_DRIVER_H_ |
---|
[258] | 30 | |
---|
| 31 | /////////////////////////////////////////////////////////////////////////////////// |
---|
[437] | 32 | // registers offsets |
---|
[258] | 33 | /////////////////////////////////////////////////////////////////////////////////// |
---|
| 34 | |
---|
| 35 | enum TIMER_registers |
---|
| 36 | { |
---|
| 37 | TIMER_VALUE = 0, |
---|
| 38 | TIMER_MODE = 1, |
---|
| 39 | TIMER_PERIOD = 2, |
---|
| 40 | TIMER_RESETIRQ = 3, |
---|
| 41 | /**/ |
---|
| 42 | TIMER_SPAN = 4, |
---|
| 43 | }; |
---|
| 44 | |
---|
| 45 | /////////////////////////////////////////////////////////////////////////////////// |
---|
[437] | 46 | // access functions |
---|
[258] | 47 | /////////////////////////////////////////////////////////////////////////////////// |
---|
| 48 | |
---|
[437] | 49 | /////////////////////////////////////////////////////////////////////////////////// |
---|
| 50 | // This function activates a timer in the vci_timer external peripheral. |
---|
| 51 | // - channel : Timer channel global index |
---|
| 52 | // - period : interrupt period (cycles) |
---|
| 53 | /////////////////////////////////////////////////////////////////////////////////// |
---|
| 54 | extern int _timer_start( unsigned int channel, |
---|
| 55 | unsigned int period ); |
---|
[258] | 56 | |
---|
[437] | 57 | /////////////////////////////////////////////////////////////////////////////////// |
---|
| 58 | // This function desactivates a timer in the vci_timer external component. |
---|
| 59 | /////////////////////////////////////////////////////////////////////////////////// |
---|
| 60 | extern int _timer_stop( unsigned int channel ); |
---|
[258] | 61 | |
---|
[437] | 62 | /////////////////////////////////////////////////////////////////////////////////// |
---|
| 63 | // This function resets the timer counter. To do so, it read the period, |
---|
| 64 | // and re-write it in the timer register, what causes the count to restart. |
---|
| 65 | /////////////////////////////////////////////////////////////////////////////////// |
---|
| 66 | extern int _timer_reset_cpt( unsigned int channel ); |
---|
[258] | 67 | |
---|
[437] | 68 | /////////////////////////////////////////////////////////////////////////////////// |
---|
| 69 | // This Interrupt Service Routine handles the IRQs generated by the "user" timers. |
---|
| 70 | // It can be a HWI or a PTI. |
---|
| 71 | // The channel argument is the user timer global index. |
---|
| 72 | // The ISR acknowledges the IRQ, registers the event in the proper entry |
---|
| 73 | // of the _user_timer_event[] array, and a log message is displayed on TTY0. |
---|
| 74 | /////////////////////////////////////////////////////////////////////////////////// |
---|
[295] | 75 | extern void _timer_isr( unsigned int irq_type, |
---|
| 76 | unsigned int irq_id, |
---|
| 77 | unsigned int channel ); |
---|
[258] | 78 | |
---|
| 79 | |
---|
| 80 | #endif |
---|
| 81 | |
---|
| 82 | // Local Variables: |
---|
| 83 | // tab-width: 4 |
---|
| 84 | // c-basic-offset: 4 |
---|
| 85 | // c-file-offsets:((innamespace . 0)(inline-open . 0)) |
---|
| 86 | // indent-tabs-mode: nil |
---|
| 87 | // End: |
---|
| 88 | // vim: filetype=c:expandtab:shiftwidth=4:tabstop=4:softtabstop=4 |
---|
| 89 | |
---|