CROSS Technical Documentation User Manual and Technical Doc.
INFN Milano Bicocca
Loading...
Searching...
No Matches
Timer.c
Go to the documentation of this file.
1// DOCUMENTAZIONE DOXYGEN
2/*!
3\file
4\page Timer_ Timer page
5*\brief <span style="color:red;"> <b> Timing functions </b> </span>
6*\tableofcontents
7
8 \b SUMMARY:
9*\arg \ref Timer_fun
10
11
12*\section Timer_fun User use of the Timer
13<hr width="75%" size="10" align="left">
14
15\n A very simple and friendly function has been created for waiting time during slow operations
16such as relay setting. The function is blocking and is Aspetta_tanti_ms(int m) and wait \b m milliseconds. Example:
17
18<span style="color:orange;"> <I>
19\code {.c}
20//Wait 10 ms
21Aspetta_tanti_ms(10);
22\endcode
23</I> </span>
24
25\n The counter is bae on the SysTick_Handler() which increases the counter every ms.
26
27\n The code:
28*\snippet{lineno} Timer.c fun_timer
29
30*/
31
32#include "tutti_gli_header.h"
33
34
35// Vengono inizializzati dei parametri
36
37volatile bool timer = 0;
38volatile uint32_t ticks = 0;
39volatile uint32_t N = 100;
40
41
42/*****************************************************************************
43 Aspetta_tanti_ms
44******************************************************************************/
45/*! \brief The timing function
46\param[in] millisecondi the time to wait in millisec
47*\return No Parameters
48 \showrefby
49*\snippet{lineno} Timer.c fun_timer
50 */
51//! <!-- [fun_timer] -->
52void Aspetta_tanti_ms(int millisecondi)
53{
54#define come_dovrebbe_funzionare
55//#define uso_di_timer0
56#ifdef come_dovrebbe_funzionare
57 N = millisecondi; // Viene stabilito quanti ms il micro dovr\'a aspettare
58 timer = 1; // Viene impostato il flag timer a 1
59 while(timer!=0) // Viene fatto un ciclo infinito finch\'e il flag non viene azzerato
60 {
61 }
62#endif
63#ifdef uso_di_timer0
64 int32_t partenza,arrivo ;
65 millisecondi = millisecondi * TIMER0_coefficiente_per_millisec ;
66 LPC_TIM0->MR0 = millisecondi ;
67 LPC_TIM0->TC =0;
68 TIMER0_start_conteggio
69 while( (LPC_TIM0->IR & 1) ==0 ){}
70 LPC_TIM0->IR |=1 ; //Azzero il flag di fine misura
71#endif
72}
73//! <!-- [fun_timer] -->
74
75/******************************************************************************
76 SysTick Handler
77 ******************************************************************************/
78/*! \brief The timing function
79\param[in] m the time to wait in millisec
80*\return No Parameters
81 \showrefby
82*\snippet{lineno} Timer.c fun_SysTick_Handler
83 */
84//! <!-- [fun_SysTick_Handler] -->
85void SysTick_Handler (void)
86{ // Se il flag timer \'e 0, non viene fatto niente
87 if (timer == 1) // Se il flag timer \'e 1, viene aumentato ticks finch\'e non diventa N-1
88 {
89 if(ticks>=(N-1))
90 {
91 ticks=0; // Quando ticks = N-1, vengono azzerati ticks e timer
92 timer=0;
93// return;
94 }
95 else
96 {
97 ++ticks;
98// return;
99 }
100 }
101#ifdef true
102 //temporizzatore LED rosso
103 if (LED_rosso_attivo || prolungamento){
104 if( prolungamento==0){
105 prolungamento=10;
106 LED_rosso_tempo=0;
108 acceso=0;
109 }
110 if( (LED_rosso_tempo >= LED_rosso_fondo_scala) ){
111 LED_rosso_tempo =0;
113 prolungamento--;
114 if(prolungamento==0)LED_accendi_spegni(LED_RED, spegni);
115 }else{
116 LED_rosso_tempo++;
117 }
118 }
119
120//temporizzatore LED verde
122 if( (LED_verde_tempo >= LED_verde_fondo_scala) ){
123 LED_verde_tempo =0;
125 }else{
126 LED_verde_tempo++;
127 }
128 }
129#endif
130 //temporizzazione powerdown
132
133}
134//! <!-- [fun_SysTick_Handler] -->
135
136/*! \brief Use of timer0 as a delay
137
138*\return No Parameters
139 \showrefby
140*\snippet{lineno} Timer.c fun_TIMER0_setup
141 */
142//! <!-- [fun_TIMER0_setup] -->
143void TIMER0_setup(void){
144 LPC_SC->PCONP |= 1; //Acensione timer0 (\'e gi\'a acceso, ma per sicurezza)
145 LPC_SC->PCLKSEL0 |= 1 << 2; //Clock = a quello della cpu
146 LPC_TIM0->PR = SystemCoreClock / TIMER0_freqeunza ; // 1 contenggio ogni 100 micros
147 LPC_TIM0 -> MCR |= TIM0_MR0I | TIM0_MR0S | TIM0_MR0R ; //Interrupt + reset conteggio e stop
148}
149//! <!-- [fun_TIMER0_setup] -->
150
151/*! \brief Use of timer0 as an endless counter
152
153*\return No Parameters
154 \showrefby
155*\snippet{lineno} Timer.c fun_TIMER1_setup
156 */
157//! <!-- [fun_TIMER1_setup] -->
158void TIMER1_setup(void){
159 LPC_SC->PCONP |= 2; //Acensione timer1 (\'e gi\'a acceso, ma per sicurezza)
160 LPC_SC->PCLKSEL0 |= 1 << 4; //Clock = a quello della cpu
161 LPC_TIM1->PR = SystemCoreClock / TIMER0_freqeunza ; // 1 contenggio ogni 100 micros
162// LPC_TIM1 -> MCR |= TIM0_MR0I | TIM0_MR0S | TIM0_MR0R ; //Interrupt + reset conteggio e stop
163 TIMER1_start_conteggio
164}
165//! <!-- [fun_TIMER1_setup] -->
166
void LED_accendi_spegni(uint8_t LED, uint8_t accendi_1_spegni_0)
This function turns ON or OFF any of the selcted LED.
Definition: Led.c:123
volatile uint8_t LED_rosso_attivo
Definition: Led.c:57
void LED_VERDE_lampeggio(void)
This function toggles the green LED and it is launched by SysTick_Handler() every time LED_verde_temp...
Definition: Led.c:100
volatile uint16_t LED_verde_fondo_scala
Definition: Led.c:63
volatile uint16_t LED_rosso_fondo_scala
Definition: Led.c:56
volatile uint8_t LED_verde_attivo
Definition: Led.c:61
void LED_RED_lampeggio(void)
This function toggles the Red LED and it is launched by SysTick_Handler() every time LED_rosso_tempo ...
Definition: Led.c:77
#define LED_RED
Definition: Led.h:10
#define spegni
Definition: Led.h:13
#define accendi
Definition: Led.h:12
volatile uint32_t POWER_DOWN_ABILITA_CONTEGGIO
Power down couter and anable is set if this variable is true.
Definition: Power_down.c:120
volatile uint32_t POWER_DOWN_TEMPO_ATTESA
Counter to wait for power down, multiple of 10 ms.
Definition: Power_down.c:116
void Aspetta_tanti_ms(int millisecondi)
The timing function.
Definition: Timer.c:52
void TIMER1_setup(void)
Use of timer0 as an endless counter.
Definition: Timer.c:158
void TIMER0_setup(void)
Use of timer0 as a delay.
Definition: Timer.c:143
void SysTick_Handler(void)
The timing function.
Definition: Timer.c:85
#define TIM0_MR0I
Abilitazione interrupt timer0.
Definition: Timer.h:10
#define TIM0_MR0R
Reset contatori timer0.
Definition: Timer.h:12
#define TIM0_MR0S
Stop al fondo scala timer0.
Definition: Timer.h:11