This commit is contained in:
sunbeam 2025-02-05 14:07:51 +08:00
parent 1c27e6d539
commit cae5c4a0a6
10 changed files with 134 additions and 47 deletions

View File

@ -25,7 +25,7 @@ if not "%~1" == "" goto debugFile
@echo on
"D:\software\IAR\common\bin\cspybat" -f "E:\work\wk\K86\CVM0118BOOT\cva_asw_m0118\settings\cva_asw_m0118.Debug.general.xcl" --backend -f "E:\work\wk\K86\CVM0118BOOT\cva_asw_m0118\settings\cva_asw_m0118.Debug.driver.xcl"
"D:\Program Files\IAR Systems\Embedded Workbench 9.2\common\bin\cspybat" -f "F:\work\wk\2025\K86\code\cva_asw_m0118\settings\cva_asw_m0118.Debug.general.xcl" --backend -f "F:\work\wk\2025\K86\code\cva_asw_m0118\settings\cva_asw_m0118.Debug.driver.xcl"
@echo off
goto end
@ -34,7 +34,7 @@ goto end
@echo on
"D:\software\IAR\common\bin\cspybat" -f "E:\work\wk\K86\CVM0118BOOT\cva_asw_m0118\settings\cva_asw_m0118.Debug.general.xcl" "--debug_file=%~1" --backend -f "E:\work\wk\K86\CVM0118BOOT\cva_asw_m0118\settings\cva_asw_m0118.Debug.driver.xcl"
"D:\Program Files\IAR Systems\Embedded Workbench 9.2\common\bin\cspybat" -f "F:\work\wk\2025\K86\code\cva_asw_m0118\settings\cva_asw_m0118.Debug.general.xcl" "--debug_file=%~1" --backend -f "F:\work\wk\2025\K86\code\cva_asw_m0118\settings\cva_asw_m0118.Debug.driver.xcl"
@echo off
:end

View File

@ -23,9 +23,9 @@
if ($debugfile -eq "")
{
& "D:\software\IAR\common\bin\cspybat" -f "E:\work\wk\K86\CVM0118BOOT\cva_asw_m0118\settings\cva_asw_m0118.Debug.general.xcl" --backend -f "E:\work\wk\K86\CVM0118BOOT\cva_asw_m0118\settings\cva_asw_m0118.Debug.driver.xcl"
& "D:\Program Files\IAR Systems\Embedded Workbench 9.2\common\bin\cspybat" -f "F:\work\wk\2025\K86\code\cva_asw_m0118\settings\cva_asw_m0118.Debug.general.xcl" --backend -f "F:\work\wk\2025\K86\code\cva_asw_m0118\settings\cva_asw_m0118.Debug.driver.xcl"
}
else
{
& "D:\software\IAR\common\bin\cspybat" -f "E:\work\wk\K86\CVM0118BOOT\cva_asw_m0118\settings\cva_asw_m0118.Debug.general.xcl" --debug_file=$debugfile --backend -f "E:\work\wk\K86\CVM0118BOOT\cva_asw_m0118\settings\cva_asw_m0118.Debug.driver.xcl"
& "D:\Program Files\IAR Systems\Embedded Workbench 9.2\common\bin\cspybat" -f "F:\work\wk\2025\K86\code\cva_asw_m0118\settings\cva_asw_m0118.Debug.general.xcl" --debug_file=$debugfile --backend -f "F:\work\wk\2025\K86\code\cva_asw_m0118\settings\cva_asw_m0118.Debug.driver.xcl"
}

View File

@ -6,7 +6,7 @@
"-p"
"D:\software\IAR\arm\config\debugger\CVAChip\CVM0118.ddf"
"D:\Program Files\IAR Systems\Embedded Workbench 9.2\arm\config\debugger\CVAChip\CVM0118.ddf"
"--semihosting"

View File

@ -1,10 +1,10 @@
"D:\software\IAR\arm\bin\armPROC.dll"
"D:\Program Files\IAR Systems\Embedded Workbench 9.2\arm\bin\armPROC.dll"
"D:\software\IAR\arm\bin\armJLINK.dll"
"D:\Program Files\IAR Systems\Embedded Workbench 9.2\arm\bin\armJLINK.dll"
"E:\work\wk\K86\CVM0118BOOT\cva_asw_m0118\Debug_FLASH\Exe\cva_asw_m0118.out"
"F:\work\wk\2025\K86\code\cva_asw_m0118\Debug_FLASH\Exe\cva_asw_m0118.out"
--plugin="D:\software\IAR\arm\bin\armbat.dll"
--plugin="D:\Program Files\IAR Systems\Embedded Workbench 9.2\arm\bin\armbat.dll"

