All the mail mirrored from lore.kernel.org
 help / color / mirror / Atom feed
* [Patch] bccmd - add ability to read ADC
@ 2015-05-27 15:32 simon
  2015-06-06  5:49 ` Marcel Holtmann
  0 siblings, 1 reply; 5+ messages in thread
From: simon @ 2015-05-27 15:32 UTC (permalink / raw)
  To: linux-bluetooth

[-- Attachment #1: Type: text/plain, Size: 773 bytes --]

Hi,
Some BlueCore devices are equipped with an 'Analogue In' pin which is
internally connected to a MUX and ADC. This patch adds the ability to
control the MUX and read the ADC.

The ADC is also connected internal to a temp sensor, which can also be
read via this method.

The (only) MUX values expected to be used are:
1 Internal 1V25 reference
16 BlueCore01b pin Test_A; BlueCore2-External pin AIO0
17 BlueCore01b pin Test_B; BlueCore2-External pin AIO1
36 Chip’s internal temperature (change) sensor. BlueCore2-ROM and later only.

The MUX can also select other (undocumented) test points.

Example usage
--
# ./bccmd -t HCI -d hci1 adc 17
ADC value from Mux 0x11 : 0x0054 (valid)
# ./bccmd -t HCI -d hci1 adc 1
ADC value from Mux 0x01 : 0x00b2 (valid)
--

Enjoy,
Simon.

[-- Warning: decoded text below may be mangled, UTF-8 assumed --]
[-- Attachment #2: bccmd_adc.patch --]
[-- Type: text/x-patch; name="bccmd_adc.patch", Size: 2465 bytes --]

diff --git a/tools/bccmd.c b/tools/bccmd.c
index 7cce426..64c5f56 100644
--- a/tools/bccmd.c
+++ b/tools/bccmd.c
@@ -1040,6 +1040,47 @@ static int cmd_pscheck(int transport, int argc, char *argv[])
 	return 0;
 }
 
+static int cmd_adc(int transport, int argc, char *argv[])
+{
+	uint8_t array[8];
+	uint16_t mux, value;
+	int err;
+
+	OPT_HELP(1, NULL);
+
+	if (!strncasecmp(argv[0], "0x", 2))
+		mux = strtol(argv[0], NULL, 16);
+	else
+		mux = atoi(argv[0]);
+
+	// Request an ADC read from a particular mux'ed input
+	memset(array, 0, sizeof(array));
+	array[0] = mux & 0xff;
+	array[1] = mux >> 8;
+
+	err = transport_write(transport, CSR_VARID_ADC, array, 2);
+	if (err < 0) {
+		errno = -err;
+		return -1;
+	}
+
+	// sleep, then read result
+	usleep(50000);
+	err = transport_read(transport, CSR_VARID_ADC_RES, array, 8);
+	if (err < 0) {
+		errno = -err;
+		return -1;
+	}
+
+	mux = array[0] | (array[1] << 8);
+	value = array[4] | (array[5] << 8);
+
+	printf("ADC value from Mux 0x%02x : 0x%04x (%s)\n", mux, value,
+					array[2] == 1 ? "valid" : "invalid");
+
+	return 0;
+}
+
 static struct {
 	char *str;
 	int (*func)(int transport, int argc, char *argv[]);
@@ -1070,6 +1111,7 @@ static struct {
 	{ "psread",    cmd_psread,    NULL,                  "Read all PS keys"               },
 	{ "psload",    cmd_psload,    "<file>",              "Load all PS keys from PSR file" },
 	{ "pscheck",   cmd_pscheck,   "<file>",              "Check PSR file"                 },
+	{ "adc",       cmd_adc,       "<mux>",               "Read ADC value of <mux> input"  },
 	{ NULL }
 };
 
diff --git a/tools/csr.h b/tools/csr.h
index 8b94d7b..cc245a5 100644
--- a/tools/csr.h
+++ b/tools/csr.h
@@ -39,6 +39,7 @@
 #define CSR_VARID_BT_CLOCK			0x2c00	/* uint32 */
 #define CSR_VARID_PS_NEXT			0x3005	/* complex */
 #define CSR_VARID_PS_SIZE			0x3006	/* complex */
+#define CSR_VARID_ADC_RES			0x3007	/* complex */
 #define CSR_VARID_CRYPT_KEY_LENGTH		0x3008	/* complex */
 #define CSR_VARID_PICONET_INSTANCE		0x3009	/* complex */
 #define CSR_VARID_GET_CLR_EVT			0x300a	/* complex */
@@ -62,6 +63,7 @@
 #define CSR_VARID_CANCEL_PAGE			0x4012	/* valueless */
 #define CSR_VARID_PS_CLR			0x4818	/* uint16 */
 #define CSR_VARID_MAP_SCO_PCM			0x481c	/* uint16 */
+#define CSR_VARID_ADC				0x4829	/* uint16 */
 #define CSR_VARID_SINGLE_CHAN			0x482e	/* uint16 */
 #define CSR_VARID_RADIOTEST			0x5004	/* complex */
 #define CSR_VARID_PS_CLR_STORES			0x500c	/* complex */

^ permalink raw reply related	[flat|nested] 5+ messages in thread

* Re: [Patch] bccmd - add ability to read ADC
  2015-05-27 15:32 [Patch] bccmd - add ability to read ADC simon
@ 2015-06-06  5:49 ` Marcel Holtmann
  2015-06-08 18:04   ` [PATCH] " Simon Wood
  0 siblings, 1 reply; 5+ messages in thread
From: Marcel Holtmann @ 2015-06-06  5:49 UTC (permalink / raw)
  To: simon; +Cc: linux-bluetooth

Hi Simon,

> Some BlueCore devices are equipped with an 'Analogue In' pin which is
> internally connected to a MUX and ADC. This patch adds the ability to
> control the MUX and read the ADC.
> 
> The ADC is also connected internal to a temp sensor, which can also be
> read via this method.
> 
> The (only) MUX values expected to be used are:
> 1 Internal 1V25 reference
> 16 BlueCore01b pin Test_A; BlueCore2-External pin AIO0
> 17 BlueCore01b pin Test_B; BlueCore2-External pin AIO1
> 36 Chip’s internal temperature (change) sensor. BlueCore2-ROM and later only.
> 
> The MUX can also select other (undocumented) test points.
> 
> Example usage
> --
> # ./bccmd -t HCI -d hci1 adc 17
> ADC value from Mux 0x11 : 0x0054 (valid)
> # ./bccmd -t HCI -d hci1 adc 1
> ADC value from Mux 0x01 : 0x00b2 (valid)

please send a patch created via git format-patch.

Regards

Marcel


^ permalink raw reply	[flat|nested] 5+ messages in thread

* [PATCH] bccmd - add ability to read ADC
  2015-06-06  5:49 ` Marcel Holtmann
