CROSS Technical Documentation User Manual and Technical Doc.
INFN Milano Bicocca
Loading...
Searching...
No Matches
Power_down.c
Go to the documentation of this file.
1
2
3
4#include "tutti_gli_header.h"
5#include "RTE_Device.h"
6#include "core_cm3.h"
7
8
9// DOCUMENTAZIONE DOXYGEN
10
11/// \file
12
13/*! \page Power_down The Power down
14\anchor Power_down_ref
15*\brief <span style="color:red;"> <b> Power Down operation </b> </span>
16*\tableofcontents
17
18 \b SUMMARY:
19*\arg \ref introduction_to_Power_down
20*\arg \ref Power_down_managing
21*\arg \ref Wake_up_managing
22
23*\section introduction_to_Power_down Power Down introduction
24<hr width="90%" size="10" align="left">
25\n &mu;-controller power down it's a feature that allows to mitigate disturbances by stopping &mu;-controller clock.
26In addition a small save is also obtained in ower consumption.
27Power Down implementation in our fw is quite flexible: it can be set ON or OFF and the time to wait before
28power down is active can be also set.
29\n The variable that account for the power down wait is #POWER_DOWN_TEMPO_ATTESA. It is reset after any wake up and
30at startup. It is increased within SysTick_Handler() and is a multiple of \b 10 \b ms. Maximum elapsed time before power down is
31set by the user through #POWER_DOWN_MAX_ATTESA. This is done in the main() :
32
33*\snippet{lineno} main_for_CROSS_FrontEnd.c fun_power_down_main
34
35As it can be seen, power down is enabled or not in relation to the 2 boolean variables #POWER_DOWN_ABILITA_CONTEGGIO and #flag_power_down.
36The first one, #POWER_DOWN_ABILITA_CONTEGGIO, is set false by the fw whenever there is an action into operation. The switch #flag_power_down
37is instead set by the user with the proper instuction, se below.
38\n The function that manages the poower down, invoked above, is PowerControl_PowerDown().
39
40*\section Power_down_managing Power down managing
41<hr width="90%" size="10" align="left">
42\n Power down to take place needs of a few steps:
43- Preparation of the peripheral which will be sensitive to wake up;
44- Turn off of all the peripherals that could inhibit the power down to start;
45- turn off of the PLL and set the clock to a default;
46- Start of power down;
47- Operations to be down at wake up: clock, peripherals,...
48
49\n Our &mu;-controller has the possibility to be waked-up from the activity on the CAN bus line.
50However, we encontered some difficulties in exploiting that feature and have used in previous
51&mu;-controllers the wake-up from the pin. For doing that the CAN is first disabled, than the receiving
52pin is set as GPIO input, and enabled as interruput from wake-up, as listed here:
53
54*\snippet{lineno} Power_down.c code_PowerDown_int_enable
55
56As it can be seen, the other communication peripherals used are disabled, too.
57\n The next important step is to disable the PLL of the clock:
58
59*\snippet{lineno} Power_down.c code_PowerDown_clock_disable
60
61Finally, the &mu;-controller is ready to sleep:
62
63*\snippet{lineno} Power_down.c code_PowerDown_sleep_set
64
65The switch on \b CoreDebug ->DHCSR is done to avoid conflict during the debug phase,
66if the debugger is connected to the JTAG.
67
68*\section Wake_up_managing Wake-up managing
69<hr width="90%" size="10" align="left">
70
71The function EINT3_IRQHandler() is called at the wake-up, when the control room starts
72the activity on the CAN bus.
73The first action is to restor the pins dedicated to CAN and the shutting down of the waking interrupt pin in the
74function WakeResetCAN():
75
76*\snippet{lineno} Power_down.c fun_PowerControl_CAN_restoring
77
78Finally the clock and all the communication peripherals are re-activated in CANActivity_IRQHandler_mio():
79
80*\snippetlineno Power_down.c fun_PowerControl_wake_up_peripherals
81
82\sa The instruction over the CAN to set the Power Down parametrs is \ref instr_Shut_Down_ON_OFF_option "instr_Shut_Down_ON_OFF".
83
84*/
85uint32_t tempo = 0U;
86uint8_t volatile fuffa=0;
87volatile uint32_t can_clock;
88
89#define power_down_conEINT3
90//#define power_down_conCAN
91
92//#define CLOCK_SETUP 1 //Definizioni per il System_Init()
93//#define SCS_Val 0x00000020
94//#define CLKSRCSEL_Val 0x00000001
95//#define PLL0CFG_Val 0x00050063
96//#define CCLKCFG_Val 0x00000003
97//#define PCLKSEL0_Val 0x00000000
98//#define PCLKSEL1_Val 0x00000000
99
100
101
102#define LPC_CAN (LPC_CAN1)
103
104#define CAN_RD_PORT (RTE_CAN1_RD_PORT)
105#define CAN_RD_BIT (RTE_CAN1_RD_BIT)
106#define CAN_RD_FUNC (RTE_CAN1_RD_FUNC)
107
108#define CAN_TD_PORT (RTE_CAN1_TD_PORT)
109#define CAN_TD_BIT (RTE_CAN1_TD_BIT)
110
111#define CAN_INT_F_Enable ((CAN_RD_PORT == 0) ? (LPC_GPIOINT->IO0IntEnF |= (1 << CAN_RD_BIT)) : (LPC_GPIOINT->IO2IntEnF |= (1 << CAN_RD_BIT)))
112#define CAN_INT_F_Disable ((CAN_RD_PORT == 0) ? (LPC_GPIOINT->IO0IntEnF &= ~(1 << CAN_RD_BIT)) : (LPC_GPIOINT->IO2IntEnF &= ~(1 << CAN_RD_BIT)))
113#define CAN_INT_Clear ((CAN_RD_PORT == 0) ? (LPC_GPIOINT->IO0IntClr |= (1 << CAN_RD_BIT)) : (LPC_GPIOINT->IO2IntClr |= (1 << CAN_RD_BIT)))
114#define CAN_INT_Status ((CAN_RD_PORT == 0) ? ((LPC_GPIOINT->IO0IntStatF & (1 << CAN_RD_BIT)) != 0) : ((LPC_GPIOINT->IO2IntStatF & (1 << CAN_RD_BIT)) != 0))
115
116volatile uint32_t POWER_DOWN_TEMPO_ATTESA=0; //!< Counter to wait for power down, multiple of 10 ms
117
118volatile uint32_t POWER_DOWN_MAX_ATTESA=5000; //!< upper limit for POWER_DOWN_TEMPO_ATTESA
119
120volatile uint32_t POWER_DOWN_ABILITA_CONTEGGIO=0; //!< Power down couter and anable is set if this variable is true
121
122//typedef enum
123//{
124// EXTI_EINT0 = 0,
125// EXTI_EINT1 = 1,
126// EXTI_EINT2 = 2,
127// EXTI_EINT3 = 3
128//} EXTI_LINE_ENUM;
129
130//typedef enum
131//{
132// EXTI_MODE_LEVEL_SENSITIVE,
133// EXTI_MODE_EDGE_SENSITIVE
134//} EXTI_MODE_ENUM;
135
136//typedef enum
137//{
138// EXTI_POLARITY_LOW_ACTIVE_OR_FALLING_EDGE = 1,
139// EXTI_POLARITY_HIGH_ACTIVE_OR_RISING_EDGE = 0
140//} EXTI_POLARITY_ENUM;
141
142//typedef struct
143//{
144// EXTI_LINE_ENUM EXTI_Line;
145// EXTI_MODE_ENUM EXTI_Mode;
146// EXTI_POLARITY_ENUM EXTI_Polarity;
147//} EXTI_InitTypeDef;
148
149/*****************************************************************************
150 Funzione che rigenera il PLL0
151 ******************************************************************************/
152void System_init(void)
153{
154
155 //ATTENZIONE: le macro XXX_Val sono costruite dal configuration wizard
156 LPC_SC->SCS = mio_SCS_Val; //Abilitazione main oscillator
157 if (LPC_SC->SCS & (1 << 5)) { /* If Main Oscillator is enabled */
158 while ((LPC_SC->SCS & (1<<6)) == 0);/* Main oscillator status, Wait for Oscillator to be ready, quando diventa 1 */
159 }
160
161 LPC_SC->CCLKCFG = mio_CCLKCFG_Val; /* Setup Clock Divider */
162 /* Periphral clock must be selected before PLL0 enabling and connecting
163 * - according errata.lpc1768-16.March.2010 -
164 */
165 LPC_SC->PCLKSEL0 = mio_PCLKSEL0_Val; /* Peripheral Clock Selection */
166 LPC_SC->PCLKSEL1 = mio_PCLKSEL1_Val;
167
168 LPC_SC->CLKSRCSEL = mio_CLKSRCSEL_Val; /* Select Clock Source sysclk / PLL0 */
169 LPC_SC->PLL0CFG = mio_PLL0CFG_Val; /* configure PLL0 */
170 LPC_SC->PLL0FEED = 0xAA;
171 LPC_SC->PLL0FEED = 0x55;
172
173 LPC_SC->PLL0CON = mio_PLL0_SETUP;//0x01; /* PLL0 Enable */
174 LPC_SC->PLL0FEED = 0xAA;
175 LPC_SC->PLL0FEED = 0x55;
176 if(mio_PLL0_SETUP){
177 while (!(LPC_SC->PLL0STAT & (1<<26)));/* Wait for PLOCK0 */
178
179
180 LPC_SC->PLL0CON = 0x03; /* PLL0 Enable & Connect */
181 LPC_SC->PLL0FEED = 0xAA;
182 LPC_SC->PLL0FEED = 0x55;
183 while ((LPC_SC->PLL0STAT & ((1<<25) | (1<<24))) != ((1<<25) | (1<<24))); /* Wait for PLLC0_STAT & PLLE0_STAT */
184 }
185 // Configurazione del Timer
186 SystemCoreClockUpdate(); // Viene aggiornato il system core clock
187 SysTick_Config(SystemCoreClock/1000); // Viene generato l'interrupt ogni 1
188// SysTick->CTRL &= ~SysTick_CTRL_ENABLE_Msk;
189 NVIC_SetPriority (SysTick_IRQn, 29); /* set Priority for Systick Interrupt */
190// SysTick->CTRL |= SysTick_CTRL_ENABLE_Msk;
191}
192// void CANActivity_IRQHandler (void){
193//
194// CANActivity_IRQHandler_mio();
195// }
196
197
198 /*****************************************************************************
199 Interrupt che viene chiamato subito dopo il risveglio
200 ******************************************************************************/
201
202/*! \brief Peripherals Wake-up
203
204*\param[in,out] no param
205*\return No Parameters, the actual result is sent to the CAN bus output throught \ref tx_data.
206
207*\snippetlineno Power_down.c fun_PowerControl_wake_up_peripherals
208*/
209//! <!-- [fun_PowerControl_wake_up_peripherals] -->
211
212#ifdef power_down_conCAN
213 //Queste 3 istruzioni sono necessarie al risveglio
214 LPC_SC->CANSLEEPCLR|=2U; //Il clock viene ri-dato al CAN1
215 LPC_CAN1->MOD &=~(1<<4); //SCrivendo 0 in questo bit si ritorna al normal mode
216 LPC_SC->CANWAKEFLAGS|= 2U; //Reset dell'avvenuto risveglio
217 LPC_CAN1->IER &= ~(1<< 4); //Spegnamo l'interruput da wakeup del CAN
218 NVIC_DisableIRQ(CANActivity_IRQn); //Via anche la chiamata
219#endif
220
221 System_init();
222
223 I2C_1_Initialize(); // Viene inizializzata la periferica I2C_A
224 I2C_0_Initialize(); // Viene inizializzata la periferica I2C_B
226
227 // Disable CANActivity interrupt
228 LPC_SC->PCON &=~ 0x01; // Reset powerdown mode to idle mode
229 SCB->SCR &=~ (1UL << 2); // Reset SLEEPDEEP
230 CAN_Inizialize(); // Viene inizializzato il CAN
231 can_clock= CANdrv->GetClock();
232// NVIC_EnableIRQ(CAN_IRQn);
233 CANdrv->Control(ARM_CAN_ABORT_MESSAGE_SEND, tx_obj_idx);
234 LPC_CAN1->MOD |=1; //Si annullano tutte le possibili azioni pendenti
235 LPC_CAN1->GSR &= ~CAN_GSR_TXERR_Msk; // Azzeriamo gli errori di trasmissione
236 LPC_CAN1->MOD &=~1; //Si riabilita il CAN
237 uint32_t LPC_dummy= LPC_CAN1->ICR;
238 SystemCoreClockUpdate();
239 rx_msg_info.id = ARM_CAN_EXTENDED_ID(indirizzo_CAN_della_scheda); // Viene settato l'indirizzo esteso per il messaggio da ricevere
240 fuffa=1;
241}
242 //! <!-- [fun_PowerControl_wake_up_peripherals] -->
243
244 /*****************************************************************************
245 Funzione che disabilita e spegne il PLL0
246 ******************************************************************************/
247//void PLL0_Stop_Sequence (void)
248//{
249////#if (PLL0_SETUP)
250// LPC_SC->PLL0CON &= ~(1<<1); //Viene disconnesso il PLL principale
251// LPC_SC->PLL0FEED = 0xAA; //Feed
252// LPC_SC->PLL0FEED = 0x55; //Feed
253//
254// while ((LPC_SC->PLL0STAT & (1<<25)) != 0x00); //Si attendi finch\'e il PLL non viene disconnesso
255
256// LPC_SC->PLL0CON &= ~(1<<0); // Viene spento il PLL0
257//
258// LPC_SC->PLL0FEED = 0xAA;
259// LPC_SC->PLL0FEED = 0x55;
260//
261// while ((LPC_SC->PLL0STAT & (1<<24)) != 0x00) {} //Si aspetta il PLL0 per spegnere
262////#endif
263//}
264
265
266/*! \brief Power down managing function
267
268*\param[in,out] no param
269*\return No Parameters, the actual result is sent to the CAN bus output throught \ref tx_data.
270
271*\snippetlineno Power_down.c fun_PowerControl_PowerDown
272*/
273//! <!-- [fun_PowerControl_PowerDown] -->
275{
276 //The CCLKCFG register controls the division of the PLL0 output before it is used by the CPU.
277 //When PLL0 is bypassed, the division may be by 1.
278 //When PLL0 is running, the output must be divide in order to bring the CPU clock frequency (CCLK) within operating limits.
279// int CAN_IER_BUFFER=LPC_CAN1->IER; //Ci ricordiamo delle sorgenti di interrupt perch\'e si perdono e l'inizializzazione non le reassegna
280
281// int CCLKDIV = LPC_SC->CCLKCFG;
282
283// int PLLMULT = LPC_SC->PLL0CFG; //The PLL0CFG register contains PLL0 multiplier and divider value.
284
285#ifdef power_down_conCAN
286 //Questo \'e ilpowerdown con wakeup col CAN: mai che funzioni
287 LPC_CAN1->MOD |=1; //Si annullano tutte le possibili azioni pendenti
288 LPC_CAN1->IER = 1<< 4; // Abilito WUIE: l'interrupt del CAN per il wakeup
289 LPC_CAN1->MOD &=~1; //Si riabilita il CAN
290
291 NVIC_ClearPendingIRQ(CANActivity_IRQn);
292 NVIC_ClearPendingIRQ(CAN_IRQn);
293 #define CAN_PORT 1
294 while ((LPC_SC->CANWAKEFLAGS>>CAN_PORT) & 0x01) //Ci si assicura che non ci siano wakeup in corso e si aspetta che finiscano, eventualmente
295 LPC_SC->CANWAKEFLAGS |= (1<<CAN_PORT); //Ora si resettano le possbili attivit\'a
296 LPC_CAN1->MOD |=(1<<4);
297// LPC_CAN1->IER = 1<< 4; // Abilito WUIE: l'interrupt del CAN per il wakeup
298 NVIC_SetPriority(CANActivity_IRQn,31);
299 NVIC_SetPriority (SysTick_IRQn, 29); /* set Priority for Systick Interrupt */
300 NVIC_EnableIRQ(CANActivity_IRQn); //Abilitiamo il CAN come sorgente di interrupt di risveglio
301#endif
302//! <!-- [code_PowerDown_int_enable] -->
303#ifdef power_down_conEINT3
304//Questo \'e il powerdown con wake col pin EINT3, di Paolo. L'laternativa sempre valida
305
306 // All the RXD pin reconfigurations are implemented as C preprocessor macros
307 status = CANdrv ->PowerControl(ARM_POWER_OFF); //AL risveglio serve per resettare tutti i registri, altrimenti
308 status = CANdrv -> Uninitialize();
309// NVIC_DisableIRQ(CAN_IRQn);
310 PIN_Configure(CAN_RD_PORT, CAN_RD_BIT, PIN_FUNC_0, PIN_PINMODE_TRISTATE, PIN_PINMODE_NORMAL); // Configure pin as GPIO
311 NVIC_DisableIRQ(EINT3_IRQn); // EINT3 could have been enabled somewhere else
312 CAN_INT_F_Enable; // Enable GPIO falling edge interrupt
313 CAN_INT_Clear; // Clear GPIO interrupt
314 NVIC_SetPriority(EINT3_IRQn,31);
315 NVIC_SetPriority (SysTick_IRQn, 29); /* set Priority for Systick Interrupt */
316 NVIC_ClearPendingIRQ(EINT3_IRQn);
317 NVIC_EnableIRQ(EINT3_IRQn);
318 fuffa=0;
319
320//Occorre ricordare che la funzione che viene chiamta dall'interupt \'e
321// EINT3_IRQHandler();
322#endif
323
324 I2CAdrv->PowerControl (ARM_POWER_OFF); // Terminate any pending transfers, reset IRQ/DMA, power off peripheral
325 I2CAdrv->Uninitialize ();
326 I2CBdrv->PowerControl (ARM_POWER_OFF); // Terminate any pending transfers, reset IRQ/DMA, power off peripheral
327 I2CBdrv->Uninitialize ();
328 SPIdrv->PowerControl (ARM_POWER_OFF); // Terminate any pending transfers, reset IRQ/DMA, power off peripheral
329 SPIdrv->Uninitialize ();
330//! <!-- [code_PowerDown_int_enable] -->
331
332//! <!-- [code_PowerDown_clock_disable] -->
333 //The SCR (System Control Register) register controls features of entry to and exit from low power modes
334 //In order to set the Power Down Mode in the PCON register, it's necessary set to 1 the SLEEPDEEP bit in the scr register
335 SCB->SCR |= 4; //(1UL << 2); // Set SLEEPDEEP, il tipo di powerdown
336 LPC_SC->PCON = 0x9; // 1+8: 1=l'esecuzione di WFI o WFE inizia il power down, se SLEEPDEEP=1, 8=il brown-out \'e disabilitato e non consuma potenza
337
338 //If PLL0 (the main pll) is enabled and connected before etering Deep Sleep or
339 //Power-down modes, it will remain enabled and connected afeter the chip enters
340 //Deep Sleep or Power-down mode, causing the power consumption to be higher.
341 //The code below disable and disconnect PLL0 (See Errata sheet Rev. 10.2)
342
343if(mio_PLL0_SETUP){
344 LPC_SC->PLL0CON &= ~(1<<1) ; //Disconnect the main PLL, il PLL0
345
346 //A feed sequence must be written to the PLL0FEED register in order for changes
347 //to the PLL0CON and PLL0CFG registers to take effect.
348 //The feed sequence is:
349 //1) write the value 0xAA to PLL0FEED
350 //2) write the value 0x55 to PLL0FEED
351
352 LPC_SC->PLL0FEED = 0xAA; //Feed
353 LPC_SC->PLL0FEED = 0x55; //Feed
354
355 while ((LPC_SC->PLL0STAT & (1<<25)) != 0x00); //Wait for PLL0 to disconnect
356
357 LPC_SC->PLL0CON &= ~(1<<0); //Turn off PLL0
358
359 LPC_SC->PLL0FEED = 0xAA;
360 LPC_SC->PLL0FEED = 0x55;
361
362 while ((LPC_SC->PLL0STAT & (1<<24)) != 0x00){} //Wait PLL0 to shut down
363 }
364//! <!-- [code_PowerDown_clock_disable] -->
365
366 // Execution of the WFI instruction will cause immediate entry to any of the four reduced
367 // power modes based on the SLEEPDEEP bit and PCON Register settings.
368 //SysTick->CTRL &= ~1; //Spegnamo il systick counter
369//! <!-- [code_PowerDown_sleep_set] -->
370 if( ( CoreDebug ->DHCSR & 1 )==0 ){ // questo per non fare pasticci se c'e' connesso il debugger
371 __WFI(); //Sonno... (WFI sta per Wait For Interrupt)
372 }else{
373// CANActivity_IRQHandler_mio();
374// while(riaccendi_tutto==0);
375// CANActivity_IRQHandler(); //Al risveglio del CAN viene chiamata questa funzione registrata
376 while(fuffa==0){
377 __NOP();
378 }
379 }
380//! <!-- [code_PowerDown_sleep_set] -->
381
382// LPC_CAN1->IER=CAN_IER_BUFFER;//Ristabiliamo tutte le sorgenti di interruzione del CAN
383}
384//! <!-- [fun_PowerControl_PowerDown] -->
385
386
387/*! \brief CAN pins restoring
388
389*\param[in,out] no param
390*\return No Parameters, the actual result is sent to the CAN bus output throught \ref tx_data.
391
392*\snippetlineno Power_down.c fun_PowerControl_CAN_restoring
393*/
394//! <!-- [fun_PowerControl_CAN_restoring] -->
395void WakeResetCAN (void)
396{
397 CAN_INT_F_Disable;
398 CAN_INT_Clear;
399 NVIC_ClearPendingIRQ(EINT3_IRQn);
400 NVIC_DisableIRQ(EINT3_IRQn);
401 PIN_Configure(CAN_RD_PORT, CAN_RD_BIT, CAN_RD_FUNC, PIN_PINMODE_TRISTATE, PIN_PINMODE_NORMAL);
402
403}
404//! <!-- [fun_PowerControl_CAN_restoring] -->
405
406
407//void EXTI_ClearEXTIFlag(EXTI_LINE_ENUM EXTILine)
408//{
409// LPC_SC->EXTINT |= (1 << EXTILine);
410//}
411
412/*! \brief Wake-up managing function
413
414*\param[in,out] no param
415*\return No Parameters, the actual result is sent to the CAN bus output throught \ref tx_data.
416
417*\snippetlineno Power_down.c fun_PowerControl_wake_up
418*/
419//! <!-- [fun_PowerControl_wake_up] -->
421{
422#define risveglio_di_Paolo
423#define risveglio_di_gianluigi
424#ifdef risveglio_di_Paolo
425 WakeResetCAN(); //Il pin ritorna ad essere CAN
426#endif
427#ifdef risveglio_di_gianluigi
429#endif
431}
432//! <!-- [fun_PowerControl_wake_up] -->
433
434//void EXTI_SetMode(EXTI_LINE_ENUM EXTILine, EXTI_MODE_ENUM mode)
435//{
436// if (mode == EXTI_MODE_EDGE_SENSITIVE)
437// {
438// LPC_SC->EXTMODE |= (1 << EXTILine);
439// }
440// else if (mode == EXTI_MODE_LEVEL_SENSITIVE)
441// {
442// LPC_SC->EXTMODE &= ~(1 << EXTILine);
443// }
444//}
445
446/*********************************************************************/
447//void EXTI_SetPolarity(EXTI_LINE_ENUM EXTILine, EXTI_POLARITY_ENUM polarity)
448//{
449// if (polarity == EXTI_POLARITY_HIGH_ACTIVE_OR_RISING_EDGE)
450// {
451// LPC_SC->EXTPOLAR |= (1 << EXTILine);
452// }
453// else if (polarity == EXTI_POLARITY_LOW_ACTIVE_OR_FALLING_EDGE)
454// {
455// LPC_SC->EXTPOLAR &= ~(1 << EXTILine);
456// }
457//}
458
459//void EXTI_SetPin (EXTI_LINE_ENUM EXTILine)
460//{
461// LPC_PINCON->PINSEL4 &=~ (0x3 << (20 + EXTILine*2));
462// LPC_PINCON->PINSEL4 |= (0x1 << (20 + EXTILine*2));
463// LPC_PINCON->PINMODE4 &=~ (0x3 << (20 + EXTILine*2));
464//}
465
466//void EXTI_Config(EXTI_InitTypeDef *EXTICfg)
467//{
468// //LPC_SC->EXTINT = 0x0;
469// EXTI_SetMode(EXTICfg->EXTI_Line, EXTICfg->EXTI_Mode);
470// EXTI_SetPolarity(EXTICfg->EXTI_Line, EXTICfg->EXTI_Polarity);
471// EXTI_SetPin(EXTICfg->EXTI_Line);
472//}
473
474//void Pwd_Paolo (void) {
475//
476// //EXTI_InitTypeDef EXTI_InitStruct;
477//
478// //EXTI_InitStruct.EXTI_Line = EXTI_EINT3;
479// //EXTI_InitStruct.EXTI_Mode = EXTI_MODE_EDGE_SENSITIVE;
480// //EXTI_InitStruct.EXTI_Polarity = EXTI_POLARITY_LOW_ACTIVE_OR_FALLING_EDGE;
481
482// //EXTI_Config(&EXTI_InitStruct); // Init EINT3
483// SCB->SCR |= 4; //(1UL << 2); // Set SLEEPDEEP
484// LPC_SC->PCON = 0x9; // Set powerdown mode
485
486//
487//
488// LPC_CAN->MOD |= 0x01; // Switch off can
489//// LPC_CAN1->IER =0;
490//
491// // All the RXD pin reconfigurations are implemented as C preprocessor macros
492// PIN_Configure(CAN_RD_PORT, CAN_RD_BIT, PIN_FUNC_0, PIN_PINMODE_TRISTATE, PIN_PINMODE_NORMAL); // Configure pin as GPIO
493// NVIC_DisableIRQ(EINT3_IRQn); // EINT3 could have been enabled somewhere else
494// CAN_INT_F_Enable; // Enable GPIO falling edge interrupt
495// CAN_INT_Clear; // Clear GPIO interrupt
496//
497// // Clear and (re-)enable GPIO interrupt
498//
499//// NVIC_DisableIRQ(EINT0_IRQn); // Disable EINT0 interrupt avoiding unintentional wakeup
500//// NVIC_DisableIRQ(EINT2_IRQn); // Disable EINT2 interrupt avoiding unintentional wakeup
501//// NVIC_DisableIRQ(EINT3_IRQn); // Disable EINT3 interrupt avoiding unintentional wakeup
502//// NVIC_DisableIRQ(SPI_IRQn); // Disable UART0 interrupt avoiding unintentional wakeup
503//// NVIC_DisableIRQ(I2C0_IRQn); // Disable I2C0 interrupt
504//// NVIC_DisableIRQ(I2C1_IRQn); // Disable I2C1 interrupt
505//// NVIC_DisableIRQ(I2C2_IRQn); // Disable I2C2 interrupt
506//// NVIC_DisableIRQ(CAN_IRQn); // Disable CAN interrupt
507
508//
509//
510// NVIC_ClearPendingIRQ(EINT3_IRQn);
511// NVIC_EnableIRQ(EINT3_IRQn);
512//
513//
514//
515// // If PLL0 (the main pll) is enabled and connected before etering Deep Sleep or
516// // Powerdown modes, it will remain enabled and connected after the chip enters
517// // Deep Sleep or Powerdown mode, causing the power consumption to be higher.
518// // The code below disable and disconnect PLL0 (See Errata sheet Rev. 10.2)
519// PLL0_Stop_Sequence();
520//
521// // These instructions were suggested by Lorenzo but it seems that it works also
522// // without them at 100 kbit (1 Mbit might cause problems)
523//// LPC_SC->PCLKSEL0 |= (0x54000000); // Sets peripheral divider to 1 for CAN1, CAN2 and CAN_Filters
524//// LPC_SC->CCLKCFG &= ~(0xFF); // Sets clock divider to 1
525// // PLL0_Start_Sequence (after power-down) sets the values back to normal
526// // Set LEDs to powerdown mode (green LED)
527// if ((CoreDebug->DHCSR & 1) == 0) { // Check C_DEBUGEN
528// // Debugger disconnected, enter powerdown
529// __WFE(); // Enter powerdown mode
530//
531// } else{ // Reset LEDs to active mode (red LED)
532// EINT3_IRQHandler();
533// }
534
535//// EINT3_IRQHandler();
536// // PLL0 re-initialization. This function uses the options set in system_LPC17xx.c Configuration Wizard
537//// NVIC_DisableIRQ(EINT3_IRQn);
538//// CAN_Inizialize();
539// System_init();
540// LPC_SC->PCON &=~ 0x01; // Reset powerdown mode to idle mode
541// SCB->SCR &=~ (1UL << 2); // Reset SLEEPDEEP
542// CAN_Inizialize(); // Viene inizializzata la periferica CAN
543// rx_msg_info.id = ARM_CAN_EXTENDED_ID(indirizzo_CAN_della_scheda);
544//// NVIC_EnableIRQ(CAN_IRQn);
545//// SPI_Inizialize(); // Viene inizializzata la periferica SPI
546//// I2C_1_Initialize(); // Viene inizializzata la periferica I2C_A
547//// I2C_0_Initialize(); // Viene inizializzata la periferica I2C_B
548//// I2C_termometro_Initialize(); // Viene inizializzata la periferica I2C_termometro_Inizialize
549
550//}
551
552
uint32_t tx_obj_idx
This is the variable which resembles the flags from the communication.
Definition: Can.c:323
unsigned int indirizzo_CAN_della_scheda
Per ora lo assegnamo cos\i l'indirizzo della scheda.
Definition: Can.c:335
void CAN_Inizialize(void)
The CAN initialization function.
Definition: Can.c:433
ARM_DRIVER_CAN * CANdrv
Definition: Can.c:333
void I2C_0_Initialize(void)
The I2C_0 initialize.
Definition: I2C_0.c:369
void I2C_1_Initialize(void)
The I2C_1 initialize.
Definition: I2C_1.c:106
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
#define LED_RED
Definition: Led.h:10
#define accendi
Definition: Led.h:12
volatile uint32_t POWER_DOWN_MAX_ATTESA
upper limit for POWER_DOWN_TEMPO_ATTESA
Definition: Power_down.c:118
void EINT3_IRQHandler(void)
Wake-up managing function.
Definition: Power_down.c:420
void CANActivity_IRQHandler_mio(void)
Peripherals Wake-up.
Definition: Power_down.c:210
volatile uint32_t POWER_DOWN_ABILITA_CONTEGGIO
Power down couter and anable is set if this variable is true.
Definition: Power_down.c:120
void WakeResetCAN(void)
CAN pins restoring.
Definition: Power_down.c:395
void PowerControl_PowerDown(void)
Power down managing function.
Definition: Power_down.c:274
volatile uint32_t POWER_DOWN_TEMPO_ATTESA
Counter to wait for power down, multiple of 10 ms.
Definition: Power_down.c:116
void SPI_Inizialize(void)
SPI is initialized here. Its ise t at 8 bits and 100 KHz, as default.
Definition: Spi.c:205