2014-12-01 22:12:41 -04:00
|
|
|
/*
|
|
|
|
simple test of UART interfaces
|
|
|
|
*/
|
2015-10-20 09:34:10 -03:00
|
|
|
|
2015-08-11 03:28:43 -03:00
|
|
|
#include <AP_HAL/AP_HAL.h>
|
2014-12-01 22:12:41 -04:00
|
|
|
|
|
|
|
#if HAL_OS_POSIX_IO
|
|
|
|
#include <stdio.h>
|
|
|
|
#endif
|
|
|
|
|
2017-04-13 08:31:16 -03:00
|
|
|
void setup();
|
|
|
|
void loop();
|
|
|
|
|
2015-10-16 17:22:11 -03:00
|
|
|
const AP_HAL::HAL& hal = AP_HAL::get_HAL();
|
2014-12-01 22:12:41 -04:00
|
|
|
|
|
|
|
/*
|
|
|
|
setup one UART at 57600
|
|
|
|
*/
|
|
|
|
static void setup_uart(AP_HAL::UARTDriver *uart, const char *name)
|
|
|
|
{
|
2016-10-30 02:24:21 -03:00
|
|
|
if (uart == nullptr) {
|
2014-12-01 22:12:41 -04:00
|
|
|
// that UART doesn't exist on this platform
|
|
|
|
return;
|
|
|
|
}
|
|
|
|
uart->begin(57600);
|
|
|
|
}
|
|
|
|
|
|
|
|
|
2017-04-13 08:31:16 -03:00
|
|
|
void setup(void)
|
2014-12-01 22:12:41 -04:00
|
|
|
{
|
|
|
|
/*
|
|
|
|
start all UARTs at 57600 with default buffer sizes
|
2017-11-21 12:35:52 -04:00
|
|
|
*/
|
|
|
|
|
|
|
|
hal.scheduler->delay(1000); //Ensure that the uartA can be initialized
|
|
|
|
|
2020-12-10 20:56:53 -04:00
|
|
|
setup_uart(hal.serial(0), "SERIAL0"); // console
|
|
|
|
setup_uart(hal.serial(1), "SERIAL1"); // telemetry 1
|
|
|
|
setup_uart(hal.serial(2), "SERIAL2"); // telemetry 2
|
|
|
|
setup_uart(hal.serial(3), "SERIAL3"); // 1st GPS
|
|
|
|
setup_uart(hal.serial(4), "SERIAL4"); // 2nd GPS
|
2014-12-01 22:12:41 -04:00
|
|
|
}
|
|
|
|
|
|
|
|
static void test_uart(AP_HAL::UARTDriver *uart, const char *name)
|
|
|
|
{
|
2016-10-30 02:24:21 -03:00
|
|
|
if (uart == nullptr) {
|
2014-12-01 22:12:41 -04:00
|
|
|
// that UART doesn't exist on this platform
|
|
|
|
return;
|
|
|
|
}
|
|
|
|
uart->printf("Hello on UART %s at %.3f seconds\n",
|
2017-04-13 08:31:16 -03:00
|
|
|
name, (double)(AP_HAL::millis() * 0.001f));
|
2014-12-01 22:12:41 -04:00
|
|
|
}
|
|
|
|
|
2017-04-13 08:31:16 -03:00
|
|
|
void loop(void)
|
|
|
|
{
|
2020-12-10 20:56:53 -04:00
|
|
|
test_uart(hal.serial(0), "SERIAL0");
|
|
|
|
test_uart(hal.serial(1), "SERIAL1");
|
|
|
|
test_uart(hal.serial(2), "SERIAL2");
|
|
|
|
test_uart(hal.serial(3), "SERIAL3");
|
|
|
|
test_uart(hal.serial(4), "SERIAL4");
|
2014-12-01 22:12:41 -04:00
|
|
|
|
|
|
|
// also do a raw printf() on some platforms, which prints to the
|
|
|
|
// debug console
|
|
|
|
#if HAL_OS_POSIX_IO
|
2017-04-13 08:31:16 -03:00
|
|
|
::printf("Hello on debug console at %.3f seconds\n", (double)(AP_HAL::millis() * 0.001f));
|
2014-12-01 22:12:41 -04:00
|
|
|
#endif
|
|
|
|
|
|
|
|
hal.scheduler->delay(1000);
|
|
|
|
}
|
|
|
|
|
|
|
|
AP_HAL_MAIN();
|