@ 2015-06-08 18:04   ` Simon Wood
  2015-06-17 12:48     ` Johan Hedberg
  0 siblings, 1 reply; 5+ messages in thread
From: Simon Wood @ 2015-06-08 18:04 UTC (permalink / raw)
  To: linux-bluetooth; +Cc: simon, Marcel Holtmann

Some BlueCore devices are equipped with an 'Analogue In' pin which is
internally connected to a MUX and ADC. This patch adds the ability to
control the MUX and read the ADC.

The ADC is also connected internal to a temp sensor, which can also be
read via this method.

The (only) MUX values expected to be used are:
1  Internal 1V25 reference
16 BlueCore01b pin Test_A; BlueCore2-External pin AIO0
17 BlueCore01b pin Test_B; BlueCore2-External pin AIO1
36 Chip’s internal temperature (change) sensor. BlueCore2-ROM and later only.

The MUX can also select other (undocumented) test points.

Example usage
--
$ ./bccmd -t HCI -d hci1 adc 17
ADC value from Mux 0x11 : 0x0054 (valid)
$ ./bccmd -t HCI -d hci1 adc 1
ADC value from Mux 0x01 : 0x00b2 (valid)

Signed-off-by: Simon Wood <simon@mungewell.org>
---
 tools/bccmd.c | 42 ++++++++++++++++++++++++++++++++++++++++++
 tools/csr.h   |  2 ++
 2 files changed, 44 insertions(+)

