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

📄 target.c

📁 基于 Luminary Micro 公司的 Cortex-M3 (ARM)内核使用之 uC/OS-II 作业系统,此例程是移植于 LM3S310 上的应用,于 Keil MDK 工程编译,而 uC/O
💻 C
📖 第 1 页 / 共 2 页
字号:
** Created by:				Steven Zhou 周绍刚
** Created Date:			2007-01-18
**-------------------------------------------------------------------------------------------------------
** Modified by:
** Modified date:
**------------------------------------------------------------------------------------------------------
********************************************************************************************************/
#if TARGET_BUZ_EN > 0
void  Buz_On(void)
{
 	GPIOPinWrite(BUZ_GPIO_PORT, BUZ_PIN, ~BUZ_PIN);
}
#endif



/*********************************************************************************************************
** Function name:			Buz_Off
**
** Descriptions:			Switch off the buzzer 关闭蜂鸣器
**
** Input parameters:		None 无
** Returned value:		None 无
**         
** Used global variables:	None 无
** Calling modules:		GPIOPinWrite
**
** Created by:				Steven Zhou 周绍刚
** Created Date:			2007-01-18
**-------------------------------------------------------------------------------------------------------
** Modified by:
** Modified date:
**------------------------------------------------------------------------------------------------------
********************************************************************************************************/
#if TARGET_BUZ_EN > 0
void  Buz_Off(void)
{
	GPIOPinWrite(BUZ_GPIO_PORT, BUZ_PIN, BUZ_PIN);
}
#endif



/*********************************************************************************************************
** Function name:			Buz_Toggle
**
** Descriptions:			Toggle the buzzer 取反蜂鸣器
**
** Input parameters:		None 无
** Returned value:		None 无
**         
** Used global variables:	None 无
** Calling modules:		GPIOPinWrite,GPIOPinRead
**
** Created by:				Steven Zhou 周绍刚
** Created Date:			2007-01-18
**-------------------------------------------------------------------------------------------------------
** Modified by:
** Modified date:
**------------------------------------------------------------------------------------------------------
********************************************************************************************************/
#if TARGET_BUZ_EN > 0
void  Buz_Toggle(void)    
{
	  GPIOPinWrite(BUZ_GPIO_PORT, BUZ_PIN, ~GPIOPinRead(BUZ_GPIO_PORT, BUZ_PIN));
}
#endif



/*********************************************************************************************************
** Function name:			Key_Init
**
** Descriptions:			Initialize the target board's keys,support up to 4 keys 
**                       初始化目标板的按键,最多支持4个
**
** Input parameters:		None 无
** Returned value:		None 无
**         
** Used global variables:	None 无
** Calling modules:		GPIOPinWrite,GPIOPinRead
**
** Created by:				Steven Zhou 周绍刚
** Created Date:			2007-01-18
**-------------------------------------------------------------------------------------------------------
** Modified by:
** Modified date:
**------------------------------------------------------------------------------------------------------
********************************************************************************************************/
#if (TARGET_KEY1_EN>0) ||  (TARGET_KEY2_EN>0) || (TARGET_KEY3_EN>0) || (TARGET_KEY4_EN>0)
void  Key_Init(void)    
{
 #if TARGET_KEY1_EN>0
 	SysCtlPeripheralEnable(KEY1_SYSCTL);
	GPIODirModeSet(KEY1_GPIO_PORT, KEY1_PIN, GPIO_DIR_MODE_IN);
 #endif	
 
 #if TARGET_KEY2_EN>0
 	SysCtlPeripheralEnable(KEY2_SYSCTL);
	GPIODirModeSet(KEY2_GPIO_PORT, KEY2_PIN, GPIO_DIR_MODE_IN);
 #endif	    

 #if TARGET_KEY3_EN>0
 	SysCtlPeripheralEnable(KEY3_SYSCTL);
	GPIODirModeSet(KEY3_GPIO_PORT, KEY3_PIN, GPIO_DIR_MODE_IN);
 #endif	  

 #if TARGET_KEY4_EN>0
 	SysCtlPeripheralEnable(KEY4_SYSCTL);
	GPIODirModeSet(KEY4_GPIO_PORT, KEY4_PIN, GPIO_DIR_MODE_IN);
 #endif	  
}
#endif



