Funpack2-2:TC275点灯大法
Funpack2-2,TC275,任务一,多核轮流唤醒翻转LED
标签
嵌入式系统
LED
TC275
wakojosin
更新2022-10-09
419

内容介绍

1. 介绍用本板卡最终实现了什么功能
板卡实现任务一,使用TC275的三个核心,轮流休眠待机,分别控制板卡上的LED灯,功能1是基于IDLE模式,core0检测按键按下,唤醒core0,通过core0唤醒core1,core0进入IDLE模式,core1翻转LED1,一秒后,唤醒core2,core1进入IDLE模式,core2翻转LED2,core2进入IDLE模式;功能2是基于STANDBY模式,core0检测到按键按下,唤醒系统,core0激活core1,core0进入IDLE模式,core1点亮LED1,一秒后,core1激活core2,core1进入IDLE模式,core2点亮LED2,一秒后,core2激活core0,core2进入IDLE模式,core0使系统进入standby模式。
2. 各功能对应的主要代码片段及说明
以下是cpu0的主函数说明:
int core0_main (void)
{
//略
    // 初始化日志串口
    init_UART();
//略
    //IO中断初始化,P15_1对应着PINB以及REQ16
    IfxScuEru_initReqPin(&IfxScu_REQ16_P15_1_IN, IfxPort_InputMode_noPullDevice);
    IfxScuEru_enableRisingEdgeDetection(IfxScu_REQ16_P15_1_IN.channelId); /* Interrupt triggers on rising edge (Register RENx) and  */
    IfxScuEru_enableTriggerPulse(IfxScu_REQ16_P15_1_IN.channelId);
    /* Determination of output channel for trigger event (Register INPx) */
    IfxScuEru_connectTrigger(IfxScu_REQ16_P15_1_IN.channelId, IfxScuEru_InputNodePointer_0);
    /* Configure Output channels, OutputGating Unit OGU (Register IGPy) */
    IfxScuEru_setInterruptGatingPattern(IfxScuEru_OutputChannel_0, IfxScuEru_InterruptGatingPattern_alwaysActive);
    /* Service request configuration */
    /* Get source pointer depending on outputChannel (SRC_SCUERU0 for outputChannel0) */
    volatile Ifx_SRC_SRCR *src = &MODULE_SRC.SCU.SCU.ERU[(int) IfxScuEru_OutputChannel_0 % 4];
    IfxSrc_init(src, IfxSrc_Tos_cpu0, ISR_PRIORITY_SCUERU_INT0);
    IfxSrc_enable(src);

    while (1)
    {
#ifdef USE_STANDBY_MODE
        //功能2
        if(!rststat.B.PORST) {
            //唤醒core1
            IfxCpu_setCoreMode(&MODULE_CPU1, IfxCpu_CoreMode_run);
            //core0进入IDLE模式
            IfxCpu_setCoreMode(&MODULE_CPU0, IfxCpu_CoreMode_idle);
        }
        stepIntoStandbyMode();
#else
        //功能1
        //core0进入IDLE模式
        IfxCpu_setCoreMode(&MODULE_CPU0, IfxCpu_CoreMode_idle);
        //唤醒core1
        IfxCpu_setCoreMode(&MODULE_CPU1, IfxCpu_CoreMode_run);
#endif
    }
    return (1);
}
//中断函数注册
IFX_INTERRUPT(SCUERU_Int0_Handler, 0, ISR_PRIORITY_SCUERU_INT0);
void SCUERU_Int0_Handler (void)
{
    //唤醒core0
    IfxCpu_setCoreMode(&MODULE_CPU0, IfxCpu_CoreMode_run);
}
void stepIntoStandbyMode (void)
{
    IfxScuWdt_clearSafetyEndinit(IfxScuWdt_getSafetyWatchdogPassword()); /* Clear Safety EndInit protection        */
    IfxScuWdt_clearCpuEndinit(IfxScuWdt_getCpuWatchdogPassword()); /* Clear CPU EndInit protection           */

    MODULE_SCU.PMSWSTATCLR.U = 0x1FC;   /* Clear all Standby and Wake-up flags    */

    Ifx_SCU_PMSWCR0 pmswcr0;            /* Stdby and Wake-up Ctrl Reg 0 handle    */
    pmswcr0.U = MODULE_SCU.PMSWCR0.U;   /* Assign current register value to it    */
    pmswcr0.B.ESR1WKEN = 0x00;          /* Disable WakeUpTrigger at any ESR1 edge */
    pmswcr0.B.ESR1EDCON = 0x3;
    //是能PINA和PINB来唤醒系统
    pmswcr0.B.PINAWKEN = 0x1;           /* Enable WakeUp on Pin A(P14.1). */
    pmswcr0.B.PINAEDCON = 0x3;          /* Generate WakeUp Trigger at any edge    */
    pmswcr0.B.PINBWKEN = 0x1;           /* Disable WakeUp on Pin B(P15.1). */
    pmswcr0.B.PINBEDCON = 0x3;          /* Generate WakeUp Trigger at any edge    */
    pmswcr0.B.ESR0EDCON = 0x0;          /* Disable WakeUpTrigger at any ESR0 edge */
    pmswcr0.B.PWRWKEN = 0x0;            /* Disable WakeUpTrigger on VEXT ramp up  */
    MODULE_SCU.PMSWCR0.U = pmswcr0.U;   /* Assign object to register              */
    //进入standby模式
    MODULE_SCU.PMCSR[0].B.REQSLP = 0x3; /* Request Standby Mode for the system    */

    IfxScuWdt_setSafetyEndinit(IfxScuWdt_getSafetyWatchdogPassword()); /* Set Safety EndInit protection          */
    IfxScuWdt_setCpuEndinit(IfxScuWdt_getCpuWatchdogPassword()); /* Set CPU EndInit - Standby becomes active */
}
以下是cpu1和cpu2的主函数说明:
int core1_main (void)
{
//略
    // LED1初始化
    // LED1=P00.5, LED2=P00.6
    IfxPort_setPinModeOutput(LED1_PIN, IfxPort_OutputMode_pushPull, IfxPort_OutputIdx_general);
    IfxPort_setPinState(LED1_PIN, IfxPort_State_high);
    while (1)
    {
        //core1进入IDLE模式
        IfxCpu_setCoreMode(&MODULE_CPU1, IfxCpu_CoreMode_idle);
        //反转LED1
        IfxPort_setPinState(LED1_PIN, IfxPort_State_toggled);
        delay_ms(1000);
        //唤醒core2
        IfxCpu_setCoreMode(&MODULE_CPU2, IfxCpu_CoreMode_run);
    }
    return (1);
}
int core2_main(void)
{
//略
    //初始化LED2
    // LED1=P00.5, LED2=P00.6
    IfxPort_setPinModeOutput(LED2_PIN, IfxPort_OutputMode_pushPull, IfxPort_OutputIdx_general);
    IfxPort_setPinState(LED2_PIN, IfxPort_State_high);
    while(1)
    {
        //core2进入IDLE模式
        IfxCpu_setCoreMode(&MODULE_CPU2, IfxCpu_CoreMode_idle);
        //反转LED2
        IfxPort_setPinState(LED2_PIN, IfxPort_State_toggled);
#ifdef USE_STANDBY_MODE
        delay_ms(1000);
        //唤醒core0
        IfxCpu_setCoreMode(&MODULE_CPU0, IfxCpu_CoreMode_run);
#endif
    }
    return (1);
}
3. 功能展示

