Skip to content
This repository has been archived by the owner on Nov 11, 2024. It is now read-only.

Commit

Permalink
Device addition: add U_DEVICE_TRANSPORT_TYPE_UART_USB. (#1078)
Browse files Browse the repository at this point in the history
When running on platforms that provide USB interfaces (e.g. Windows and Linux) the UART driver/transport may be used in all cases, this is not an issue. However, the configuration of periodic messaging out of a GNSS chip is port specific, i.e. this code has to tell the GNSS chip to emit a given message ID, say, once a second, on its UART port or on its USB port. Hence this code needs to know whether the HW transport is, under the hood, USB or UART.

Previously we assumed the HW was USB on Windows/Zephyr-Posix but we could not do that on Linux since, on Linux, a Raspberry Pi, which has a couple of UARTs, I2C and SPI, may be using any one of those; for that case the customer had to use a compile-time flag U_CFG_GNSS_PORT_NUMBER to override the GNSS port number to be USB, which was cumbersome. The customer can now use U_DEVICE_TRANSPORT_TYPE_UART_USB to indicate that the GNSS connection is USB; the ability to override at compile time with U_CFG_GNSS_PORT_NUMBER remains.

The cellular and short-range device code is updated so that, should a customer decide to use U_DEVICE_TRANSPORT_TYPE_UART_USB, it is treated the same way as U_DEVICE_TRANSPORT_TYPE_UART.
  • Loading branch information
RobMeades authored Jan 23, 2024
1 parent b7dffb7 commit bb93cdb
Show file tree
Hide file tree
Showing 7 changed files with 46 additions and 13 deletions.
13 changes: 13 additions & 0 deletions common/device/api/u_device.h
Original file line number Diff line number Diff line change
Expand Up @@ -78,6 +78,19 @@ typedef enum {
second one, otherwise please just use
#U_DEVICE_TRANSPORT_TYPE_UART (or
#U_DEVICE_TRANSPORT_TYPE_UART_1). */
U_DEVICE_TRANSPORT_TYPE_UART_USB, /**< Internally this is no different to
#U_DEVICE_TRANSPORT_TYPE_UART, despite
the HW being USB the UART driver is
still used in all cases and that works
on all supported platforms; IT SHOULD
BE USED in the GNSS case to indicate
that the connection is ultimately to
the USB port of the GNSS chip, rather
than the UART port of the GNSS chip
(this code needs to know that because
the configuration of periodic message
transmission from within the GNSS
device is port-specific). */
U_DEVICE_TRANSPORT_TYPE_MAX_NUM,
U_DEVICE_TRANSPORT_TYPE_UART_1 = U_DEVICE_TRANSPORT_TYPE_UART
} uDeviceTransportType_t;
Expand Down
3 changes: 2 additions & 1 deletion common/device/src/u_device_private_cell.c
Original file line number Diff line number Diff line change
Expand Up @@ -247,7 +247,8 @@ int32_t uDevicePrivateCellAdd(const uDeviceCfg_t *pDevCfg,
const uDeviceCfgCell_t *pCfgCell;

if ((pDevCfg != NULL) &&
(pDevCfg->transportType == U_DEVICE_TRANSPORT_TYPE_UART) &&
((pDevCfg->transportType == U_DEVICE_TRANSPORT_TYPE_UART) ||
(pDevCfg->transportType == U_DEVICE_TRANSPORT_TYPE_UART_USB)) &&
(pDeviceHandle != NULL)) {
pCfgUart = &(pDevCfg->transportCfg.cfgUart);
pCfgCell = &(pDevCfg->deviceCfg.cfgCell);
Expand Down
15 changes: 11 additions & 4 deletions common/device/src/u_device_private_gnss.c
Original file line number Diff line number Diff line change
Expand Up @@ -76,11 +76,12 @@
*/
const uGnssTransportType_t gDeviceToGnssTransportType[] = {
U_GNSS_TRANSPORT_NONE, // U_DEVICE_TRANSPORT_TYPE_NONE,
U_GNSS_TRANSPORT_UART, // U_DEVICE_TRANSPORT_TYPE_UART or U_DEVICE_TRANSPORT_TYPE_UART_1,
U_GNSS_TRANSPORT_I2C, // U_DEVICE_TRANSPORT_TYPE_I2C,
U_GNSS_TRANSPORT_SPI, // U_DEVICE_TRANSPORT_TYPE_SPI,
U_GNSS_TRANSPORT_UART, // U_DEVICE_TRANSPORT_TYPE_UART or U_DEVICE_TRANSPORT_TYPE_UART_1
U_GNSS_TRANSPORT_I2C, // U_DEVICE_TRANSPORT_TYPE_I2C
U_GNSS_TRANSPORT_SPI, // U_DEVICE_TRANSPORT_TYPE_SPI
U_GNSS_TRANSPORT_VIRTUAL_SERIAL, // U_DEVICE_TRANSPORT_TYPE_VIRTUAL_SERIAL
U_GNSS_TRANSPORT_UART_2 // U_DEVICE_TRANSPORT_TYPE_UART_2,
U_GNSS_TRANSPORT_UART_2, // U_DEVICE_TRANSPORT_TYPE_UART_2
U_GNSS_TRANSPORT_USB // U_DEVICE_TRANSPORT_TYPE_UART_USB
};

/* ----------------------------------------------------------------
Expand All @@ -95,6 +96,8 @@ static void populateContext(uDeviceGnssInstance_t *pContext,
switch (deviceTransportType) {
case U_DEVICE_TRANSPORT_TYPE_UART:
// fall-through
case U_DEVICE_TRANSPORT_TYPE_UART_USB:
// fall-through
case U_DEVICE_TRANSPORT_TYPE_UART_2:
pContext->transportHandle.int32Handle = gnssTransportHandle.uart;
break;
Expand Down Expand Up @@ -233,6 +236,8 @@ int32_t uDevicePrivateGnssAdd(const uDeviceCfg_t *pDevCfg,
switch (pDevCfg->transportType) {
case U_DEVICE_TRANSPORT_TYPE_UART:
// fall-through
case U_DEVICE_TRANSPORT_TYPE_UART_USB:
// fall-through
case U_DEVICE_TRANSPORT_TYPE_UART_2:
pCfgUart = &(pDevCfg->transportCfg.cfgUart);
if (pCfgUart->pPrefix != NULL) {
Expand Down Expand Up @@ -379,6 +384,8 @@ int32_t uDevicePrivateGnssRemove(uDeviceHandle_t devHandle,
switch (deviceTransportType) {
case U_DEVICE_TRANSPORT_TYPE_UART:
// fall-through
case U_DEVICE_TRANSPORT_TYPE_UART_USB:
// fall-through
case U_DEVICE_TRANSPORT_TYPE_UART_2:
uPortUartClose(transportHandle.int32Handle);
break;
Expand Down
3 changes: 2 additions & 1 deletion common/device/src/u_device_private_short_range.c
Original file line number Diff line number Diff line change
Expand Up @@ -116,7 +116,8 @@ int32_t uDevicePrivateShortRangeAdd(const uDeviceCfg_t *pDevCfg,
uShortRangeUartConfig_t uartCfg;

if ((pDevCfg != NULL) &&
(pDevCfg->transportType == U_DEVICE_TRANSPORT_TYPE_UART) &&
((pDevCfg->transportType == U_DEVICE_TRANSPORT_TYPE_UART) ||
(pDevCfg->transportType == U_DEVICE_TRANSPORT_TYPE_UART_USB)) &&
(pDeviceHandle != NULL)) {
pCfgUart = &(pDevCfg->transportCfg.cfgUart);
pCfgSho = &(pDevCfg->deviceCfg.cfgSho);
Expand Down
6 changes: 5 additions & 1 deletion gnss/api/u_gnss_type.h
Original file line number Diff line number Diff line change
Expand Up @@ -179,6 +179,9 @@ typedef enum {
U_GNSS_TRANSPORT_UART_2, /**< the transport handle should be a UART handle;
use this if your GNSS chip has two UART ports
and you are connected to the second one. */
U_GNSS_TRANSPORT_USB, /**< the transport handle should STILL be a UART handle;
use this if your GNSS chip is connected via USB;
the UART driver will still be used. */
U_GNSS_TRANSPORT_MAX_NUM,
U_GNSS_TRANSPORT_UART_1 = U_GNSS_TRANSPORT_UART /**< the transport handle should
be a UART handle; equivalent
Expand All @@ -195,7 +198,8 @@ typedef enum {
*/
typedef union {
void *pAt; /**< for transport type #U_GNSS_TRANSPORT_AT. */
int32_t uart; /**< for transport types #U_GNSS_TRANSPORT_UART, #U_GNSS_TRANSPORT_UART_1 and #U_GNSS_TRANSPORT_UART_2). */
int32_t uart; /**< for transport types #U_GNSS_TRANSPORT_UART, #U_GNSS_TRANSPORT_UART_1,
#U_GNSS_TRANSPORT_UART_2 and #U_GNSS_TRANSPORT_USB. */
int32_t i2c; /**< for transport type #U_GNSS_TRANSPORT_I2C. */
int32_t spi; /**< for transport type #U_GNSS_TRANSPORT_SPI. */
void *pDeviceSerial; /**< for transport type #U_GNSS_TRANSPORT_VIRTUAL_SERIAL. */
Expand Down
13 changes: 9 additions & 4 deletions gnss/src/u_gnss.c
Original file line number Diff line number Diff line change
Expand Up @@ -85,7 +85,8 @@ static const char *const gpTransportTypeText[] = {"None", // U_GNSS_TRANSP
"I2C", // U_GNSS_TRANSPORT_I2C
"SPI", // U_GNSS_TRANSPORT_SPI
"Virtual Serial", // U_GNSS_TRANSPORT_VIRTUAL_SERIAL
"UART 2" // U_GNSS_TRANSPORT_UART_2
"UART 2", // U_GNSS_TRANSPORT_UART_2
"UART USB" // U_GNSS_TRANSPORT_USB
};
#endif

Expand All @@ -104,8 +105,9 @@ static uGnssPrivateInstance_t *pGetGnssInstanceTransportHandle(uGnssTransportTyp
bool match = false;

while ((pInstance != NULL) && !match) {
// Either UART transport type (on the GNSS-side) should be treated the same way
if (transportType == U_GNSS_TRANSPORT_UART_2) {
// Either UART transport type (on the GNSS-side), or USB transport
// (which just looks like UART to us) should be treated the same way
if ((transportType == U_GNSS_TRANSPORT_UART_2) || (transportType == U_GNSS_TRANSPORT_USB)) {
transportType = U_GNSS_TRANSPORT_UART;
}
if (pInstance->transportType == transportType) {
Expand Down Expand Up @@ -357,10 +359,13 @@ int32_t uGnssAdd(uGnssModuleType_t moduleType,
pInstance->portNumber = U_GNSS_PORT_UART2;
} else if (transportType == U_GNSS_TRANSPORT_SPI) {
pInstance->portNumber = U_GNSS_PORT_SPI;
} else if (transportType == U_GNSS_TRANSPORT_USB) {
pInstance->portNumber = U_GNSS_PORT_USB;
}
#if defined(_WIN32) || (defined(__ZEPHYR__) && defined(CONFIG_UART_NATIVE_POSIX))
// For Windows and Posix-Zephyr the GNSS-side connection is assumed to be USB
// (for Linux, on a Raspberry Pi, it's not forced, just good 'ole UART)
// (for Linux, assumed to be on a Raspberry Pi, it is not forced, as it
// could still be any one of UART, I2C or SPI)
pInstance->portNumber = 3;
#endif
#ifdef U_CFG_GNSS_PORT_NUMBER
Expand Down
6 changes: 4 additions & 2 deletions gnss/test/u_gnss_mga_test.c
Original file line number Diff line number Diff line change
Expand Up @@ -350,10 +350,12 @@ static const char *gpOfflineOperation[] = {"send everything", "write to flash",
* GNSS chip attached so it is useful to know which one we've selected.
*/
static const char *const gpTransportType[] = {"None", // U_DEVICE_TRANSPORT_TYPE_NONE
"UART", // U_DEVICE_TRANSPORT_TYPE_UART
"UART 1", // U_DEVICE_TRANSPORT_TYPE_UART
"I2C", // U_DEVICE_TRANSPORT_TYPE_I2C
"SPI", // U_DEVICE_TRANSPORT_TYPE_SPI
"Virtual Serial" // U_DEVICE_TRANSPORT_TYPE_VIRTUAL_SERIAL
"Virtual Serial", // U_DEVICE_TRANSPORT_TYPE_VIRTUAL_SERIAL
"UART 2", // U_DEVICE_TRANSPORT_TYPE_UART_2
"UART USB" // U_DEVICE_TRANSPORT_TYPE_UART_USB
};

# endif // #if defined(U_CFG_APP_GNSS_ASSIST_NOW_AUTHENTICATION_TOKEN) && defined(U_CFG_TEST_GNSS_MGA) &&
Expand Down

0 comments on commit bb93cdb

Please sign in to comment.