/*********************************************************************************************************
** Function name:			Key_Read
**
** Descriptions:			Read the status of the keys. 读取按键的状态
**
** Input parameters:		None 无
** Returned value:	    8-bit unsigned char data. Bit0-bit3 stand for the status of Key1-Key4, bit4-Bit7 no meaning
**                       8位无符号数,位0-位3表示Key1-Key4的状态,位4-位7无意义
**         
** Used global variables:	None 无
** Calling modules:		GPIOPinWrite,GPIOPinRead
**
** Created by:				Steven Zhou 周绍刚
** Created Date:			2007-01-18
**-------------------------------------------------------------------------------------------------------
** Modified by:
** Modified date:
**------------------------------------------------------------------------------------------------------
********************************************************************************************************/
#if (TARGET_KEY1_EN>0) ||  (TARGET_KEY2_EN>0) || (TARGET_KEY3_EN>0) || (TARGET_KEY4_EN>0)
uint8 Key_Read(void)
{
 	uint8 uTemp;

 	uTemp=0xFF;

 #if TARGET_KEY1_EN > 0
	if(!GPIOPinRead(KEY1_GPIO_PORT, KEY1_PIN))  uTemp &=0xFE; 
 #endif

 #if TARGET_KEY2_EN > 0
	if(!GPIOPinRead(KEY2_GPIO_PORT, KEY2_PIN))  uTemp &=0xFD; 
 #endif

 #if TARGET_KEY3_EN > 0
	if(!GPIOPinRead(KEY3_GPIO_PORT, KEY3_PIN))  uTemp &=0xFB; 
 #endif

 #if TARGET_KEY4_EN > 0
	if(!GPIOPinRead(KEY4_GPIO_PORT, KEY4_PIN))  uTemp &=0xF7; 
 #endif

 	return(uTemp);
}
#endif



/*********************************************************************************************************
** Function name:			Timer0A_Init
**
** Descriptions:			Initialize Timer0A to 32bit timeout 初始化定时器0A为32位超时
**
** Input parameters:		Tick: Number of timeout tick 超时脉冲数
                         Prio: Interrupt priority 中断优先级
** Returned value:		None 无
**         
** Used global variables:	None 无
** Calling modules:		SysCtlPeripheralEnable,TimerConfigure,TimerLoadSet,TimerIntEnable,
                         IntEnable,IntPrioritySet,TimerEnable
**
** Created by:				Steven Zhou 周绍刚
** Created Date:			2007-01-18
**-------------------------------------------------------------------------------------------------------
** Modified by:
** Modified date:
**------------------------------------------------------------------------------------------------------
********************************************************************************************************/
#if TARGET_TMR0A_EN > 0
void Timer0A_Init(uint32 Tick, uint8 Prio)
{

	SysCtlPeripheralEnable(SYSCTL_PERIPH_TIMER0);

  	TimerConfigure(TIMER0_BASE, TIMER_CFG_32_BIT_PER);
  
  	TimerLoadSet(TIMER0_BASE, TIMER_A, Tick);

  	TimerIntEnable(TIMER0_BASE, TIMER_TIMA_TIMEOUT);

  	IntEnable(INT_TIMER0A);

  	IntPrioritySet(INT_TIMER0A, Prio);

	TimerEnable(TIMER0_BASE, TIMER_A);  	  
}
#endif



/*********************************************************************************************************
** Function name:			Timer0A_ISR
**
** Descriptions:			Timeout interrupt handler of Timer0A 定时器0A超时中断
**
** Input parameters:		None 无
** Returned value:		None 无
**         
** Used global variables:	None 无
** Calling modules:		TimerIntClear,LED_Toggle
**
** Created by:				Steven Zhou 周绍刚
** Created Date:			2007-01-18
**-------------------------------------------------------------------------------------------------------
** Modified by:
** Modified date:
**------------------------------------------------------------------------------------------------------
********************************************************************************************************/
#if TARGET_TMR0A_EN > 0
void Timer0A_ISR(void)
{
  /***Optional Code. If you don't call any uC/OS-II's functions & variables, this code can be cancelled***/ 
  /***选择代码。如果你没有调用任何的uC/OS-II的函数和变量,可删除这段代码***/ 
  /*
  #if OS_CRITICAL_METHOD ==3
    OS_CPU_SR  cpu_sr;
  #endif 

  OS_ENTER_CRITICAL();                       
  OSIntNesting++;
  OS_EXIT_CRITICAL();
  */

  
  TimerIntClear(TIMER0_BASE, TIMER_TIMA_TIMEOUT);	 //Clear the interrupt flag. 清除中断标志
  
  /****Add you initialization code here. 在这里加入你的初始化代码。******/
  Buz_Toggle();	  								 	// 取反蜂鸣器  




  /***Optional Code. If you don't call any uC/OS-II's functions & variables, this code can be cancelled***/ 
  /***选择代码。如果你没有调用任何的uC/OS-II的函数和变量,可删除这段代码***/ 
  //OSIntExit();      					        
}
#endif



