英飞凌TC275

news/2024/11/30 8:50:04/

 部分代码简单介绍如下:

基于英飞凌iLLD库进行集成,主要用到的模块和函数介绍如下。

1)  GPIO模块//存储引脚电平状态boolean IfxPort_getPinStateDio[5];void Dio_init_input(void){// 配置热释电1信号采集引脚P2.6为输入,上拉IfxPort_setPinMode(&MODULE_P02,6,IfxPort_Mode_inputPullUp); //X103连接器  PIN_19}void Dio_init_output(void){// 配置蜂鸣器驱动引脚P33.0为输出,上拉IfxPort_setPinMode(&MODULE_P33,0,  IfxPort_Mode_outputPushPullGeneral);IfxPort_setPinHigh(&MODULE_P33,0);  //默认禁能// 配置监控主机驱动控制引脚P14.9为输出,上拉IfxPort_setPinMode(&MODULE_P14,9, IfxPort_Mode_outputPushPullGeneral);IfxPort_setPinLow(&MODULE_P14,9);//默认禁能}void DIO_State_Read(void){//读取热释电1信号IfxPort_getPinStateDio[0] = IfxPort_getPinState(&MODULE_P02, 6);}2)  LED模块介绍void GPIO_Led_init(void){// configure P33.8 as general outputIfxPort_setPinMode(&MODULE_P33,8, IfxPort_Mode_outputPushPullGeneral);// configure P33.9 as general outputIfxPort_setPinMode(&MODULE_P33,9,  IfxPort_Mode_outputPushPullGeneral);// configure P33.10 as general outputIfxPort_setPinMode(&MODULE_P33,10, IfxPort_Mode_outputPushPullGeneral);// configure P33.11 as general outputIfxPort_setPinMode(&MODULE_P33, 11,  IfxPort_Mode_outputPushPullGeneral);}void GPIO_Led(void){IfxPort_togglePin(&MODULE_P33, 8);IfxStm_waitTicks(&MODULE_STM0, 5000000);IfxPort_togglePin(&MODULE_P33, 9);IfxStm_waitTicks(&MODULE_STM0, 5000000);IfxPort_togglePin(&MODULE_P33, 10);IfxStm_waitTicks(&MODULE_STM0, 5000000);IfxPort_togglePin(&MODULE_P33, 11);IfxStm_waitTicks(&MODULE_STM0, 5000000);}3)  蜂鸣器模块//蜂鸣器报警void Beep_On(void){int i;for(i=0;i<10000;i++){IfxPort_setPinLow(&MODULE_P33,0);IfxStm_waitTicks(&MODULE_STM0, 50000);IfxPort_setPinHigh(&MODULE_P33,0);IfxStm_waitTicks(&MODULE_STM0, 50000);IfxPort_setPinLow(&MODULE_P33,0);IfxStm_waitTicks(&MODULE_STM0, 50000);IfxPort_setPinHigh(&MODULE_P33,0);IfxStm_waitTicks(&MODULE_STM0, 50000);}}//蜂鸣器报警禁能void Beep_Off(void){IfxPort_setPinHigh(&MODULE_P33,0);}4)  CAN通信模块//定义全局变量IfxMultican_Message txMsg;uint32 dataLow = 0x03020100;uint32 dataHigh = 0x07060504;const unsigned id=0xcf00203;//定义扩展IDextern  uint32 dataLow;extern uint32 dataHigh;extern IfxMultican_Message txMsg;//CAN handleIfxMultican_Can can;//指向全CAN的模块地址//Nodes handlesIfxMultican_Can_Node canSrcNode;//指向节点寄存器地址//Message Object handlesIfxMultican_Can_MsgObj canSrcMsgObj;//指向消息体寄存器地址//通道、节点、报文的初始化void CAN_Init(void){//CAN模块初始化 //CAN配置结构体IfxMultican_Can_Config canConfig;IfxMultican_Can_initModuleConfig(&canConfig, &MODULE_CAN);IfxMultican_Can_initModule(&can, &canConfig);//CAN节点初始化//CAN节点配置结构体IfxMultican_Can_NodeConfig canNodeConfig;IfxMultican_Can_Node_initConfig(&canNodeConfig, &can);canNodeConfig.baudrate = 1000000;//波特率设为1M//CAN源节点{canNodeConfig.nodeId = IfxMultican_NodeId_0;canNodeConfig.rxPin =&IfxMultican_RXD0B_P20_7_IN;//P20.7作为输入引脚canNodeConfig.rxPinMode = IfxPort_InputMode_pullUp;canNodeConfig.txPin = &IfxMultican_TXD0_P20_8_OUT;//P20.8作为输出引脚canNodeConfig.txPinMode = IfxPort_OutputMode_pushPull;// 源节点初始化IfxMultican_Can_Node_init(&canSrcNode,&canNodeConfig);}//Message Object Initialisation{//    创建报文对象配置IfxMultican_Can_MsgObjConfig canMsgObjConfig;IfxMultican_Can_MsgObj_initConfig(&canMsgObjConfig, &canSrcNode);//    分配报文对象canMsgObjConfig.msgObjId = 0;canMsgObjConfig.messageId = id;//消息IDcanMsgObjConfig.acceptanceMask =0x7FFFFFFFUL;canMsgObjConfig.frame = IfxMultican_Frame_transmit;canMsgObjConfig.control.messageLen=IfxMultican_DataLengthCode_8;//数据长度canMsgObjConfig.control.extendedFrame = TRUE;//扩展帧帧格式canMsgObjConfig.control.matchingId = TRUE;//匹配ID//      初始化报文对象IfxMultican_Can_MsgObj_init(&canSrcMsgObj, &canMsgObjConfig);}}//上面已经把通道 、节点、报文配置好了,下面开始收发void CAN_Trannsfer(void){//全CAN报文初始化IfxMultican_Message_init(&txMsg,id,dataLow,dataHigh, IfxMultican_DataLengthCode_8);//数据的高低位,低位在前,高位在后//发送数据while(IfxMultican_Can_MsgObj_sendMessage(&canSrcMsgObj, &txMsg)==IfxMultican_Status_notSentBusy);}5)  ADC采集模块// VADC模块IfxVadc_Adc vadc;// VDC 组//选择ADC0转换器IfxVadc_Adc_Group adcGroup[1];// VDC 通道//选择AN0和AN1分别作为温度和湿度传感器输入通道IfxVadc_Adc_Channel adcChannel[1][2];// 存储转换结果uint16  ADC_result[1][2];void ADC_init(void){int chnIx;// 创建配置变量IfxVadc_Adc_Config adcConfig;IfxVadc_Adc_initModuleConfig(&adcConfig, &MODULE_VADC);//初始化ADC模块全局参数,采样周期和结果精度IfxVadc_Adc_initModule(&vadc, &adcConfig);// 创建组配置变量IfxVadc_Adc_GroupConfig adcGroupConfig;IfxVadc_Adc_initGroupConfig(&adcGroupConfig, &vadc);//初始化Convertor0的 AN0和AN1通道int group_i = 0;for(group_i = 0; group_i<1;group_i++){// 定义组IDadcGroupConfig.groupId = group_i;// 设置Master ID为自己的ID,即自己作为MasteradcGroupConfig.master = adcGroupConfig.groupId;// 使能队列中断源adcGroupConfig.arbiter.requestSlotQueueEnabled = TRUE;// 使能扫描中断源adcGroupConfig.arbiter.requestSlotScanEnabled = TRUE;// 使能后台中断源adcGroupConfig.arbiter.requestSlotBackgroundScanEnabled = TRUE;//使能所有源的门adcGroupConfig.queueRequest.triggerConfig.gatingMode         = IfxVadc_GatingMode_always;adcGroupConfig.scanRequest.triggerConfig.gatingMode           = IfxVadc_GatingMode_always;adcGroupConfig.backgroundScanRequest.triggerConfig.gatingMode = IfxVadc_GatingMode_always;// 初始化组配置IfxVadc_Adc_initGroup(&adcGroup[group_i], &adcGroupConfig);// 创建通道配置变量IfxVadc_Adc_ChannelConfig adcChannelConfig[2];for(chnIx=0; chnIx<2; ++chnIx){IfxVadc_Adc_initChannelConfig(&adcChannelConfig[chnIx], &adcGroup[group_i]);//配置通道IDadcChannelConfig[chnIx].channelId = (IfxVadc_ChannelId)(chnIx);//配置通道结果寄存器,采用专用结果寄存器adcChannelConfig[chnIx].resultRegister = (IfxVadc_ChannelResult)(chnIx);// 初始化通道IfxVadc_Adc_initChannel(&adcChannel[group_i][chnIx], &adcChannelConfig[chnIx]);//添加到扫描源unsigned channels = (1 << adcChannelConfig[chnIx].channelId);unsigned mask = channels;boolean continuous = TRUE;IfxVadc_Adc_setScan(&adcGroup[group_i],channels,mask, continuous);}}}void ADC_Scan(void){int group_m;unsigned char chnIx;Ifx_VADC_RES conversionResult;for (group_m = 0; group_m < 1; group_m++){// 开启自动扫描IfxVadc_Adc_startScan(&adcGroup[group_m]);// 判断转换结果是否 有效,然后读取转换结果for (chnIx = 0; chnIx < 2; ++chnIx){// wait for valid result//Ifx_VADC_RES conversionResult;do {conversionResult = IfxVadc_Adc_getResult(&adcChannel[group_m][chnIx]);} while (!conversionResult.B.VF);ADC_result[group_m][chnIx] = conversionResult.B.RESULT;}}}6)  MAIN主程序int core0_main (void){//使能中断__enable ();//看门狗禁能/** !!WATCHDOG0 AND SAFETY WATCHDOG ARE DISABLED HERE!!* Enable the watchdog in the demo if it is required and also service the watchdog periodically* */IfxScuWdt_disableCpuWatchdog (IfxScuWdt_getCpuWatchdogPassword ());IfxScuWdt_disableSafetyWatchdog (IfxScuWdt_getSafetyWatchdogPassword ());//变量初始化dataLow = 0x0;dataHigh = 0x0;//模块初始化GPIO_Led_init();CAN_Init();ADC_init();Dio_init_input();Dio_init_output();while (1){//LED点亮GPIO_Led();//ADC模块扫描ADC_Scan();//查询读取IO状态DIO_State_Read();//热释电传感器模块采集到人红外信号有效if(IfxPort_getPinStateDio[0]==0){//打开摄像头主机开始录像Camera_On();dataLow = 0xeeeeeeee;dataHigh = 0xeeeeeeee;//上报有人异常信息CAN_Trannsfer();//蜂鸣器报警Beep_On();}//热释电传感器模块没采集到人红外信号else{//关闭摄像头主机Camera_Off();//蜂鸣器不报警Beep_Off();//上报温湿度信息dataLow =  (uint32)ADC_result[0][0];dataHigh = (uint32)ADC_result[0][1];CAN_Trannsfer();}}return (1);}


