/*
 * b1553_driver.h
 *
 */

#ifndef B1553_DRIVER_H_
#define B1553_DRIVER_H_

#include <stdint.h>

#ifdef __cplusplus
extern "C" {
#endif

extern void b1553_drv_set_default_rt_address(unsigned int swrt); //0=use HW, to be call prior to b1553_drv_initialize()

extern int b1553_drv_initialize();
extern int b1553_drv_start();
extern int b1553_drv_stop();

extern int b1553_drv_ready();

extern void b1553_drv_ssflag_watchdog_enable(int enabled);
extern void b1553_drv_ssflag_sw_enable(int enabled);

extern void b1553_drv_enable_interrupts(int mode);	//mode=0 - level, 1=edge
extern void b1553_drv_disable_interrupts();

extern int b1553_drv_remap(unsigned int ctrl_area, unsigned int cmd_area, unsigned int mem_area, unsigned int flags);

extern int b1553_drv_set_rt_sw_address(unsigned int rt);
extern int b1553_drv_enable_sw_rt_address(int enable);

extern int b1553_drv_get_rta(unsigned int *sw_adr, unsigned int* hw_adr);//return actual address

extern int b1553_drv_msg_configure(unsigned int sa, int rxtx, unsigned int wc_min, unsigned int wc_max, unsigned int flags);

extern int b1553_drv_msg_update(unsigned int sa, int rxtx, const void* data, unsigned int wc);

extern int b1553_drv_msg_get(unsigned int sa, int rxtx, void* data, unsigned int wc);

extern int b1553_drv_msg_get_noupdate(unsigned int sa, int rxtx, void* data, unsigned int wc);

typedef void (*b1153_drv_synch_handler_t)(int synch_word_valid, unsigned int synch_word);

extern int b1553_drv_set_synch_handler(b1153_drv_synch_handler_t handler);

enum b1553_drv_status_flags_t { b1553_drv_busy_flag, b1553_drv_subsystem_flag, b1553_drv_terminal_flag };

extern int b1553_drv_set_status_flag(unsigned int bit, int sts_flag);

extern int b1553_drv_set_busy(int busy);
extern int b1553_drv_set_terminal_flag(int ts);
extern int b1553_drv_set_subsystem_flag(int ss);	//-1= HW controlled, 0: sw not set, 1= sw set

extern void b1553_drv_set_bite_word(unsigned int bw);
extern unsigned int b1553_drv_get_bite_word(void);

extern int b1553_drv_msg_dbg_all_valid(void); //only for debug, make all messages valid

extern int b1553_drv_simulate_msg(uint16_t cwraw, unsigned int sa, int rxtx, unsigned int wc, void* data);
	//This routine decode the CW and, if valid:
    //  RX: copy from data to the device internal buffers
    //  TX: copy from device internal buffer to data
    // Return !=0 if message is not valid

#ifdef __cplusplus
}
#endif


#endif /* B1553_DRIVER_H_ */
