Pluto Logo

by Drona Aviation

Profile
Menu
Documentation
Pluto-IDE & MagisV2 SDK
Pluto-IDE & MagisV2 API Reference

Scheduler Timer

Code with Pluto-IDE

Pluto-IDE is the professional development environment required to build, flash, and monitor firmware using the MagisV2 library on Pluto Drones.

Get Pluto-IDE

Scheduler-Timer.h

Advanced task scheduling and timing utilities for real-time operations.

Type Definitions

task_fn_t

typedef void (*task_fn_t)(void);    // Function pointer for tasks

Structures

ScheduledFn

typedef struct ScheduledFn {
    task_fn_t task_function;     // Function to execute
    uint32_t interval_ms;        // Execution interval in milliseconds
    uint32_t last_run_ms;        // Last execution time
    bool repeat;                 // Whether task repeats
    struct ScheduledFn *next;    // Next task in linked list
} ScheduledFn;

Scheduler_Task

typedef struct {
    uint32_t _cookie;     // Initialization guard
    ScheduledFn *head;    // Head of task list
} Scheduler_Task;

Functions

Timing Functions

  • uint32_t micros(void) - Get current time in microseconds
  • uint32_t millis(void) - Get current time in milliseconds

Scheduler Functions

  • bool Scheduler_Add(Scheduler_Task *t, task_fn_t _task_function, uint32_t interval_ms, bool repeat) - Add task
  • bool Scheduler_Cancel(Scheduler_Task *t, task_fn_t _task_function) - Cancel task
  • void Scheduler_Clear(Scheduler_Task *t) - Clear all tasks
  • void Execute_Scheduled(Scheduler_Task *t) - Execute scheduled tasks

Interval Class

Methods

  • bool set(uint32_t time, bool repeat) - Configure interval (1-5000ms)
  • void reset(void) - Reset interval timing
  • bool check(void) - Check if interval elapsed

Usage Example

// Basic timing
uint32_t startTime = micros();
// ... operation ...
uint32_t duration = micros() - startTime;

// Interval usage
Interval sensorUpdate;
Interval statusReport;

void loop() {
    if (sensorUpdate.set(50, true)) {  // Every 50ms
        // Read sensors
    }
    
    if (statusReport.set(1000, true)) {  // Every second
        Monitor_Println("Status OK");
    }
}

// Advanced scheduling
Scheduler_Task mainScheduler;

void sensorTask() {
    uint32_t accel = Sensor_Get(Accelerometer, X);
    Monitor_Print("Accel: ", accel);
}

void setupScheduler() {
    Scheduler_Add(&mainScheduler, sensorTask, 100, true);  // Every 100ms
}

void runScheduler() {
    Execute_Scheduled(&mainScheduler);
}