123456789101112131415161718192021222324252627282930313233343536373839404142434445464748495051525354555657585960616263646566676869707172737475767778798081828384858687888990919293 |
- #include "ch.h"
- #if !defined(SYSTEM_CLOCK)
- #define SYSTEM_CLOCK 8000000U
- #endif
- CH_IRQ_HANDLER(SysTick_Handler) {
- CH_IRQ_PROLOGUE();
- chSysLockFromISR();
- chSysTimerHandlerI();
- chSysUnlockFromISR();
- CH_IRQ_EPILOGUE();
- }
- static uint32_t seconds_counter;
- static uint32_t minutes_counter;
- static THD_WORKING_AREA(waThread1, 128);
- static THD_FUNCTION(Thread1, arg) {
- (void)arg;
- chRegSetThreadName("counter");
- while (true) {
- chThdSleepMilliseconds(1000);
- seconds_counter++;
- }
- }
- int main(void) {
-
- SysTick->LOAD = SYSTEM_CLOCK / CH_CFG_ST_FREQUENCY - (systime_t)1;
- SysTick->VAL = (uint32_t)0;
- SysTick->CTRL = SysTick_CTRL_CLKSOURCE_Msk | SysTick_CTRL_ENABLE_Msk |
- SysTick_CTRL_TICKINT_Msk;
-
- NVIC_SetPriority(SysTick_IRQn, 1);
-
- chSysInit();
-
- (void) chThdCreateStatic(waThread1, sizeof(waThread1), NORMALPRIO, Thread1, NULL);
-
- while (true) {
- chThdSleepSeconds(60);
- minutes_counter++;
- }
- }
|