mirror of
https://github.com/ArduPilot/ardupilot
synced 2025-01-10 18:08:30 -04:00
AP_HAL_AVR: Scheduler unit tests
This commit is contained in:
parent
ba7a596ec3
commit
01e34825f3
0
libraries/AP_HAL_AVR/examples/Scheduler/Arduino.h
Normal file
0
libraries/AP_HAL_AVR/examples/Scheduler/Arduino.h
Normal file
1
libraries/AP_HAL_AVR/examples/Scheduler/Makefile
Normal file
1
libraries/AP_HAL_AVR/examples/Scheduler/Makefile
Normal file
@ -0,0 +1 @@
|
||||
include ../../../AP_Common/Arduino.mk
|
112
libraries/AP_HAL_AVR/examples/Scheduler/Scheduler.pde
Normal file
112
libraries/AP_HAL_AVR/examples/Scheduler/Scheduler.pde
Normal file
@ -0,0 +1,112 @@
|
||||
|
||||
#include <AP_Common.h>
|
||||
#include <AP_HAL.h>
|
||||
#include <AP_HAL_AVR.h>
|
||||
|
||||
const AP_HAL::HAL& hal = AP_HAL_AVR_APM2;
|
||||
|
||||
/**
|
||||
* 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);
|
||||
}
|
||||
|
||||
void failsafe_toggle(uint32_t machtnichts) {
|
||||
volatile int i;
|
||||
hal.gpio->write(FAILSAFE_TOGGLE_PIN, 1);
|
||||
for (i = 0; i < 10; i++);
|
||||
hal.gpio->write(FAILSAFE_TOGGLE_PIN, 0);
|
||||
}
|
||||
|
||||
|
||||
void schedule_toggle_1(uint32_t machtnichts) {
|
||||
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);
|
||||
}
|
||||
|
||||
void schedule_toggle_2(uint32_t machtnichts) {
|
||||
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);
|
||||
}
|
||||
|
||||
void schedule_toggle_hang(uint32_t machtnichts) {
|
||||
hal.gpio->write(SCHEDULED_TOGGLE_PIN_2, 1);
|
||||
for(;;);
|
||||
}
|
||||
|
||||
void setup_pin(int pin_num) {
|
||||
hal.uart0->printf_P(PSTR("Setup pin %d\r\n"), pin_num);
|
||||
hal.gpio->pinMode(pin_num,GPIO_OUTPUT);
|
||||
/* 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) {
|
||||
hal.uart0->printf_P(PSTR("Starting AP_HAL_AVR::Scheduler test\r\n"));
|
||||
|
||||
setup_pin(DELAY_TOGGLE_PIN);
|
||||
setup_pin(FAILSAFE_TOGGLE_PIN);
|
||||
setup_pin(SCHEDULED_TOGGLE_PIN_1);
|
||||
setup_pin(SCHEDULED_TOGGLE_PIN_2);
|
||||
|
||||
hal.uart0->printf_P(PSTR("Testing delay callback. "
|
||||
"Pin %d should toggle at 1khz:\r\n"),
|
||||
(int) DELAY_TOGGLE_PIN);
|
||||
|
||||
hal.scheduler->register_delay_callback(delay_toggle);
|
||||
|
||||
hal.scheduler->delay(100);
|
||||
|
||||
hal.uart0->printf_P(PSTR("Testing failsafe callback. "
|
||||
"Pin %d should toggle at 1khz:\r\n"),
|
||||
(int) FAILSAFE_TOGGLE_PIN);
|
||||
|
||||
hal.scheduler->register_timer_failsafe(failsafe_toggle, 1000);
|
||||
|
||||
hal.scheduler->delay(100);
|
||||
|
||||
hal.uart0->printf_P(PSTR("Testing running timer processes.\r\n"));
|
||||
hal.uart0->printf_P(PSTR("Pin %d should toggle at 1khz.\r\n"),
|
||||
(int) SCHEDULED_TOGGLE_PIN_1);
|
||||
hal.uart0->printf_P(PSTR("Pin %d should toggle at 1khz.\r\n"),
|
||||
(int) SCHEDULED_TOGGLE_PIN_2);
|
||||
|
||||
hal.scheduler->register_timer_process(schedule_toggle_1, 1000, 0);
|
||||
hal.scheduler->register_timer_process(schedule_toggle_2, 1000, 0);
|
||||
|
||||
hal.scheduler->delay(100);
|
||||
|
||||
hal.uart0->printf_P(PSTR("Test running a pathological timer process.\r\n"
|
||||
"Failsafe should continue even as pathological process "
|
||||
"dominates the processor."));
|
||||
hal.uart0->printf_P(PSTR("Pin %d should toggle then go high forever.\r\n"),
|
||||
(int) SCHEDULED_TOGGLE_PIN_2);
|
||||
hal.scheduler->register_timer_process(schedule_toggle_hang, 1000, 0);
|
||||
}
|
||||
|
||||
void loop (void) { }
|
||||
|
||||
extern "C" {
|
||||
int main (void) {
|
||||
hal.init(NULL);
|
||||
setup();
|
||||
for(;;) loop();
|
||||
return 0;
|
||||
}
|
||||
}
|
Loading…
Reference in New Issue
Block a user