Delays driver for AT32F421 MCU

RT-890
Silvano Seva 2023-12-20 13:44:08 +01:00
rodzic 7628b4fc37
commit 1d8b766f9c
2 zmienionych plików z 71 dodań i 0 usunięć

Wyświetl plik

@ -260,6 +260,7 @@ at32f421_src = ['platform/mcu/AT32F421/boot/startup.cpp',
'platform/mcu/AT32F421/boot/bsp.cpp',
'platform/mcu/AT32F421/boot/libc_integration.cpp',
'platform/mcu/AT32F421/drivers/gpio.c',
'platform/mcu/AT32F421/drivers/delays.cpp',
'platform/mcu/CMSIS/Device/Artery/AT32F421/Source/system_at32f421.c']
at32f421_inc = ['platform/mcu/AT32F421',

Wyświetl plik

@ -0,0 +1,70 @@
/***************************************************************************
* Copyright (C) 2023 by Silvano Seva IU2KWO *
* and Niccolò Izzo IU2KIN *
* *
* 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/> *
***************************************************************************/
#include <interfaces/delays.h>
#include <miosix.h>
/**
* Implementation of the delay functions for AT32F421 MCU.
* Delays have been calibrated for a clock frequency of 120MHz.
*/
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, #29 \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=23175;
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");
}
}
void sleepFor(unsigned int seconds, unsigned int mseconds)
{
unsigned int time = (seconds * 1000) + mseconds;
miosix::Thread::sleep(time);
}
void sleepUntil(long long timestamp)
{
miosix::Thread::sleepUntil(timestamp);
}
long long getTick()
{
return miosix::getTick();
}