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

📄 hw_config.c

📁 STR912 arm9实现的以太网通信程序
💻 C
字号:
/******************** (C) COPYRIGHT 2007 STMicroelectronics ********************
* File Name          : hw_config.c
* Author             : MCD Application Team
* Version            : V2.0
* Date               : 12/07/2007
* Description        : ENET Hardware Configuration & Setup
********************************************************************************
* THE PRESENT SOFTWARE WHICH IS FOR GUIDANCE ONLY AIMS AT PROVIDING CUSTOMERS
* WITH CODING INFORMATION REGARDING THEIR PRODUCTS IN ORDER FOR THEM TO SAVE TIME.
* AS A RESULT, STMICROELECTRONICS SHALL NOT BE HELD LIABLE FOR ANY DIRECT,
* INDIRECT OR CONSEQUENTIAL DAMAGES WITH RESPECT TO ANY CLAIMS ARISING FROM THE
* CONTENT OF SUCH SOFTWARE AND/OR THE USE MADE BY CUSTOMERS OF THE CODING
* INFORMATION CONTAINED HEREIN IN CONNECTION WITH THEIR PRODUCTS.
*******************************************************************************/

/* Includes ------------------------------------------------------------------*/
#include "91x_lib.h"
#include "91x_enet.h"
#include"hw_config.h"

/* Private typedef -----------------------------------------------------------*/
/* Private define ------------------------------------------------------------*/
/* Private macro -------------------------------------------------------------*/
/* Private variables ---------------------------------------------------------*/
/* External variables --------------------------------------------------------*/
/* Private function prototypes -----------------------------------------------*/
static void MCLK_Config (void);
static void ENET_InitClocksGPIO(void);
static void T0_Init(void);
/* Extern function prototypes ------------------------------------------------*/
/* Private functions ---------------------------------------------------------*/

/*******************************************************************************
* Function Name  : Set_System
* Description    : Set System clock.
* Input          : None.
* Return         : None.
*******************************************************************************/
void Set_System(void)
{

  ENET_MACConfig MAC_Config;
  
  /*CPU running @96MHZ*/
  MCLK_Config();

  T0_Init();
  /* Configure Clock and all GPIO */  
  ENET_InitClocksGPIO();  
  GPIO_WriteBit(GPIO6,GPIO_Pin_4,Bit_RESET);
  /* Initialize MAC control structure  with common values */
  MAC_Config.ReceiveALL = DISABLE;
  if (SCU_GetHCLKFreqValue() > 50000)
  MAC_Config.MIIPrescaler = MIIPrescaler_2;
  MAC_Config.LoopbackMode = DISABLE;
  MAC_Config.AddressFilteringMode = MAC_Perfect_Multicast_Perfect;
  MAC_Config.VLANFilteringMode = VLANfilter_VLTAG;
  MAC_Config.PassWrongFrame = DISABLE;
  MAC_Config.LateCollision = ENABLE;
  MAC_Config.BroadcastFrameReception = ENABLE;
  MAC_Config.PacketRetry = ENABLE;
  MAC_Config.RxFrameFiltering = ENABLE;
  MAC_Config.AutomaticPadRemoval = ENABLE;
  MAC_Config.DeferralCheck = ENABLE;
  
  /* ENET MAC&DMA and PHY device initializations */
  ENET_Init(&MAC_Config);                     
  
  /* Set the ENET Operating Mode */
  ENET_SetOperatingMode(FULLDUPLEX_100M);    
 
  /* Start Receive & Transmit */
   //ENET_PHYReset(PHY_ADDRESS); 
   ENET_Start();

 
}
/*******************************************************************************
* Function Name  : MCLK_Config
* Description    : Configures PLL @96MHZ.
* Input          : None
* Output         : None
* Return         : None
*******************************************************************************/
void MCLK_Config (void)

