From 4faf997a5724ba2f12f0387f6345d63506499f69 Mon Sep 17 00:00:00 2001
From: nwright-mcc <32554608+nwright-mcc@users.noreply.github.com>
Date: Fri, 24 Jun 2022 14:42:32 -0400
Subject: [PATCH] Bugfix for MCC 134 init; remove 2GB file limit from data
logger (#41)
* Fix reading ADC ID register during init.
* Remove 2GB log file limit from data logger examples.
---
README.md | 2 +-
examples/c/mcc118/data_logger/logger/errors.c | 2 +-
examples/c/mcc118/data_logger/logger/makefile | 2 +-
examples/c/mcc128/data_logger/logger/errors.c | 2 +-
examples/c/mcc128/data_logger/logger/makefile | 2 +-
examples/c/mcc134/data_logger/logger/errors.c | 2 +-
examples/c/mcc134/data_logger/logger/makefile | 2 +-
examples/c/mcc172/data_logger/logger/errors.c | 2 +-
examples/c/mcc172/data_logger/logger/makefile | 2 +-
lib/makefile | 2 +-
lib/mcc134_adc.c | 96 +++++++++----------
setup.py | 2 +-
version_history.txt | 4 +
13 files changed, 63 insertions(+), 59 deletions(-)
diff --git a/README.md b/README.md
index 3048faf..89bced7 100644
--- a/README.md
+++ b/README.md
@@ -3,7 +3,7 @@
Info | Contains C and Python Libraries for interacting with
Measurement Computing DAQ HAT boards. |
Author | Measurement Computing |
- Library Version | 1.4.0.3 |
+ Library Version | 1.4.0.4 |
## About
diff --git a/examples/c/mcc118/data_logger/logger/errors.c b/examples/c/mcc118/data_logger/logger/errors.c
index 13d850c..2e65851 100644
--- a/examples/c/mcc118/data_logger/logger/errors.c
+++ b/examples/c/mcc118/data_logger/logger/errors.c
@@ -35,7 +35,7 @@ gboolean show_error(int* error_code_ptr)
error_msg = "Unable to open the log file.";
break;
case MAXIMUM_FILE_SIZE_EXCEEDED:
- error_msg = "The maximum file size of 2GB has been exceeded.";
+ error_msg = "The maximum file size has been exceeded.";
break;
case THREAD_ERROR:
error_msg = "Error creating worker thread.";
diff --git a/examples/c/mcc118/data_logger/logger/makefile b/examples/c/mcc118/data_logger/logger/makefile
index 020bcb9..4670926 100644
--- a/examples/c/mcc118/data_logger/logger/makefile
+++ b/examples/c/mcc118/data_logger/logger/makefile
@@ -1,7 +1,7 @@
NAME = logger
OBJ = $(NAME).o log_file.o errors.o
LIBS = -ldaqhats -lgtkdatabox -pthread `pkg-config --libs gtk+-3.0` -lm
-CFLAGS = `pkg-config --cflags gtk+-3.0`
+CFLAGS = `pkg-config --cflags gtk+-3.0` -D_FILE_OFFSET_BITS=64
CC = gcc
diff --git a/examples/c/mcc128/data_logger/logger/errors.c b/examples/c/mcc128/data_logger/logger/errors.c
index 13d850c..2e65851 100644
--- a/examples/c/mcc128/data_logger/logger/errors.c
+++ b/examples/c/mcc128/data_logger/logger/errors.c
@@ -35,7 +35,7 @@ gboolean show_error(int* error_code_ptr)
error_msg = "Unable to open the log file.";
break;
case MAXIMUM_FILE_SIZE_EXCEEDED:
- error_msg = "The maximum file size of 2GB has been exceeded.";
+ error_msg = "The maximum file size has been exceeded.";
break;
case THREAD_ERROR:
error_msg = "Error creating worker thread.";
diff --git a/examples/c/mcc128/data_logger/logger/makefile b/examples/c/mcc128/data_logger/logger/makefile
index 020bcb9..4670926 100644
--- a/examples/c/mcc128/data_logger/logger/makefile
+++ b/examples/c/mcc128/data_logger/logger/makefile
@@ -1,7 +1,7 @@
NAME = logger
OBJ = $(NAME).o log_file.o errors.o
LIBS = -ldaqhats -lgtkdatabox -pthread `pkg-config --libs gtk+-3.0` -lm
-CFLAGS = `pkg-config --cflags gtk+-3.0`
+CFLAGS = `pkg-config --cflags gtk+-3.0` -D_FILE_OFFSET_BITS=64
CC = gcc
diff --git a/examples/c/mcc134/data_logger/logger/errors.c b/examples/c/mcc134/data_logger/logger/errors.c
index 13d850c..2e65851 100644
--- a/examples/c/mcc134/data_logger/logger/errors.c
+++ b/examples/c/mcc134/data_logger/logger/errors.c
@@ -35,7 +35,7 @@ gboolean show_error(int* error_code_ptr)
error_msg = "Unable to open the log file.";
break;
case MAXIMUM_FILE_SIZE_EXCEEDED:
- error_msg = "The maximum file size of 2GB has been exceeded.";
+ error_msg = "The maximum file size has been exceeded.";
break;
case THREAD_ERROR:
error_msg = "Error creating worker thread.";
diff --git a/examples/c/mcc134/data_logger/logger/makefile b/examples/c/mcc134/data_logger/logger/makefile
index 020bcb9..4670926 100644
--- a/examples/c/mcc134/data_logger/logger/makefile
+++ b/examples/c/mcc134/data_logger/logger/makefile
@@ -1,7 +1,7 @@
NAME = logger
OBJ = $(NAME).o log_file.o errors.o
LIBS = -ldaqhats -lgtkdatabox -pthread `pkg-config --libs gtk+-3.0` -lm
-CFLAGS = `pkg-config --cflags gtk+-3.0`
+CFLAGS = `pkg-config --cflags gtk+-3.0` -D_FILE_OFFSET_BITS=64
CC = gcc
diff --git a/examples/c/mcc172/data_logger/logger/errors.c b/examples/c/mcc172/data_logger/logger/errors.c
index 13d850c..2e65851 100644
--- a/examples/c/mcc172/data_logger/logger/errors.c
+++ b/examples/c/mcc172/data_logger/logger/errors.c
@@ -35,7 +35,7 @@ gboolean show_error(int* error_code_ptr)
error_msg = "Unable to open the log file.";
break;
case MAXIMUM_FILE_SIZE_EXCEEDED:
- error_msg = "The maximum file size of 2GB has been exceeded.";
+ error_msg = "The maximum file size has been exceeded.";
break;
case THREAD_ERROR:
error_msg = "Error creating worker thread.";
diff --git a/examples/c/mcc172/data_logger/logger/makefile b/examples/c/mcc172/data_logger/logger/makefile
index 5dcab3b..3e7d3db 100644
--- a/examples/c/mcc172/data_logger/logger/makefile
+++ b/examples/c/mcc172/data_logger/logger/makefile
@@ -2,7 +2,7 @@ NAME = logger
OBJ = $(NAME).o fft.o log_file.o errors.o
DEPS = kiss_fft/kiss_fftr.o kiss_fft/kiss_fft.o
LIBS = -ldaqhats -lm -lgtkdatabox -pthread `pkg-config --libs gtk+-3.0`
-CFLAGS = -Wall -I/usr/local/include -Ikiss_fft `pkg-config --cflags gtk+-3.0` -g
+CFLAGS = -Wall -I/usr/local/include -Ikiss_fft `pkg-config --cflags gtk+-3.0` -g -D_FILE_OFFSET_BITS=64
CC = gcc
EXTENSION = .c
diff --git a/lib/makefile b/lib/makefile
index 5e35de3..0c9b308 100644
--- a/lib/makefile
+++ b/lib/makefile
@@ -1,6 +1,6 @@
MAJOR = 1
MINOR = 4
-SUB = 0.3
+SUB = 0.4
NAME = daqhats
VERSION = $(MAJOR).$(MINOR).$(SUB)
INSTALL_DIR = /usr/local/lib
diff --git a/lib/mcc134_adc.c b/lib/mcc134_adc.c
index 283e960..b631a9f 100644
--- a/lib/mcc134_adc.c
+++ b/lib/mcc134_adc.c
@@ -22,9 +22,9 @@
// isolators
#define SPI_MODE SPI_MODE_1
#define SPI_DELAY 0
-#define SPI_BITS 8
+#define SPI_BITS 8
+
-
//*****************************
// Register definitions
#define REG_ID 0x00
@@ -76,7 +76,7 @@
// worst case timing.
#ifdef GLOBAL_CHOP
#define N_SETTLE 28
-static const uint32_t _conversion_times_us[] =
+static const uint32_t _conversion_times_us[] =
{
(uint32_t)((813.008*1.015*1000 + N_SETTLE*16*1.015/4.096e3) + 0.5),
(uint32_t)((413.008*1.015*1000 + N_SETTLE*16*1.015/4.096e3) + 0.5),
@@ -95,7 +95,7 @@ static const uint32_t _conversion_times_us[] =
};
#else
#define N_SETTLE 14
-static const uint32_t _conversion_times_us[] =
+static const uint32_t _conversion_times_us[] =
{
(uint32_t)((406.504*1.015*1000 + N_SETTLE*16*1.015/4.096e3) + 0.5),
(uint32_t)((206.504*1.015*1000 + N_SETTLE*16*1.015/4.096e3) + 0.5),
@@ -145,9 +145,9 @@ int _mcc134_spi_transfer(uint8_t address, void* tx_data, void* rx_data,
// could not get a lock within 5 seconds, report as a timeout
return RESULT_LOCK_TIMEOUT;
}
-
+
_set_address(address);
-
+
// check spi mode and change if necessary
ret = ioctl(spi_fd, SPI_IOC_RD_MODE, &temp);
if (ret == -1)
@@ -165,7 +165,7 @@ int _mcc134_spi_transfer(uint8_t address, void* tx_data, void* rx_data,
return RESULT_COMMS_FAILURE;
}
}
-
+
// Init the spi ioctl structure
struct spi_ioc_transfer tr = {
.tx_buf = (uintptr_t)tx_data,
@@ -184,14 +184,14 @@ int _mcc134_spi_transfer(uint8_t address, void* tx_data, void* rx_data,
{
ret = RESULT_SUCCESS;
}
-
+
// clear the SPI lock
_release_lock(lock_fd);
-
+
return ret;
}
-
+
int _mcc134_adc_init(uint8_t address)
{
uint8_t buffer[10];
@@ -200,51 +200,51 @@ int _mcc134_adc_init(uint8_t address)
if (address >= MAX_NUMBER_HATS) // check address failed
{
return RESULT_BAD_PARAMETER;
- }
+ }
if (spi_fd == -1)
{
// SPI device has not been opened yet.
spi_fd = open(SPI_DEVICE_0, O_RDWR);
-
+
if (spi_fd < 0)
{
return RESULT_RESOURCE_UNAVAIL;
}
}
-
+
// lock the board
if (_obtain_board_lock(address) != RESULT_SUCCESS)
{
// could not get a lock within 5 seconds, report as a timeout
return RESULT_LOCK_TIMEOUT;
}
-
+
// reset the ADC to defaults
buffer[0] = CMD_RESET;
- if ((result = _mcc134_spi_transfer(address, buffer, NULL, 1)) !=
+ if ((result = _mcc134_spi_transfer(address, buffer, NULL, 1)) !=
RESULT_SUCCESS)
{
_release_board_lock(address);
return result;
}
-
+
// wait 4096 clocks (1ms) before using the ADC
usleep(1000);
-
+
// check ID and device ready
buffer[0] = CMD_RREG | REG_ID;
buffer[1] = 2 - 1; // count - 1
buffer[2] = CMD_NOP;
buffer[3] = CMD_NOP;
- if ((result = _mcc134_spi_transfer(address, buffer, NULL, 4)) !=
+ if ((result = _mcc134_spi_transfer(address, buffer, buffer, 4)) !=
RESULT_SUCCESS)
{
_release_board_lock(address);
return result;
}
-
- if ((buffer[2] & 0x0E) != 0x000)
+
+ if ((buffer[2] & 0x07) != 0x000)
{
// incorrect ID
_release_board_lock(address);
@@ -255,7 +255,7 @@ int _mcc134_adc_init(uint8_t address)
_release_board_lock(address);
return RESULT_BUSY;
}
-
+
// Initialize the registers that don't use default values
buffer[0] = CMD_WREG | REG_INPMUX;
buffer[1] = 8-1; // count - 1
@@ -263,33 +263,33 @@ int _mcc134_adc_init(uint8_t address)
buffer[3] = 0x08 + TC_PGA_GAIN_INDEX; // PGA
#ifdef GLOBAL_CHOP
buffer[4] = 0x90 + DATA_RATE_INDEX; // DATARATE
-#else
+#else
buffer[4] = 0x10 + DATA_RATE_INDEX; // DATARATE
-#endif
+#endif
buffer[5] = 0x3A; // REF
buffer[6] = 0x80; // IDACMAG
buffer[7] = 0xFF; // IDACMUX
buffer[8] = 0x00; // VBIAS
buffer[9] = 0x01; // SYS
- if ((result = _mcc134_spi_transfer(address, buffer, NULL, 10)) !=
+ if ((result = _mcc134_spi_transfer(address, buffer, NULL, 10)) !=
RESULT_SUCCESS)
{
_release_board_lock(address);
return result;
}
-
+
buffer[0] = CMD_START;
- if ((result = _mcc134_spi_transfer(address, buffer, NULL, 1)) !=
+ if ((result = _mcc134_spi_transfer(address, buffer, NULL, 1)) !=
RESULT_SUCCESS)
{
_release_board_lock(address);
return result;
}
-
+
usleep(1000);
-
+
_release_board_lock(address);
-
+
return RESULT_SUCCESS;
}
@@ -308,14 +308,14 @@ int _mcc134_adc_read_tc_code(uint8_t address, uint8_t hi_input,
// could not get a lock within 5 seconds, report as a timeout
return RESULT_LOCK_TIMEOUT;
}
-
+
// change the mux before the pga in case we are on a CJC channel
regval = (hi_input << 4) | (lo_input);
buffer[0] = CMD_WREG | REG_INPMUX;
buffer[1] = 2-1;
buffer[2] = regval; // INPMUX: select positive and negative ADC inputs
buffer[3] = 0x08 + TC_PGA_GAIN_INDEX; // PGA
- if ((result = _mcc134_spi_transfer(address, buffer, NULL, 4)) !=
+ if ((result = _mcc134_spi_transfer(address, buffer, NULL, 4)) !=
RESULT_SUCCESS)
{
_release_board_lock(address);
@@ -324,16 +324,16 @@ int _mcc134_adc_read_tc_code(uint8_t address, uint8_t hi_input,
// wait for conversion
usleep(_conversion_times_us[DATA_RATE_INDEX]);
-
+
buffer[0] = CMD_RDATA;
buffer[1] = CMD_NOP;
buffer[2] = CMD_NOP;
buffer[3] = CMD_NOP;
buffer[4] = CMD_NOP;
-
+
memset(rbuffer, 0, 5);
- if ((result = _mcc134_spi_transfer(address, buffer, rbuffer, 5)) !=
+ if ((result = _mcc134_spi_transfer(address, buffer, rbuffer, 5)) !=
RESULT_SUCCESS)
{
_release_board_lock(address);
@@ -352,7 +352,7 @@ int _mcc134_adc_read_tc_code(uint8_t address, uint8_t hi_input,
buffer[0] = CMD_WREG | REG_INPMUX;
buffer[1] = 1-1;
buffer[2] = 0x88; // INPMUX: select positive and negative ADC inputs
- if ((result = _mcc134_spi_transfer(address, buffer, NULL, 3)) !=
+ if ((result = _mcc134_spi_transfer(address, buffer, NULL, 3)) !=
RESULT_SUCCESS)
{
_release_board_lock(address);
@@ -361,16 +361,16 @@ int _mcc134_adc_read_tc_code(uint8_t address, uint8_t hi_input,
}
_release_board_lock(address);
-
+
if (code)
{
*code = mycode;
}
-
+
return RESULT_SUCCESS;
}
-int _mcc134_adc_read_cjc_code(uint8_t address, uint8_t hi_input,
+int _mcc134_adc_read_cjc_code(uint8_t address, uint8_t hi_input,
uint8_t lo_input, uint32_t* code)
{
int32_t mycode;
@@ -385,13 +385,13 @@ int _mcc134_adc_read_cjc_code(uint8_t address, uint8_t hi_input,
// could not get a lock within 5 seconds, report as a timeout
return RESULT_LOCK_TIMEOUT;
}
-
+
buffer[0] = CMD_WREG | REG_INPMUX;
buffer[1] = 2-1;
regval = (hi_input << 4) | (lo_input);
buffer[2] = regval; // INPMUX: select positive and negative ADC inputs
buffer[3] = 0x08 + CJC_PGA_GAIN_INDEX; // PGA
- if ((result = _mcc134_spi_transfer(address, buffer, NULL, 4)) !=
+ if ((result = _mcc134_spi_transfer(address, buffer, NULL, 4)) !=
RESULT_SUCCESS)
{
_release_board_lock(address);
@@ -400,16 +400,16 @@ int _mcc134_adc_read_cjc_code(uint8_t address, uint8_t hi_input,
// wait for conversion
usleep(_conversion_times_us[DATA_RATE_INDEX]);
-
+
buffer[0] = CMD_RDATA;
buffer[1] = CMD_NOP;
buffer[2] = CMD_NOP;
buffer[3] = CMD_NOP;
buffer[4] = CMD_NOP;
-
+
memset(rbuffer, 0, 5);
-
- if ((result = _mcc134_spi_transfer(address, buffer, rbuffer, 5)) !=
+
+ if ((result = _mcc134_spi_transfer(address, buffer, rbuffer, 5)) !=
RESULT_SUCCESS)
{
_release_board_lock(address);
@@ -419,20 +419,20 @@ int _mcc134_adc_read_cjc_code(uint8_t address, uint8_t hi_input,
mycode = (int32_t)rbuffer[2] << 16 |
(int32_t)rbuffer[3] << 8 |
rbuffer[4];
-
+
_release_board_lock(address);
-
+
// check sign - should never be negative
if (mycode & 0x00800000)
{
return RESULT_UNDEFINED;
}
-
+
if (code)
{
*code = (uint32_t)mycode;
}
-
+
return RESULT_SUCCESS;
}
diff --git a/setup.py b/setup.py
index abc9433..9b36ff4 100755
--- a/setup.py
+++ b/setup.py
@@ -10,7 +10,7 @@
setup(
name='daqhats',
- version='1.4.0.3',
+ version='1.4.0.4',
description='MCC DAQ HAT Python Library',
author='Measurement Computing Corp.',
author_email='info@mccdaq.com',
diff --git a/version_history.txt b/version_history.txt
index 9f348f9..2056bfc 100644
--- a/version_history.txt
+++ b/version_history.txt
@@ -1,3 +1,7 @@
+1.4.0.4:
+ - Fixed reading the ID register when initializing MCC 134.
+ - Removed 2GB file size limit from data logger applications.
+
1.4.0.3:
- Added missing checks that mcc152_open() has been called in the MCC 152 DIO functions.
- Fixed issues preventing library building in Bullseye.