61 lines
1.6 KiB
C
61 lines
1.6 KiB
C
//
|
|
// Created by cfif on 16.05.23.
|
|
//
|
|
#include "Modem_Timer.h"
|
|
#include "CmsisRtosThreadUtils.h"
|
|
|
|
#define LOGGER env->logger
|
|
#define LOG_SIGN "GONEC"
|
|
|
|
void ModemTimer_Init(tModemTimer *env, tModemMain *modemMain, tSerialPortIO *io, tFileLogger *flog, tGpios *gpios) {
|
|
|
|
env->modemMain = modemMain;
|
|
env->io = io;
|
|
env->flog = flog;
|
|
env->gpios = gpios;
|
|
|
|
InitThreadAtrStatic(&env->thread.attr, "ModemTimer", env->thread.controlBlock, env->thread.stack, osPriorityHigh);
|
|
env->thread.id = 0;
|
|
}
|
|
|
|
extern volatile uint32_t timeModemStuckGetMs;
|
|
|
|
static _Noreturn void ModemTimer_Thread(tModemTimer *env) {
|
|
uint8_t data[] = {'A', 'T', '\r', '\n'};
|
|
|
|
|
|
|
|
for (;;) {
|
|
|
|
if (env->modemMain->location.isOneDateTime == false) {
|
|
|
|
uint32_t dlStuckGetMs = SystemGetMs() - timeModemStuckGetMs;
|
|
|
|
|
|
// Если завис больше 30 секунд
|
|
if (dlStuckGetMs > 30000) {
|
|
GpioPinSet(&env->gpios->Power.gonec_reset, false);
|
|
SystemDelayMs(1000);
|
|
GpioPinSet(&env->gpios->Power.gonec_reset, true);
|
|
SystemDelayMs(6000);
|
|
|
|
timeModemStuckGetMs = SystemGetMs();
|
|
LoggerInfoStatic(LOGGER, LOG_SIGN, "Контроль задачи модема");
|
|
|
|
SerialPortTransmit(env->io, data, 4, 1000);
|
|
}
|
|
|
|
}
|
|
|
|
SystemDelayMs(1000);
|
|
|
|
}
|
|
}
|
|
|
|
void ModemTimer_StartThread(tModemTimer *env) {
|
|
if (!env->thread.id) {
|
|
env->thread.id = osThreadNew((osThreadFunc_t) (ModemTimer_Thread), (void *) (env), &env->thread.attr);
|
|
} else {
|
|
osThreadResume(env->thread.id);
|
|
}
|
|
} |