Skip to content

Commit

Permalink
Updates for ESP8266 platform
Browse files Browse the repository at this point in the history
  • Loading branch information
pstolarz committed Jun 2, 2020
1 parent 67ccab5 commit e552c27
Show file tree
Hide file tree
Showing 7 changed files with 54 additions and 11 deletions.
2 changes: 2 additions & 0 deletions README.md
Original file line number Diff line number Diff line change
Expand Up @@ -11,6 +11,8 @@ The library has been tested on the following platforms:
* Tested on Arduino UNO (ATmega328P).
* Arduino ESP32.
* Tested on ESP32-DevKitC (ESP32-WROOM-32)
* Arduino ESP8266.
* Tested on WeMos D1

## Features

Expand Down
8 changes: 6 additions & 2 deletions examples/CoopBasic/CoopBasic.ino
Original file line number Diff line number Diff line change
Expand Up @@ -18,15 +18,19 @@
*/
#include "coop_threads.h"

#ifdef ARDUINO_ARCH_ESP32
# define THREAD_STACK_SIZE 0x200
#if defined(ARDUINO_ARCH_ESP32) || defined(ARDUINO_ARCH_ESP8266)
# define THREAD_STACK_SIZE 0x250
#elif ARDUINO_ARCH_AVR
# define THREAD_STACK_SIZE 0x50
#else
/* use default */
# define THREAD_STACK_SIZE 0
#endif

#if CONFIG_MAX_THREADS < 5
# error CONFIG_MAX_THREADS >= 5 is required
#endif

/*
* Thread routine
*/
Expand Down
14 changes: 12 additions & 2 deletions examples/CoopIdle/CoopIdle.ino
Original file line number Diff line number Diff line change
Expand Up @@ -20,15 +20,25 @@
*/
#include "coop_threads.h"

#ifdef ARDUINO_ARCH_ESP32
# define THREAD_STACK_SIZE 0x200
#if defined(ARDUINO_ARCH_ESP32) || defined(ARDUINO_ARCH_ESP8266)
# define THREAD_STACK_SIZE 0x250
#elif ARDUINO_ARCH_AVR
# define THREAD_STACK_SIZE 0x50
#else
/* use default */
# define THREAD_STACK_SIZE 0
#endif

#if CONFIG_MAX_THREADS < 3
# error CONFIG_MAX_THREADS >= 3 is required
#endif
#ifndef CONFIG_OPT_IDLE
# error CONFIG_OPT_IDLE need to be configured
#endif
#ifndef CONFIG_IDLE_CB_ALT
# error CONFIG_IDLE_CB_ALT need to be configured
#endif

/*
* The callback is called by the library to handle the idle state on the
* system (global) level. A user may leverage this callback to save battery
Expand Down
14 changes: 12 additions & 2 deletions examples/CoopWaitCond/CoopWaitCond.ino
Original file line number Diff line number Diff line change
Expand Up @@ -20,15 +20,25 @@
*/
#include "coop_threads.h"

#ifdef ARDUINO_ARCH_ESP32
# define THREAD_STACK_SIZE 0x200
#if defined(ARDUINO_ARCH_ESP32) || defined(ARDUINO_ARCH_ESP8266)
# define THREAD_STACK_SIZE 0x250
#elif ARDUINO_ARCH_AVR
# define THREAD_STACK_SIZE 0x50
#else
/* use default */
# define THREAD_STACK_SIZE 0
#endif

#if CONFIG_MAX_THREADS < 3
# error CONFIG_MAX_THREADS >= 3 is required
#endif
#ifndef CONFIG_OPT_IDLE
# error CONFIG_OPT_IDLE need to be configured
#endif
#ifndef CONFIG_OPT_WAIT
# error CONFIG_OPT_WAIT need to be configured
#endif

#define FLAG_1 (1 << 0)
#define FLAG_2 (1 << 1)
#define FLAG_3 (1 << 2)
Expand Down
14 changes: 12 additions & 2 deletions examples/CoopWaitNotify/CoopWaitNotify.ino
Original file line number Diff line number Diff line change
Expand Up @@ -20,15 +20,25 @@
*/
#include "coop_threads.h"

#ifdef ARDUINO_ARCH_ESP32
# define THREAD_STACK_SIZE 0x200
#if defined(ARDUINO_ARCH_ESP32) || defined(ARDUINO_ARCH_ESP8266)
# define THREAD_STACK_SIZE 0x250
#elif ARDUINO_ARCH_AVR
# define THREAD_STACK_SIZE 0x50
#else
/* use default */
# define THREAD_STACK_SIZE 0
#endif

#if CONFIG_MAX_THREADS < 2
# error CONFIG_MAX_THREADS >= 2 is required
#endif
#ifndef CONFIG_OPT_IDLE
# error CONFIG_OPT_IDLE need to be configured
#endif
#ifndef CONFIG_OPT_WAIT
# error CONFIG_OPT_WAIT need to be configured
#endif

static int cnt = 0;

/*
Expand Down
11 changes: 9 additions & 2 deletions examples/CoopYieldAfter/CoopYieldAfter.ino
Original file line number Diff line number Diff line change
Expand Up @@ -20,15 +20,22 @@
*/
#include "coop_threads.h"

#ifdef ARDUINO_ARCH_ESP32
# define THREAD_STACK_SIZE 0x200
#if defined(ARDUINO_ARCH_ESP32) || defined(ARDUINO_ARCH_ESP8266)
# define THREAD_STACK_SIZE 0x250
#elif ARDUINO_ARCH_AVR
# define THREAD_STACK_SIZE 0x50
#else
/* use default */
# define THREAD_STACK_SIZE 0
#endif

#if CONFIG_MAX_THREADS < 3
# error CONFIG_MAX_THREADS >= 3 is required
#endif
#ifndef CONFIG_OPT_YIELD_AFTER
# error CONFIG_OPT_YIELD_AFTER need to be configured
#endif

/*
* Thread routine
*/
Expand Down
2 changes: 1 addition & 1 deletion src/coop_threads.c
Original file line number Diff line number Diff line change
Expand Up @@ -149,7 +149,7 @@ typedef struct
coop_thrd_ctx_t thrds[CONFIG_MAX_THREADS];
} coop_sched_ctx_t;

static coop_sched_ctx_t sched = {};
static coop_sched_ctx_t sched = {0};

#ifdef CONFIG_NOEXIT_STATIC_THREADS
# define _ACTIVE_THREADS() (sched.busy_n)
Expand Down

0 comments on commit e552c27

Please sign in to comment.