一、自我介绍:
我是来自广东的工程师钱卫国,目前主做VB编程.
二、硬件介绍:
参数KIT_AURIX_TC275_LITE家庭微控制器产品描述AURIX™ TC275 lite 套件配备了基于 32 位单芯片 AurixTM TriCoreTM 的微控制器 AurixTM TC275。它可以与一系列开发工具一起使用,包括 AURIXTM Development Studio、英飞凌免费的基于 Eclipse 的 IDE,或来自 Hitecs/PLS/Infineon 的基于 Eclipse 的“FreeEntryToolchain”类型评估板
- 该芯片有三个运算核、两个校验核,类似于将三个高性能单片机集成在一起,功能非常强大;
- 该芯片推出较早、各种开发例子、资料文档、开发工具相对较为齐全;其他型号均是在TC275之后推出,如性价比更高的TC234、TC212、TC297等等
- 由于集成3核、价格优势不是太明显;
- 有4通道can接口,4个can公用256个接收发送器;
- 有电机控制器专用接口;
- 内部Flash有4Mbyte;
三、实现的功能和代码:
任务1: 使用TC275的三个核心,轮流休眠待机,分别控制板卡上的LED灯,如core0检测按键按下,唤醒core1翻转LED1,一秒后,唤醒core2翻转LED2,系统休眠
主要实现的功能是按键控制LED显示,串口实时显示电位器的模拟采样值和按键状态。代码主要参考综合例程。下面描述下具体实现:
1. 设置各个CPU的状态, 设置他们为休眠模式或者运行模式, 在各个main方法中调用就可以对特定CPU进行设置
int core0_main(void)
{
IfxCpu_enableInterrupts();
/* !!WATCHDOG0 AND SAFETY WATCHDOG ARE DISABLED HERE!!
* Enable the watchdogs and service them periodically if it is required
*/
IfxScuWdt_disableCpuWatchdog(IfxScuWdt_getCpuWatchdogPassword());
IfxScuWdt_disableSafetyWatchdog(IfxScuWdt_getSafetyWatchdogPassword());
/* Wait for CPU sync event */
IfxCpu_emitEvent(&g_cpuSyncEvent);
IfxCpu_waitEvent(&g_cpuSyncEvent, 1);
/* Initialize Power Down Idle Training */
// configSystemTimer();
initStm(void);
init_GPIOs(void);
// configLED();
setidle1(); //set cpu1 to idle
setidle2(); //set cpu2 to idle
while(1)
{
if (key_push()) {switch_to_c1();}
}
return (1);
}
2. 设置一些全局变量,其中包含延迟的时间, 各个GPIO口的设置,闪烁的时间等参数
/* LED */
#define LED1 &MODULE_P00,5
#define LED2 &MODULE_P00,6
#define BUTTON &MODULE_P00,7 /* Port pin for the button */
#define ALLOW_SLEEP_MODE 0x0 /* Allow sleep mode for GTM */
#define BLOCK_SLEEP_MODE 0x1 /* Block sleep mode for STM */
#define PMSWCR1_CPUSEL 0x1 /* Set the CPU0 as CPU master */
#define PMCSR0_REQSLP 0x2 /* Request sleep mode
#define ISR_PRIORITY_2 2
/* Defines CPU that triggers the interrupt */
#define ISR_PROVIDER_CPU0 0
/* Defines CPU that triggers the interrupt */
#define ISR_PROVIDER_CPU2 2
/* Rate 0.5 Hz */
#define RATE_0_5_HZ 0.25
/* Rate 1 Hz */
#define RATE_1_HZ 0.5
3. GPIO初始化, 定时器的初始化, 相关外设初始化
void init_GPIOs(void)
{
/* Setup the port pin connected to the LED to general output mode push-pull. This function can be used
* to initialize any port pin by specifying the port number, pin number and port pin mode.
*/
IfxPort_setPinMode(LED, IfxPort_Mode_outputPushPullGeneral);
/* Setup the port pin connected to the push button to input mode. This function can be used to initialize any
* port to input mode by just specifying the port number as illustrated.
*/
IfxPort_setPinMode(BUTTON, IfxPort_Mode_inputPullUp);
}
/* Depending on the the state of the "BUTTON" port pin, the LED is turned on or off */
void control_LED(void)
{
/* With the routine getPinState() the value of a particular pin can be retrieved. This
* function can be used to retrieve any port state by just specifying the port number
* as illustrated.
*/
if(IfxPort_getPinState(BUTTON) == 0)
{
/* With the routine setPinState() the state of the port can be set to drive either
* LOW or HIGH. This function can be used to retrieve any port state by just
* specifying the port number as illustrated.
*/
IfxPort_setPinState(LED, IfxPort_State_low);
}
else
{
IfxPort_setPinState(LED, IfxPort_State_high);
}
}
void initTom(void)
{
IfxGtm_enable(&MODULE_GTM); /* Enable the GTM */
IfxGtm_Tom_Timer_Config timerConfig; /* Timer configuration structure */
IfxGtm_Tom_Timer_initConfig(&timerConfig, &MODULE_GTM); /* Initialize the timer configuration */
timerConfig.base.frequency = TOM_FREQ; /* Set the timer frequency */
timerConfig.base.isrPriority = ISR_PRIORITY_TOM; /* Set the interrupt priority */
timerConfig.base.isrProvider = IfxSrc_Tos_cpu0; /* Set the interrupt provider */
timerConfig.tom = IfxGtm_Tom_1; /* Define the used timer */
timerConfig.timerChannel = IfxGtm_Tom_Ch_0; /* Define the used channel */
timerConfig.clock = IfxGtm_Tom_Ch_ClkSrc_cmuFxclk3; /* Define the used CMU clock */
IfxGtm_Cmu_enableClocks(&MODULE_GTM, IFXGTM_CMU_CLKEN_FXCLK); /* Enable the CMU clock */
IfxGtm_Tom_Timer_init(&g_gtmTimer, &timerConfig); /* Initialize the TOM */
IfxPort_setPinModeOutput(LED, IfxPort_OutputMode_pushPull, IfxPort_OutputIdx_general); /* Set port pin mode */
IfxGtm_Tom_Timer_run(&g_gtmTimer); /* Start the TOM */
}
/* This function initialize the STM to trigger an interrupt every two seconds */
void initStm(void)
{
IfxStm_Timer_Config timerConfig; /* Timer configuration structure */
IfxStm_Timer_initConfig(&timerConfig, &MODULE_STM0); /* Initialize it with default values */
timerConfig.base.frequency = 1 / g_stmPeriod; /* Interrupt rate every STM_PERIOD seconds */
timerConfig.base.isrPriority = ISR_PRIORITY_STM; /* Interrupt priority */
timerConfig.base.isrProvider = IfxSrc_Tos_cpu0; /* CPU0 to trigger the interrupt */
timerConfig.comparator = IfxStm_Comparator_0; /* Comparator 0 register is used */
IfxStm_Timer_init(&g_stmTimer, &timerConfig); /* Use timerConfig to initialize the STM */
IfxStm_Timer_run(&g_stmTimer); /* Run the STM and set the compare Value */
}
四、运行的情况
开机
第一次按下Button时翻转LED1
等待一秒后翻转LED2, 并且系统休眠
五、感想
用了挺长时间的Arduino,第一次使用英飞凌的开发环境 ,虽然感觉性能方面确实和Arduino差距挺大,首先核心数就是没法比的, TC275上有三个核心, 运行多线程任务的时候就不用再束手束脚了,做一些对性能需求不是很大的应用,比如这次任务,就非常适合使用TC275来进行开发。对于一些成本敏感的应用,但是价格相对来说就比较高了, 对价格敏感的项目就不适合使用TC275.
最后也要感谢电子森林提供这样的平台, 我从这个项目里面学到了很多, 希望电子森林越办越好.
一、自我介绍:
我是来自广东的工程师钱卫国,目前主做VB编程.
二、硬件介绍:
参数KIT_AURIX_TC275_LITE家庭微控制器产品描述AURIX™ TC275 lite 套件配备了基于 32 位单芯片 AurixTM TriCoreTM 的微控制器 AurixTM TC275。它可以与一系列开发工具一起使用,包括 AURIXTM Development Studio、英飞凌免费的基于 Eclipse 的 IDE,或来自 Hitecs/PLS/Infineon 的基于 Eclipse 的“FreeEntryToolchain”类型评估板
- 该芯片有三个运算核、两个校验核,类似于将三个高性能单片机集成在一起,功能非常强大;
- 该芯片推出较早、各种开发例子、资料文档、开发工具相对较为齐全;其他型号均是在TC275之后推出,如性价比更高的TC234、TC212、TC297等等
- 由于集成3核、价格优势不是太明显;
- 有4通道can接口,4个can公用256个接收发送器;
- 有电机控制器专用接口;
- 内部Flash有4Mbyte;
三、实现的功能和代码:
主要实现的功能是按键控制LED显示,串口实时显示电位器的模拟采样值和按键状态。代码主要参考综合例程。下面描述下具体实现:
1. 设置各个CPU的状态, 设置他们为休眠模式或者运行模式, 在各个main方法中调用就可以对特定CPU进行设置
int core0_main(void)
{
IfxCpu_enableInterrupts();
/* !!WATCHDOG0 AND SAFETY WATCHDOG ARE DISABLED HERE!!
* Enable the watchdogs and service them periodically if it is required
*/
IfxScuWdt_disableCpuWatchdog(IfxScuWdt_getCpuWatchdogPassword());
IfxScuWdt_disableSafetyWatchdog(IfxScuWdt_getSafetyWatchdogPassword());
/* Wait for CPU sync event */
IfxCpu_emitEvent(&g_cpuSyncEvent);
IfxCpu_waitEvent(&g_cpuSyncEvent, 1);
/* Initialize Power Down Idle Training */
// configSystemTimer();
initStm(void);
init_GPIOs(void);
// configLED();
setidle1(); //set cpu1 to idle
setidle2(); //set cpu2 to idle
while(1)
{
if (key_push()) {switch_to_c1();}
}
return (1);
}
2. 设置一些全局变量,其中包含延迟的时间, 各个GPIO口的设置,闪烁的时间等参数
/* LED */
#define LED1 &MODULE_P00,5
#define LED2 &MODULE_P00,6
#define BUTTON &MODULE_P00,7 /* Port pin for the button */
#define ALLOW_SLEEP_MODE 0x0 /* Allow sleep mode for GTM */
#define BLOCK_SLEEP_MODE 0x1 /* Block sleep mode for STM */
#define PMSWCR1_CPUSEL 0x1 /* Set the CPU0 as CPU master */
#define PMCSR0_REQSLP 0x2 /* Request sleep mode
#define ISR_PRIORITY_2 2
/* Defines CPU that triggers the interrupt */
#define ISR_PROVIDER_CPU0 0
/* Defines CPU that triggers the interrupt */
#define ISR_PROVIDER_CPU2 2
/* Rate 0.5 Hz */
#define RATE_0_5_HZ 0.25
/* Rate 1 Hz */
#define RATE_1_HZ 0.5
3. GPIO初始化, 定时器的初始化, 相关外设初始化
void init_GPIOs(void)
{
/* Setup the port pin connected to the LED to general output mode push-pull. This function can be used
* to initialize any port pin by specifying the port number, pin number and port pin mode.
*/
IfxPort_setPinMode(LED, IfxPort_Mode_outputPushPullGeneral);
/* Setup the port pin connected to the push button to input mode. This function can be used to initialize any
* port to input mode by just specifying the port number as illustrated.
*/
IfxPort_setPinMode(BUTTON, IfxPort_Mode_inputPullUp);
}
/* Depending on the the state of the "BUTTON" port pin, the LED is turned on or off */
void control_LED(void)
{
/* With the routine getPinState() the value of a particular pin can be retrieved. This
* function can be used to retrieve any port state by just specifying the port number
* as illustrated.
*/
if(IfxPort_getPinState(BUTTON) == 0)
{
/* With the routine setPinState() the state of the port can be set to drive either
* LOW or HIGH. This function can be used to retrieve any port state by just
* specifying the port number as illustrated.
*/
IfxPort_setPinState(LED, IfxPort_State_low);
}
else
{
IfxPort_setPinState(LED, IfxPort_State_high);
}
}
void initTom(void)
{
IfxGtm_enable(&MODULE_GTM); /* Enable the GTM */
IfxGtm_Tom_Timer_Config timerConfig; /* Timer configuration structure */
IfxGtm_Tom_Timer_initConfig(&timerConfig, &MODULE_GTM); /* Initialize the timer configuration */
timerConfig.base.frequency = TOM_FREQ; /* Set the timer frequency */
timerConfig.base.isrPriority = ISR_PRIORITY_TOM; /* Set the interrupt priority */
timerConfig.base.isrProvider = IfxSrc_Tos_cpu0; /* Set the interrupt provider */
timerConfig.tom = IfxGtm_Tom_1; /* Define the used timer */
timerConfig.timerChannel = IfxGtm_Tom_Ch_0; /* Define the used channel */
timerConfig.clock = IfxGtm_Tom_Ch_ClkSrc_cmuFxclk3; /* Define the used CMU clock */
IfxGtm_Cmu_enableClocks(&MODULE_GTM, IFXGTM_CMU_CLKEN_FXCLK); /* Enable the CMU clock */
IfxGtm_Tom_Timer_init(&g_gtmTimer, &timerConfig); /* Initialize the TOM */
IfxPort_setPinModeOutput(LED, IfxPort_OutputMode_pushPull, IfxPort_OutputIdx_general); /* Set port pin mode */
IfxGtm_Tom_Timer_run(&g_gtmTimer); /* Start the TOM */
}
/* This function initialize the STM to trigger an interrupt every two seconds */
void initStm(void)
{
IfxStm_Timer_Config timerConfig; /* Timer configuration structure */
IfxStm_Timer_initConfig(&timerConfig, &MODULE_STM0); /* Initialize it with default values */
timerConfig.base.frequency = 1 / g_stmPeriod; /* Interrupt rate every STM_PERIOD seconds */
timerConfig.base.isrPriority = ISR_PRIORITY_STM; /* Interrupt priority */
timerConfig.base.isrProvider = IfxSrc_Tos_cpu0; /* CPU0 to trigger the interrupt */
timerConfig.comparator = IfxStm_Comparator_0; /* Comparator 0 register is used */
IfxStm_Timer_init(&g_stmTimer, &timerConfig); /* Use timerConfig to initialize the STM */
IfxStm_Timer_run(&g_stmTimer); /* Run the STM and set the compare Value */
}
四、运行的情况
开机时core0启动, 监听按键
按下Button是core1启动, core0休眠,led1翻转
等待一秒后core2启动,core1休眠,led2翻转, 之后所有core休眠
五、感想
用了挺长时间的Arduino,第一次使用英飞凌的开发环境 ,虽然感觉性能方面确实和Arduino差距挺大,首先核心数就是没法比的, TC275上有三个核心, 运行多线程任务的时候就不用再束手束脚了,做一些对性能需求不是很大的应用,比如这次任务,就非常适合使用TC275来进行开发。对于一些成本敏感的应用,但是价格相对来说就比较高了, 对价格敏感的项目就不适合使用TC275.
最后也要感谢电子森林提供这样的平台, 我从这个项目里面学到了很多, 希望电子森林越办越好.