2020-09-23 10:00:39 +00:00
|
|
|
/***************************************************************************
|
2022-06-02 07:56:05 +00:00
|
|
|
* Copyright (C) 2020 - 2022 by Silvano Seva IU2KWO *
|
|
|
|
* and Niccolò Izzo IU2KIN *
|
2020-09-23 10:00:39 +00:00
|
|
|
* *
|
|
|
|
* 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 <http://www.gnu.org/licenses/> *
|
|
|
|
***************************************************************************/
|
|
|
|
|
2020-12-24 15:24:35 +00:00
|
|
|
#include <interfaces/delays.h>
|
2021-03-10 14:17:22 +00:00
|
|
|
#include <miosix.h>
|
2020-09-23 10:00:39 +00:00
|
|
|
|
|
|
|
/**
|
|
|
|
* Implementation of the delay functions for STM32F405 MCU.
|
|
|
|
*/
|
|
|
|
|
|
|
|
void delayUs(unsigned int useconds)
|
|
|
|
{
|
|
|
|
// This delay has been calibrated to take x microseconds
|
|
|
|
// It is written in assembler to be independent on compiler optimization
|
|
|
|
asm volatile(" mov r1, #42 \n"
|
|
|
|
" mul r2, %0, r1 \n"
|
|
|
|
" mov r1, #0 \n"
|
|
|
|
"___loop_u: cmp r1, r2 \n"
|
|
|
|
" itt lo \n"
|
|
|
|
" addlo r1, r1, #1 \n"
|
|
|
|
" blo ___loop_u \n"::"r"(useconds):"r1","r2");
|
|
|
|
}
|
|
|
|
|
|
|
|
void delayMs(unsigned int mseconds)
|
|
|
|
{
|
|
|
|
register const unsigned int count=42000;
|
|
|
|
|
|
|
|
for(unsigned int i=0;i<mseconds;i++)
|
|
|
|
{
|
|
|
|
// This delay has been calibrated to take 1 millisecond
|
|
|
|
// It is written in assembler to be independent on compiler optimization
|
|
|
|
asm volatile(" mov r1, #0 \n"
|
|
|
|
"___loop_m: cmp r1, %0 \n"
|
|
|
|
" itt lo \n"
|
|
|
|
" addlo r1, r1, #1 \n"
|
|
|
|
" blo ___loop_m \n"::"r"(count):"r1");
|
|
|
|
}
|
|
|
|
}
|
2021-03-10 14:17:22 +00:00
|
|
|
|
|
|
|
void sleepFor(unsigned int seconds, unsigned int mseconds)
|
|
|
|
{
|
|
|
|
unsigned int time = (seconds * 1000) + mseconds;
|
|
|
|
miosix::Thread::sleep(time);
|
|
|
|
}
|
|
|
|
|
2022-06-29 15:51:06 +00:00
|
|
|
void sleepUntil(long long timestamp)
|
|
|
|
{
|
|
|
|
miosix::Thread::sleepUntil(timestamp);
|
|
|
|
}
|
|
|
|
|
2021-03-10 14:17:22 +00:00
|
|
|
long long getTick()
|
|
|
|
{
|
|
|
|
return miosix::getTick();
|
|
|
|
}
|