diff options
author | daniel <danieruru@gmail.com> | 2012-10-07 19:46:17 +0900 |
---|---|---|
committer | daniel <danieruru@gmail.com> | 2012-10-07 19:46:17 +0900 |
commit | 3870833ae365162eccd5e1416682de02c498467b (patch) | |
tree | 7eb21d1aab245e094d7e51b9ad252115094e050e /gpib.c | |
parent | db682a18e8c7b1711f101d655a4f12e53c71b73d (diff) | |
parent | b2c2c72d381ab1b32fa5b5fc4e890fef6c2bf1e0 (diff) |
Merge branch 'master' of grenfell.avtechpulse.com:Instrument
Conflicts:
instr-daemon.c
Diffstat (limited to 'gpib.c')
-rw-r--r-- | gpib.c | 123 |
1 files changed, 96 insertions, 27 deletions
@@ -240,6 +240,8 @@ /* TNT4882 GLOBAL VARIABLES -------------------------------------------------*/ +int is_gpib; + int INTERFACE_ERROR; /* Error Code */ int INTERFACE_STATUS; /* Interface Status */ unsigned char MR_4882_status[5]; /* 4882 status memory registers */ @@ -416,34 +418,38 @@ void GPIB_initialize(void) { int i; - for(i=0; i<5; ++i) { - MR_4882_status[i]=0; /* do this because these variable are 2-byte integers */ - } - /* but Nat Inst code assumes they are one-byte */ - - INTERFACE_STATUS=0; /* Initialize Globals to zero */ + INTERFACE_STATUS=0; /* Initialize Globals to zero */ INTERFACE_ERROR=0; DATA_COUNT=0; Requested_Count=0; - TNT_Out(R_cmdr,F_softreset); /* Reset FIFOS */ + TNT_Out(R_cmdr,F_softreset); /* Reset FIFOS */ + + TNT_Out(R_spmr ,0x80); /* This sequence of commands */ + + if (TNT_In(R_spmr) == 0x80) { + is_gpib = 1; + } else { + is_gpib = 0; + printf ("Error: TNT4882 chip not found\n"); + return; + } - TNT_Out(R_spmr ,0x80); /* This sequence of commands */ - TNT_Out(R_auxmr,0x80); /* insures that the TNT */ - TNT_Out(R_auxmr,0x99); /* will be in the normal 7210 */ - TNT_Out(R_keyrg,0); /* mode and not 9914 */ + TNT_Out(R_auxmr,0x80); /* insures that the TNT */ + TNT_Out(R_auxmr,0x99); /* will be in the normal 7210 */ + TNT_Out(R_keyrg,0); /* mode and not 9914 */ - TNT_Out(R_hssel,F_onechip); /* Set TNT to one chip WINK mode */ - TNT_Out(R_misc,0); /* Disable HS mode */ - TNT_Out(R_hier,B_dga|B_dgb); /* Set deglitching circuits to */ + TNT_Out(R_hssel,F_onechip); /* Set TNT to one chip WINK mode */ + TNT_Out(R_misc,0); /* Disable HS mode */ + TNT_Out(R_hier,B_dga|B_dgb); /* Set deglitching circuits to */ - TNT_Out(R_auxmr,F_chrst); /* Reset TNT */ + TNT_Out(R_auxmr,F_chrst); /* Reset TNT */ - TNT_4882_Status(STB,0xff,CLEAR); /* Initialize Serial Poll Byte */ - TNT_4882_Status(SRE,0xff,CLEAR); /* Initialize SRE memory register */ - TNT_4882_Status(ESR,0xff,CLEAR); /* Initialize ESR memory register */ - TNT_4882_Status(ESR,0x80,SET); /* Indicate power on */ - TNT_4882_Status(ESE,0xff,CLEAR); /* Initialize ESE memory register */ + TNT_4882_Status(STB,0xff,CLEAR); /* Initialize Serial Poll Byte */ + TNT_4882_Status(SRE,0xff,CLEAR); /* Initialize SRE memory register */ + TNT_4882_Status(ESR,0xff,CLEAR); /* Initialize ESR memory register */ + TNT_4882_Status(ESR,0x80,SET); /* Indicate power on */ + TNT_4882_Status(ESE,0xff,CLEAR); /* Initialize ESE memory register */ TNT_Adr_Mode(); GPIB_change_address(globals.Flash.gpib_address); @@ -454,10 +460,9 @@ void GPIB_initialize(void) /* If not using HS488 set only hst1*/ TNT_Out(R_auxmr,HR_auxrb|((USE_HIGH_SPEED_T1)? B_hst1 : 0)); - TNT_Out(R_auxmr,F_hldi); /* Issue hold off immediately */ - TNT_Out(R_auxmr,F_pon); /* Clear Power On */ - - TNT_Out(R_imr0,B_glint); /* Enable setting of tlcint */ + TNT_Out(R_auxmr,F_hldi); /* Issue hold off immediately */ + TNT_Out(R_auxmr,F_pon); /* Clear Power On */ + TNT_Out(R_imr0,B_glint); /* Enable setting of tlcint */ } @@ -474,6 +479,10 @@ static void TNT_Adr_Mode() void GPIB_change_address(int new_address) { + if (!is_gpib) { + return; + } + int eprom_loc; TNT_Out(R_adr,new_address); /* Load new address setting */ @@ -628,6 +637,10 @@ int GPIB_check_for_device_clear_signal(void) /* added by MJC - June 20/06 */ /* reset interface if a device clear is received */ + if (!is_gpib) { + return FALSE; + } + if (TNT_INT_STATUS() & DCAS) { TNT_Out(R_auxmr,F_clrDEC); TNT_INT_STATUS(); @@ -642,6 +655,10 @@ int GPIB_check_for_messages(char *gpib_buf) { #define ib_empty (!(strlen(gpib_buf))) + if (!is_gpib) { + return FALSE; + } + /* If the GPIB has requested data, and no output messages are in the TNT4882 FIFOs, generate a query error */ if (TNT_update_brq() && !TNT_input_bav() && ib_empty) { queue_error_for_gpib_only(query_error_unterminated); @@ -670,6 +687,10 @@ int GPIB_check_for_messages(char *gpib_buf) int GPIB_handle_new_input(char *gpib_buf) { + if (!is_gpib) { + return FALSE; + } + /* read until done or buffers empty. Then reset DAC holdoff */ unsigned long int count_sent; /* Local count variable */ @@ -754,6 +775,10 @@ static void TNT_Holdoff_off() int GPIB_send_query_response(char *out_buffer) { + if (!is_gpib) { + return OK; + } + /* message must be available if this function has been called */ unsigned long int out_cnt; @@ -877,6 +902,9 @@ int GPIB_send_query_response(char *out_buffer) void GPIB_check_remote_status (int *is_remote, int *is_lockout) { *is_remote = *is_lockout = 0; + if (!is_gpib) { + return; + } TNT_INT_STATUS(); /* Update to get current status */ if ((INTERFACE_STATUS&REM) == REM) { @@ -892,12 +920,20 @@ void GPIB_check_remote_status (int *is_remote, int *is_lockout) unsigned char GPIB_response_already_pending () { + if (!is_gpib) { + return 0; + } + return TNT_In(R_spsr) & 0x10; } void GPIB_go_to_local () { + if (!is_gpib) { + return; + } + TNT_Out(R_auxmr,0x05); /* issue TNT rtl command */ return; } @@ -905,6 +941,10 @@ void GPIB_go_to_local () void GPIB_clear_events () { + if (!is_gpib) { + return; + } + TNT_4882_Status(ESR,0xff,CLEAR); /* Clear ESR register */ TNT_4882_Status(STB,0x20,CLEAR); /* Clear ESB bit in STB */ return; @@ -931,51 +971,80 @@ unsigned int GPIB_get_ESE () unsigned int GPIB_get_STB () { + if (!is_gpib) { + return; + } + return (TNT_In(R_spsr)&0xbf) | (((TNT_In(R_spsr)&0xbf) & MR_4882_status[SRE])?0x40:0); } void GPIB_set_ESR (unsigned int byte,int operation) { + if (!is_gpib) { + return; + } + TNT_4882_Status(ESR,byte,operation); - return; } void GPIB_set_SRE (unsigned int byte,int operation) { + if (!is_gpib) { + return; + } + TNT_4882_Status(SRE,byte,operation); - return; } void GPIB_set_ESE (unsigned int byte,int operation) { + if (!is_gpib) { + return; + } + TNT_4882_Status(ESE,byte,operation); - return; } void GPIB_Set_Execution_Error () { + if (!is_gpib) { + return; + } + TNT_4882_Status(3,0x10,1); } void GPIB_Set_Command_Error () { + if (!is_gpib) { + return; + } + TNT_4882_Status(3,0x20,1); } void GPIB_Set_Query_Error () { + if (!is_gpib) { + return; + } + TNT_4882_Status(3,0x04,1); } void GPIB_Set_Device_Dependent_Error () { + if (!is_gpib) { + return; + } + TNT_4882_Status(3,0x08,1); } |