1
0
mirror of https://github.com/RIOT-OS/RIOT.git synced 2024-12-29 04:50:03 +01:00
RIOT/boards/native/drivers/native-ltc4150.c

106 lines
2.4 KiB
C
Raw Normal View History

2013-03-06 10:48:14 +01:00
/**
* Native Board ltc4150_arch.h implementation
*
2013-03-13 21:45:28 +01:00
* Only measures time at the moment. Uses POSIX real-time extension
* timer to generate periodic signal/interrupt.
*
2013-03-06 10:48:14 +01:00
* Copyright (C) 2013 Ludwig Ortmann
*
2013-11-23 13:11:23 +01:00
* This file is subject to the terms and conditions of the LGPLv2. See
* the file LICENSE in the top level directory for more details.
2013-03-06 10:48:14 +01:00
*
2013-03-13 21:45:28 +01:00
* @ingroup native_board
* @ingroup ltc4150
2013-03-06 10:48:14 +01:00
* @{
* @file
* @author Ludwig Ortmann <ludwig.ortmann@fu-berlin.de>
*/
2013-03-06 01:10:50 +01:00
#include <stdio.h>
#include <signal.h>
#include <time.h>
#include <err.h>
#include "ltc4150_arch.h"
#include "cpu.h"
#include "cpu-conf.h"
#include "hwtimer.h"
2013-12-18 20:36:42 +01:00
#include "irq.h"
2013-03-06 01:10:50 +01:00
2013-12-17 17:23:41 +01:00
#define ENABLE_DEBUG (0)
#include "debug.h"
#define LTC_TIMER_INTERVAL (10 * 1000UL) // 10 ms
2013-03-06 01:10:50 +01:00
2013-12-17 17:23:41 +01:00
static int _native_ltc_hwtimer_id = -1;
/**
* native ltc4150 hwtimer - interrupt handler proxy
*/
static void _native_ltc_int_handler()
{
2013-12-17 17:23:41 +01:00
DEBUG("_native_ltc_int_handler()\n");
if (_native_ltc_hwtimer_id != -1) {
ltc4150_interrupt();
_native_ltc_hwtimer_id = hwtimer_set(LTC_TIMER_INTERVAL, _native_ltc_int_handler, NULL);
if (_native_ltc_hwtimer_id == -1) {
errx(1, "_int_handler: hwtimer_set");
}
2013-12-17 17:23:41 +01:00
else {
DEBUG("_native_ltc_int_handler: _native_ltc_hwtimer_id is %d\n", _native_ltc_hwtimer_id);
}
}
else {
DEBUG("_native_ltc_int_handler was called although no hwtimer is set\n");
}
}
2013-03-06 01:10:50 +01:00
2013-03-13 21:45:28 +01:00
/**
* unregister signal handler
*/
2013-03-06 01:10:50 +01:00
void ltc4150_disable_int(void)
{
2013-12-18 20:36:42 +01:00
unsigned state = disableIRQ();
2013-03-06 01:10:50 +01:00
DEBUG("ltc4150_disable_int()\n");
if (_native_ltc_hwtimer_id != -1) {
hwtimer_remove(_native_ltc_hwtimer_id);
_native_ltc_hwtimer_id = -1;
}
2013-12-18 20:36:42 +01:00
restoreIRQ(state);
2013-03-06 01:10:50 +01:00
}
2013-03-13 21:45:28 +01:00
/**
* register signal handler
*/
2013-03-06 01:10:50 +01:00
void ltc4150_enable_int(void)
{
DEBUG("ltc4150_enable_int()\n");
_native_ltc_hwtimer_id = hwtimer_set(LTC_TIMER_INTERVAL, _native_ltc_int_handler, NULL);
if (_native_ltc_hwtimer_id == -1) {
errx(1, "ltc4150_enable_int: hwtimer_set");
}
2013-12-17 17:23:41 +01:00
else {
DEBUG("ltc4150_enable_int: _native_ltc_hwtimer_id is %d\n", _native_ltc_hwtimer_id);
}
2013-03-06 01:10:50 +01:00
}
2013-03-13 21:45:28 +01:00
/**
* elaborate nop
*/
2013-03-06 01:10:50 +01:00
void ltc4150_sync_blocking(void)
{
DEBUG("ltc4150_sync_blocking()\n");
}
2013-03-13 21:45:28 +01:00
/**
* set up posix real-time timer to simulate coloumb counter ticks
*/
2013-03-06 01:10:50 +01:00
void ltc4150_arch_init(void)
{
ltc4150_disable_int();
puts("Native LTC4150 initialized.");
}
2013-03-13 21:45:28 +01:00
/** @} */