#ifndef HARDWARE_MSCRUB_H_
#define HARDWARE_MSCRUB_H_

typedef struct
{
	volatile unsigned ctrl;
	volatile unsigned badAddr;
	volatile unsigned curAddr;
	volatile unsigned timer;
	struct
	{
		volatile unsigned init;
		volatile unsigned fin;
	} a[8];
	volatile unsigned sctrl;
	volatile unsigned ecnt0;
	volatile unsigned ecnt1;
} MscrubRegs;

#define MSCRUB_CTRL_EE_RAM          (1U << 17)
#define MSCRUB_CTRL_EE_DBG_RAM      (1U << 16)
#define MSCRUB_CTRL_ACT             (1U << 14)
#define MSCRUB_CTRL_CE              (1U << 13)
#define MSCRUB_CTRL_EV              (1U << 12)
#define MSCRUB_CTRL_MODE_CYCLIC     (1U << 10)
#define MSCRUB_CTRL_MODE_ONETIME    (0U << 10)
#define MSCRUB_CTRL_STOP            (1U << 9)
#define MSCRUB_CTRL_RUN             (1U << 8)
#define MSCRUB_CTRL_RE(_x)          (1U << ((_x) & 7)

#define MSCRUB_TIMER_RI(_x) (((_x) & 0xFF) << 24)
#define MSCRUB_TIMER_TI(_x) (((_x) & 0xFFFFFF) << 0)

#define MSCRUB_SCTRL_SM(_x) (1U << ((_x) & 7)

#define MSCRUB_ECNT(_reg, _no)  ((reg_) >> (((_no) & 3) * 8))

#define MSCRUB_ECNT0_ECNT3(_reg, _no)   MSCRUB_ECNT(reg_, 3)
#define MSCRUB_ECNT0_ECNT2(_reg, _no)   MSCRUB_ECNT(reg_, 2)
#define MSCRUB_ECNT0_ECNT1(_reg, _no)   MSCRUB_ECNT(reg_, 1)
#define MSCRUB_ECNT0_ECNT0(_reg, _no)   MSCRUB_ECNT(reg_, 0)

#define MSCRUB_ECNT1_ECNT7(_reg, _no)   MSCRUB_ECNT(reg_, 7)
#define MSCRUB_ECNT1_ECNT6(_reg, _no)   MSCRUB_ECNT(reg_, 6)
#define MSCRUB_ECNT1_ECNT5(_reg, _no)   MSCRUB_ECNT(reg_, 5)
#define MSCRUB_ECNT1_ECNT4(_reg, _no)   MSCRUB_ECNT(reg_, 4)

#endif /* HARDWARE_MSCRUB_H_ */
