/*                                              -*- mode:C++; fill-column:100 -*-
  SFBReflex.h - Main reflex-level operational control
  Copyright (C) 2008 The Regents of the University of New Mexico.  All rights 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 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
*/

/**
  \file SFBReflex.h Reflex-related declarations and macros.  
  \author David H. Ackley.  
  \date (C) 2008 All rights reserved.
  \lgpl
 */

#ifndef SFBREFLEX_H_
#define SFBREFLEX_H_

#include "SFBTypes.h"

#ifdef __cplusplus
extern "C" {
#endif

/* Reflex library operational flags */

#define RF_DIE_PACKET_ERROR    0x00000001 /**< Die if a packet has any transmission error or buffer overflow */
#define RF_RED_BOOT_CODE_FLOW  0x00000002 /**< Allow outbound code flow even if in red boot mode @since 0.9.6 */
#define RF_NO_CODE_FLOW        0x00000004 /**< Do not advertise or flow our code to anybody */
#define RF_OKAY_NEW_GUY        0x00000008 /**< Reenter bootloader after blinking code (else just blink) */
#define RF_KARMIC_REBIRTH      0x00000010 /**< Invalidate sketch on fatal (i.e., blink code) error */
#define RF_LESS_EEPROM         0x00000020 /**< Avoid frequent EEPROM writes (e.g., don't count power on hours) */
#define RF_DIE_ALOUD           0x00000040 /**< Try to seize NORTH at 9600 and report death info while dying */
#define RF_DIE_NESTED_DISPATCH 0x00000080 /**< Die if dispatching occurs on a locked packet buffer (else ignored) */
#define RF_DONT_FEED_DOG       0x00000100 /**< Even if the watchdog timer is running, the library won't feed it */
#define RF_RESERVED09          0x00000200 /**< Reserved flag / should be 0 / value must be ignored */
#define RF_RESERVED10          0x00000400 /**< Reserved flag / should be 0 / value must be ignored */
#define RF_RESERVED11          0x00000800 /**< Reserved flag / should be 0 / value must be ignored */
#define RF_RESERVED12          0x00001000 /**< Reserved flag / should be 0 / value must be ignored */
#define RF_RESERVED13          0x00002000 /**< Reserved flag / should be 0 / value must be ignored */
#define RF_RESERVED14          0x00004000 /**< Reserved flag / should be 0 / value must be ignored */
#define RF_RESERVED15          0x00008000 /**< Reserved flag / should be 0 / value must be ignored */
#define RF_RESERVED16          0x00010000 /**< Reserved flag / should be 0 / value must be ignored */
#define RF_RESERVED17          0x00020000 /**< Reserved flag / should be 0 / value must be ignored */
#define RF_RESERVED18          0x00040000 /**< Reserved flag / should be 0 / value must be ignored */
#define RF_RESERVED19          0x00080000 /**< Reserved flag / should be 0 / value must be ignored */
#define RF_RESERVED20          0x00100000 /**< Reserved flag / should be 0 / value must be ignored */
#define RF_RESERVED21          0x00200000 /**< Reserved flag / should be 0 / value must be ignored */
#define RF_RESERVED22          0x00400000 /**< Reserved flag / should be 0 / value must be ignored */
#define RF_RESERVED23          0x00800000 /**< Reserved flag / should be 0 / value must be ignored */
#define RF_RESERVED24          0x01000000 /**< Reserved flag / should be 0 / value must be ignored */
#define RF_RESERVED25          0x02000000 /**< Reserved flag / should be 0 / value must be ignored */
#define RF_RESERVED26          0x04000000 /**< Reserved flag / should be 0 / value must be ignored */
#define RF_RESERVED27          0x08000000 /**< Reserved flag / should be 0 / value must be ignored */
#define RF_DEBUG0              0x10000000 /**< Debug flag 0 */
#define RF_DEBUG1              0x20000000 /**< Debug flag 1 */
#define RF_DEBUG2              0x40000000 /**< Debug flag 2 */
#define RF_DEBUG3              0x80000000 /**< Debug flag 3 */

extern int reflex_maybe_dispatch(u32 deadline) ;
extern int reflex_dispatch(u32 deadline) ;

extern void reflex_startup_initialization() ;

extern u32 reflexLibraryFlags;
#define TEST_REFLEX_FLAGS(flags) ((reflexLibraryFlags&(flags))!=0)  /**< Non-zero if any of the \a
                                                                       flags bits are set in the
                                                                       core software reflex flags */
#define SET_REFLEX_FLAGS(flags) (reflexLibraryFlags |= (flags))     /**< Set the \a flags bits in
                                                                       the core software reflex
                                                                       flags */
#define CLEAR_REFLEX_FLAGS(flags) (reflexLibraryFlags &= ~(flags))  /**< Clear the \a flags bits in
                                                                       the core software reflex
                                                                       flags */

#ifdef __cplusplus
}
#endif

#endif /*SFBREFLEX_H_*/
