您好,欢迎访问三七文档
当前位置:首页 > 办公文档 > 工作范文 > LDC1314参考程序
#includeintrinsics.h#includestring.h#includestdint.h#includecstring#includestdio.h#includeLDC13xx16xx_evm.h#includescheduler.h#includehost_interface.h#includehost_packet.h#includeUSB_API/USB_Common/device.h#includeUSB_API/USB_Common/types.h//BasicTypedeclarations#includeUSB_API/USB_Common/usb.h//USB-specificfunctions#includeF5xx_F6xx_Core_Lib/HAL_UCS.h#includeF5xx_F6xx_Core_Lib/HAL_PMM.h#includeUSB_API/USB_CDC_API/UsbCdc.h#includeusbConstructs.h#includeUSB_config/descriptors.h//prototypesvoidInitMCU(void);voidInit_Clock(void);voidUSBCommunicationTask(void);voidLDC16_13_Evm_Test_Routine();uint16_tL_Noise(uint16_t*t_buf,uint8_tch_num);uint8_tL_Sample(uint16_t*t_buf,uint8_tch_num);volatileuint8_tbCDCDataReceived_event=FALSE;//Indicatesdatahasbeenreceivedwithoutanopenrcvoperationvolatileuint16_tusbEvents=(kUSB_VbusOnEvent+kUSB_VbusOffEvent+kUSB_receiveCompletedEvent+kUSB_dataReceivedEvent+kUSB_UsbSuspendEvent+kUSB_UsbResumeEvent+kUSB_UsbResetEvent);//usedasanedge-triggerforUSBconnect/disconnectuint8_tusb_led_flag;voidmain(void){WDTCTL=WDTPW+WDTHOLD;//Stopwatchdogtimer//hardwarebootloaderentryEVM_SHUTDOWN_SEL&=~EVM_SHUTDOWN_BIT;//gpioEVM_SHUTDOWN_DIR&=~EVM_SHUTDOWN_BIT;//inputEVM_SHUTDOWN_REN|=EVM_SHUTDOWN_BIT;//enablepull-downEVM_SHUTDOWN_OUT&=~EVM_SHUTDOWN_BIT;//pulllow__delay_cycles(36000);if(EVM_SHUTDOWN_IN&EVM_SHUTDOWN_BIT){_disable_interrupts();((void(*)())0x1000)();}EVM_SHUTDOWN_REN&=~EVM_SHUTDOWN_BIT;//disablepull-down//InitMCU();//includedinevminitevm_init();LDC16_13_Evm_Test_Routine();_enable_interrupts();//evm_LED_Set(ALLON);initHostInterface();//evm_LED_Set(RED);//redononlyusb_led_flag=0;while(1){//USBCommsUSBCommunicationTask();}}/**InitialzeMCUInitializestheMSP430peripheralsandmodules.*/voidInitMCU(void){__disable_interrupt();//DisableglobalinterruptsSetVCore(3);Init_Clock();//InitclocksUSB_init();//InitUSBUSB_setEnabledEvents((WORD)usbEvents);//Checkifwe'realreadyphysicallyattachedtoUSB,andifso,connecttoit//ThisisthesamefunctionthatgetscalledautomaticallywhenVBUSgetsattached.if(USB_connectionInfo()&kUSB_vbusPresent){USB_handleVbusOnEvent();}__enable_interrupt();//enableglobalinterrupts}/**USBCommunicationHandlesUSBComms*/voidUSBCommunicationTask(void){uint16_tbytesSent,bytesReceived;uint8_terror=0,status;switch(USB_connectionState()){caseST_ENUM_ACTIVE:if(!usb_led_flag){//evm_LED_Set(GREEN);//greenononlyusb_led_flag=1;}status=USBCDC_intfStatus(CDC0_INTFNUM,&bytesSent,&bytesReceived);if(status&kUSBCDC_waitingForSend){error=1;}if(bCDCDataReceived_event||(status&kUSBCDC_dataWaiting)){bCDCDataReceived_event=FALSE;processCmdPacket();}else{evm_processDRDY();//processDRDYaddedhereforspeed(notscheduler-assigned)executeTasks();}break;caseST_USB_DISCONNECTED:caseST_USB_CONNECTED_NO_ENUM:caseST_ENUM_IN_PROGRESS:caseST_NOENUM_SUSPENDED:caseST_ERROR:if(usb_led_flag){//evm_LED_Set(RED);//redononlyusb_led_flag=0;}removeAllTasks();break;default:;}//endofswitch-casesentenceif(error){error=0;_nop();//TODO:Usercanplacecodeheretohandleerror}}/**InitializeClockInitializesallclocks:ACLK,MCLK,SMCLK.*/voidInit_Clock(void){//Initializationofclockmoduleif(USB_PLL_XT==2){#ifdefined(__MSP430F552x)||defined(__MSP430F550x)P5SEL|=0x0C;//enableXT2pinsforF5529#elifdefined(__MSP430F563x_F663x)P7SEL|=0x0C;#endif#if0//useREFOforFLLandACLKUCSCTL3=(UCSCTL3&~(SELREF_7))|(SELREF__REFOCLK);UCSCTL4=(UCSCTL4&~(SELA_7))|(SELA__REFOCLK);//MCLKwillbedrivenbytheFLL(notbyXT2),referencedtotheREFOInit_FLL_Settle(USB_MCLK_FREQ/1000,USB_MCLK_FREQ/32768);//StarttheFLL,atthefreqindicatedbytheconfig//constantUSB_MCLK_FREQXT2_Start(XT2DRIVE_0);//StarttheUSBcrystal#endif//forUSB2ANYwhichhasXT2crytstal=24MHzUCSCTL4=SELA_5+SELS_5+SELM_5;//ACLK=XT2SMCLK=XT2MCLK=XT2XT2_Start(XT2DRIVE_3);}else{#ifdefined(__MSP430F552x)||defined(__MSP430F550x)P5SEL|=0x10;//enableXT1pins#endif//UsetheREFOoscillatortosourcetheFLLandACLKUCSCTL3=SELREF__REFOCLK;UCSCTL4=(UCSCTL4&~(SELA_7))|(SELA__REFOCLK);//MCLKwillbedrivenbytheFLL(notbyXT2),referencedtotheREFOInit_FLL_Settle(USB_MCLK_FREQ/1000,USB_MCLK_FREQ/32768);//setFLL(DCOCLK)XT1_Start(XT1DRIVE_0);//StarttheUSBcrystal}}//Lnoisemeasurement//take16samplingaveragesofsize1024//returnsnoisemeasurementuint16_tL_Noise(uint16_t*t_buf,uint8_tch_num){uint8_ti;uint32_tj,sample,min,max;uint16_tavg=0;//ifLnoiseisoutofrangeaftertuningreturnFALSEfor(i=0;i4;i++){//evm_LED_Set(ALLTOGGLE);min=0xFFFFFFFF;//minmax=0;//max//measureLnoisefor(j=0;j1024;j++){#ifdefSERIES_16smbus_readWord(0x2A,ch_num,&t_buf[0]);smbus_readWord(0x2A,ch_num+1,&t_buf[1]);sample=((uint32_t)t_buf[1])|(((uint32_t)t_buf[0])16);#endif#ifdefSERIES_13smbus_readWord(0x2A,ch_num,&t_buf[0]);sample=((uint32_t)t_buf[0]);#endifif(samplemin)min=sample;if(samplemax)max=sample;}if(maxmin){avg+=(max-min);}elseif(minmax){return0xFFFF;}}avg/=4;//shouldcompiletorightshiftby4returnavg;}//Lsamplerangemeasurement//take64samplingwindowsofsize16//FALSEifnoerrors,TRUEotherwiseuint8_tL_Sample(uint16_t*t_buf,uint8_tch_num){uint8_ti,j;uint32_tavg;for(i=0;i16;i++){//evm_LED_Set(ALL
本文标题:LDC1314参考程序
链接地址:https://www.777doc.com/doc-4815643 .html