[nrf52840] add basic gpio diag commands (#2139)

This commit is contained in:
Martin Turon
2017-09-15 11:31:11 -07:00
committed by Jonathan Hui
parent 908d7dae83
commit 4ccc23a511
2 changed files with 126 additions and 3 deletions
+47
View File
@@ -6,6 +6,7 @@ New commands allow for more accurate low level radio testing.
### New commands
* [diag ccathreshold](#diag-ccathreshold)
* [diag gpio](#diag-gpio)
* [diag id](#diag-id)
* [diag listen](#diag-listen)
* [diag temp](#diag-temp)
@@ -52,6 +53,52 @@ Value range 0 to 255.
Default: `45`.
### diag gpio
Set of commands for managing gpio pins.
### diag gpio \<pinnum\>
Return the current value of the gpio.
Note: \<pinnum\> is an integer that combines port and pin into a single,
contiguous number space as follows:
```
pinnum = (port * 32) + pin
```
See also the [`NRF_GPIO_PIN_MAP`](../../../third_party/NordicSemiconductor/hal/nrf_gpio.h) macro.
```bash
> diag gpio 47
gpio 47 = 0
```
### diag gpio out \<pinnum\>
Sets the given gpio to output mode.
```bash
> diag gpio out 47
gpio 47: out
```
### diag gpio in \<pinnum\>
Sets the given gpio to input, no pull mode.
```bash
> diag gpio in 47
gpio 47: in no pull
```
### diag gpio set \<pinnum\>
Sets the given output gpio to high.
```bash
> diag gpio set 47
gpio 47 = 1
```
### diag gpio clr \<pinnum\>
Sets the given output gpio to low.
```bash
> diag gpio clr 47
gpio 47 = 0
```
### diag id
Get board ID.
+79 -3
View File
@@ -37,6 +37,8 @@
#include "platform-nrf5.h"
#include <hal/nrf_gpio.h>
#include <openthread/cli.h>
#include <openthread/platform/alarm-milli.h>
#include <openthread/platform/diag.h>
@@ -239,6 +241,79 @@ exit:
appendErrorResult(error, aOutput, aOutputMaxLen);
}
static void processGpio(otInstance *aInstance, int argc, char *argv[],
char *aOutput, size_t aOutputMaxLen)
{
OT_UNUSED_VARIABLE(aInstance);
long pinnum;
otError error = OT_ERROR_NONE;
otEXPECT_ACTION(otPlatDiagModeGet(), error = OT_ERROR_INVALID_STATE);
if (argc == 1)
{
uint32_t value;
error = parseLong(argv[0], &pinnum);
otEXPECT(error == OT_ERROR_NONE);
value = nrf_gpio_pin_read(pinnum);
snprintf(aOutput, aOutputMaxLen, "gpio %d = %d\r\n",
(uint8_t)pinnum, (uint8_t)value);
}
else if (strcmp(argv[0], "set") == 0)
{
otEXPECT_ACTION(argc == 2, error = OT_ERROR_INVALID_ARGS);
error = parseLong(argv[1], &pinnum);
otEXPECT(error == OT_ERROR_NONE);
nrf_gpio_pin_set(pinnum);
snprintf(aOutput, aOutputMaxLen, "gpio %d = 1\r\n", (uint8_t)pinnum);
}
else if (strcmp(argv[0], "clr") == 0)
{
otEXPECT_ACTION(argc == 2, error = OT_ERROR_INVALID_ARGS);
error = parseLong(argv[1], &pinnum);
otEXPECT(error == OT_ERROR_NONE);
nrf_gpio_pin_clear(pinnum);
snprintf(aOutput, aOutputMaxLen, "gpio %d = 0\r\n", (uint8_t)pinnum);
}
else if (strcmp(argv[0], "out") == 0)
{
otEXPECT_ACTION(argc == 2, error = OT_ERROR_INVALID_ARGS);
error = parseLong(argv[1], &pinnum);
otEXPECT(error == OT_ERROR_NONE);
nrf_gpio_cfg_output(pinnum);
snprintf(aOutput, aOutputMaxLen, "gpio %d: out\r\n", (uint8_t)pinnum);
}
else if (strcmp(argv[0], "in") == 0)
{
otEXPECT_ACTION(argc == 2, error = OT_ERROR_INVALID_ARGS);
error = parseLong(argv[1], &pinnum);
otEXPECT(error == OT_ERROR_NONE);
nrf_gpio_cfg_input(pinnum, NRF_GPIO_PIN_NOPULL);
snprintf(aOutput, aOutputMaxLen, "gpio %d: in no pull\r\n",
(uint8_t)pinnum);
}
else
{
error = OT_ERROR_INVALID_ARGS;
}
exit:
appendErrorResult(error, aOutput, aOutputMaxLen);
}
static void processTemp(otInstance *aInstance, int argc, char *argv[], char *aOutput, size_t aOutputMaxLen)
{
OT_UNUSED_VARIABLE(aInstance);
@@ -296,11 +371,12 @@ exit:
const struct PlatformDiagCommand sCommands[] =
{
{ "listen", &processListen },
{ "transmit", &processTransmit },
{ "ccathreshold", &processCcaThreshold },
{ "gpio", &processGpio },
{ "id", &processID },
{ "listen", &processListen },
{ "temp", &processTemp },
{ "ccathreshold", &processCcaThreshold }
{ "transmit", &processTransmit },
};
void otPlatDiagProcess(otInstance *aInstance, int argc, char *argv[], char *aOutput, size_t aOutputMaxLen)