#ifndef UTIL_H
#define UTIL_H

#include "config.h"

/* Convert from ascii hex digit to number */
uint8_t from_hex(uint8_t ch);
extern const uint8_t hex[16];
int32_t hex_to_u16(char x[4]);

/* Array length */
#define array_len(x) (sizeof(x)/sizeof(x[0]))

/* ISR disable/enable with saving of previous state */
#define __int_top() int __sr_save
#define __int_disable() __sr_save=SR; SRbits.IPL=7
#define __int_enable() SR=__sr_save
#define disable_int(x) do { \
        __int_top(); \
        __int_disable(); \
        x; \
        __int_enable(); } while(0)

#endif
