AMTS/Mieke/SW/ODD/systick.c

46 lines
1.3 KiB
C
Raw Permalink Normal View History

2018-04-03 15:32:24 +00:00
/*
Demo program for the 2017/18 open door day at HTL Hollabrunn
Copyright (C) 2018 Andreas Mieke
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 3 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, see <https://www.gnu.org/licenses/>.
*/
2018-03-18 22:43:59 +00:00
#include "systick.h"
volatile uint32_t SysTickCnt;
void SysTick_Handler()
{
2018-04-03 15:18:28 +00:00
// SysTick_Handler increments SysTickCnt
2018-03-18 22:43:59 +00:00
SysTickCnt++;
}
void systick_init(void)
{
2018-04-03 15:18:28 +00:00
// Init the systick clocks to a T = 1 ms
2018-03-18 22:43:59 +00:00
RCC_ClocksTypeDef clocks;
RCC_GetClocksFreq(&clocks);
SysTick_Config(clocks.HCLK_Frequency/1000 - 1);
2018-04-03 15:18:28 +00:00
// Set count to 0
2018-03-18 22:43:59 +00:00
SysTickCnt = 0;
}
void Wait(uint32_t ms)
{
2018-04-03 15:18:28 +00:00
// Wait specified time in milliseconds
2018-03-18 22:43:59 +00:00
uint32_t SysTickCntHold = SysTickCnt;
2018-04-03 15:18:28 +00:00
while((SysTickCnt - SysTickCntHold) <= ms);
2018-03-18 22:43:59 +00:00
}