View File

@ -13,11 +13,11 @@
</Stack>
<PlDriver>
<FirstRun>0</FirstRun>
<MemConfigValue>D:\software\IAR\arm\config\debugger\CVAChip\CVM0118.ddf</MemConfigValue>
<MemConfigValue>D:\Program Files\IAR Systems\Embedded Workbench 9.2\arm\config\debugger\CVAChip\CVM0118.ddf</MemConfigValue>
</PlDriver>
<ArmDriver>
<EnforceMemoryConfiguration>1</EnforceMemoryConfiguration>
<EnableCache>0</EnableCache>
<EnforceMemoryConfiguration>1</EnforceMemoryConfiguration>
</ArmDriver>
<DebugChecksum>
<Checksum>334396109</Checksum>

File diff suppressed because one or more lines are too long

View File

@ -110,7 +110,7 @@ void appTask(void)
CANMsgTask();
if (gSystick1msCnt % 5 == 0)
{
AD_Task();
}
if (gSystick1msCnt % 50 == 0)
{

View File

@ -5,6 +5,7 @@
#include "appTask.h"
#include "can_message.h"
#include "key.h"
#include "hwctrl.h"
/*******************************************************************************
* the defines
******************************************************************************/
@ -267,7 +268,7 @@ void FillK86Msg(uint8_t *pdata)
uint8_t K86MsgBuf[8] = {0};
void CANMsgTask(void)//1ms task
{
static uint16_t msg_counter=0;
static uint16_t msg_counter=0,test_conter=0;
FlexCan_FrameStructureType rxMsg;
FillK86Msg(K86MsgBuf);
if ((K86MsgBuf[0] & 0x3F) != 0)
@ -286,7 +287,19 @@ void CANMsgTask(void)//1ms task
{
TxK86Msg(K86MsgBuf);
}
test_conter++;
if (test_conter >= 500)
{
test_conter = 0;
uint16_t temp = getBatVoltage();
uint8_t buf[8] = {0};
buf[0] = (temp >> 8) & 0xFF;
buf[1] = temp & 0xFF;
temp = getACCVoltage();
buf[2] = (temp >> 8) & 0xFF;
buf[3] = temp & 0xFF;
TxTestMsg(buf);
}
if (msg_counter >= 1000)

View File

@ -19,11 +19,16 @@
******************************************************************************/
extern McuType mcu;
uint32_t gCpuClockFrequency = 0;
uint32_t adcResult[8];
/*******************************************************************************
* the const
******************************************************************************/
/*! \brief The trgmux in out mappings table for trgmux configure
*/
const TrgMuxDrv_InOutMappingType c_trgmuxInOutMappings[] = {
{TRGMUXDRV_TRIGSOURCE_SIM_SW_TRIG, TRGMUXDRV_TARGETMODULE_PDB0_TRG_IN, false}, /* Use SIM_SW_TRIG trigger PDB0 */
};
const uint16_t c_numOfTrgmuxInOutMappings = sizeof(c_trgmuxInOutMappings) / sizeof(TrgMuxDrv_InOutMappingType);
/*******************************************************************************
@ -31,7 +36,7 @@
******************************************************************************/
static void hw_clock_init(void);
static void GPIO_init(void);
static void AD_Init(void);
void hw_init(void)
@ -48,6 +53,8 @@ void hw_init(void)
/* get CAN controller default configuration */
FlexCanBoot_Init();
AD_Init();
GPIO_init();
}
@ -71,6 +78,16 @@ static void hw_clock_init(void)
ClockDrv_ConfigureClock(&mcu.clockDrv, CLOCKDRV_PORTD, &clockConfig);
ClockDrv_ConfigureClock(&mcu.clockDrv, CLOCKDRV_PORTE, &clockConfig);
/* Enable the clock for ADC */
clockConfig.gating = true;
clockConfig.source = CLOCKDRV_PLL;
clockConfig.div = 4;
ClockDrv_ConfigureClock(&mcu.clockDrv, CLOCKDRV_ADC, &clockConfig);
/* Enable the clock for PDB0 */
clockConfig.gating = true;
ClockDrv_ConfigureClock(&mcu.clockDrv, CLOCKDRV_PDB, &clockConfig);
/* Set system tick clock, 1ms event */
ClockDrv_GetFreq(&mcu.clockDrv, CLOCKDRV_SYS, &gCpuClockFrequency);
@ -132,3 +149,59 @@ uint8_t getKeyIO(KEYID_t keyid)
}
}
static void AD_Init(void)
{
/* TRGMUX */
TrgMuxDrv_ConfigType trgmuxConfig;
trgmuxConfig.numOfInOutMappings = c_numOfTrgmuxInOutMappings;
trgmuxConfig.inOutMapping = c_trgmuxInOutMappings;
TrgMuxDrv_Configure(&mcu.trgMuxDrv, &trgmuxConfig);
/* Configure ADC module */
AdcDrv_ConfigType adcCfg;
AdcDrv_GetDefaultConfig(&adcCfg);
adcCfg.conversionMode = ADCDRV_CONVERSION_12BIT; /* Selects the ADC resolution to 12-bit conversion */
adcCfg.avgEnable = true; /* Enable hardware average function */
adcCfg.avgSamplesSel = ADCDRV_AVERAGE_32; /* Select 32 samples average */
adcCfg.continuousMode = ADCDRV_ONESHOT; /* Select one-shot mode */
adcCfg.chnCfg[0].chnSel = ADCDRV_INCHN_EXT10;
adcCfg.chnCfg[1].chnSel = ADCDRV_INCHN_EXT11;
AdcDrv_Configure(&mcu.adcDrv, &adcCfg);
uint32_t pdbFreq;
ClockDrv_GetFreq(&mcu.clockDrv, CLOCKDRV_PDB, &pdbFreq);
PdbDrv_ConfigType pdbCfg;
PdbDrv_GetDefaultConfig(&pdbCfg);
pdbCfg.ldmode = PDBDRV_LDMOD_LOAD_VAL_IMMEDIATELY; /* The internal registers are loaded with the values from their buffers, immediately after 1 is written to LDOK */
pdbCfg.trgInSel = PDBDRV_TRGSEL_TRGGER_IN_0; /* Use hardware trigger source */
pdbCfg.cMode = PDBDRV_CONT_CONTINUOUS; /* PDB operation in Continuous mode */
pdbCfg.prescalerFactor = PDBDRV_PRESCALER_128MULT; /* Counting uses the peripheral clock divided by MULT (the multiplication factor) */
pdbCfg.mult = PDBDRV_MULT_FACTOR_40; /* Multiplication factor is 40 */
pdbCfg.preTrgCfg.mode[0][0] = PDBDRV_PRETRG_DELAY_MODE; /* The first channel start with delay operation */
pdbCfg.preTrgCfg.mode[0][1] = PDBDRV_PRETRG_BB_MODE; /* PDB channel[0][1-7] with Back-to-Back operation*/
pdbCfg.dlyCfg.modCnt = 1*pdbFreq / 128 / 40 / 1000; /* Periodic triggering PDB in 1ms*/
pdbCfg.dlyCfg.dlyCnt[0][0] = 0; /* first channel don't need delay time*/
PdbDrv_Configure(&mcu.pdbDrv, &pdbCfg);
PdbDrv_EnablePdb(&mcu.pdbDrv); /* Enable PDB0 */
TrgMuxDrv_GenSWTrigger(&mcu.trgMuxDrv, 100); /* Trigger PDB0 */
}
void AD_Task(void)
{
adcResult[0] = AdcDrv_GetRn(&mcu.adcDrv, 0);
adcResult[1] = AdcDrv_GetRn(&mcu.adcDrv, 0);
}
uint16_t getBatVoltage(void)
{
return adcResult[0];
}
uint16_t getACCVoltage(void)
{
return adcResult[1];
}

View File

@ -27,7 +27,8 @@
******************************************************************************/
void hw_init(void);
uint8_t getKeyIO(KEYID_t keyid);
void AD_Task(void);
uint16_t getBatVoltage(void);
uint16_t getACCVoltage(void);
#endif