2018-02-06 17:05:51 +00:00
|
|
|
/*
|
2018-07-19 14:44:39 +00:00
|
|
|
* Copyright (c) 2018, Texas Instruments Incorporated - http://www.ti.com/
|
2018-02-06 17:05:51 +00:00
|
|
|
* All rights reserved.
|
|
|
|
*
|
|
|
|
* Redistribution and use in source and binary forms, with or without
|
|
|
|
* modification, are permitted provided that the following conditions
|
|
|
|
* are met:
|
|
|
|
* 1. Redistributions of source code must retain the above copyright
|
|
|
|
* notice, this list of conditions and the following disclaimer.
|
|
|
|
* 2. Redistributions in binary form must reproduce the above copyright
|
|
|
|
* notice, this list of conditions and the following disclaimer in the
|
|
|
|
* documentation and/or other materials provided with the distribution.
|
|
|
|
* 3. Neither the name of the copyright holder nor the names of its
|
|
|
|
* contributors may be used to endorse or promote products derived
|
|
|
|
* from this software without specific prior written permission.
|
|
|
|
*
|
|
|
|
* THIS SOFTWARE IS PROVIDED BY THE COPYRIGHT HOLDERS AND CONTRIBUTORS
|
|
|
|
* ``AS IS'' AND ANY EXPRESS OR IMPLIED WARRANTIES, INCLUDING, BUT NOT
|
|
|
|
* LIMITED TO, THE IMPLIED WARRANTIES OF MERCHANTABILITY AND FITNESS
|
|
|
|
* FOR A PARTICULAR PURPOSE ARE DISCLAIMED. IN NO EVENT SHALL THE
|
|
|
|
* COPYRIGHT HOLDER OR CONTRIBUTORS BE LIABLE FOR ANY DIRECT, INDIRECT,
|
|
|
|
* INCIDENTAL, SPECIAL, EXEMPLARY, OR CONSEQUENTIAL DAMAGES
|
|
|
|
* (INCLUDING, BUT NOT LIMITED TO, PROCUREMENT OF SUBSTITUTE GOODS OR
|
|
|
|
* SERVICES; LOSS OF USE, DATA, OR PROFITS; OR BUSINESS INTERRUPTION)
|
|
|
|
* HOWEVER CAUSED AND ON ANY THEORY OF LIABILITY, WHETHER IN CONTRACT,
|
|
|
|
* STRICT LIABILITY, OR TORT (INCLUDING NEGLIGENCE OR OTHERWISE)
|
|
|
|
* ARISING IN ANY WAY OUT OF THE USE OF THIS SOFTWARE, EVEN IF ADVISED
|
|
|
|
* OF THE POSSIBILITY OF SUCH DAMAGE.
|
|
|
|
*/
|
|
|
|
/**
|
2018-07-19 14:44:39 +00:00
|
|
|
* \addtogroup cc13xx-cc26xx-cpu
|
2018-02-06 17:05:51 +00:00
|
|
|
* @{
|
|
|
|
*
|
2018-07-19 14:44:39 +00:00
|
|
|
* \defgroup cc13xx-cc26xx-clock CC13xx/CC26xx clock library
|
2018-02-06 17:05:51 +00:00
|
|
|
*
|
|
|
|
* @{
|
|
|
|
* \file
|
2018-07-19 14:44:39 +00:00
|
|
|
* Implementation of the clock libary for CC13xx/CC26xx.
|
|
|
|
* \author
|
|
|
|
* Edvard Pettersen <e.pettersen@ti.com>
|
2018-02-06 17:05:51 +00:00
|
|
|
*/
|
|
|
|
/*---------------------------------------------------------------------------*/
|
2018-07-19 14:44:39 +00:00
|
|
|
#include "contiki.h"
|
|
|
|
#include "sys/etimer.h"
|
|
|
|
/*---------------------------------------------------------------------------*/
|
2018-05-28 11:17:01 +00:00
|
|
|
#include <ti/devices/DeviceFamily.h>
|
|
|
|
#include DeviceFamily_constructPath(driverlib/aon_rtc.h)
|
|
|
|
#include DeviceFamily_constructPath(driverlib/cpu.h)
|
|
|
|
#include DeviceFamily_constructPath(driverlib/interrupt.h)
|
|
|
|
#include DeviceFamily_constructPath(driverlib/prcm.h)
|
|
|
|
#include DeviceFamily_constructPath(driverlib/timer.h)
|
2018-07-19 14:44:39 +00:00
|
|
|
|
2018-02-07 16:20:54 +00:00
|
|
|
#include <ti/drivers/dpl/ClockP.h>
|
2018-07-19 14:44:39 +00:00
|
|
|
#include <ti/drivers/dpl/HwiP.h>
|
2018-02-07 16:20:54 +00:00
|
|
|
#include <ti/drivers/power/PowerCC26XX.h>
|
2018-07-19 14:44:39 +00:00
|
|
|
/*---------------------------------------------------------------------------*/
|
|
|
|
static volatile clock_time_t count;
|
|
|
|
static ClockP_Struct etimer_clock;
|
|
|
|
/*---------------------------------------------------------------------------*/
|
|
|
|
static void
|
|
|
|
clock_update_cb(void)
|
|
|
|
{
|
|
|
|
const uintptr_t key = HwiP_disable();
|
|
|
|
count += 1;
|
|
|
|
HwiP_restore(key);
|
2018-02-06 17:05:51 +00:00
|
|
|
|
2018-07-19 14:44:39 +00:00
|
|
|
/* Notify the etimer system. */
|
2018-07-23 15:49:18 +00:00
|
|
|
if(etimer_pending()) {
|
2018-07-19 14:44:39 +00:00
|
|
|
etimer_request_poll();
|
|
|
|
}
|
|
|
|
}
|
|
|
|
/*---------------------------------------------------------------------------*/
|
|
|
|
static inline clock_time_t
|
|
|
|
get_count(void)
|
|
|
|
{
|
|
|
|
clock_time_t count_read;
|
2018-02-06 17:05:51 +00:00
|
|
|
|
2018-07-19 14:44:39 +00:00
|
|
|
const uintptr_t key = HwiP_disable();
|
|
|
|
count_read = count;
|
|
|
|
HwiP_restore(key);
|
2018-02-07 16:20:54 +00:00
|
|
|
|
2018-07-19 14:44:39 +00:00
|
|
|
return count_read;
|
|
|
|
}
|
2018-02-06 17:05:51 +00:00
|
|
|
/*---------------------------------------------------------------------------*/
|
|
|
|
void
|
|
|
|
clock_init(void)
|
|
|
|
{
|
2018-07-19 14:44:39 +00:00
|
|
|
/* ClockP_getSystemTickPeriod() returns ticks per us. */
|
|
|
|
const uint32_t clockp_ticks_second =
|
2018-07-24 10:16:53 +00:00
|
|
|
(uint32_t)(1000 * 1000) / (CLOCK_SECOND) / ClockP_getSystemTickPeriod();
|
2018-07-19 14:44:39 +00:00
|
|
|
|
2018-02-06 17:05:51 +00:00
|
|
|
count = 0;
|
2018-07-19 14:44:39 +00:00
|
|
|
|
2018-02-07 16:20:54 +00:00
|
|
|
ClockP_Params params;
|
|
|
|
ClockP_Params_init(¶ms);
|
2018-07-19 14:44:39 +00:00
|
|
|
|
2018-07-25 16:16:27 +00:00
|
|
|
params.period = clockp_ticks_second;
|
2018-02-07 16:20:54 +00:00
|
|
|
params.startFlag = true;
|
2018-07-19 14:44:39 +00:00
|
|
|
|
2018-07-25 16:16:27 +00:00
|
|
|
ClockP_construct(&etimer_clock, (ClockP_Fxn)clock_update_cb,
|
2018-07-19 14:44:39 +00:00
|
|
|
clockp_ticks_second, ¶ms);
|
2018-02-06 17:05:51 +00:00
|
|
|
}
|
|
|
|
/*---------------------------------------------------------------------------*/
|
2018-06-29 17:03:17 +00:00
|
|
|
clock_time_t
|
2018-02-06 17:05:51 +00:00
|
|
|
clock_time(void)
|
|
|
|
{
|
2018-07-19 14:44:39 +00:00
|
|
|
return get_count();
|
2018-02-06 17:05:51 +00:00
|
|
|
}
|
|
|
|
/*---------------------------------------------------------------------------*/
|
2018-06-29 17:03:17 +00:00
|
|
|
unsigned long
|
2018-02-06 17:05:51 +00:00
|
|
|
clock_seconds(void)
|
|
|
|
{
|
2018-07-19 14:44:39 +00:00
|
|
|
return (unsigned long)get_count() / CLOCK_SECOND;
|
2018-02-06 17:05:51 +00:00
|
|
|
}
|
|
|
|
/*---------------------------------------------------------------------------*/
|
|
|
|
void
|
|
|
|
clock_wait(clock_time_t i)
|
|
|
|
{
|
2018-07-19 14:44:39 +00:00
|
|
|
clock_time_t start;
|
|
|
|
|
|
|
|
start = clock_time();
|
|
|
|
while(clock_time() - start < i);
|
2018-02-06 17:05:51 +00:00
|
|
|
}
|
|
|
|
/*---------------------------------------------------------------------------*/
|
|
|
|
void
|
2018-07-19 14:44:39 +00:00
|
|
|
clock_delay_usec(uint16_t usec)
|
2018-02-06 17:05:51 +00:00
|
|
|
{
|
2018-07-19 14:44:39 +00:00
|
|
|
ClockP_usleep(usec);
|
2018-02-06 17:05:51 +00:00
|
|
|
}
|
|
|
|
/*---------------------------------------------------------------------------*/
|
|
|
|
/**
|
2018-07-19 14:44:39 +00:00
|
|
|
* \brief Obsolete delay function but we implement it here since some code
|
|
|
|
* still uses it.
|
2018-02-06 17:05:51 +00:00
|
|
|
*/
|
|
|
|
void
|
|
|
|
clock_delay(unsigned int i)
|
|
|
|
{
|
|
|
|
clock_delay_usec(i);
|
|
|
|
}
|
|
|
|
/*---------------------------------------------------------------------------*/
|
|
|
|
/**
|
|
|
|
* @}
|
|
|
|
* @}
|
|
|
|
*/
|