⭐ 欢迎来到虫虫下载站! | 📦 资源下载 📁 资源专辑 ℹ️ 关于我们
⭐ 虫虫下载站

📄 power_main.c

📁 用 Hitex 工具软件开发 stm32 的例子
💻 C
📖 第 1 页 / 共 2 页
字号:
/********************************************************************
 * Project:    Tasking-STM32-Stick
 * File:       power_main.c
 *
 * System:     Cortex ARMv7 32 Bit (STM32FRT)
 * Compiler:   Tasking Altuim VX Toolchain v2.01
 *
 * Date:       2007-08-20
 * Author:     Application@Hitex.de
 *
 * Rights:     Hitex Development Tools GmbH
 *             Greschbachstr. 12
 *             D-76229 Karlsruhe
 ********************************************************************
 * Description:
 *
 * This file is part of the Tasking Example chain
 * The code is based on usage of the STmicro library functions
 * This is a small implementation of different features
 * The application runs in ARM mode with high optimization level.
 *
 ********************************************************************
 * History:
 *
 *    Revision 1.0    2007/08/20      Gn
 *    Initial revision
 ********************************************************************
 * This is a preliminary version.
 *
 * WARRANTY:  HITEX warrants that the media on which the SOFTWARE is
 * furnished is free from defects in materials and workmanship under
 * normal use and service for a period of ninety (90) days. HITEX entire
 * liability and your exclusive remedy shall be the replacement of the
 * SOFTWARE if the media is defective. This Warranty is void if failure
 * of the media resulted from unauthorized modification, accident, abuse,
 * or misapplication.
 *
 * DISCLAIMER:  OTHER THAN THE ABOVE WARRANTY, THE SOFTWARE IS FURNISHED
 * "AS IS" WITHOUT WARRANTY OF ANY KIND. HITEX DISCLAIMS ALL OTHER WARRANTIES,
 * EITHER EXPRESS OR IMPLIED, INCLUDING BUT NOT LIMITED TO IMPLIED WARRANTIES
 * OF MERCHANTABILITY AND FITNESS FOR A PARTICULAR PURPOSE.
 *
 * NEITHER HITEX NOR ITS AFFILIATES SHALL BE LIABLE FOR ANY DAMAGES ARISING
 * OUT OF THE USE OF OR INABILITY TO USE THE SOFTWARE, INCLUDING DAMAGES FOR
 * LOSS OF PROFITS, BUSINESS INTERRUPTION, OR ANY SPECIAL, INCIDENTAL, INDIRECT
 * OR CONSEQUENTIAL DAMAGES EVEN IF HITEX HAS BEEN ADVISED OF THE POSSIBILITY
 * OF SUCH DAMAGES.
 ********************************************************************/

#include "system.h"
#include "power_main.h"
#include "systick.h"
#include "hardware.h"

// Define NULL
#ifndef NULL
#define NULL (void *)0
#endif

#define PwrReg0 6
#define PwrReg1 ((0x0A<<2) + 1)
#define PwrReg2 ((4<<3) + 8 + 2)
#define PwrReg3 (2<<4)

TaskInfo PwrState;
TaskInfo LEDBlinkState = {TRUE, FALSE};
u8 PowerModes[2] = {0x01,0x01};
u8 GatingSet[6] = {0x11,0xFF,0x12,0x84,0x08,0x02};
u8 PLLSet[5] = {0x06,0x7D,0x04,0x0A,0x20};
u8 RegSet[5] = {0x06,0x7D,0x04,0x0A,0x20};
u8 RTCVal[4] = {0x01,0x36,0x69,0xA0};
u8 RTCAlarm[4] ={0,0,0,0};
u8 CPU_Clock_Selected = 0;
u16 LatencyMeasured = 0;


void All_PeriphClock_Disable(void)
{
   RCC_APB1PeriphClockCmd(RCC_APB1Periph_ALL, DISABLE);
   RCC_APB2PeriphClockCmd(RCC_APB2Periph_ALL, DISABLE);
}