diff --git a/tools/bccmd.c b/tools/bccmd.c
index 7cce426..64c5f56 100644
--- a/tools/bccmd.c
+++ b/tools/bccmd.c
@@ -1040,6 +1040,47 @@ static int cmd_pscheck(int transport, int argc, char *argv[])
 	return 0;
 }
 
+static int cmd_adc(int transport, int argc, char *argv[])
+{
+	uint8_t array[8];
+	uint16_t mux, value;
+	int err;
+
+	OPT_HELP(1, NULL);
+
+	if (!strncasecmp(argv[0], "0x", 2))
+		mux = strtol(argv[0], NULL, 16);
+	else
+		mux = atoi(argv[0]);
+
+	// Request an ADC read from a particular mux'ed input
+	memset(array, 0, sizeof(array));
+	array[0] = mux & 0xff;
+	array[1] = mux >> 8;
+
+	err = transport_write(transport, CSR_VARID_ADC, array, 2);
+	if (err < 0) {
+		errno = -err;
+		return -1;
+	}
+
+	// sleep, then read result
+	usleep(50000);
+	err = transport_read(transport, CSR_VARID_ADC_RES, array, 8);
+	if (err < 0) {
+		errno = -err;
+		return -1;
+	}
+
+	mux = array[0] | (array[1] << 8);
+	value = array[4] | (array[5] << 8);
+
+	printf("ADC value from Mux 0x%02x : 0x%04x (%s)\n", mux, value,
+					array[2] == 1 ? "valid" : "invalid");
+
+	return 0;
+}
+
 static struct {
 	char *str;
 	int (*func)(int transport, int argc, char *argv[]);
@@ -1070,6 +1111,7 @@ static struct {
 	{ "psread",    cmd_psread,    NULL,                  "Read all PS keys"               },
 	{ "psload",    cmd_psload,    "<file>",              "Load all PS keys from PSR file" },
 	{ "pscheck",   cmd_pscheck,   "<file>",              "Check PSR file"                 },
+	{ "adc",       cmd_adc,       "<mux>",               "Read ADC value of <mux> input"  },
 	{ NULL }
 };
 
diff --git a/tools/csr.h b/tools/csr.h
index 8b94d7b..cc245a5 100644
--- a/tools/csr.h
+++ b/tools/csr.h
@@ -39,6 +39,7 @@
 #define CSR_VARID_BT_CLOCK			0x2c00	/* uint32 */
 #define CSR_VARID_PS_NEXT			0x3005	/* complex */
 #define CSR_VARID_PS_SIZE			0x3006	/* complex */
+#define CSR_VARID_ADC_RES			0x3007	/* complex */
 #define CSR_VARID_CRYPT_KEY_LENGTH		0x3008	/* complex */
 #define CSR_VARID_PICONET_INSTANCE		0x3009	/* complex */
 #define CSR_VARID_GET_CLR_EVT			0x300a	/* complex */
@@ -62,6 +63,7 @@
 #define CSR_VARID_CANCEL_PAGE			0x4012	/* valueless */
 #define CSR_VARID_PS_CLR			0x4818	/* uint16 */
 #define CSR_VARID_MAP_SCO_PCM			0x481c	/* uint16 */
+#define CSR_VARID_ADC				0x4829	/* uint16 */
 #define CSR_VARID_SINGLE_CHAN			0x482e	/* uint16 */
 #define CSR_VARID_RADIOTEST			0x5004	/* complex */
 #define CSR_VARID_PS_CLR_STORES			0x500c	/* complex */
-- 
2.1.4

^ permalink raw reply related	[flat|nested] 5+ messages in thread

* Re: [PATCH] bccmd - add ability to read ADC
  2015-06-08 18:04   ` [PATCH] " Simon Wood
@ 2015-06-17 12:48     ` Johan Hedberg
  2015-06-17 15:16       ` simon
  0 siblings, 1 reply; 5+ messages in thread
From: Johan Hedberg @ 2015-06-17 12:48 UTC (permalink / raw)
  To: Simon Wood; +Cc: linux-bluetooth, Marcel Holtmann

Hi Simon,

On Mon, Jun 08, 2015, Simon Wood wrote:
> Some BlueCore devices are equipped with an 'Analogue In' pin which is
> internally connected to a MUX and ADC. This patch adds the ability to
> control the MUX and read the ADC.
> 
> The ADC is also connected internal to a temp sensor, which can also be
> read via this method.
> 
> The (only) MUX values expected to be used are:
> 1  Internal 1V25 reference
> 16 BlueCore01b pin Test_A; BlueCore2-External pin AIO0
> 17 BlueCore01b pin Test_B; BlueCore2-External pin AIO1
> 36 Chip’s internal temperature (change) sensor. BlueCore2-ROM and later only.
> 
> The MUX can also select other (undocumented) test points.
> 
> Example usage
> --
> $ ./bccmd -t HCI -d hci1 adc 17
> ADC value from Mux 0x11 : 0x0054 (valid)
> $ ./bccmd -t HCI -d hci1 adc 1
> ADC value from Mux 0x01 : 0x00b2 (valid)
> 
> Signed-off-by: Simon Wood <simon@mungewell.org>

No Signed-off-by lines for user space patches please.

> +static int cmd_adc(int transport, int argc, char *argv[])
> +{
> +	uint8_t array[8];
> +	uint16_t mux, value;
> +	int err;
> +
> +	OPT_HELP(1, NULL);
> +
> +	if (!strncasecmp(argv[0], "0x", 2))
> +		mux = strtol(argv[0], NULL, 16);
> +	else
> +		mux = atoi(argv[0]);
> +
> +	// Request an ADC read from a particular mux'ed input

No C++ style comments please. Use /* ... */

> +	// sleep, then read result

Same here.

And the patch doesn't actually compile:

tools/bccmd.c:1068:2: error: implicit declaration of function ‘usleep’ [-Werror=implicit-function-declaration]
  usleep(50000);
  ^

Please add the necessary include for that (unistd.h, I believe).

Johan

^ permalink raw reply	[flat|nested] 5+ messages in thread

* Re: [PATCH] bccmd - add ability to read ADC
  2015-06-17 12:48     ` Johan Hedberg
@ 2015-06-17 15:16       ` simon
  0 siblings, 0 replies; 5+ messages in thread
From: simon @ 2015-06-17 15:16 UTC (permalink / raw)
  To: linux-bluetooth, Marcel Holtmann


> And the patch doesn't actually compile:
>
> tools/bccmd.c:1068:2: error: implicit declaration of function ‘usleep’
> [-Werror=implicit-function-declaration]
>   usleep(50000);

Huh, builds on Xubuntu 14.10...
--
simon@LinuxBuild:~/bluez-git$ make
make --no-print-directory all-am
  CC       tools/bccmd.o
  CCLD     tools/bccmd
simon@LinuxBuild:~/bluez-git$ grep  ADC tools/bccmd.c
	// Request an ADC read from a particular mux'ed input
	err = transport_write(transport, CSR_VARID_ADC, array, 2);
	err = transport_read(transport, CSR_VARID_ADC_RES, array, 8);
	printf("ADC value from Mux 0x%02x : 0x%04x (%s)\n", mux, value,
	{ "adc",       cmd_adc,       "<mux>",               "Read ADC value of
<mux> input"  },
--

Anyhow, will fix and re-submit. Thanks,
Simon.


^ permalink raw reply	[flat|nested] 5+ messages in thread

end of thread, other threads:[~2015-06-17 15:16 UTC | newest]

Thread overview: 5+ messages (download: mbox.gz / follow: Atom feed)
-- links below jump to the message on this page --
2015-05-27 15:32 [Patch] bccmd - add ability to read ADC simon
2015-06-06  5:49 ` Marcel Holtmann
2015-06-08 18:04   ` [PATCH] " Simon Wood
2015-06-17 12:48     ` Johan Hedberg
2015-06-17 15:16       ` simon

This is an external index of several public inboxes,
see mirroring instructions on how to clone and mirror
all data and code used by this external index.