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
47 lines
1.3 KiB
C
47 lines
1.3 KiB
C
#include "systick.h"
|
|
|
|
#include "MQTT/mqtt_interface.h"
|
|
#include "ch32v003fun.h"
|
|
#include "debug.h"
|
|
|
|
// ms counter
|
|
volatile uint32_t systick_millis = 0;
|
|
|
|
void systick_init(void) {
|
|
SysTick->CTLR = 0;
|
|
SysTick->CMP = SYSTICK_ONE_MILLISECOND - 1;
|
|
SysTick->CNT = 0;
|
|
systick_millis = 0;
|
|
|
|
// Enable the SysTick IRQ
|
|
NVIC_SetPriority(SysTicK_IRQn, 0x60);
|
|
NVIC_EnableIRQ(SysTicK_IRQn);
|
|
/* Enable SysTick counter, IRQ, HCLK/1 */
|
|
SysTick->CTLR = SYSTICK_CTLR_STE | SYSTICK_CTLR_STIE | SYSTICK_CTLR_STCLK;
|
|
}
|
|
|
|
/*
|
|
* SysTick ISR - must be lightweight to prevent the CPU from bogging down.
|
|
* Increments Compare Register and systick_millis when triggered (every 1ms)
|
|
* NOTE: the `__attribute__((interrupt))` attribute is very important
|
|
*/
|
|
void SysTick_Handler(void) __attribute__((interrupt));
|
|
void SysTick_Handler(void) {
|
|
// if (toggle_state) {
|
|
// GPIOB->BSHR = (1 << 9); // Set PB9 high
|
|
// } else {
|
|
// GPIOB->BCR = (1 << 9); // Set PB9 low
|
|
// }
|
|
// toggle_state = !toggle_state;
|
|
// Increment the Compare Register for the next trigger
|
|
// If more than this number of ticks elapse before the trigger is reset,
|
|
// you may miss your next interrupt trigger
|
|
// (Make sure the IQR is lightweight and CMP value is reasonable)
|
|
SysTick->CMP += SYSTICK_ONE_MILLISECOND;
|
|
|
|
// clear irq
|
|
SysTick->SR = 0;
|
|
systick_millis++;
|
|
MilliTimer_Handler();
|
|
}
|