/*********************************************************************************************************
** Function name:			Tmr_TickInit
**
** Descriptions:			Initialize uC/OS-II's tick source(system timer),
                         初始化uC/OS-II的时钟源(系统定时器)
**
** Input parameters:		None 无
** Returned value:		None 无
**         
** Used global variables:	OS_TICKS_PER_SEC
** Calling modules:		SysCtlClockGet,SysTickPeriodSet,SysTickEnable,SysTickIntEnable
**
** Created by:				Steven Zhou 周绍刚
** Created Date:			2007-01-18
**-------------------------------------------------------------------------------------------------------
** Modified by:
** Modified date:
**------------------------------------------------------------------------------------------------------
********************************************************************************************************/
static  void  Tmr_TickInit (void)
{
	SysTickPeriodSet( (uint32)(SysCtlClockGet() / OS_TICKS_PER_SEC) -1 );
    SysTickEnable();
    SysTickIntEnable();
}



/*********************************************************************************************************
** Function name:			Tmr_TickISR_Handler
**
** Descriptions:			Timeout interrupt handler of system timer 系统定时器超时中断
**
** Input parameters:		None 无
** Returned value:		None 无
**         				 
** Used global variables:	OSIntNesting
** Calling modules:		OS_ENTER_CRITICAL,OS_EXIT_CRITICAL,OSTimeTick,OSIntExit
**
** Created by:				Steven Zhou 周绍刚
** Created Date:			2007-01-18
**-------------------------------------------------------------------------------------------------------
** Modified by:
** Modified date:
**------------------------------------------------------------------------------------------------------
********************************************************************************************************/
void  Tmr_TickISR_Handler (void)
{
  #if OS_CRITICAL_METHOD ==3
    OS_CPU_SR  cpu_sr;
  #endif 

    OS_ENTER_CRITICAL();                         
    OSIntNesting++;
    OS_EXIT_CRITICAL();

    OSTimeTick();                        // Call uC/OS-II's OSTimeTick()  调用uC/OS-II的OSTimeTick()函数

    OSIntExit();                                 
}



/*********************************************************************************************************
** Function name:			TargetInit
**
** Descriptions:			Initialize the target board 初始化目标板
**
** Input parameters:		None 无
** Returned value:		None 无
**         
** Used global variables:	None 无
** Calling modules:		SysCtlClockSet,Tmr_TickInit
**
** Created by:				Steven Zhou 周绍刚
** Created Date:			2007-01-18
**-------------------------------------------------------------------------------------------------------
** Modified by:
** Modified date:
**------------------------------------------------------------------------------------------------------
********************************************************************************************************/
void  TargetInit (void)
{
    #if PLL_EN == 0                                                            //Not use PLL  不使用PLL 
		SysCtlClockSet(CCLK_DIV | SYSCTL_USE_OSC | SYSCTL_OSC_MAIN | EXT_CLK); //System clock=EXT_CLK/CCLK_DIV 系统时钟=EXT_CLK/CCLK_DIV 
	#else                                                                      //Use PLL  使用PLL  
		SysCtlClockSet(CCLK_DIV | SYSCTL_USE_PLL | SYSCTL_OSC_MAIN | EXT_CLK); //System clock=200MHz/CCLK_DIV 系统时钟=200MHz/CCLK_DIV 
	#endif
 
  
    Tmr_TickInit();         // Initialize the uC/OS-II tick interrupt,using the Kernal's timer  
	                        // 初始化uC/OS-II的时钟中断,使用内核定时器   
	
	
	/****Add you initialization code here. 在这里加入你的初始化代码。******/
	Timer0A_Init(6000000 /10, 2<<5);     // 初始化定时器0  			
	Buz_Init();           				 // 初始化蜂鸣器的IO口      

}



/*********************************************************************************************************
*                                        End Of File                                                     *
*********************************************************************************************************/					   

⌨️ 快捷键说明

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