Files
Adafruit_nRF52_Arduino/cores/nRF5/delay.c
T
2017-03-11 00:49:36 +07:00

60 lines
1.4 KiB
C

/*
Copyright (c) 2015 Arduino LLC. All right reserved.
This library is free software; you can redistribute it and/or
modify it under the terms of the GNU Lesser General Public
License as published by the Free Software Foundation; either
version 2.1 of the License, or (at your option) any later version.
This library 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 Lesser General Public License for more details.
You should have received a copy of the GNU Lesser General Public
License along with this library; if not, write to the Free Software
Foundation, Inc., 51 Franklin St, Fifth Floor, Boston, MA 02110-1301 USA
*/
#include "nrf.h"
#include "delay.h"
#include "Arduino.h"
#ifdef __cplusplus
extern "C" {
#endif
uint32_t millis( void )
{
return tick2ms(xTaskGetTickCount());
}
uint32_t micros( void )
{
return tick2us(xTaskGetTickCount());
}
void delay( uint32_t ms )
{
vTaskDelay(ms2tick(ms));
}
void dwt_enable(void)
{
CoreDebug->DEMCR |= CoreDebug_DEMCR_TRCENA_Msk; /* Global Enable for DWT */
DWT->CYCCNT = 0; /* Reset the counter */
DWT->CTRL |= DWT_CTRL_CYCCNTENA_Msk; /* Enable cycle counter */
}
void dwt_disable(void)
{
DWT->CTRL &= ~DWT_CTRL_CYCCNTENA_Msk;
CoreDebug->DEMCR &= ~CoreDebug_DEMCR_TRCENA_Msk;
}
#ifdef __cplusplus
}
#endif