dhcp attempts
This commit is contained in:
50
src/systick.c
Normal file
50
src/systick.c
Normal file
@@ -0,0 +1,50 @@
|
||||
#include "systick.h"
|
||||
|
||||
#include <stdint.h>
|
||||
|
||||
#include "ch32v003fun.h"
|
||||
|
||||
// ms counter
|
||||
volatile uint32_t systick_millis = 0;
|
||||
|
||||
void systick_init(void) {
|
||||
// Reset any pre-existing configuration
|
||||
SysTick->CTLR = 0x0000;
|
||||
|
||||
// Set the compare register to trigger once per millisecond
|
||||
SysTick->CMP = SYSTICK_ONE_MILLISECOND - 1;
|
||||
|
||||
// Reset the Count Register and variables
|
||||
SysTick->CNT = 0x00000000;
|
||||
systick_millis = 0x00000000;
|
||||
|
||||
// Set the SysTick Configuration
|
||||
// NOTE: By not setting SYSTICK_CTLR_STRE, we maintain compatibility with
|
||||
// busywait delay funtions used by ch32v003_fun.
|
||||
SysTick->CTLR |= SYSTICK_CTLR_STE | // Enable Counter
|
||||
SYSTICK_CTLR_STIE | // Enable Interrupts
|
||||
SYSTICK_CTLR_STCLK; // Set Clock Source to HCLK/1
|
||||
|
||||
// Enable the SysTick IRQ
|
||||
NVIC_EnableIRQ(SysTicK_IRQn);
|
||||
}
|
||||
|
||||
/*
|
||||
* 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) {
|
||||
// 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 the trigger state for the next IRQ
|
||||
SysTick->SR = 0x00000000;
|
||||
|
||||
// Increment the milliseconds count
|
||||
systick_millis++;
|
||||
}
|
||||
Reference in New Issue
Block a user