#ifndef PCI_8134_H
    #define PCI_8134_H
/****************************************************************************/
/*  Copyright (c) 1995-1998, ADLink Technology Inc.  All rights reserved.   */
/*                                                                          */
/*  File Name   :   PCI_8134.H                                              */
/*  Purpose     :   Header file for PCI_8134.C module                       */
/*  Date        :   04/29/1999                                              */
/*  Revision    :   1.00                                                    */
/*  Programmer  :   Yi_Tun Huang                                           */
/****************************************************************************/

#include "motion.h"
#include "type_def.h"

#if defined _MYWIN32
	#ifndef _WIN32_WINNT
	#define _WIN32_WINNT 0x0400
	#endif
	#include <windows.h>
#endif

#if defined _MYWINCE
	#include <windows.h>
#endif

#ifdef __cplusplus
extern "C" {
#endif

/****************************************************************************/
/*      Typedef  Definitions                                                */
/****************************************************************************/
#ifndef TYPE_DEF
typedef unsigned char   U8;
typedef short           I16;
typedef unsigned short  U16;
typedef long            I32;
typedef unsigned long   U32;
typedef float           F32;
typedef double          F64;
typedef char            Boolean;
#endif

#define     TRUE                1
#define     FALSE               0

#define     HIGH                1
#define     LOW                 0


/* ------------ I/O Status Definition ------------------------------------- */
#define         pos_limit       0x01
#define         neg_limit       0x02
#define         psd_switch      0x04
#define         nsd_switch      0x08
#define         org_limit       0x10
#define         idx_switch      0x20
#define         alm_switch      0x40
#define         svon_sts        0x80
#define         rdy_sts         0x100
#define         int_sts         0x200
#define         erc_sts         0x400
#define         inp_sts         0x800

/* ------------ Motion Done Reurn Value Definition ------------------------ */
#define         BUSY            0x00
#define         DONE            0x01
#define         POS_LIM         0x02
#define         NEG_LIM         0x03
#define         ORG_LIM         0x04
#define         ALARM           0x05

/****************************************************************************/
/*      Function  Declerations                                              */
/****************************************************************************/
U16  FNTYPE W_8134_Initial(I32 card_number);
U16  FNTYPE W_8134_InitialA(I16 *TotalCard);

U16  FNTYPE W_8134_Close(I32 card_number);

U16  FNTYPE W_8134_Set_SVON(I32 axis, I32 on_off);

void FNTYPE W_8134_Get_IRQ_Channel(U16 cardNo, U16 *irq_no );
void FNTYPE W_8134_Get_Base_Addr(U16 cardNo, U16 *base_addr );
void FNTYPE W_8134_Set_INT_Control(U16 cardNo, U16 intFlag );

#if defined(_MSDOS)  || defined(_MYWATCOMC)
	I16 FNTYPE _8134_enter_isr(I16 CardNo);
	I16 FNTYPE _8134_leave_isr(I16 CardNo);
	I16 FNTYPE _8134_get_irq_status(U16 cardNo, U16 *sts);
	I16 FNTYPE _8134_not_my_irq(I16 CardNo);

	// ISR
	void interrupt _8134_isr0 (void);
	void interrupt _8134_isr1 (void);
	void interrupt _8134_isr2 (void);
	void interrupt _8134_isr3 (void);
	void interrupt _8134_isr4 (void);
	void interrupt _8134_isr5 (void);
	void interrupt _8134_isr6 (void);
	void interrupt _8134_isr7 (void);
	void interrupt _8134_isr8 (void);
	void interrupt _8134_isr9 (void);
	void interrupt _8134_isra (void);
	void interrupt _8134_isrb (void);
#endif


U16 FNTYPE W_8134_Set_Config(U8 *fileName);

U16 FNTYPE start_a_move(I16 axis, F64 pos, F64 str_vel, F64 max_vel, F64 accel);
U16 FNTYPE a_move(I16 axis, F64 pos, F64 str_vel, F64 max_vel, F64 accel);
U16 FNTYPE start_r_move(I16 axis, F64 distance, F64 str_vel, F64 max_vel, F64 accel);
U16 FNTYPE r_move(I16 axis, F64 distance, F64 str_vel, F64 max_vel, F64 accel);
U16 FNTYPE start_t_move(I16 axis, F64 distance, F64 str_vel, F64 max_vel, F64 accel, F64 decel);
U16 FNTYPE t_move(I16 axis, F64 distance, F64 str_vel, F64 max_vel, F64 accel, F64 decel);
U16 FNTYPE wait_for_done(I16 axis);

U16 FNTYPE set_move_ratio(I16 axis, F64 ratio);
U16 FNTYPE get_position(I16 axis, F64 *pos);
U16 FNTYPE set_position(I16 axis, F64 pos);
U16 FNTYPE get_command(I16 axis, F64 *pos);
U16 FNTYPE set_command(I16 axis, F64 pos);
U16 FNTYPE v_move(I16 axis, F64 str_vel, F64 max_vel, F64 accel);
U16 FNTYPE sv_move(I16 axis, F64 str_vel, F64 max_vel, F64 Tlacc, F64 Tsacc);
U16 FNTYPE v_change(I16 axis, F64 max_vel, F64 accel);
U16 FNTYPE v_stop(I16 axis, F64 decel);
U16 FNTYPE fix_max_speed(I16 axis, F64 max_vel);

U16 FNTYPE get_io_status(I16 axis, U16 *io_sts);

U16 FNTYPE motion_done(I16 axis);


U16 FNTYPE set_move_accel(F64 accel);
U16 FNTYPE set_move_speed(F64 str_vel, F64 max_vel);
U16 FNTYPE map_axes(I16 n_axes, I16 *map_array);
U16 FNTYPE manu_move(I32 axis, F64 max_vel);

U16 FNTYPE start_move_xy(I32 cardNo, F64 x, F64 y);
U16 FNTYPE start_move_zu(I32 cardNo, F64 z, F64 u);
U16 FNTYPE move_xy(I32 cardNo, F64 x, F64 y);
U16 FNTYPE move_zu(I32 cardNo, F64 z, F64 u);
U16 FNTYPE set_home_config(I32 axis,I32 home_mode,I32 org_logic,I32 org_latch,I32 EZ_logic);
U16 FNTYPE home_move(I32 axis,F64 str_vel,F64 max_vel,F64 accel);

U16 FNTYPE set_manu_iptmode(I32 axis, I32 manu_iptmode, I32 op_mode);

U16 FNTYPE set_pls_outmode(I32 axis, I32 pls_outmode);
U16 FNTYPE set_pls_iptmode(I32 axis, I32 pls_iptmode);
U16 FNTYPE set_cnt_src(I32 axis, I32 cnt_src);

U16 FNTYPE set_alm_logic(I32 axis, I32 alm_logic, I32 alm_mode);
U16 FNTYPE set_inp_logic(I32 axis, I32 inp_logic, I32 inp_enable);
U16 FNTYPE set_erc_enable(I32 axis, I32 erc_enable);
U16 FNTYPE set_sd_logic(I32 axis, I32 sd_logic, I32 sd_latch, I32 sd_enable); 

U16 FNTYPE set_int_factor(U16 axis, U32 int_factor );
U16 FNTYPE get_int_status(I32 axis, U32 *int_status );

#ifdef _MYWIN32
U16 FNTYPE W_8134_INT_Enable(I32 card_number,HANDLE *phEvent);
#endif

#ifdef _MYLINUX
    I16 FNTYPE W_8134_INT_Enable(I16 CardNo, void (*event_handler1)(I32), void (*event_handler2)(I32),        void (*event_handler3)(I32), void (*event_handler4)(I32));
#endif

U16 FNTYPE W_8134_INT_Disable(I32 card_number);

U16 FNTYPE start_ta_move(I16 axis, F64 pos, F64 str_vel, F64 max_vel, F64 Tacc, F64 Tdec);
U16 FNTYPE ta_move(I16 axis, F64 pos, F64 str_vel, F64 max_vel, F64 Tacc, F64 Tdec);
U16 FNTYPE start_s_move(I16 axis, F64 pos, F64 str_vel, F64 max_vel, F64 Tlacc, F64 Tsacc);
U16 FNTYPE s_move(I16 axis, F64 pos, F64 str_vel, F64 max_vel, F64 Tlacc, F64 Tsacc);
U16 FNTYPE start_rs_move(I16 axis, F64 distance, F64 str_vel, F64 max_vel, F64 Tlacc, F64 Tsacc);
U16 FNTYPE rs_move(I16 axis, F64 distance, F64 str_vel, F64 max_vel, F64 Tlacc, F64 Tsacc);
U16 FNTYPE start_tas_move(I16 axis, F64 pos, F64 str_vel, F64 max_vel, F64 Tlacc, F64 Tsacc, F64 Tldec, F64 Tsdec);
U16 FNTYPE tas_move(I16 axis, F64 pos, F64 str_vel, F64 max_vel, F64 Tlacc, F64 Tsacc, F64 Tldec, F64 Tsdec);

U16 FNTYPE start_move_all(I16 TotalAxes, I16 *map_array, F64 *pos, F64 *str_vel, F64 *max_vel, F64 *Tacc);
U16 FNTYPE wait_for_all(I16 TotalAxes, I16 *map_array);
U16 FNTYPE start_sa_move_all(I16 len, I16 *map_array, F64 *pos, F64 *str_vel, F64 *max_vel, F64 *Tlacc, F64 *Tsacc);

U16 FNTYPE move_all(I16 TotalAxes, I16 *map_array, F64 *pos, F64 *str_vel, F64 *max_vel, F64 *Tacc);
U16 FNTYPE set_sd_stop_mode(I16 axisno, I16 stop_mode);
U16 FNTYPE set_step_unit(I16 axisno, I16 unit);

U16 FNTYPE start_ta_move_xy(I16 cardNo, F64 PosX, F64 PosY, F64 StrVel, F64 MaxVel, F64 Tacc, F64 Tdec);
U16 FNTYPE start_tr_move_xy(I16 cardNo, F64 DistX, F64 DistY, F64 StrVel, F64 MaxVel, F64 Tacc, F64 Tdec);
U16 FNTYPE start_sa_move_xy(I16 cardNo, F64 PosX, F64 PosY, F64 StrVel, F64 MaxVel, F64 Tacc, F64 Tdec);
U16 FNTYPE start_sr_move_xy(I16 cardNo, F64 DistX, F64 DistY, F64 StrVel, F64 MaxVel, F64 Tacc, F64 Tdec);

U16 FNTYPE start_ta_move_zu(I16 cardNo, F64 PosZ, F64 PosU, F64 StrVel, F64 MaxVel, F64 Tacc, F64 Tdec);
U16 FNTYPE start_tr_move_zu(I16 cardNo, F64 DistZ, F64 DistU, F64 StrVel, F64 MaxVel, F64 Tacc, F64 Tdec);
U16 FNTYPE start_sa_move_zu(I16 cardNo, F64 PosZ, F64 PosU, F64 StrVel, F64 MaxVel, F64 Tacc, F64 Tdec);
U16 FNTYPE start_sr_move_zu(I16 cardNo, F64 DistZ, F64 DistU, F64 StrVel, F64 MaxVel, F64 Tacc, F64 Tdec);

// New Function
#ifdef _MYWIN32
I16 FNTYPE link_axis_interrupt(I16 AxisNo,void ( __stdcall *callbackAddr)( void ));
#endif
U16 FNTYPE set_sw_limit(I16 axisno,F64 p_limit, F64 n_limit);
U16 FNTYPE unset_sw_limit(I16 axisno);
U16 FNTYPE unfix_max_speed(I16 axis);
I16 FNTYPE version_info(I16 CardNo, U16 *HardwareInfo, I32 *SoftwareInfo, I32 *DriverInfo);
I16 FNTYPE get_current_speed(I16 AxisNo, F64 *speed);
F64 FNTYPE verify_speed(F64 StrVel,F64 MaxVel,F64 *minAccT,F64 *maxAccT, F64 MaxSpeed);
I16 FNTYPE set_rdp_mode(I16 AxisNO, I16 Mode);
I16 FNTYPE set_org_offset(I16 AxisNo, F64 Offset);
I16 FNTYPE set_feedback_error_detect(I16 AxisNo, I32 max_error);
I16 FNTYPE get_error_counter(I16 AxisNo, I16 *error_counter);
I16 FNTYPE reset_error_counter(I16 AxisNo);
void FNTYPE set_ez_count(I16 AxisNo,I16 ez_count);

I16 FNTYPE _8134_set_pulser_ratio(I16 AxisNo, I16 Value);
I16 FNTYPE _8134_reset_when_home_finish(I16 AxisNo, U8 Enable);

// Speed Profile Section
I16 FNTYPE _8134_get_tr_move_profile(I16 AxisNo, F64 Dist, F64 StrVel, F64 MaxVel, F64 Tacc, F64 Tdec, F64 *pStrVel, F64 *pMaxVel, F64 *pTacc, F64 *pTdec, F64 *pTconst );
I16 FNTYPE _8134_get_ta_move_profile(I16 AxisNo, F64 Pos, F64 StrVel, F64 MaxVel, F64 Tacc, F64 Tdec, F64 *pStrVel, F64 *pMaxVel, F64 *pTacc, F64 *pTdec, F64 *pTconst );
I16 FNTYPE _8134_get_sr_move_profile(I16 AxisNo, F64 Dist, F64 StrVel, F64 MaxVel, F64 Tacc, F64 Tdec, F64 SVacc, F64 SVdec,F64 *pStrVel, F64 *pMaxVel, F64 *pTacc, F64 *pTdec, F64 *pSVacc, F64 *pSVdec, F64 *pTconst);
I16 FNTYPE _8134_get_sa_move_profile(I16 AxisNo, F64 Pos, F64 StrVel, F64 MaxVel, F64 Tacc, F64 Tdec, F64 SVacc, F64 SVdec,F64 *pStrVel, F64 *pMaxVel, F64 *pTacc, F64 *pTdec, F64 *pSVacc, F64 *pSVdec, F64 *pTconst);

// New Function
I16 FNTYPE _8134_preset_tr_v_change(I16 AxisNo, I16 NumberOfChange, F64 Distance, F64 MaxVel, F64 Tacc, F64 Tdec, F64 *VChange_Offset_Array, F64 *VChange_Speed_Array, F64 *VChange_Tacc, I16 Compare_Method);
I16 FNTYPE _8134_preset_v_change_status(I16 AxisNo, I16 *Points_Compared);
F64 FNTYPE _8134_verify_preset_v_change(F64 StrVel, F64 MaxVel, F64 FixSpeedRange, F64 *minAccT, F64 *maxAccT, F64 *Resolution);


/* Stop Functions
U16 FNTYPE set_backlash_comp(U16 axis,I16 comp_pls);
U16 FNTYPE unset_backlash_comp(U16 axis);
U16 FNTYPE init_comp_data(I16 axisno,  char *f_ntbl, char *f_ptbl, F64 ratio_i, F64 ratio_o);
F64 FNTYPE compen( I16 axisno, F64 in_mm , F64 slope);
F64 FNTYPE mm2ps( I16 axisno, F64 in_mm );
F64 FNTYPE ps2mm( I16 axisno, F64 in_pls );
U16 FNTYPE special_home_move(I16 axis, F64 str_vel, F64 max_vel, F64 sliding_vel,F64 accel);
U16 FNTYPE check_reg(I16 axis, U32 *Reg_Data);
I16 FNTYPE _8134_try_leave_critical_section(void);

U16 FNTYPE set_move_mode(int mode);
U16 FNTYPE set_move_pos(double pos);

U16 FNTYPE set_move_saccel(double tlacc, double tsacc);
U16 FNTYPE start_motion(void);
U16 FNTYPE stop_motion(void);
U16 FNTYPE set_sync_mode(I16 ext_trig, I16 trig_mode);
U16 FNTYPE set_arc_division(I16 axis, F64 degrees);
U16 FNTYPE arc_optimization(int optimize);

U16 FNTYPE arc_xy(int cardNo, double x_center, double y_center, double angle);
U16 FNTYPE arc_zu(int cardNo, double z_center, double u_center, double angle);
U16 FNTYPE home_a_move(I16 axis, F64 pos, F64 str_vel, F64 max_vel, F64 accel);
U16 FNTYPE home_r_move(I16 axis, F64 distance, F64 str_vel, F64 max_vel, F64 accel);
*/

#ifdef __cplusplus
}
#endif

#endif


