1 Star 1 Fork 0

飞跃/mspm0g3507SensorV1.4

加入 Gitee
与超过 1200万 开发者一起发现、参与优秀开源项目,私有仓库也完全免费 :)
免费加入
克隆/下载
ti_msp_dl_config.c 23.71 KB
一键复制 编辑 原始数据 按行查看 历史
飞跃 提交于 2024-04-26 14:11 . first
123456789101112131415161718192021222324252627282930313233343536373839404142434445464748495051525354555657585960616263646566676869707172737475767778798081828384858687888990919293949596979899100101102103104105106107108109110111112113114115116117118119120121122123124125126127128129130131132133134135136137138139140141142143144145146147148149150151152153154155156157158159160161162163164165166167168169170171172173174175176177178179180181182183184185186187188189190191192193194195196197198199200201202203204205206207208209210211212213214215216217218219220221222223224225226227228229230231232233234235236237238239240241242243244245246247248249250251252253254255256257258259260261262263264265266267268269270271272273274275276277278279280281282283284285286287288289290291292293294295296297298299300301302303304305306307308309310311312313314315316317318319320321322323324325326327328329330331332333334335336337338339340341342343344345346347348349350351352353354355356357358359360361362363364365366367368369370371372373374375376377378379380381382383384385386387388389390391392393394395396397398399400401402403404405406407408409410411412413414415416417418419420421422423424425426427428429430431432433434435436437438439440441442443444445446447448449450451452453454455456457458459460461462463464465466467468469470471472473474475476477478479480481482483484485486487488489490491492493494495496497498499500501502503504505506507508509510511512513514515516517518519520521522523524525526527528529530531532533534535536537538539540541542543544545546547548549550551552553554555556557558559560561562563564565566567568569570571572573574575576577578579580581582583584585586587588589590591592593594595596597598599600601602603604605606607608609610611612613614615616617618619620621622623624625626627628629630
/*
* Copyright (c) 2023, Texas Instruments Incorporated
* All rights reserved.
*
* Redistribution and use in source and binary forms, with or without
* modification, are permitted provided that the following conditions
* are met:
*
* * Redistributions of source code must retain the above copyright
* notice, this list of conditions and the following disclaimer.
*
* * Redistributions in binary form must reproduce the above copyright
* notice, this list of conditions and the following disclaimer in the
* documentation and/or other materials provided with the distribution.
*
* * Neither the name of Texas Instruments Incorporated nor the names of
* its contributors may be used to endorse or promote products derived
* from this software without specific prior written permission.
*
* THIS SOFTWARE IS PROVIDED BY THE COPYRIGHT HOLDERS AND CONTRIBUTORS "AS IS"
* AND ANY EXPRESS OR IMPLIED WARRANTIES, INCLUDING, BUT NOT LIMITED TO,
* THE IMPLIED WARRANTIES OF MERCHANTABILITY AND FITNESS FOR A PARTICULAR
* PURPOSE ARE DISCLAIMED. IN NO EVENT SHALL THE COPYRIGHT OWNER OR
* CONTRIBUTORS BE LIABLE FOR ANY DIRECT, INDIRECT, INCIDENTAL, SPECIAL,
* EXEMPLARY, OR CONSEQUENTIAL DAMAGES (INCLUDING, BUT NOT LIMITED TO,
* PROCUREMENT OF SUBSTITUTE GOODS OR SERVICES; LOSS OF USE, DATA, OR PROFITS;
* OR BUSINESS INTERRUPTION) HOWEVER CAUSED AND ON ANY THEORY OF LIABILITY,
* WHETHER IN CONTRACT, STRICT LIABILITY, OR TORT (INCLUDING NEGLIGENCE OR
* OTHERWISE) ARISING IN ANY WAY OUT OF THE USE OF THIS SOFTWARE,
* EVEN IF ADVISED OF THE POSSIBILITY OF SUCH DAMAGE.
*/
/*
* ============ ti_msp_dl_config.c =============
* Configured MSPM0 DriverLib module definitions
*
* DO NOT EDIT - This file is generated for the MSPM0G350X
* by the SysConfig tool.
*/
#include "ti_msp_dl_config.h"
DL_TimerA_backupConfig gPWM_0Backup;
DL_TimerA_backupConfig gTIMER_0Backup;
/*
* ======== SYSCFG_DL_init ========
* Perform any initialization needed before using any board APIs
*/
SYSCONFIG_WEAK void SYSCFG_DL_init(void)
{
SYSCFG_DL_initPower();
SYSCFG_DL_GPIO_init();
/* Module-Specific Initializations*/
SYSCFG_DL_SYSCTL_init();
SYSCFG_DL_PWM_0_init();
SYSCFG_DL_TIMER_0_init();
SYSCFG_DL_ADC12_0_init();
SYSCFG_DL_ADC12_1_init();
SYSCFG_DL_VREF_init();
SYSCFG_DL_DMA_init();
SYSCFG_DL_SYSTICK_init();
SYSCFG_DL_DAC12_init();
SYSCFG_DL_MCAN0_init();
/* Ensure backup structures have no valid state */
gPWM_0Backup.backupRdy = false;
gTIMER_0Backup.backupRdy = false;
}
/*
* User should take care to save and restore register configuration in application.
* See Retention Configuration section for more details.
*/
SYSCONFIG_WEAK bool SYSCFG_DL_saveConfiguration(void)
{
bool retStatus = true;
retStatus &= DL_TimerA_saveConfiguration(PWM_0_INST, &gPWM_0Backup);
retStatus &= DL_TimerA_saveConfiguration(TIMER_0_INST, &gTIMER_0Backup);
return retStatus;
}
SYSCONFIG_WEAK bool SYSCFG_DL_restoreConfiguration(void)
{
bool retStatus = true;
retStatus &= DL_TimerA_restoreConfiguration(PWM_0_INST, &gPWM_0Backup, false);
retStatus &= DL_TimerA_restoreConfiguration(TIMER_0_INST, &gTIMER_0Backup, false);
return retStatus;
}
SYSCONFIG_WEAK void SYSCFG_DL_initPower(void)
{
DL_GPIO_reset(GPIOA);
DL_GPIO_reset(GPIOB);
DL_TimerA_reset(PWM_0_INST);
DL_TimerA_reset(TIMER_0_INST);
DL_ADC12_reset(ADC12_0_INST);
DL_ADC12_reset(ADC12_1_INST);
DL_VREF_reset(VREF);
DL_DAC12_reset(DAC0);
DL_MathACL_reset(MATHACL);
DL_MCAN_reset(MCAN0_INST);
DL_GPIO_enablePower(GPIOA);
DL_GPIO_enablePower(GPIOB);
DL_TimerA_enablePower(PWM_0_INST);
DL_TimerA_enablePower(TIMER_0_INST);
DL_ADC12_enablePower(ADC12_0_INST);
DL_ADC12_enablePower(ADC12_1_INST);
DL_VREF_enablePower(VREF);
DL_DAC12_enablePower(DAC0);
DL_MathACL_enablePower(MATHACL);
DL_MCAN_enablePower(MCAN0_INST);
delay_cycles(POWER_STARTUP_DELAY);
}
SYSCONFIG_WEAK void SYSCFG_DL_GPIO_init(void)
{
DL_GPIO_initPeripheralAnalogFunction(GPIO_HFXIN_IOMUX);
DL_GPIO_initPeripheralAnalogFunction(GPIO_HFXOUT_IOMUX);
DL_GPIO_initPeripheralOutputFunction(GPIO_PWM_0_C0_IOMUX,GPIO_PWM_0_C0_IOMUX_FUNC);
DL_GPIO_enableOutput(GPIO_PWM_0_C0_PORT, GPIO_PWM_0_C0_PIN);
DL_GPIO_initDigitalOutput(GPIO_GRP_0_ICP_SELECT_IOMUX);
DL_GPIO_initDigitalOutput(GPIO_GRP_0_VS_I_SELECT_IOMUX);
DL_GPIO_initDigitalInputFeatures(GPIO_GRP_0_CAN_SET_IOMUX,
DL_GPIO_INVERSION_DISABLE, DL_GPIO_RESISTOR_PULL_UP,
DL_GPIO_HYSTERESIS_DISABLE, DL_GPIO_WAKEUP_DISABLE);
DL_GPIO_initDigitalOutputFeatures(GPIO_GRP_0_RPVS_SELECT_IOMUX,
DL_GPIO_INVERSION_DISABLE, DL_GPIO_RESISTOR_PULL_UP,
DL_GPIO_DRIVE_STRENGTH_LOW, DL_GPIO_HIZ_DISABLE);
DL_GPIO_initDigitalOutputFeatures(GPIO_GRP_0_COM_SELECT_IOMUX,
DL_GPIO_INVERSION_DISABLE, DL_GPIO_RESISTOR_PULL_UP,
DL_GPIO_DRIVE_STRENGTH_LOW, DL_GPIO_HIZ_DISABLE);
DL_GPIO_initDigitalOutputFeatures(GPIO_GRP_0_VS_I_OUT_SELECT_IOMUX,
DL_GPIO_INVERSION_DISABLE, DL_GPIO_RESISTOR_PULL_UP,
DL_GPIO_DRIVE_STRENGTH_LOW, DL_GPIO_HIZ_DISABLE);
DL_GPIO_initDigitalOutputFeatures(GPIO_GRP_0_IP2P_SELECT_IOMUX,
DL_GPIO_INVERSION_DISABLE, DL_GPIO_RESISTOR_PULL_UP,
DL_GPIO_DRIVE_STRENGTH_LOW, DL_GPIO_HIZ_DISABLE);
DL_GPIO_initDigitalOutput(GPIO_GRP_0_IP2_BOOST_SELECT_IOMUX);
DL_GPIO_clearPins(GPIO_GRP_0_PORT, GPIO_GRP_0_ICP_SELECT_PIN |
GPIO_GRP_0_VS_I_SELECT_PIN |
GPIO_GRP_0_RPVS_SELECT_PIN |
GPIO_GRP_0_VS_I_OUT_SELECT_PIN |
GPIO_GRP_0_IP2P_SELECT_PIN |
GPIO_GRP_0_IP2_BOOST_SELECT_PIN);
DL_GPIO_setPins(GPIO_GRP_0_PORT, GPIO_GRP_0_COM_SELECT_PIN);
DL_GPIO_enableOutput(GPIO_GRP_0_PORT, GPIO_GRP_0_ICP_SELECT_PIN |
GPIO_GRP_0_VS_I_SELECT_PIN |
GPIO_GRP_0_RPVS_SELECT_PIN |
GPIO_GRP_0_COM_SELECT_PIN |
GPIO_GRP_0_VS_I_OUT_SELECT_PIN |
GPIO_GRP_0_IP2P_SELECT_PIN |
GPIO_GRP_0_IP2_BOOST_SELECT_PIN);
DL_GPIO_initPeripheralOutputFunction(
GPIO_MCAN0_IOMUX_CAN_TX, GPIO_MCAN0_IOMUX_CAN_TX_FUNC);
DL_GPIO_initPeripheralInputFunction(
GPIO_MCAN0_IOMUX_CAN_RX, GPIO_MCAN0_IOMUX_CAN_RX_FUNC);
}
static const DL_SYSCTL_SYSPLLConfig gSYSPLLConfig = {
.inputFreq = DL_SYSCTL_SYSPLL_INPUT_FREQ_32_48_MHZ,
.rDivClk2x = 1,
.rDivClk1 = 0,
.rDivClk0 = 0,
.enableCLK2x = DL_SYSCTL_SYSPLL_CLK2X_DISABLE,
.enableCLK1 = DL_SYSCTL_SYSPLL_CLK1_DISABLE,
.enableCLK0 = DL_SYSCTL_SYSPLL_CLK0_ENABLE,
.sysPLLMCLK = DL_SYSCTL_SYSPLL_MCLK_CLK0,
.sysPLLRef = DL_SYSCTL_SYSPLL_REF_HFCLK,
.qDiv = 3,
.pDiv = DL_SYSCTL_SYSPLL_PDIV_1
};
SYSCONFIG_WEAK void SYSCFG_DL_SYSCTL_init(void)
{
//Low Power Mode is configured to be SLEEP0
DL_SYSCTL_setBORThreshold(DL_SYSCTL_BOR_THRESHOLD_LEVEL_0);
DL_SYSCTL_setFlashWaitState(DL_SYSCTL_FLASH_WAIT_STATE_2);
DL_SYSCTL_setSYSOSCFreq(DL_SYSCTL_SYSOSC_FREQ_BASE);
DL_SYSCTL_setHFCLKSourceHFXTParams(DL_SYSCTL_HFXT_RANGE_32_48_MHZ,10, true);
DL_SYSCTL_configSYSPLL((DL_SYSCTL_SYSPLLConfig *) &gSYSPLLConfig);
DL_SYSCTL_setULPCLKDivider(DL_SYSCTL_ULPCLK_DIV_2);
DL_SYSCTL_setHFCLKDividerForMFPCLK(DL_SYSCTL_HFCLK_MFPCLK_DIVIDER_15);
DL_SYSCTL_enableMFCLK();
DL_SYSCTL_enableMFPCLK();
DL_SYSCTL_setMFPCLKSource(DL_SYSCTL_MFPCLK_SOURCE_SYSOSC);
DL_SYSCTL_setMCLKSource(SYSOSC, HSCLK, DL_SYSCTL_HSCLK_SOURCE_SYSPLL);
}
/*
* Timer clock configuration to be sourced by / 1 (80000000 Hz)
* timerClkFreq = (timerClkSrc / (timerClkDivRatio * (timerClkPrescale + 1)))
* 1000000 Hz = 80000000 Hz / (1 * (79 + 1))
*/
static const DL_TimerA_ClockConfig gPWM_0ClockConfig = {
.clockSel = DL_TIMER_CLOCK_BUSCLK,
.divideRatio = DL_TIMER_CLOCK_DIVIDE_1,
.prescale = 79U
};
static const DL_TimerA_PWMConfig gPWM_0Config = {
.pwmMode = DL_TIMER_PWM_MODE_EDGE_ALIGN_UP,
.period = 10000,
.isTimerWithFourCC = false,
.startTimer = DL_TIMER_STOP,
};
SYSCONFIG_WEAK void SYSCFG_DL_PWM_0_init(void) {
DL_TimerA_setClockConfig(
PWM_0_INST, (DL_TimerA_ClockConfig *) &gPWM_0ClockConfig);
DL_TimerA_initPWMMode(
PWM_0_INST, (DL_TimerA_PWMConfig *) &gPWM_0Config);
DL_TimerA_setCaptureCompareValue(PWM_0_INST, 1199, DL_TIMER_CC_0_INDEX);
DL_TimerA_setCaptureCompareOutCtl(PWM_0_INST, DL_TIMER_CC_OCTL_INIT_VAL_LOW,
DL_TIMER_CC_OCTL_INV_OUT_DISABLED, DL_TIMER_CC_OCTL_SRC_FUNCVAL,
DL_TIMERA_CAPTURE_COMPARE_0_INDEX);
DL_TimerA_setCaptCompUpdateMethod(PWM_0_INST, DL_TIMER_CC_UPDATE_METHOD_IMMEDIATE, DL_TIMERA_CAPTURE_COMPARE_0_INDEX);
DL_TimerA_enableClock(PWM_0_INST);
DL_TimerA_enableInterrupt(PWM_0_INST , DL_TIMER_INTERRUPT_CC0_UP_EVENT);
DL_TimerA_setCCPDirection(PWM_0_INST , DL_TIMER_CC0_OUTPUT );
}
/*
* Timer clock configuration to be sourced by BUSCLK / (80000000 Hz)
* timerClkFreq = (timerClkSrc / (timerClkDivRatio * (timerClkPrescale + 1)))
* 1000000 Hz = 80000000 Hz / (1 * (79 + 1))
*/
static const DL_TimerA_ClockConfig gTIMER_0ClockConfig = {
.clockSel = DL_TIMER_CLOCK_BUSCLK,
.divideRatio = DL_TIMER_CLOCK_DIVIDE_1,
.prescale = 79U,
};
/*
* Timer load value (where the counter starts from) is calculated as (timerPeriod * timerClockFreq) - 1
* TIMER_0_INST_LOAD_VALUE = (10 us * 1000000 Hz) - 1
*/
static const DL_TimerA_TimerConfig gTIMER_0TimerConfig = {
.period = TIMER_0_INST_LOAD_VALUE,
.timerMode = DL_TIMER_TIMER_MODE_PERIODIC_UP,
.startTimer = DL_TIMER_STOP,
};
SYSCONFIG_WEAK void SYSCFG_DL_TIMER_0_init(void) {
DL_TimerA_setClockConfig(TIMER_0_INST,
(DL_TimerA_ClockConfig *) &gTIMER_0ClockConfig);
DL_TimerA_initTimerMode(TIMER_0_INST,
(DL_TimerA_TimerConfig *) &gTIMER_0TimerConfig);
DL_TimerA_enableInterrupt(TIMER_0_INST , DL_TIMERA_INTERRUPT_ZERO_EVENT);
DL_TimerA_enableClock(TIMER_0_INST);
}
/* ADC12_0 Initialization */
static const DL_ADC12_ClockConfig gADC12_0ClockConfig = {
.clockSel = DL_ADC12_CLOCK_ULPCLK,
.divideRatio = DL_ADC12_CLOCK_DIVIDE_1,
.freqRange = DL_ADC12_CLOCK_FREQ_RANGE_32_TO_40,
};
SYSCONFIG_WEAK void SYSCFG_DL_ADC12_0_init(void)
{
DL_ADC12_setClockConfig(ADC12_0_INST, (DL_ADC12_ClockConfig *) &gADC12_0ClockConfig);
DL_ADC12_initSeqSample(ADC12_0_INST,
DL_ADC12_REPEAT_MODE_DISABLED, DL_ADC12_SAMPLING_SOURCE_AUTO, DL_ADC12_TRIG_SRC_SOFTWARE,
DL_ADC12_SEQ_START_ADDR_00, DL_ADC12_SEQ_END_ADDR_05, DL_ADC12_SAMP_CONV_RES_12_BIT,
DL_ADC12_SAMP_CONV_DATA_FORMAT_UNSIGNED);
DL_ADC12_configConversionMem(ADC12_0_INST, ADC12_0_ADCMEM_IP1_ADC,
DL_ADC12_INPUT_CHAN_0, DL_ADC12_REFERENCE_VOLTAGE_EXTREF, DL_ADC12_SAMPLE_TIMER_SOURCE_SCOMP0, DL_ADC12_AVERAGING_MODE_DISABLED,
DL_ADC12_BURN_OUT_SOURCE_DISABLED, DL_ADC12_TRIGGER_MODE_AUTO_NEXT, DL_ADC12_WINDOWS_COMP_MODE_DISABLED);
DL_ADC12_configConversionMem(ADC12_0_INST, ADC12_0_ADCMEM_VS_S_F_ADC,
DL_ADC12_INPUT_CHAN_1, DL_ADC12_REFERENCE_VOLTAGE_EXTREF, DL_ADC12_SAMPLE_TIMER_SOURCE_SCOMP0, DL_ADC12_AVERAGING_MODE_DISABLED,
DL_ADC12_BURN_OUT_SOURCE_DISABLED, DL_ADC12_TRIGGER_MODE_AUTO_NEXT, DL_ADC12_WINDOWS_COMP_MODE_DISABLED);
DL_ADC12_configConversionMem(ADC12_0_INST, ADC12_0_ADCMEM_IP2_ADC,
DL_ADC12_INPUT_CHAN_2, DL_ADC12_REFERENCE_VOLTAGE_EXTREF, DL_ADC12_SAMPLE_TIMER_SOURCE_SCOMP0, DL_ADC12_AVERAGING_MODE_DISABLED,
DL_ADC12_BURN_OUT_SOURCE_DISABLED, DL_ADC12_TRIGGER_MODE_AUTO_NEXT, DL_ADC12_WINDOWS_COMP_MODE_DISABLED);
DL_ADC12_configConversionMem(ADC12_0_INST, ADC12_0_ADCMEM_IP2N_ADC,
DL_ADC12_INPUT_CHAN_3, DL_ADC12_REFERENCE_VOLTAGE_EXTREF, DL_ADC12_SAMPLE_TIMER_SOURCE_SCOMP0, DL_ADC12_AVERAGING_MODE_DISABLED,
DL_ADC12_BURN_OUT_SOURCE_DISABLED, DL_ADC12_TRIGGER_MODE_AUTO_NEXT, DL_ADC12_WINDOWS_COMP_MODE_DISABLED);
DL_ADC12_configConversionMem(ADC12_0_INST, ADC12_0_ADCMEM_IP1N_S_ADC,
DL_ADC12_INPUT_CHAN_7, DL_ADC12_REFERENCE_VOLTAGE_EXTREF, DL_ADC12_SAMPLE_TIMER_SOURCE_SCOMP0, DL_ADC12_AVERAGING_MODE_DISABLED,
DL_ADC12_BURN_OUT_SOURCE_DISABLED, DL_ADC12_TRIGGER_MODE_AUTO_NEXT, DL_ADC12_WINDOWS_COMP_MODE_DISABLED);
DL_ADC12_configConversionMem(ADC12_0_INST, ADC12_0_ADCMEM_INPUT_POWER_ADC,
DL_ADC12_INPUT_CHAN_12, DL_ADC12_REFERENCE_VOLTAGE_EXTREF, DL_ADC12_SAMPLE_TIMER_SOURCE_SCOMP0, DL_ADC12_AVERAGING_MODE_DISABLED,
DL_ADC12_BURN_OUT_SOURCE_DISABLED, DL_ADC12_TRIGGER_MODE_AUTO_NEXT, DL_ADC12_WINDOWS_COMP_MODE_DISABLED);
DL_ADC12_setPowerDownMode(ADC12_0_INST,DL_ADC12_POWER_DOWN_MODE_MANUAL);
DL_ADC12_setSampleTime0(ADC12_0_INST,1200);
DL_ADC12_setSampleTime1(ADC12_0_INST,0);
DL_ADC12_enableDMA(ADC12_0_INST);
DL_ADC12_setDMASamplesCnt(ADC12_0_INST,6);
DL_ADC12_enableDMATrigger(ADC12_0_INST,(DL_ADC12_DMA_MEM5_RESULT_LOADED));
/* Enable ADC12 interrupt */
DL_ADC12_clearInterruptStatus(ADC12_0_INST,(DL_ADC12_INTERRUPT_DMA_DONE));
DL_ADC12_enableInterrupt(ADC12_0_INST,(DL_ADC12_INTERRUPT_DMA_DONE));
DL_ADC12_enableConversions(ADC12_0_INST);
}
/* ADC12_1 Initialization */
static const DL_ADC12_ClockConfig gADC12_1ClockConfig = {
.clockSel = DL_ADC12_CLOCK_ULPCLK,
.divideRatio = DL_ADC12_CLOCK_DIVIDE_4,
.freqRange = DL_ADC12_CLOCK_FREQ_RANGE_32_TO_40,
};
SYSCONFIG_WEAK void SYSCFG_DL_ADC12_1_init(void)
{
DL_ADC12_setClockConfig(ADC12_1_INST, (DL_ADC12_ClockConfig *) &gADC12_1ClockConfig);
DL_ADC12_initSeqSample(ADC12_1_INST,
DL_ADC12_REPEAT_MODE_DISABLED, DL_ADC12_SAMPLING_SOURCE_AUTO, DL_ADC12_TRIG_SRC_SOFTWARE,
DL_ADC12_SEQ_START_ADDR_00, DL_ADC12_SEQ_END_ADDR_02, DL_ADC12_SAMP_CONV_RES_12_BIT,
DL_ADC12_SAMP_CONV_DATA_FORMAT_UNSIGNED);
DL_ADC12_configConversionMem(ADC12_1_INST, ADC12_1_ADCMEM_VS_ADC,
DL_ADC12_INPUT_CHAN_1, DL_ADC12_REFERENCE_VOLTAGE_EXTREF, DL_ADC12_SAMPLE_TIMER_SOURCE_SCOMP0, DL_ADC12_AVERAGING_MODE_DISABLED,
DL_ADC12_BURN_OUT_SOURCE_DISABLED, DL_ADC12_TRIGGER_MODE_AUTO_NEXT, DL_ADC12_WINDOWS_COMP_MODE_DISABLED);
DL_ADC12_configConversionMem(ADC12_1_INST, ADC12_1_ADCMEM_I_RPVS_ADC,
DL_ADC12_INPUT_CHAN_2, DL_ADC12_REFERENCE_VOLTAGE_EXTREF, DL_ADC12_SAMPLE_TIMER_SOURCE_SCOMP0, DL_ADC12_AVERAGING_MODE_DISABLED,
DL_ADC12_BURN_OUT_SOURCE_DISABLED, DL_ADC12_TRIGGER_MODE_AUTO_NEXT, DL_ADC12_WINDOWS_COMP_MODE_DISABLED);
DL_ADC12_configConversionMem(ADC12_1_INST, ADC12_1_ADCMEM_COM_ADC,
DL_ADC12_INPUT_CHAN_3, DL_ADC12_REFERENCE_VOLTAGE_EXTREF, DL_ADC12_SAMPLE_TIMER_SOURCE_SCOMP0, DL_ADC12_AVERAGING_MODE_DISABLED,
DL_ADC12_BURN_OUT_SOURCE_DISABLED, DL_ADC12_TRIGGER_MODE_AUTO_NEXT, DL_ADC12_WINDOWS_COMP_MODE_DISABLED);
DL_ADC12_setPowerDownMode(ADC12_1_INST,DL_ADC12_POWER_DOWN_MODE_MANUAL);
DL_ADC12_setSampleTime0(ADC12_1_INST,300);
DL_ADC12_enableDMA(ADC12_1_INST);
DL_ADC12_setDMASamplesCnt(ADC12_1_INST,2);
DL_ADC12_enableDMATrigger(ADC12_1_INST,(DL_ADC12_DMA_MEM2_RESULT_LOADED));
/* Enable ADC12 interrupt */
DL_ADC12_clearInterruptStatus(ADC12_1_INST,(DL_ADC12_INTERRUPT_DMA_DONE));
DL_ADC12_enableInterrupt(ADC12_1_INST,(DL_ADC12_INTERRUPT_DMA_DONE));
DL_ADC12_enableConversions(ADC12_1_INST);
}
static const DL_VREF_Config gVREFConfig = {
.vrefEnable = DL_VREF_ENABLE_DISABLE,
.bufConfig = DL_VREF_BUFCONFIG_OUTPUT_2_5V,
.shModeEnable = DL_VREF_SHMODE_DISABLE,
.holdCycleCount = DL_VREF_HOLD_MIN,
.shCycleCount = DL_VREF_SH_MIN,
};
SYSCONFIG_WEAK void SYSCFG_DL_VREF_init(void) {
DL_VREF_configReference(VREF,
(DL_VREF_Config *) &gVREFConfig);
delay_cycles(VREF_READY_DELAY);
}
static const DL_DMA_Config gDMA_CH0Config = {
.transferMode = DL_DMA_SINGLE_TRANSFER_MODE,
.extendedMode = DL_DMA_NORMAL_MODE,
.destIncrement = DL_DMA_ADDR_INCREMENT,
.srcIncrement = DL_DMA_ADDR_INCREMENT,
.destWidth = DL_DMA_WIDTH_WORD,
.srcWidth = DL_DMA_WIDTH_WORD,
.trigger = ADC12_0_INST_DMA_TRIGGER,
.triggerType = DL_DMA_TRIGGER_TYPE_EXTERNAL,
};
SYSCONFIG_WEAK void SYSCFG_DL_DMA_CH0_init(void)
{
DL_DMA_initChannel(DMA, DMA_CH0_CHAN_ID , (DL_DMA_Config *) &gDMA_CH0Config);
}
static const DL_DMA_Config gDMA_CH1Config = {
.transferMode = DL_DMA_SINGLE_TRANSFER_MODE,
.extendedMode = DL_DMA_NORMAL_MODE,
.destIncrement = DL_DMA_ADDR_INCREMENT,
.srcIncrement = DL_DMA_ADDR_INCREMENT,
.destWidth = DL_DMA_WIDTH_WORD,
.srcWidth = DL_DMA_WIDTH_WORD,
.trigger = ADC12_1_INST_DMA_TRIGGER,
.triggerType = DL_DMA_TRIGGER_TYPE_EXTERNAL,
};
SYSCONFIG_WEAK void SYSCFG_DL_DMA_CH1_init(void)
{
DL_DMA_initChannel(DMA, DMA_CH1_CHAN_ID , (DL_DMA_Config *) &gDMA_CH1Config);
}
SYSCONFIG_WEAK void SYSCFG_DL_DMA_init(void){
SYSCFG_DL_DMA_CH0_init();
SYSCFG_DL_DMA_CH1_init();
}
SYSCONFIG_WEAK void SYSCFG_DL_SYSTICK_init(void)
{
/*
* Initializes the SysTick period to 1.00 ms,
* enables the interrupt, and starts the SysTick Timer
*/
DL_SYSTICK_config(80000);
}
static const DL_DAC12_Config gDAC12Config = {
.outputEnable = DL_DAC12_OUTPUT_ENABLED,
.resolution = DL_DAC12_RESOLUTION_12BIT,
.representation = DL_DAC12_REPRESENTATION_BINARY,
.voltageReferenceSource = DL_DAC12_VREF_SOURCE_VEREFP_VEREFN,
.amplifierSetting = DL_DAC12_AMP_ON,
.fifoEnable = DL_DAC12_FIFO_DISABLED,
.fifoTriggerSource = DL_DAC12_FIFO_TRIGGER_SAMPLETIMER,
.dmaTriggerEnable = DL_DAC12_DMA_TRIGGER_DISABLED,
.dmaTriggerThreshold = DL_DAC12_FIFO_THRESHOLD_ONE_QTR_EMPTY,
.sampleTimeGeneratorEnable = DL_DAC12_SAMPLETIMER_DISABLE,
.sampleRate = DL_DAC12_SAMPLES_PER_SECOND_500,
};
SYSCONFIG_WEAK void SYSCFG_DL_DAC12_init(void)
{
DL_DAC12_init(DAC0, (DL_DAC12_Config *) &gDAC12Config);
DL_DAC12_output12(DAC0, 1000);
DL_DAC12_enable(DAC0);
}
static const DL_MCAN_ClockConfig gMCAN0ClockConf = {
.clockSel = DL_MCAN_FCLK_HFCLK,
.divider = DL_MCAN_FCLK_DIV_1,
};
static const DL_MCAN_InitParams gMCAN0InitParams= {
/* Initialize MCAN Init parameters. */
.fdMode = false,
.brsEnable = false,
.txpEnable = false,
.efbi = false,
.pxhddisable = false,
.darEnable = false,
.wkupReqEnable = true,
.autoWkupEnable = true,
.emulationEnable = true,
.tdcEnable = true,
.wdcPreload = 255,
/* Transmitter Delay Compensation parameters. */
.tdcConfig.tdcf = 10,
.tdcConfig.tdco = 6,
};
static const DL_MCAN_ConfigParams gMCAN0ConfigParams={
/* Initialize MCAN Config parameters. */
.monEnable = false,
.asmEnable = false,
.tsPrescalar = 15,
.tsSelect = 0,
.timeoutSelect = DL_MCAN_TIMEOUT_SELECT_CONT,
.timeoutPreload = 65535,
.timeoutCntEnable = false,
.filterConfig.rrfs = true,
.filterConfig.rrfe = true,
.filterConfig.anfe = 1,
.filterConfig.anfs = 1,
};
static const DL_MCAN_MsgRAMConfigParams gMCAN0MsgRAMConfigParams ={
/* Standard ID Filter List Start Address. */
.flssa = MCAN0_INST_MCAN_STD_ID_FILT_START_ADDR,
/* List Size: Standard ID. */
.lss = MCAN0_INST_MCAN_STD_ID_FILTER_NUM,
/* Extended ID Filter List Start Address. */
.flesa = MCAN0_INST_MCAN_EXT_ID_FILT_START_ADDR,
/* List Size: Extended ID. */
.lse = MCAN0_INST_MCAN_EXT_ID_FILTER_NUM,
/* Tx Buffers Start Address. */
.txStartAddr = MCAN0_INST_MCAN_TX_BUFF_START_ADDR,
/* Number of Dedicated Transmit Buffers. */
.txBufNum = MCAN0_INST_MCAN_TX_BUFF_SIZE,
.txFIFOSize = 0,
/* Tx Buffer Element Size. */
.txBufMode = 0,
.txBufElemSize = DL_MCAN_ELEM_SIZE_8BYTES,
/* Tx Event FIFO Start Address. */
.txEventFIFOStartAddr = MCAN0_INST_MCAN_TX_EVENT_START_ADDR,
/* Event FIFO Size. */
.txEventFIFOSize = MCAN0_INST_MCAN_TX_BUFF_SIZE,
/* Level for Tx Event FIFO watermark interrupt. */
.txEventFIFOWaterMark = 0,
/* Rx FIFO0 Start Address. */
.rxFIFO0startAddr = MCAN0_INST_MCAN_FIFO_0_START_ADDR,
/* Number of Rx FIFO elements. */
.rxFIFO0size = MCAN0_INST_MCAN_FIFO_0_NUM,
/* Rx FIFO0 Watermark. */
.rxFIFO0waterMark = 0,
.rxFIFO0OpMode = 0,
/* Rx FIFO1 Start Address. */
.rxFIFO1startAddr = MCAN0_INST_MCAN_FIFO_1_START_ADDR,
/* Number of Rx FIFO elements. */
.rxFIFO1size = MCAN0_INST_MCAN_FIFO_1_NUM,
/* Level for Rx FIFO 1 watermark interrupt. */
.rxFIFO1waterMark = 3,
/* FIFO blocking mode. */
.rxFIFO1OpMode = 0,
/* Rx Buffer Start Address. */
.rxBufStartAddr = MCAN0_INST_MCAN_RX_BUFF_START_ADDR,
/* Rx Buffer Element Size. */
.rxBufElemSize = DL_MCAN_ELEM_SIZE_8BYTES,
/* Rx FIFO0 Element Size. */
.rxFIFO0ElemSize = DL_MCAN_ELEM_SIZE_8BYTES,
/* Rx FIFO1 Element Size. */
.rxFIFO1ElemSize = DL_MCAN_ELEM_SIZE_8BYTES,
};
static const DL_MCAN_ExtMsgIDFilterElement gMCAN0ExtFiltelem = {
.efec = 0x001,
.eft = 0x10,
.efid1 = 0,
.efid2 = 536870911,
};
static const DL_MCAN_BitTimingParams gMCAN0BitTimes = {
/* Arbitration Baud Rate Pre-scaler. */
.nomRatePrescalar = 0,
/* Arbitration Time segment before sample point. */
.nomTimeSeg1 = 138,
/* Arbitration Time segment after sample point. */
.nomTimeSeg2 = 19,
/* Arbitration (Re)Synchronization Jump Width Range. */
.nomSynchJumpWidth = 19,
/* Data Baud Rate Pre-scaler. */
.dataRatePrescalar = 0,
/* Data Time segment before sample point. */
.dataTimeSeg1 = 0,
/* Data Time segment after sample point. */
.dataTimeSeg2 = 0,
/* Data (Re)Synchronization Jump Width. */
.dataSynchJumpWidth = 0,
};
SYSCONFIG_WEAK void SYSCFG_DL_MCAN0_init(void) {
DL_MCAN_RevisionId revid_MCAN0;
DL_MCAN_setClockConfig(MCAN0_INST, (DL_MCAN_ClockConfig *) &gMCAN0ClockConf);
DL_MCAN_enableModuleClock(MCAN0_INST);
/* Get MCANSS Revision ID. */
DL_MCAN_getRevisionId(MCAN0_INST, &revid_MCAN0);
/* Wait for Memory initialization to be completed. */
while(false == DL_MCAN_isMemInitDone(MCAN0_INST));
/* Put MCAN in SW initialization mode. */
DL_MCAN_setOpMode(MCAN0_INST, DL_MCAN_OPERATION_MODE_SW_INIT);
/* Wait till MCAN is not initialized. */
while (DL_MCAN_OPERATION_MODE_SW_INIT != DL_MCAN_getOpMode(MCAN0_INST));
/* Initialize MCAN module. */
DL_MCAN_init(MCAN0_INST, (DL_MCAN_InitParams *) &gMCAN0InitParams);
/* Configure MCAN module. */
DL_MCAN_config(MCAN0_INST, (DL_MCAN_ConfigParams*) &gMCAN0ConfigParams);
/* Configure Bit timings. */
DL_MCAN_setBitTime(MCAN0_INST, (DL_MCAN_BitTimingParams*) &gMCAN0BitTimes);
/* Configure Message RAM Sections */
DL_MCAN_msgRAMConfig(MCAN0_INST, (DL_MCAN_MsgRAMConfigParams*) &gMCAN0MsgRAMConfigParams);
/* Configure Extended ID filter element*/
DL_MCAN_addExtMsgIDFilter(MCAN0_INST, 0U, (DL_MCAN_ExtMsgIDFilterElement *) &gMCAN0ExtFiltelem);
/* Set Extended ID Mask. */
DL_MCAN_setExtIDAndMask(MCAN0_INST, MCAN0_INST_MCAN_EXT_ID_AND_MASK );
/* Loopback mode */
/* Take MCAN out of the SW initialization mode */
DL_MCAN_setOpMode(MCAN0_INST, DL_MCAN_OPERATION_MODE_NORMAL);
while (DL_MCAN_OPERATION_MODE_NORMAL != DL_MCAN_getOpMode(MCAN0_INST));
/* Enable MCAN mopdule Interrupts */
DL_MCAN_enableIntr(MCAN0_INST, MCAN0_INST_MCAN_INTERRUPTS, 1U);
DL_MCAN_selectIntrLine(MCAN0_INST, DL_MCAN_INTR_MASK_ALL, DL_MCAN_INTR_LINE_NUM_1);
DL_MCAN_enableIntrLine(MCAN0_INST, DL_MCAN_INTR_LINE_NUM_1, 1U);
/* Enable MSPM0 MCAN interrupt */
DL_MCAN_clearInterruptStatus(MCAN0_INST,(DL_MCAN_MSP_INTERRUPT_LINE1));
DL_MCAN_enableInterrupt(MCAN0_INST,(DL_MCAN_MSP_INTERRUPT_LINE1));
}
马建仓 AI 助手
尝试更多
代码解读
代码找茬
代码优化
C
1
https://gitee.com/zyqfeiyue/mspm0g3507-sensor-v1.4.git
git@gitee.com:zyqfeiyue/mspm0g3507-sensor-v1.4.git
zyqfeiyue
mspm0g3507-sensor-v1.4
mspm0g3507SensorV1.4
master

搜索帮助