Funpack2-2 TC275完成任务1多核控制
1 启动时,两个LED时熄灭的状态 2 按下按键的时候, 第一个LED翻转 3 第二次按下按键的时候,第一个LED停止翻转,第二个LED开始翻转, 一秒后停止翻转
标签
Funpack
MCU
TC275
john
更新2022-10-11
468

1. 本板卡最终实现了什么功能

使用TC275的三个核心,轮流休眠待机,分别控制板卡上的LED灯,如core0检测按键按下,唤醒core1翻转LED1,一秒后,唤醒core2翻转LED2,系统休眠

基本功能

  • 读取按键状态,读取用户输入
  • 设置LED的点亮和熄灭
  • 控制核心的运行和休眠

项目环境

  • AURIX: 英飞凌提供的开发环境
  • VS code v1.60.0: 微软开发的跨平台源代码编辑器

硬件

AURIX TC275 lite: 套件配备了基于 32 位单芯片 AURIX TM TriCore TM的微控制器 Aurix TM TC275。它可以与一系列开发工具一起使用,包括 AURIX TM Development Studio、英飞凌免费的基于 Eclipse 的 IDE,或来自 Hightec/PLS/Infineon 的基于 Eclipse 的“FreeEntryToolchain”。

  • 用于 AURIX™ TM的 20 MHz 晶振和用于 OCDS 的 12 MHz 晶振
  • 用于 WIFI/BLE 的 Mikrobus 连接器
  • 英飞凌 CAN 收发器 TLE9251VSJ 和 CAN 连接器
  • 针连接器 X2
  • 电源指示灯 (D5)
  • LED D1/D2 用于 ADBUS7/4 和 LED3 用于 ESR0 信号(低电平有效)
  • Arduino 针连接器(电源和模拟输入)
  • 电位器 (10 kOhm) 和可焊接的 0 Ohm 电阻器(0805 英制中的 R33)
  • 微型 USB(推荐 USB3.0)
  • 10 针 DAP 连接器
  • 复位按钮
  • 2 x Shield2GO 连接器,用于 Infineon Maker Shields
  • EEPROM 1Kbit

FiVOcV6yXfKNAuKF9n2nGe0NPjG5

2. 各功能对应的主要代码片段及说明

1. 初始化相关参数

IfxGtm_Tom_Timer g_gtmTimer;                    /* TOM driver handle                                                */
IfxStm_Timer g_stmTimer;                        /* STM driver handle                                                */
float32 g_stmPeriod = 0.1;                      /* Period in seconds at which power modes toggle                    */
uint8 g_sleep = 0;                              /* Variable used to monitor the current set mode (sleep/run mode)   */
define ISR_PRIORITY_TOM    10                  /* TOM Interrupt priority                                           */
define TOM_FREQ            25.0f               /* TOM frequency                                                    */
define LED                 &MODULE_P00, 5      /* LED which is toggled in Interrupt Service Routine (ISR)          */
/*-----------------------------------------------------Includes------------------------------------------------------*/
/*********************************************************************************************************************/
#include "SCU_Power_Down_Idle.h"
#include "IfxStm_Timer.h"
#include "Bsp.h"

#include "IfxGtm_Tom_Timer.h"
#include "IfxStm_Timer.h"
#include "IfxCpu.h"
#include "IfxScuWdt.h"
#include "Ifx_Types.h"

/*********************************************************************************************************************/
/*-------------------------------------------------Global variables--------------------------------------------------*/
/*********************************************************************************************************************/
IfxStm_Timer g_myTimer;

/*********************************************************************************************************************/
/*------------------------------------------------------Macros-------------------------------------------------------*/
/*********************************************************************************************************************/
/* Defines Priority 2 out of 255. Note: highest possible priority is 255 */
#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
/* 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                                               */
/*********************************************************************************************************************/
/*----------------------------------------------Function Implementations---------------------------------------------*/
/*********************************************************************************************************************/
/* Maps the Interrupt Service Routine with the CPU and Priority */
IFX_INTERRUPT(systemTimerIsrCmp0, ISR_PROVIDER_CPU2, ISR_PRIORITY_2);

2. 设置CPU的状态

void configLED0(void)
{
    /* Set Port Pin 00.5 to output mode and turn off the LED (LED is low-level active) */
    IfxPort_setPinModeOutput(LED1, IfxPort_OutputMode_pushPull, IfxPort_OutputIdx_general);
    IfxPort_setPinHigh(LED1);
}

/* Toggle the LED port pin state */
void toggleLED0(void)
{
    IfxPort_togglePin(LED1);                                             /* Toggle Port Pin 00.5                     */
}


void configLED1(void)
{
    /* Set Port Pin 00.5 to output mode and turn off the LED (LED is low-level active) */
    IfxPort_setPinModeOutput(LED2, IfxPort_OutputMode_pushPull, IfxPort_OutputIdx_general);
    IfxPort_setPinHigh(LED2);
    IfxPort_setPinMode(BUTTON, IfxPort_Mode_inputPullUp);
}

/* Toggle the LED port pin state */
void toggleLED1(void)
{
    IfxPort_togglePin(LED2);                                             /* Toggle Port Pin 00.5                     */
}
#define WAIT_TIME   50
static boolean setIdle = TRUE;                                      /* Alternating between Idle and non-Idle    */

int if_key_is_pushed(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.
         */

        waitTime(IfxStm_getTicksFromMilliseconds(BSP_DEFAULT_TIMER, WAIT_TIME));
        if (IfxPort_getPinState(BUTTON) == 0){

            IfxCpu_enableInterrupts();                                          /* Enabling interrupts as ISR disables it   */
//            IfxStm_Timer_acknowledgeTimerIrq(&g_myTimer);                       /* IR acknowledge and set new compare value */

//            if(setIdle == TRUE)
//            {
//                IfxCpu_setCoreMode(&MODULE_CPU0, IfxCpu_CoreMode_idle);         /* Set CPU0 in IDLE mode                    */
//                setIdle = FALSE;
//            }
//            else
//            {
//                IfxCpu_setCoreMode(&MODULE_CPU0, IfxCpu_CoreMode_run);         /* Set CPU0 in IDLE mode                    */
//                setIdle = TRUE;
//            }
            while (1) {
                if (IfxPort_getPinState(BUTTON) != 0) {
                    return 1;
                }
            }
        }
    }
    return 0;

}

3. 实现功能的演示及说明

1 启动时,两个LED时熄灭的状态

FlT_JnZAEsrMrKaJqLEhAgAZLqTS

2 按下按键的时候, 第一个LED翻转

Fo-WREkgEyBGVFKmwjRtDAnHwyLM

3 第二次按下按键的时候,第一个LED停止翻转,第二个LED开始翻转, 一秒后停止翻转

Fo_BzawCUjBQdfknneHLzj-PLqF7

4. 对本活动的心得体会

英飞凌提供了非常好的开发文档和开发工具, 外设和功能的设置非常流畅.

了解到了英飞凌的开发方法和和芯片特性

学习到了多核编程的原理,核心之间通讯的原理

附件下载
Main.zip
团队介绍
黄煜鑫
团队成员
john
评论
0 / 100
查看更多
目录
硬禾服务号
关注最新动态
0512-67862536
info@eetree.cn
江苏省苏州市苏州工业园区新平街388号腾飞创新园A2幢815室
苏州硬禾信息科技有限公司
Copyright © 2023 苏州硬禾信息科技有限公司 All Rights Reserved 苏ICP备19040198号