• Main Page
  • Related Pages
  • Data Structures
  • Files
  • File List
  • Globals

power_spe.c

Go to the documentation of this file.
00001 /****************** COPYRIGHT (C) 2007-2010 RAISONANCE S.A.S. *****************/
00011 /******************************************************************************/
00012 
00013 /* Includes ------------------------------------------------------------------*/
00014 #include "circle.h"
00015 
00017 
00018 /*******************************************************************************
00019 *
00020 *                                POWER_Init
00021 *
00022 *******************************************************************************/
00030 /******************************************************************************/
00031 void POWER_Init( void )
00032 {
00033     GPIO_InitTypeDef GPIO_InitStructure;
00034 
00035     /* Enable Status GPIO clock */
00036     RCC_PERIPH_GPIO_CLOCK_CMD( GPIO_PWR_PERIPH_STAT, ENABLE );
00037 
00038     /* Configure status pins as floating input */
00039     GPIO_InitStructure.GPIO_Mode  = GPIO_Mode_IN_FLOATING;
00040     GPIO_InitStructure.GPIO_Speed = GPIO_Speed_50MHz;
00041     GPIO_InitStructure.GPIO_Pin   = GPIO_PWR_LOADING_PIN | GPIO_PWR_DONE_PIN;
00042     GPIO_Init( GPIOx_PWR_STAT, &GPIO_InitStructure );
00043 
00044     POWER_Set_Time();
00045 }
00046 
00048 
00049 /*******************************************************************************
00050 *
00051 *                                SHUTDOWN_Action
00052 *
00053 *******************************************************************************/
00060 /******************************************************************************/
00061 void SHUTDOWN_Action( void )
00062 {
00063     //-- Backup system values --
00064 
00065     // CPU frequency
00066     u16 baksys2 = UTIL_GetPll() & BKPMASK_S2_PLL;              // 3 bits
00067     u16 baksys7 = UTIL_ReadBackupRegister( BKP_SYS7 );
00068 
00069     // Option autorun
00070     baksys2 |= ( AutorunOn ? ( BKPMASK_S2_AUTORUN ) : 0 );
00071 
00072     // Option loudspeaker
00073     baksys2 |= ( AUDIO_SpeakerOn ? BKPMASK_S2_SPEAKER : 0 );
00074 
00075     // Is it currently mute?
00076     baksys2 |= ( AUDIO_Mute ? BKPMASK_S2_MUTE : 0 );
00077 
00078     // Volume
00079     baksys2 |= ( AUDIO_Volume << 8 ) & BKPMASK_S2_VOLUME;
00080 
00081     // Option buzzer
00082     baksys2 |= ( AUDIO_BuzzerOn ? ( BKPMASK_S2_BUZZER ) : 0 );
00083 
00084     // Option joystick
00085     baksys2 |= ( JoystickAsInput ? BKPMASK_S2_JOYSTICK : 0 ); 
00086 
00087     // Option Mems
00088     baksys2 |= ( MemsAsInput ? BKPMASK_S2_MEMS : 0 ); 
00089 
00090     //Option Touchscreen
00091     baksys7 &= ~BKPMASK_S7_TCHSCR;
00092     baksys7 |= ( TchscrAsInput ? ( BKPMASK_S7_TCHSCR ) : 0 );      
00093 
00094     UTIL_WriteBackupRegister( BKP_SYS2, baksys2 );
00095     UTIL_WriteBackupRegister( BKP_SYS7, baksys7 );
00096 
00097     // Backlight
00098     UTIL_WriteBackupRegister( BKP_BKLIGHT, LCD_GetBackLight() );
00099 
00100     // Font menus
00101     UTIL_WriteBackupRegister( BKP_SYS4, Menu_Font );
00102 
00103     //-- Stops peripherals --
00104 
00105     // Disable TIM2 Update interrupt (mems)
00106     TIM_ITConfig( TIM2, TIM_IT_Update, DISABLE );
00107 
00108     // Stop the audio codec
00109     AUDIO_Shutdown();
00110 
00111     //-- Power Off --
00112     
00113     /* Enable Shutdown GPIO clock */
00114     RCC_PERIPH_GPIO_CLOCK_CMD( GPIO_PWR_PERIPH, ENABLE );
00115     
00116     /* Configure pin shutdown as Push-Pull output  */
00117     GPIO_InitTypeDef GPIO_InitStructure;
00118     GPIO_InitStructure.GPIO_Pin   = GPIO_PWR_SHUTDOWN_PIN;
00119     GPIO_InitStructure.GPIO_Speed = GPIO_Speed_50MHz;
00120     GPIO_InitStructure.GPIO_Mode  = GPIO_Mode_Out_PP;
00121     GPIO_Init( GPIOx_PWR, &GPIO_InitStructure );
00122 
00123     GPIO_WriteBit( GPIOx_PWR, GPIO_PWR_SHUTDOWN_PIN, SET );
00124 
00125     // Wait for the end
00126     while ( 1 ) {;}
00127 }