Skip to content

Commit

Permalink
Fix millis corner case
Browse files Browse the repository at this point in the history
  • Loading branch information
PaulStoffregen committed Jun 4, 2016
1 parent e7084a9 commit 9b06bac
Showing 1 changed file with 11 additions and 1 deletion.
12 changes: 11 additions & 1 deletion teensy3/core_pins.h
Expand Up @@ -1529,7 +1529,17 @@ extern volatile uint32_t systick_millis_count;
static inline uint32_t millis(void) __attribute__((always_inline, unused));
static inline uint32_t millis(void)
{
return systick_millis_count; // single aligned 32 bit is atomic;
// Reading a volatile variable to another volatile
// seems redundant, but isn't for some cases.
// Eventually this should probably be replaced by a
// proper memory barrier or other technique. Please
// do not revome this "redundant" code without
// carefully verifying the case mentioned here:
//
// https://forum.pjrc.com/threads/17469-millis%28%29-on-teensy-3?p=104924&viewfull=1#post104924
//
volatile uint32_t ret = systick_millis_count; // single aligned 32 bit is atomic
return ret;
}

uint32_t micros(void);
Expand Down

2 comments on commit 9b06bac

@Defragster
Copy link
Contributor

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

Spelling error in comment line 1536:

  • // do not revome this "redundant" code without

PULL:

  • // do not remove this "redundant" code without

@PaulStoffregen
Copy link
Owner Author

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

fixed 005b355

Please sign in to comment.