http://www.ppmy.cn/news/212666.html

相关文章

【QT】Qt ApplicationManager Compositor源码分析

Qt ApplicationManager的Compositor功能分析 根据Qt ApplicationManager官网介绍&#xff0c;它基于Wayland协议实现了Compositor功能。下述为官网介绍。实际上&#xff0c;QtApplicationManager是使用了QtWayland模块来实现Compositor的。Wayland是一套旨在替代XWindow的 Com…

【Java系列】Mybatis-Plus 使用介绍二

序言 你只管努力&#xff0c;其他交给时间&#xff0c;时间会证明一切。 MyBatis-Plus 是 MyBatis 的增强工具&#xff0c;它简化了 MyBatis 的开发&#xff0c;并提供了许多实用的功能和工具类。下面是 MyBatis-Plus 的使用方法&#xff1a; 1 使用方法 1. 引入依赖 在 Maven…

Node服务器和常见模块

1 Node服务器开发 2 fs模块-文件系统 3 event模块-事件处理 4 认识二进制和buffer 5 Buffer的创建方式 6 Buffer的源码解析 node 的fs模块操作&#xff1a; 这里主要讲node如何进行读取文件&#xff0c;操作文件。服务器该有的操作node都有。 node的fs读取文本文件内容的d…

从0-1一起学习live555设计思想之一 基础运行环境 + 任务调度

