2012-09-07 20:09:29 -03:00
|
|
|
|
2015-08-11 03:28:43 -03:00
|
|
|
#include <AP_Common/AP_Common.h>
|
|
|
|
#include <AP_Math/AP_Math.h>
|
|
|
|
#include <AP_Param/AP_Param.h>
|
|
|
|
#include <AP_Progmem/AP_Progmem.h>
|
2012-12-11 20:23:02 -04:00
|
|
|
|
2015-08-11 03:28:43 -03:00
|
|
|
#include <AP_HAL/AP_HAL.h>
|
|
|
|
#include <AP_HAL_AVR/AP_HAL_AVR.h>
|
2012-09-07 20:09:29 -03:00
|
|
|
|
2012-12-11 20:23:02 -04:00
|
|
|
#if CONFIG_HAL_BOARD == HAL_BOARD_APM2
|
2012-09-07 20:09:29 -03:00
|
|
|
const AP_HAL::HAL& hal = AP_HAL_AVR_APM2;
|
2012-12-11 20:23:02 -04:00
|
|
|
#elif CONFIG_HAL_BOARD == HAL_BOARD_APM1
|
|
|
|
const AP_HAL::HAL& hal = AP_HAL_AVR_APM1;
|
|
|
|
#endif
|
2012-09-07 20:09:29 -03:00
|
|
|
|
|
|
|
/**
|
|
|
|
* You'll want to use a logic analyzer to watch the effects of this test.
|
|
|
|
* On the APM2 its pretty easy to hook up an analyzer to pins A0 through A3.
|
|
|
|
*/
|
|
|
|
#define DELAY_TOGGLE_PIN 54 /* A0 */
|
|
|
|
#define FAILSAFE_TOGGLE_PIN 55 /* A1 */
|
|
|
|
#define SCHEDULED_TOGGLE_PIN_1 56 /* A2 */
|
|
|
|
#define SCHEDULED_TOGGLE_PIN_2 57 /* A3 */
|
|
|
|
|
|
|
|
|
|
|
|
void delay_toggle() {
|
|
|
|
volatile int i;
|
|
|
|
hal.gpio->write(DELAY_TOGGLE_PIN, 1);
|
|
|
|
for (i = 0; i < 10; i++);
|
|
|
|
hal.gpio->write(DELAY_TOGGLE_PIN, 0);
|
|
|
|
}
|
|
|
|
|
2013-09-28 03:24:02 -03:00
|
|
|
void failsafe_toggle(void *) {
|
2012-09-07 20:09:29 -03:00
|
|
|
volatile int i;
|
|
|
|
hal.gpio->write(FAILSAFE_TOGGLE_PIN, 1);
|
|
|
|
for (i = 0; i < 10; i++);
|
|
|
|
hal.gpio->write(FAILSAFE_TOGGLE_PIN, 0);
|
|
|
|
}
|
|
|
|
|
|
|
|
|
2013-09-28 03:24:02 -03:00
|
|
|
void schedule_toggle_1(void *) {
|
2012-09-07 20:09:29 -03:00
|
|
|
volatile int i;
|
|
|
|
hal.gpio->write(SCHEDULED_TOGGLE_PIN_1, 1);
|
|
|
|
for (i = 0; i < 10; i++);
|
|
|
|
hal.gpio->write(SCHEDULED_TOGGLE_PIN_1, 0);
|
|
|
|
}
|
|
|
|
|
2013-09-28 03:24:02 -03:00
|
|
|
void schedule_toggle_2(void *) {
|
2012-09-07 20:09:29 -03:00
|
|
|
volatile int i;
|
|
|
|
hal.gpio->write(SCHEDULED_TOGGLE_PIN_2, 1);
|
|
|
|
for (i = 0; i < 10; i++);
|
|
|
|
hal.gpio->write(SCHEDULED_TOGGLE_PIN_2, 0);
|
|
|
|
}
|
|
|
|
|
2013-09-28 03:24:02 -03:00
|
|
|
void schedule_toggle_hang(void *) {
|
2012-09-07 20:09:29 -03:00
|
|
|
hal.gpio->write(SCHEDULED_TOGGLE_PIN_2, 1);
|
|
|
|
for(;;);
|
|
|
|
}
|
|
|
|
|
|
|
|
void setup_pin(int pin_num) {
|
2012-10-26 21:26:19 -03:00
|
|
|
hal.console->printf_P(PSTR("Setup pin %d\r\n"), pin_num);
|
2014-06-01 20:26:19 -03:00
|
|
|
hal.gpio->pinMode(pin_num,HAL_GPIO_OUTPUT);
|
2012-09-07 20:09:29 -03:00
|
|
|
/* Blink so we can see setup on the logic analyzer.*/
|
|
|
|
hal.gpio->write(pin_num,1);
|
|
|
|
hal.gpio->write(pin_num,0);
|
|
|
|
}
|
|
|
|
|
|
|
|
void setup (void) {
|
2012-10-26 21:26:19 -03:00
|
|
|
hal.console->printf_P(PSTR("Starting AP_HAL_AVR::Scheduler test\r\n"));
|
2012-09-07 20:09:29 -03:00
|
|
|
|
|
|
|
setup_pin(DELAY_TOGGLE_PIN);
|
|
|
|
setup_pin(FAILSAFE_TOGGLE_PIN);
|
|
|
|
setup_pin(SCHEDULED_TOGGLE_PIN_1);
|
|
|
|
setup_pin(SCHEDULED_TOGGLE_PIN_2);
|
|
|
|
|
2012-10-26 21:26:19 -03:00
|
|
|
hal.console->printf_P(PSTR("Testing delay callback. "
|
2012-09-07 20:09:29 -03:00
|
|
|
"Pin %d should toggle at 1khz:\r\n"),
|
|
|
|
(int) DELAY_TOGGLE_PIN);
|
|
|
|
|
2012-10-26 22:02:52 -03:00
|
|
|
hal.scheduler->register_delay_callback(delay_toggle,0);
|
2012-09-07 20:09:29 -03:00
|
|
|
|
|
|
|
hal.scheduler->delay(100);
|
|
|
|
|
2012-10-26 21:26:19 -03:00
|
|
|
hal.console->printf_P(PSTR("Testing failsafe callback. "
|
2012-09-07 20:09:29 -03:00
|
|
|
"Pin %d should toggle at 1khz:\r\n"),
|
|
|
|
(int) FAILSAFE_TOGGLE_PIN);
|
|
|
|
|
|
|
|
hal.scheduler->register_timer_failsafe(failsafe_toggle, 1000);
|
|
|
|
|
|
|
|
hal.scheduler->delay(100);
|
|
|
|
|
2012-10-26 21:26:19 -03:00
|
|
|
hal.console->printf_P(PSTR("Testing running timer processes.\r\n"));
|
|
|
|
hal.console->printf_P(PSTR("Pin %d should toggle at 1khz.\r\n"),
|
2012-09-07 20:09:29 -03:00
|
|
|
(int) SCHEDULED_TOGGLE_PIN_1);
|
2012-10-26 21:26:19 -03:00
|
|
|
hal.console->printf_P(PSTR("Pin %d should toggle at 1khz.\r\n"),
|
2012-09-07 20:09:29 -03:00
|
|
|
(int) SCHEDULED_TOGGLE_PIN_2);
|
|
|
|
|
2013-09-28 03:24:02 -03:00
|
|
|
hal.scheduler->register_timer_process(schedule_toggle_1, NULL);
|
|
|
|
hal.scheduler->register_timer_process(schedule_toggle_2, NULL);
|
2012-09-07 20:09:29 -03:00
|
|
|
|
|
|
|
hal.scheduler->delay(100);
|
|
|
|
|
2012-10-26 21:26:19 -03:00
|
|
|
hal.console->printf_P(PSTR("Test running a pathological timer process.\r\n"
|
2012-09-07 20:09:29 -03:00
|
|
|
"Failsafe should continue even as pathological process "
|
|
|
|
"dominates the processor."));
|
2012-10-26 21:26:19 -03:00
|
|
|
hal.console->printf_P(PSTR("Pin %d should toggle then go high forever.\r\n"),
|
2012-09-07 20:09:29 -03:00
|
|
|
(int) SCHEDULED_TOGGLE_PIN_2);
|
2013-09-28 03:24:02 -03:00
|
|
|
hal.scheduler->register_timer_process(schedule_toggle_hang, NULL);
|
2012-09-07 20:09:29 -03:00
|
|
|
}
|
|
|
|
|
|
|
|
void loop (void) { }
|
|
|
|
|
2012-12-03 20:25:11 -04:00
|
|
|
AP_HAL_MAIN();
|