通过user_config.h中的宏定义USE_STANDBY_MODE可以切换功能,USE_STANDBY_MODE=0为功能1,USE_STANDBY_MODE=1为功能2。

3.1 功能一照片:

上电启动的照片,此时LED等都熄灭。

FklGGeMbgAq7xNEIiCUH2d9p7Jp0

core1点亮LED1

FlQWiuq4fKu2gH-9_LpSv3MClLkL

一秒后,core2点亮LED2

FjULwG4pGO7pbihd128TKoOWnBrt

此时所有core都进入IDLE模式,等待下次按键触发。

3.2 功能二照片:

上电启动,此时所以LED灯熄灭

Fq_iA-eOipPjAq8-JE68WLwSK6NX

core1点亮LED1

Fgyf-JbPgfDWetregiCohd5fxgzW

1秒后,core2点亮LED2

FlPVtu2Jdrvbcwy3_WY9oBTYeTZt

1秒后,进入standby模式,此时所有外设关闭,所以所有LED熄灭。

Fqir90UEYPXa-WV5WlDxbXQ4OQm6

4. 对本活动的心得体会(包括意见或建议)
通过本次活动了解到了英飞凌的单片机,对英飞凌多核单片机的使用有了简单的了解,整体感受是英飞凌的文档写的很多,可能是因为不熟悉,找起相关的内容有点费劲,然后是对应开发板的例子提供的不是非常到位,关于standby模式没找到很全的说明,也没有合适的例程,所以实现的功能就没达到心里预期。

附件下载

TC275_LED.zip

团队介绍

个人团队

评论

0 / 100
查看更多
目录
硬禾服务号
关注最新动态
0512-67862536
info@eetree.cn
江苏省苏州市苏州工业园区新平街388号腾飞创新园A2幢815室
苏州硬禾信息科技有限公司
Copyright © 2023 苏州硬禾信息科技有限公司 All Rights Reserved 苏ICP备19040198号