<commit_before>/**
 * @file Cosa/Watchdog.h
 * @version 1.0
 *
 * @section License
 * Copyright (C) 2012, <NAME>
 *
 * 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., 59 Temple Place, Suite 330,
 * Boston, MA  02111-1307  USA
 *
 * @section Description
 * Watchdog abstraction. Low power timer.
 *
 * This file is part of the Arduino Che Cosa project.
 */

#ifndef __COSA_WATCHDOG_H__
#define __COSA_WATCHDOG_H__

#include <avr/wdt.h>
#include <avr/sleep.h>

#include "Cosa/Types.h"
#include "Cosa/Bits.h"
#include "Cosa/Event.h"
#include "Cosa/Thing.h"
#include "Cosa/Things.h"

class Watchdog {

public:
  /**
   * Interrupt handler function prototype.
   * @param[in] env interrupt handler environment.
   */
  typedef void (*InterruptHandler)(void* env);

  /**
   * Callback function prototype for await condition function.
   * Return true(1) to return from await() otherwise false(0).
   * @param[in] env condition function environment.
   * @return bool
   */
  typedef bool (*AwaitCondition)(void* env);

private:
  static InterruptHandler _handler;
  static void* _env;

  static const uint8_t TIMEQ_MAX = 10;
  static Things _timeq[TIMEQ_MAX];

  static volatile uint16_t _ticks;
  static uint8_t _prescale;
  static uint8_t _mode;
  
public:
  /**
   * Get number of watchdog cycles.
   * @return number of ticks.
   */
  static uint16_t get_ticks() 
  { 
    return (_ticks); 
  }

  /**
   * Get number of milli-seconds per tick.
   * @return milli-seconds.
   */
  static uint16_t ms_per_tick() 
  { 
    return (16 << _prescale); 
  }

  /**
   * Set watchdog timeout interrupt handler.
   * @param[in] fn interrupt handler.
   * @param[in] env environment pointer.
   */
  static void set(InterruptHandler fn, void* env = 0) 
  { <commit_msg>Added a function to allow the Watchdog ticks count to be reset.<commit_after>/**
 * @file Cosa/Watchdog.h
 * @version 1.0
 *
 * @section License
 * Copyright (C) 2012, <NAME>
 *
 * 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., 59 Temple Place, Suite 330,
 * Boston, MA  02111-1307  USA
 *
 * @section Description
 * Watchdog abstraction. Low power timer.
 *
 * This file is part of the Arduino Che Cosa project.
 */

#ifndef __COSA_WATCHDOG_H__
#define __COSA_WATCHDOG_H__

#include <avr/wdt.h>
#include <avr/sleep.h>

#include "Cosa/Types.h"
#include "Cosa/Bits.h"
#include "Cosa/Event.h"
#include "Cosa/Thing.h"
#include "Cosa/Things.h"

class Watchdog {

public:
  /**
   * Interrupt handler function prototype.
   * @param[in] env interrupt handler environment.
   */
  typedef void (*InterruptHandler)(void* env);

  /**
   * Callback function prototype for await condition function.
   * Return true(1) to return from await() otherwise false(0).
   * @param[in] env condition function environment.
   * @return bool
   */
  typedef bool (*AwaitCondition)(void* env);

private:
  static InterruptHandler _handler;
  static void* _env;

  static const uint8_t TIMEQ_MAX = 10;
  static Things _timeq[TIMEQ_MAX];

  static volatile uint16_t _ticks;
  static uint8_t _prescale;
  static uint8_t _mode;
  
public:
  /**
   * Get number of watchdog cycles.
   * @return number of ticks.
   */
  static uint16_t get_ticks() 
  { 
    return (_ticks); 
  }

  /**
   * Reset the ticks counter for time measurement.
   */
  static void reset() 
  { 
    _ticks = 0;
  }

  /**
   * Get number of milli-seconds per tick.
   * @return milli-seconds.
   */
  static uint16_t ms_per_tick() 
  { 
    return (16 << _prescale); 
  }

  /**
   * Set watchdog timeout interrupt handler.
   * @param[in] fn interrupt handler.
   * @param[in] env environment pointer.
   */
  static void set(InterruptHandler fn, void* env = 0) 
  { 
{'fraction_non_alphanumeric': 0.09591258599757184, 'fraction_numerical': 0.015580736543909348, 'mean_word_length': 3.3020017406440383, 'pattern_counts': {'":': 0, '<': 13, '<?xml version=': 0, '>': 9, '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': '5954526', 'n_tokens_mistral': 1623, 'n_tokens_neox': 1528, 'n_words': 579}