系列文章目录 文章目录 系列文章目录前言一、基础组件总览二、UsageEnvironment三、BasicUsageEnvironment0四、BasicUsageEnvironment五、TaskScheduler六、BasicTaskScheduler0七、DelayQueue八、BasicTaskScheduler九、基础调度总结总结前言 一、基础组件总览 本篇开始分析…

iPhone 全系尺寸大全

iPhone 设备尺寸信息

oppofindx5pro参数配置

OPPOFindX5Pro背部采用了更为先进的工艺制程&#xff0c;官方称之为“一体化纳米微晶陶瓷”&#xff0c;手感相比上一代有了大幅提升&#xff0c;温润如玉&#xff0c;但手感太滑了&#xff0c;很多时候我都是双手握持&#xff0c;由于电池容量的增加&#xff0c;这款手机的厚度…

判断手机型号

- (NSString*)deviceString { // 需要#import "sys/utsname.h" struct utsname systemInfo; uname(&systemInfo); NSString *deviceString [NSString stringWithCString:systemInfo.machine encoding:NSUTF8StringEncoding]; if ([deviceString isEqualToString…

MySQL代码错误号大全

错误&#xff1a;1000 SQLSTATE: HY000 (ER_HASHCHK) 消息&#xff1a;hashchk 错误&#xff1a;1001 SQLSTATE: HY000 (ER_NISAMCHK) 消息&#xff1a;isamchk 错误&#xff1a;1002 SQLSTATE: HY000 (ER_NO) 消息&#xff1a;NO 错误&#xff1a;1003 SQLSTATE: HY0…