设置喂狗时间为1S,并添加M3指令为复位指令,但是可能无效。修改了数据获取方式,从一直持续获取改为每次申请获取。

This commit is contained in:
2024-12-27 00:09:53 +08:00
parent 9a07dba591
commit 4d98e4dc30
6 changed files with 47 additions and 25 deletions

View File

@@ -23,16 +23,24 @@ void watchdog_init(void) {
rcu_osci_on(RCU_IRC40K);
rcu_osci_stab_wait(RCU_IRC40K);
/* Enable the FWDGT clock */
// rcu_periph_clock_enable(RCU_FWDGT);
/* Configure FWDGT counter clock: 40KHz(IRC40K) / 256 = 0.15625 KHz */
fwdgt_config(625, FWDGT_PSC_DIV256); // Set timeout to 4 seconds (625 / 0.15625 KHz)
/* Configure FWDGT counter clock: 40KHz(IRC40K) / 64 = 0.625 KHz */
fwdgt_config(625, FWDGT_PSC_DIV64); // Set timeout to 1 seconds (625 / 0.625 KHz)
/* Enable FWDGT */
fwdgt_enable();
}
void reset_mcu(void) {
/* Enable the write access to the FWDGT_CTL register */
FWDGT_CTL = FWDGT_WRITEACCESS_ENABLE;
/* Configure FWDGT to trigger a system reset */
fwdgt_config(5, FWDGT_PSC_DIV4);
/* Reload the counter to trigger the reset */
fwdgt_counter_reload();
}
/*!
\brief main function
\param[in] none
@@ -57,14 +65,10 @@ int main(void) {
/* Initialize watchdog */
watchdog_init();
printf("Hello, world!\n");
while (1) {
delay_ms(99);
g_eddy_current_value_uint32 = 0;
g_temperature_uint32 = 0;
g_eddy_current_value_uint32 = ldc1612_get_raw_channel_result(CHANNEL_0);
g_temperature_uint32 = tmp112a_get_raw_channel_result();
// printf("1");
fwdgt_counter_reload();
}
}

View File

@@ -53,8 +53,12 @@ void process_command(uint8_t *cmd, size_t length) {
sprintf(combined_str, "%c%c", cmd[3], cmd[4]);
if (strcmp(combined_str, "M1") == 0) {
eddy_current_value_report();
} else if (strcmp(combined_str, "M2") == 0) {
} else if (strcmp(combined_str, "M2") == 0)
{
tempture_value_report();
} else if (strcmp(combined_str, "M3") == 0)
{
reset_mcu();
} else {
printf("%c%c%c%c%c%c%c", 0xB5, 0xF0, 0x03, 0x65, 0x72, 0x72, 0x3C);
return;
@@ -120,10 +124,14 @@ validation_result_t validate_data_length(uint8_t *data) {
}
void eddy_current_value_report(void) {
package_data[0] = (g_eddy_current_value_uint32 >> 24) & 0xFF;
package_data[1] = (g_eddy_current_value_uint32 >> 16) & 0xFF;
package_data[2] = (g_eddy_current_value_uint32 >> 8) & 0xFF;
package_data[3] = g_eddy_current_value_uint32 & 0xFF;
static uint32_t eddy_current_value_uint32 = 0;
eddy_current_value_uint32 = ldc1612_get_raw_channel_result(CHANNEL_0);
package_data[0] = (eddy_current_value_uint32 >> 24) & 0xFF;
package_data[1] = (eddy_current_value_uint32 >> 16) & 0xFF;
package_data[2] = (eddy_current_value_uint32 >> 8) & 0xFF;
package_data[3] = eddy_current_value_uint32 & 0xFF;
uint8_t combined_data[7];
memcpy(combined_data, package_header, 3);
@@ -135,10 +143,14 @@ void eddy_current_value_report(void) {
}
void tempture_value_report(void) {
package_data[0] = (g_temperature_uint32 >> 24) & 0xFF;
package_data[1] = (g_temperature_uint32 >> 16) & 0xFF;
package_data[2] = (g_temperature_uint32 >> 8) & 0xFF;
package_data[3] = g_temperature_uint32 & 0xFF;
static uint32_t temperature_uint32 = 0;
temperature_uint32 = tmp112a_get_raw_channel_result();
package_data[0] = (temperature_uint32 >> 24) & 0xFF;
package_data[1] = (temperature_uint32 >> 16) & 0xFF;
package_data[2] = (temperature_uint32 >> 8) & 0xFF;
package_data[3] = temperature_uint32 & 0xFF;
uint8_t combined_data[7];
memcpy(combined_data, package_header, 3);