void All_PeriphClock_Ensable(void)
{
   RCC_APB1PeriphClockCmd(RCC_APB1Periph_ALL, ENABLE);
   RCC_APB2PeriphClockCmd(RCC_APB2Periph_ALL, ENABLE);
}
void GPIO_Config_ALL_AIN(void)
{
   GPIO_InitTypeDef GPIO_InitStructure;

   /* Enable GPIOD and GPIOE clock */
   RCC_APB2PeriphClockCmd(RCC_APB2Periph_GPIOA | RCC_APB2Periph_GPIOB 
                        | RCC_APB2Periph_GPIOC | RCC_APB2Periph_GPIOD 
                        | RCC_APB2Periph_GPIOE | RCC_APB2Periph_AFIO, ENABLE);
  
  
   /* Disable the Serial Wire Jtag Debug Port SWJ-DP */
   GPIO_PinRemapConfig(GPIO_Remap_SWJ_Disable, ENABLE); 
  
   /* PA  */
   GPIO_InitStructure.GPIO_Pin = GPIO_Pin_All;
   GPIO_InitStructure.GPIO_Mode = GPIO_Mode_AIN;
   GPIO_Init(GPIOA, &GPIO_InitStructure);
   /* PB  */
   GPIO_InitStructure.GPIO_Pin = GPIO_Pin_All;
   GPIO_InitStructure.GPIO_Mode = GPIO_Mode_AIN;
   GPIO_Init(GPIOB, &GPIO_InitStructure);
   /* PC  */
   GPIO_InitStructure.GPIO_Pin = GPIO_Pin_All;
   GPIO_InitStructure.GPIO_Mode = GPIO_Mode_AIN;
   GPIO_Init(GPIOC, &GPIO_InitStructure);
   /* PD  */
   GPIO_InitStructure.GPIO_Pin = GPIO_Pin_All;
   GPIO_InitStructure.GPIO_Mode = GPIO_Mode_AIN;
   GPIO_Init(GPIOD, &GPIO_InitStructure);
}
/*-----------------------------------------------------------------------------------
* Function Name  : GetPeripheralGating
* Description    : Get the current Clock Gating selection
* Input          : None
* Output         : None
* Return         : None
-----------------------------------------------------------------------------------*/
void GetPeripheralGating(void)
{
   vu32 APB2_Temp = 0, APB1_Temp = 0;
   /* Save the register */
   APB2_Temp = RCC->APB2ENR;
   GatingSet[0] = (u8)(APB2_Temp>>8);
   GatingSet[1] = (u8)APB2_Temp;
   /* Save the register */
   APB1_Temp = RCC->APB1ENR;
   GatingSet[2] = (u8)(APB1_Temp>>24);
   GatingSet[3] = (u8)(APB1_Temp>>16);
   GatingSet[4] = (u8)(APB1_Temp>>8);
   GatingSet[5] = (u8)APB1_Temp;
}
/*-----------------------------------------------------------------------------------
* Function Name  : SetPeripheralGating
* Description    : Set the decided Clock Gating selection
* Input          : None
* Output         : None
* Return         : None
-----------------------------------------------------------------------------------*/
void SetPeripheralGating(void)
{
   vu32 APB2_Temp = 0, APB1_Temp = 0;
   /* build register word */
   APB2_Temp = (u32)((GatingSet[0]<<8)+GatingSet[1]);
   /* Mask the allowed changes */
   APB2_Temp |= RCC_APB2ENR_Must;
   /* set APB2 Peripheral Clock */
   RCC->APB2ENR = APB2_Temp;
   /* build register word */
   APB1_Temp = (u32)((GatingSet[2]<<24)+(GatingSet[3]<<16)+(GatingSet[4]<<8)+GatingSet[5]);
   /* Mask the allowed changes */
   APB1_Temp |= RCC_APB1ENR_Must;
   /* Disable APB1 Peripheral Clock */
   RCC->APB1ENR = APB1_Temp;
}
/*-----------------------------------------------------------------------------------
* Function Name  : SetPLLSettings
* Description    : adjust the PLL and clock to the GUI commands
* Input          : None
* Output         : None
* Return         : None
-----------------------------------------------------------------------------------*/
void SetPLLSettings(void)
{
   u32 tmpreg = 0;
   if ((PLLSet[1] != RegSet[1])||(PLLSet[3] != RegSet[3]))
   {
      /* disable UART receive interrupt */
      USART_ITConfig(USART3, (USART_IT_RXNE),DISABLE);
      /* clear pending bits */
      USART_ClearITPendingBit(USART3,USART_IT_RXNE);

      RegSet[0] = PLLSet[0];
      if (PLLSet[1] == 0x79) PLLSet[1] = 0x39; // correct the USB divider
      RegSet[1] = PLLSet[1];
      RegSet[2] = PLLSet[2];
      RegSet[3] = PLLSet[3];
      RegSet[4] = PLLSet[4];

      tmpreg = PLLSet[3] | (u32)PLLSet[2]<<8 | (u32)PLLSet[1]<<16;

      /* Select HSE as system clock source */
      RCC_SYSCLKConfig(RCC_SYSCLKSource_HSE);

      RCC_PLLCmd(DISABLE);

      /* Store the new value */
      RCC->CFGR = tmpreg;

      RCC_PLLCmd(ENABLE);

      while(RCC_GetFlagStatus(RCC_FLAG_PLLRDY) == RESET);
      /* Select PLL as system clock source */
      RCC_SYSCLKConfig(RCC_SYSCLKSource_PLLCLK);

      /* Wait till PLL is used as system clock source */
      while(RCC_GetSYSCLKSource() != 0x08);
      /* reinit RS232 USRART3 */
      USART_Configuration();
      /* clear pending bits */
      USART_ClearITPendingBit(USART3,USART_IT_RXNE);
      /* enable UART receive interrupt */
      USART_ITConfig(USART3, (USART_IT_RXNE), ENABLE);
   }
}
/*-----------------------------------------------------------------------------------
* Function Name  : Enable_Exti
* Description    : Enable the external interrupts
* Input          : None
* Output         : None
* Return         : None
-----------------------------------------------------------------------------------*/
void Enable_Exti(void)
{
   EXTI_ClearITPendingBit(EXTI_Line2);
   EXTI_InitStructure.EXTI_Line = EXTI_Line2;
//   EXTI_InitStructure.EXTI_Mode = EXTI_Mode_Event;
   EXTI_InitStructure.EXTI_Mode = EXTI_Mode_Interrupt;
   EXTI_InitStructure.EXTI_Trigger = EXTI_Trigger_Rising;
   EXTI_InitStructure.EXTI_LineCmd = ENABLE;
   EXTI_Init(&EXTI_InitStructure);
}

⌨️ 快捷键说明

复制代码 Ctrl + C
搜索代码 Ctrl + F
全屏模式 F11
切换主题 Ctrl + Shift + D
显示快捷键 ?
增大字号 Ctrl + =
减小字号 Ctrl + -