<commit_before>/**
 * Native Board ltc4150_arch.h implementation
 *
 * Only measures time at the moment. Uses POSIX real-time extension
 * timer to generate periodic signal/interrupt.
 *
 * Copyright (C) 2013 <NAME>
 *
 * This file is subject to the terms and conditions of the LGPLv2. See
 * the file LICENSE in the top level directory for more details.
 *
 * @ingroup native_board
 * @ingroup ltc4150
 * @{
 * @file
 * @author  <NAME> <<EMAIL>>
 */

#include <stdio.h>
#include <signal.h>
#include <time.h>
#include <err.h>

#include "ltc4150_arch.h"
#include "debug.h"

#include "cpu.h"
#include "cpu-conf.h"
#include "hwtimer.h"

#define LTC_TIMER_INTERVAL (10 * 1000UL) // 10 ms

static int _native_ltc_int_enabled;
static int _native_ltc_hwtimer_id;

/**
 * native ltc4150 hwtimer - interrupt handler proxy
 */
static void _native_ltc_int_handler()
{
    DEBUG("ltc4150 _int_handler()\n");
    ltc4150_interrupt();
    if (_native_ltc_int_enabled == 1) {
        _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");
        }
    }
}

/**
 * unregister signal handler
 */
void ltc4150_disable_int(void)
{
    DEBUG("ltc4150_disable_int()\n");
    _native_ltc_int_enabled = 0;
    hwtimer_remove(_native_ltc_hwtimer_id);
}

/**
 * register signal handler
 */
void ltc4150_enable_int(void)
{
    DEBUG("ltc4150_enable_int()\n");
    _native_ltc_int_enabled = 1;
    _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");
    }
}

/**
 * elaborate nop
 */
void ltc4150_sync_blocking(void)
{
    DEBUG("ltc4150_sync_blocking()\n");
}

/**
 * set up posix real-time timer to simulate coloumb counter ticks
 */
void ltc4150_arch_init(void)
{
    ltc4150_disable_int();

    puts("Native LTC4150 initialized.");
}
/** @} */<commit_msg>initialize id and only remove a valid timer<commit_after>/**
 * Native Board ltc4150_arch.h implementation
 *
 * Only measures time at the moment. Uses POSIX real-time extension
 * timer to generate periodic signal/interrupt.
 *
 * Copyright (C) 2013 <NAME>
 *
 * This file is subject to the terms and conditions of the LGPLv2. See
 * the file LICENSE in the top level directory for more details.
 *
 * @ingroup native_board
 * @ingroup ltc4150
 * @{
 * @file
 * @author  <NAME> <<EMAIL>>
 */

#include <stdio.h>
#include <signal.h>
#include <time.h>
#include <err.h>

#include "ltc4150_arch.h"
#include "debug.h"

#include "cpu.h"
#include "cpu-conf.h"
#include "hwtimer.h"

#define LTC_TIMER_INTERVAL (10 * 1000UL) // 10 ms

static int _native_ltc_int_enabled;
static int _native_ltc_hwtimer_id;

/**
 * native ltc4150 hwtimer - interrupt handler proxy
 */
static void _native_ltc_int_handler()
{
    DEBUG("ltc4150 _int_handler()\n");
    ltc4150_interrupt();
    if (_native_ltc_int_enabled == 1) {
        _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");
        }
    }
}

/**
 * unregister signal handler
 */
void ltc4150_disable_int(void)
{
    DEBUG("ltc4150_disable_int()\n");
    _native_ltc_int_enabled = 0;
    if (_native_ltc_hwtimer_id != -1) {
        hwtimer_remove(_native_ltc_hwtimer_id);
        _native_ltc_hwtimer_id = -1;
    }
}

/**
 * register signal handler
 */
void ltc4150_enable_int(void)
{
    DEBUG("ltc4150_enable_int()\n");
    _native_ltc_int_enabled = 1;
    _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");
    }
}

/**
 * elaborate nop
 */
void ltc4150_sync_blocking(void)
{
    DEBUG("ltc4150_sync_blocking()\n");
}

/**
 * set up posix real-time timer to simulate coloumb counter ticks
 */
void ltc4150_arch_init(void)
{
    _native_ltc_hwtimer_id = -1;
    ltc4150_disable_int();

    puts("Native LTC4150 initialized.");
}
/** @} */
{'fraction_non_alphanumeric': 0.12276029055690073, 'fraction_numerical': 0.041404358353510896, 'mean_word_length': 3.842907385697538, 'pattern_counts': {'":': 0, '<': 19, '<?xml version=': 0, '>': 19, 'https://': 0, 'lorem ipsum': 0, 'www.': 0, 'xml': 0}, 'pii_count': 0, 'substrings_counts': 0, 'word_list_counts': {'cursed_substrings.json': 0, 'profanity_word_list.json': 0, 'sexual_word_list.json': 0, 'zh_pornsignals.json': 0}}
{'dir': 'git-commits-cleaned', 'id': '2541729', 'n_tokens_mistral': 1667, 'n_tokens_neox': 1572, 'n_words': 332}