62 lines
1.7 KiB
C
62 lines
1.7 KiB
C
/*
|
|
Copyright (c) 2015 Arduino LLC. All right reserved.
|
|
Copyright (c) 2016 Sandeep Mistry 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 "Arduino.h"
|
|
|
|
#ifdef __cplusplus
|
|
extern "C" {
|
|
#endif
|
|
|
|
#define BOOTLOADER_DFU_SERIAL_MAGIC 0x4e
|
|
#define BOOTLOADER_DFU_OTA_FULLRESET_MAGIC 0xA8
|
|
|
|
void init( void )
|
|
{
|
|
#if defined( USE_LFXO )
|
|
// 32Khz XTAL
|
|
NRF_CLOCK->LFCLKSRC = (uint32_t)((CLOCK_LFCLKSRC_SRC_Xtal << CLOCK_LFCLKSRC_SRC_Pos) & CLOCK_LFCLKSRC_SRC_Msk);
|
|
#elif defined(USE_LFRC)
|
|
// Internal OSC
|
|
NRF_CLOCK->LFCLKSRC = (uint32_t)((CLOCK_LFCLKSRC_SRC_RC << CLOCK_LFCLKSRC_SRC_Pos) & CLOCK_LFCLKSRC_SRC_Msk);
|
|
#else
|
|
#error Clock Source is not configured, define USE_LFXO or USE_LFRC according to your board
|
|
#endif
|
|
|
|
NRF_CLOCK->TASKS_LFCLKSTART = 1UL;
|
|
}
|
|
|
|
void enterSerialDfu(void)
|
|
{
|
|
NRF_POWER->GPREGRET = BOOTLOADER_DFU_SERIAL_MAGIC;
|
|
NVIC_SystemReset();
|
|
}
|
|
|
|
void enterOTADfu(void)
|
|
{
|
|
NRF_POWER->GPREGRET = BOOTLOADER_DFU_OTA_FULLRESET_MAGIC;
|
|
NVIC_SystemReset();
|
|
}
|
|
|
|
|
|
#ifdef __cplusplus
|
|
}
|
|
#endif
|