2018-12-20 22:14:27 +03:00

63 lines
1.9 KiB
C

/*
* main.c
*
* Copyright 2018 Edward V. Emelianoff <eddy@sao.ru, edward.emelianoff@gmail.com>
*
* This program is free software; you can redistribute it and/or modify
* it under the terms of the GNU General Public License as published by
* the Free Software Foundation; either version 2 of the License, or
* (at your option) any later version.
*
* This program is distributed in the hope that it will be useful,
* but WITHOUT ANY WARRANTY; without even the implied warranty of
* MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the
* GNU General Public License for more details.
*
* You should have received a copy of the GNU General Public License
* along with this program; if not, write to the Free Software
* Foundation, Inc., 51 Franklin Street, Fifth Floor, Boston,
* MA 02110-1301, USA.
*/
#include "stm32f0.h"
#include "hardware.h"
#include "usart.h"
#include "adc.h"
#include "protocol.h"
volatile uint32_t Tms = 0;
// Called when systick fires
void sys_tick_handler(void){
++Tms;
}
int main(void){
// uint32_t lastT = 0;
char *txt;
hw_setup();
SysTick_Config(6000, 1);
usart1_send_blocking("Chiller controller v0.1\n", 0);
if(RCC->CSR & RCC_CSR_IWDGRSTF){ // watchdog reset occured
usart1_send("WDGRESET=1\n", 0);
}
if(RCC->CSR & RCC_CSR_SFTRSTF){ // software reset occured
usart1_send("SOFTRESET=1\n", 0);
}
RCC->CSR |= RCC_CSR_RMVF; // remove reset flags
while (1){
IWDG->KR = IWDG_REFRESH;
/*if(lastT > Tms || Tms - lastT > 499){
lastT = Tms;
}*/
if(usart1_getline(&txt)){ // usart1 received command, process it
txt = process_command(txt);
}else txt = NULL;
if(txt){ // text waits for sending
while(ALL_OK != usart1_send(txt, 0)){
IWDG->KR = IWDG_REFRESH;
}
}
}
}