chore: debloat (remove platformio), onewire improvements
Squashed commit of the following: commit 5f16309f629b9928d2134b85ae64af69bc3ebbcd Author: kuwoyuki <kuwoyuki@cock.li> Date: Sun Nov 24 22:55:15 2024 +0600 fix: Makefile, improve onewire retries commit 55496a3bda941b52ff349dc75c9c06eb5a37c07d Author: kuwoyuki <kuwoyuki@cock.li> Date: Mon Nov 18 00:41:18 2024 +0600 fix: make onewire validity less strict commit 3428a9bc9792508972ce3e7e4e35a64f047bca10 Author: kuwoyuki <kuwoyuki@cock.li> Date: Sun Nov 17 23:57:55 2024 +0600 chore: rm bins commit 1594e5ed430522b15466c8afa62ff7fb1b28947c Author: kuwoyuki <kuwoyuki@cock.li> Date: Sun Nov 17 23:32:01 2024 +0600 chore: unplatformiofy
This commit is contained in:
40
timer.c
Normal file
40
timer.c
Normal file
@@ -0,0 +1,40 @@
|
||||
#include "timer.h"
|
||||
|
||||
#include <DHCP/dhcp.h>
|
||||
|
||||
#include "ch32v003fun.h"
|
||||
#include "debug.h"
|
||||
|
||||
void tim2_init(void) {
|
||||
// Enable TIM2 clock
|
||||
RCC->APB1PCENR |= RCC_APB1Periph_TIM2;
|
||||
|
||||
// Reset TIM2 to init all regs
|
||||
RCC->APB1PRSTR |= RCC_APB1Periph_TIM2;
|
||||
RCC->APB1PRSTR &= ~RCC_APB1Periph_TIM2;
|
||||
|
||||
// Set prescaler to 14400-1, 10 kHz timer clock
|
||||
TIM2->PSC = 14400 - 1;
|
||||
|
||||
// Set auto-reload value to 10,000-1 for 1 second overflow
|
||||
TIM2->ATRLR = 10000 - 1;
|
||||
|
||||
// Enable update interrupt
|
||||
TIM2->DMAINTENR |= TIM_UIE;
|
||||
|
||||
// Enable TIM2
|
||||
TIM2->CTLR1 |= TIM_CEN;
|
||||
|
||||
NVIC_SetPriority(TIM2_IRQn, 0x40);
|
||||
NVIC_EnableIRQ(TIM2_IRQn);
|
||||
}
|
||||
|
||||
void TIM2_IRQHandler(void) __attribute__((interrupt));
|
||||
void TIM2_IRQHandler(void) {
|
||||
if (TIM2->INTFR & TIM_UIF) {
|
||||
TIM2->INTFR &= ~TIM_UIF;
|
||||
|
||||
// DEBUG_PRINT("TIM2 IRQ\n");
|
||||
DHCP_time_handler();
|
||||
}
|
||||
}
|
||||
Reference in New Issue
Block a user