summaryrefslogtreecommitdiff
diff options
context:
space:
mode:
-rw-r--r--gpib.c47
-rw-r--r--i2c.c9
2 files changed, 51 insertions, 5 deletions
diff --git a/gpib.c b/gpib.c
index 1606eea..7b42939 100644
--- a/gpib.c
+++ b/gpib.c
@@ -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 */
@@ -424,6 +426,15 @@ void GPIB_initialize(void)
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_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 */
@@ -468,6 +479,8 @@ 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 */
@@ -622,6 +635,8 @@ 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();
@@ -636,6 +651,8 @@ 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);
@@ -664,6 +681,8 @@ 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 */
@@ -748,6 +767,8 @@ 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;
@@ -871,6 +892,7 @@ 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) {
@@ -886,12 +908,16 @@ 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;
}
@@ -899,6 +925,8 @@ 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;
@@ -925,51 +953,64 @@ 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);
}
diff --git a/i2c.c b/i2c.c
index 6571798..767e4f6 100644
--- a/i2c.c
+++ b/i2c.c
@@ -10,6 +10,9 @@
#define I2C_BUS "/dev/i2c-3"
+gboolean write_error_flagged;
+gboolean read_error_flagged;
+
void I2C_Write(gulong address, guchar value)
{
@@ -23,7 +26,8 @@ void I2C_Write(gulong address, guchar value)
int device = open(I2C_BUS, O_RDWR);
- if (device == -1) {
+ if ((device == -1) && !write_error_flagged) {
+ write_error_flagged = TRUE;
g_print_debug("ERROR: could not open I2C bus %s for writing\n", I2C_BUS);
return;
}
@@ -48,7 +52,8 @@ guchar I2C_Read(gulong address)
int device = open(I2C_BUS, O_RDWR);
- if (device == -1) {
+ if ((device == -1) && !read_error_flagged) {
+ read_error_flagged = TRUE;
g_print_debug("ERROR: could not open I2C bus %s for reading\n", I2C_BUS);
return 0;
}