Skip to content
New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

Add support for bare-metal AVR #43

Closed
wants to merge 1 commit into from
Closed
Show file tree
Hide file tree
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
6 changes: 6 additions & 0 deletions README
Original file line number Diff line number Diff line change
Expand Up @@ -4,6 +4,12 @@ Version 2.5.0: 2017-08-30
If you find TaskScheduler useful for your Arduino project, please drop me an email: [email protected]
----------------------------------------------------------------------------------------------------------

FORK:

This is a fork of the main TaskScheduler repo. It adds some small changes to support use with bare metal code outside of the Arduino environment. It has only been tested on AVR devices.

This library only depends on the Arduino millis() or micros() functions. You can use third-party libraries like Zak Kemble's millis lib (https://github.com/zkemble/millis) or write your own replacement. The ESP8266 target also requires a substitute for yield() and delay().

OVERVIEW:
A lightweight implementation of cooperative multitasking (task scheduling) supporting:
1. Periodic task execution (with dynamic execution period in milliseconds or microseconds)
Expand Down
7 changes: 7 additions & 0 deletions README.md
Original file line number Diff line number Diff line change
Expand Up @@ -2,6 +2,13 @@
### Cooperative multitasking for Arduino microcontrollers
#### Version 2.5.0: 2017-08-30

### FORK:

This is a fork of the main TaskScheduler repo. It adds some small changes to support use with bare metal code outside of the Arduino environment. It has only been tested on AVR devices.

This library only depends on the Arduino millis() or micros() functions. You can use third-party libraries like Zak Kemble's millis lib (https://github.com/zkemble/millis) or write your own replacement. The ESP8266 target also requires a substitute for yield() and delay().


### OVERVIEW:
A lightweight implementation of cooperative multitasking (task scheduling) supporting:
1. Periodic task execution, with dynamic execution period in `milliseconds` (default) or `microseconds` (if explicitly enabled) – frequency of execution
Expand Down
34 changes: 31 additions & 3 deletions src/TaskScheduler.h
Original file line number Diff line number Diff line change
Expand Up @@ -120,12 +120,40 @@
// 2017-08-30 - bug fix: Scheduler::addTask() checks if task is already part of an execution chain (github issue #37)
// 2017-08-30 - support for multi-tab sketches (Contributed by Adam Ryczkowski - https://github.com/adamryczkowski)

#ifndef _TASKSCHEDULER_H_
#define _TASKSCHEDULER_H_

#if defined(ARDUINO_ARCH_AVR) || defined(ARDUINO_ARCH_ESP8266) || defined(ARDUINO_ARCH_ESP32)
# include "Arduino.h"

#else // Not in Arduino environment

// Detect target arch
# if !defined(ARDUINO_ARCH_AVR) && defined(__AVR__)
# define ARDUINO_ARCH_AVR 1
# endif


// NOTE: You must supply one of these functions depending on _TASK_MICRO_RES
// ESP8266 requires micros(), delay(), and yield().
# if defined(_TASK_MICRO_RES) || defined(ARDUINO_ARCH_ESP8266)
extern unsigned long micros(void);
# endif
extern unsigned long millis(void);

# if defined(ARDUINO_ARCH_ESP8266)
extern void yield(void);
extern void delay(unsigned long);
# endif

# if !(defined(ARDUINO_ARCH_AVR) || defined(ARDUINO_ARCH_ESP8266) || defined(ARDUINO_ARCH_ESP32))
# error Missing ARDUINO_ARCH_* definition.
# endif

#endif // ARDUINO_ARCH_*

#include <Arduino.h>
#include "TaskSchedulerDeclarations.h"

#ifndef _TASKSCHEDULER_H_
#define _TASKSCHEDULER_H_

// ----------------------------------------
// The following "defines" control library functionality at compile time,
Expand Down
5 changes: 3 additions & 2 deletions src/TaskSchedulerDeclarations.h
Original file line number Diff line number Diff line change
@@ -1,7 +1,8 @@
// Cooperative multitasking library for Arduino
// Copyright (c) 2015-2017 Anatoli Arkhipenko

#include <stddef.h>
#include <stddef.h>
#include <stdint.h>

#ifndef _TASKSCHEDULERDECLARATIONS_H_
#define _TASKSCHEDULERDECLARATIONS_H_
Expand Down Expand Up @@ -90,7 +91,7 @@ typedef struct {
bool enabled : 1; // indicates that task is enabled or not.
bool inonenable : 1; // indicates that task execution is inside OnEnable method (preventing infinite loops)
#ifdef _TASK_STATUS_REQUEST
byte waiting : 2; // indication if task is waiting on the status request
uint8_t waiting : 2; // indication if task is waiting on the status request
#endif
} __task_status;

Expand Down