@TOC
- 品智科技S32K118开发板
- S32 STUDIO FOR ARM 2.2
- SDK 3.0.0
- pin_mux
- clockMan
- osif
1.FTM分类
ftm_ic 输入捕获
ftm_oc 输出比较
ftm_qd 正交解码器
ftm_pwm 脉宽调制
ftm_mc 模量计数器
2. 定时器
实现每100ms翻转一次电平
/* ###################################################################
** Filename : main.c
** Processor : S32K1xx
** Abstract :
** Main module.
** This module contains user's application code.
** Settings :
** Contents :
** No public methods
**
** ###################################################################*/
/*!
** @file main.c
** @version 01.00
** @brief
** Main module.
** This module contains user's application code.
*/
/*!
** @addtogroup main_module main module documentation
** @{
*/
/* MODULE main */
/* Including necessary module. Cpu.h contains other modules needed for compiling.*/
#include "Cpu.h"
volatile int exit_code = 0;
/* User includes (#include below this line is not maintained by Processor Expert) */
/* 定时器中断函数*/
static void FTM_IRQHandler(void)
{
PINS_DRV_TogglePins(LED1_PORT, 1 << LED1_PIN);
PINS_DRV_TogglePins(LED3_PORT, 1 << LED3_PIN);
FTM_DRV_ClearStatusFlags(INST_FLEXTIMER_MC1, (uint32_t)FTM_TIME_OVER_FLOW_FLAG);
}
/*!
\brief The main function for the project.
\details The startup initialization sequence is the following:
* - startup asm routine
* - main()
*/
int main(void)
{
/* Write your local variable definition here */
/*** Processor Expert internal initialization. DON'T REMOVE THIS CODE!!! ***/
#ifdef PEX_RTOS_INIT
PEX_RTOS_INIT(); /* Initialization of the selected RTOS. Macro is defined by the RTOS component. */
#endif
/*** End of Processor Expert internal initialization. ***/
/* Write your code here */
/* For example: for(;;) { } */
ftm_state_t ftmStateStruct;
/*时钟初始化*/
CLOCK_SYS_Init(g_clockManConfigsArr, CLOCK_MANAGER_CONFIG_CNT,
g_clockManCallbacksArr, CLOCK_MANAGER_CALLBACK_CNT);
CLOCK_SYS_UpdateConfiguration(0U,CLOCK_MANAGER_POLICY_AGREEMENT);
/*引脚初始化*/
PINS_DRV_Init(NUM_OF_CONFIGURED_PINS, g_pin_mux_InitConfigArr);
/* 初始化FTM模块 */
FTM_DRV_Init(INST_FLEXTIMER_MC1, &flexTimer_mc1_InitConfig, &ftmStateStruct);
/* 配置并使定时器能溢出中断 */
INT_SYS_InstallHandler(FTM0_Ovf_Reload_IRQn, &FTM_IRQHandler, (isr_t*)NULL);
INT_SYS_EnableIRQ(FTM0_Ovf_Reload_IRQn);
/* 初始化并开启计数器 */
FTM_DRV_InitCounter(INST_FLEXTIMER_MC1, &flexTimer_mc1_TimerConfig);
FTM_DRV_CounterStart(INST_FLEXTIMER_MC1);
PINS_DRV_WritePin(LED1_PORT, LED1_PIN, 1);
PINS_DRV_WritePin(LED2_PORT, LED2_PIN, 0);
PINS_DRV_WritePin(LED3_PORT, LED3_PIN, 0);
PINS_DRV_WritePin(LED4_PORT, LED4_PIN, 0);
for (;;)
{
/* 32位数据,表示32个引脚,为1表示设置的哪一个引脚*/
OSIF_TimeDelay(100);
PINS_DRV_TogglePins(LED2_PORT, 1 << LED2_PIN);
PINS_DRV_TogglePins(LED4_PORT, 1 << LED4_PIN);
}
/*** Don't write any code pass this line, or it will be deleted during code generation. ***/
/*** RTOS startup code. Macro PEX_RTOS_START is defined by the RTOS component. DON'T MODIFY THIS CODE!!! ***/
#ifdef PEX_RTOS_START
PEX_RTOS_START(); /* Startup of the selected RTOS. Macro is defined by the RTOS component. */
#endif
/*** End of RTOS startup code. ***/
/*** Processor Expert end of main routine. DON'T MODIFY THIS CODE!!! ***/
for(;;) {
if(exit_code != 0) {
break;
}
}
return exit_code;
/*** Processor Expert end of main routine. DON'T WRITE CODE BELOW!!! ***/
} /*** End of main routine. DO NOT MODIFY THIS TEXT!!! ***/
/* END main */
/*!
** @}
*/
/*
** ###################################################################
**
** This file was created by Processor Expert 10.1 [05.21]
** for the NXP S32K series of microcontrollers.
**
** ###################################################################
*/