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

📄 util.c

📁 FreeRTOS is a portable, open source, mini Real Time Kernel - a free to download and royalty free RTO
💻 C
📖 第 1 页 / 共 2 页
字号:
*  @param [in]   digit  The number of digits in the output string.
*  @param [in]   fillwithzero  \li 0   fill with blanks.
*                              \li 1   fill with zeros.
*
**/
/******************************************************************************/
void UTIL_int2str( char* ptr, s32 X, u16 digit, int fillwithzero )
   {
   _int2str( ptr, X, digit, 0, fillwithzero);
   }

/*******************************************************************************
*
*                                UTIL_SetPll
*
*******************************************************************************/
/**
*
*  Set clock frequency (lower to save energy)
*
*  @param [in]   speed  New clock speed from very low to very fast.
*
**/
/******************************************************************************/
void UTIL_SetPll( enum eSpeed speed )
   {
   /* Select PLL as system clock source */
   RCC_SYSCLKConfig( RCC_SYSCLKSource_HSI );

   /* Enable PLL */
   RCC_PLLCmd( DISABLE );

   if( ( speed < SPEED_VERY_LOW ) || ( speed > SPEED_VERY_HIGH ) )
      {
      speed = SPEED_MEDIUM;
      } 

   CurrentSpeed = speed; 

   switch( speed )
      {
      // 18 MHz
      case SPEED_VERY_LOW  :
         /* PLLCLK = 6MHz * 3 = 18 MHz */
         RCC_PLLConfig( RCC_PLLSource_HSE_Div2, RCC_PLLMul_3 );
         break;

      // 24MHz
      case SPEED_LOW       :
         /* PLLCLK = 12MHz * 2 = 24 MHz */
         RCC_PLLConfig( RCC_PLLSource_HSE_Div1, RCC_PLLMul_2 );
         break;

      // 36MHz
      case SPEED_MEDIUM    :   
      default              :
         /* PLLCLK = 12MHz * 3 = 36 MHz */
         RCC_PLLConfig( RCC_PLLSource_HSE_Div1, RCC_PLLMul_3 );
         break;

      // 48MHz
      case SPEED_HIGH      :
         /* PLLCLK = 12MHz * 4 = 48 MHz */
         RCC_PLLConfig( RCC_PLLSource_HSE_Div1, RCC_PLLMul_4 );
         break;

      // 72MHz
      case SPEED_VERY_HIGH :
         /* PLLCLK = 12MHz * 6 = 72 MHz */
         RCC_PLLConfig( RCC_PLLSource_HSE_Div1, RCC_PLLMul_6 );
         break;
      }

   /* Enable PLL */
   RCC_PLLCmd( ENABLE );

   /* Wait till PLL is ready */
   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 )
      { ; }

   /* This function fills a RCC_ClocksTypeDef structure with the current frequencies
     of different on chip clocks (for debug purpose) */
   RCC_GetClocksFreq( &RCC_ClockFreq );
   }

/*******************************************************************************
*
*                                UTIL_GetPll
*
*******************************************************************************/
/**
*
*  Get clock frequency
*
*  @return   Current clock speed from very low to very fast.
*
**/
/******************************************************************************/
enum eSpeed UTIL_GetPll( void )
   {
   return CurrentSpeed;
   }

/*******************************************************************************
*
*                                UTIL_GetVersion
*
*******************************************************************************/
/**
*
*  Get CircleOS version.
*
*  @return  A pointer to a string containing the CircleOS version.
*
**/
/******************************************************************************/
const char* UTIL_GetVersion( void )
   {
   return OsVersion;
   }

/*******************************************************************************
*
*                                UTIL_ReadBackupRegister
*
*******************************************************************************/
/**
*
*  Reads data from the specified Data Backup Register.
*
*  @param[in]  BKP_DR   Specifies the Data Backup Register. This parameter can be BKP_DRx where x:[1, 10]
*
*  @return  The content of the specified Data Backup Register.
*
**/
/******************************************************************************/
u16 UTIL_ReadBackupRegister( u16 BKP_DR )
   {
  return (*(vu16 *)( BKP_BASE + 4 * BKP_DR ) );
   }

/*******************************************************************************
*
*                                UTIL_WriteBackupRegister
*
*******************************************************************************/
/**
*
*  Writes data to the specified Data Backup Register.
*
*  @param[in]  BKP_DR   Specifies the Data Backup Register. This parameter can be BKP_DRx where x:[1, 10]
*  @param[in]  Data     The data to write.
*
**/
/********************************************************************************/
void UTIL_WriteBackupRegister( u16 BKP_DR, u16 Data )
   {
  *(vu16 *)( BKP_BASE + 4 * BKP_DR ) = Data;
   }


/*******************************************************************************
*
*                                UTIL_SetIrqHandler
*
*******************************************************************************/
/**
*
*  Redirect an IRQ handler.
*
*  @param[in]  Offs   Address in the NVIC table
*  @param[in]  pHDL   Pointer to the handler.
*
**/
/********************************************************************************/
void UTIL_SetIrqHandler( int Offs, tHandler pHDL )
   {
   if ( (Offs >= 8) && (Offs<0x100) )
      *(tHandler *)( CIRCLEOS_RAM_BASE + Offs ) = pHDL;
   }

/*******************************************************************************
*
*                                UTIL_GetIrqHandler
*
*******************************************************************************/
/**
*
*  Get the current IRQ handler.
*  Since (V1.6) the vector table is relocated in RAM, the vectors can be easily modified
*  by the applications. 
*
*  @param[in]  Offs   Address in the NVIC table
*  @return  A pointer to the current handler.
*
**/
/********************************************************************************/
tHandler UTIL_GetIrqHandler( int Offs )
   {
   if ( (Offs >= 8) && (Offs<0x100) )
      return *(tHandler *)( CIRCLEOS_RAM_BASE + Offs );
   }



/*******************************************************************************
*
*                                UTIL_SetSchHandler
*
*******************************************************************************/
/**
*
*  Redirect a SCHEDULER handler.
*  Set the current SCHEDULER handler. With UTIL_GetSchHandler(), these functions 
*  allow to take the control of the different handler. You can: 
*        - replace them (get-Set)by your own handler
*        - disable a handler: UTIL_SetSchHandler(Ix,0);  
*        - create a new handler (using the unused handlers).
*  See scheduler.c to understand further...
*
*  @param[in]  Ix   ID if the SCH Handler
*  @param[in]  pHDL   Pointer to the handler.
*
**/
/********************************************************************************/
void UTIL_SetSchHandler( enum eSchHandler Ix, tHandler pHDL )
   {
   if (Ix<SCH_HDL_MAX)
      SchHandler[Ix] = pHDL;
   }

/*******************************************************************************
*
*                                UTIL_GetSchHandler
*
*******************************************************************************/
/**
*
*  Get the current SCHEDULER handler. With UTIL_SetSchHandler(), these functions 
*  allow to take the control of the different handler. You can: 
*        - replace them (get-Set)by your own handler
*        - disable a handler: UTIL_SetSchHandler(Ix,0);  
*        - create a new handler (using the unused handlers).
*  See scheduler.c to understand further...
*
*  @param[in]  Ix   ID is the SCH Handler
*  @return  A pointer to the current handler.
*
**/
/********************************************************************************/
tHandler UTIL_GetSchHandler( enum eSchHandler Ix )
   {
   if ( Ix<SCH_HDL_MAX ) 
      return SchHandler [Ix] ; 
   }

⌨️ 快捷键说明

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