{
  FMI_Config(FMI_READ_WAIT_STATE_2, FMI_WRITE_WAIT_STATE_0, FMI_PWD_ENABLE, \
             FMI_LVD_ENABLE, FMI_FREQ_HIGH); /* FMI Wait States */

  SCU_PLLFactorsConfig(96, 25, 2); /* Configure Factors FPLL = 96MHz */
  SCU_PLLCmd(ENABLE);
  SCU_MCLKSourceConfig(SCU_MCLK_PLL);
  //SCU_HCLKDivisorConfig(SCU_HCLK_Div1);
  SCU_PCLKDivisorConfig(SCU_PCLK_Div1); 
  //SCU_PCLKDivisorConfig(SCU_PCLK_Div4); /* APB @12Mhz */
  SCU_APBPeriphClockConfig(__TIM01, ENABLE); /*Enable the clock for TIM0 and TIM1*/
}
/*******************************************************************************
* Function Name  : ENET_InitClocksGPIO
* Description    : Reset, clocks & GPIO Ethernet Pin initializations
* Input          : None
* Output         : None
* Return         : None
*******************************************************************************/
void ENET_InitClocksGPIO(void)
{

  GPIO_InitTypeDef GPIO_Struct;
  
  /* Enable ENET and MII PHY clocks */
  SCU_AHBPeriphClockConfig(__ENET, ENABLE);
  SCU_AHBPeriphReset(__ENET,DISABLE);

  //SCU_PHYCLKConfig(DISABLE);
  
  /** Configure ENET GPIO **/

  GPIO_DeInit(GPIO1);
  GPIO_Struct.GPIO_Pin = GPIO_Pin_1 | GPIO_Pin_2 |GPIO_Pin_3 |GPIO_Pin_4 |GPIO_Pin_7 ;
  GPIO_Struct.GPIO_Type = GPIO_Type_PushPull;
  GPIO_Struct.GPIO_Direction = GPIO_PinOutput;
  GPIO_Struct.GPIO_IPInputConnected = GPIO_IPInputConnected_Disable;
  GPIO_Struct.GPIO_Alternate=GPIO_OutputAlt2;
  GPIO_Init(GPIO1, &GPIO_Struct);

  GPIO_DeInit(GPIO5);
  GPIO_Struct.GPIO_Pin = GPIO_Pin_3;
  GPIO_Struct.GPIO_Type = GPIO_Type_PushPull;
  GPIO_Struct.GPIO_Direction = GPIO_PinOutput;
  GPIO_Struct.GPIO_IPInputConnected = GPIO_IPInputConnected_Disable;
  GPIO_Struct.GPIO_Alternate=GPIO_OutputAlt2;
  GPIO_Init(GPIO5, &GPIO_Struct);

  GPIO_DeInit(GPIO6);
  GPIO_Struct.GPIO_Pin = GPIO_Pin_4;
  GPIO_Struct.GPIO_Type = GPIO_Type_PushPull;
  GPIO_Struct.GPIO_Direction = GPIO_PinOutput;
  GPIO_Struct.GPIO_IPInputConnected = GPIO_IPInputConnected_Disable;
  GPIO_Init(GPIO6, &GPIO_Struct);

}

void T0_Init(void)
{
  TIM_InitTypeDef   TIM_InitStructure;
  /* TIM0 Configuration in Output Compare Mode */
  TIM_DeInit(TIM0);  /* TIM0 Deinitialization */
  TIM_StructInit(&TIM_InitStructure); /* TIM0 Structure Initialization */
  TIM_InitStructure.TIM_Mode = TIM_OCM_CHANNEL_1;                           
  TIM_InitStructure.TIM_OC1_Modes = TIM_TIMING;               
  TIM_InitStructure.TIM_Clock_Source = TIM_CLK_APB;         
  TIM_InitStructure.TIM_Clock_Edge = TIM_CLK_EDGE_FALLING;  
  TIM_InitStructure.TIM_Prescaler = 49;               
  TIM_InitStructure.TIM_Pulse_Length_1 = 60000;          
  TIM_Init (TIM0, &TIM_InitStructure);
  TIM_ITConfig(TIM0, TIM_IT_OC1, ENABLE); /*Enable TIM0 Output Compare1 interrupt*/
  TIM_CounterCmd(TIM0, TIM_START);	/* Start the counter of TIM0 */
}
/******************* (C) COPYRIGHT 2007 STMicroelectronics *****END OF FILE****/

⌨️ 快捷键说明

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