CROSS Technical Documentation User Manual and Technical Doc.
INFN Milano Bicocca
Loading...
Searching...
No Matches

◆ PowerControl_PowerDown()

void PowerControl_PowerDown ( void  )

Power down managing function.

Parameters
[in,out]noparam
Returns
No Parameters, the actual result is sent to the CAN bus output throught tx_data.
274void PowerControl_PowerDown(void)
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}
ARM_DRIVER_CAN * CANdrv
Definition: Can.c:333
void PowerControl_PowerDown(void)
Power down managing function.
Definition: Power_down.c:274

Definition at line 274 of file Power_down.c.