view Lib/delay.h @ 70:23600aaa5e15

Adding initial Teensy 3 support, compiles, but not fully functional yet. - CDC Output seems to be working - USB Keyboard output has not been tested, but is "ready" - UART and Timers have not been tested, or fully utilized - Issues using Timer 0 - Initial template for MBC-55X Scan module (only module currently compatible with the arm build) - Updated the interface to the AVR usb module for symmetry with the ARM usb module - Much gutting was done to the Teensy 3 usb keyboard module, though not in an ideal state yet
author Jacob Alexander <triplehaata@gmail.com>
date Sun, 27 Jan 2013 01:47:52 -0500
parents
children 6ac92b8614c0
line wrap: on
line source


#ifndef __DELAY_H
#define __DELAY_H

#include <stdint.h>

// Convenience Macros, for delay compatibility with AVR-GCC
#define _delay_ms(val) delay( val )
#define _delay_us(val) delayMicroseconds( val )


// the systick interrupt is supposed to increment this at 1 kHz rate
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;
}


static inline void delayMicroseconds(uint32_t) __attribute__((always_inline, unused));
static inline void delayMicroseconds(uint32_t usec)
{
#if F_CPU == 96000000
	uint32_t n = usec << 5;
#elif F_CPU == 48000000
	uint32_t n = usec << 4;
#elif F_CPU == 24000000
	uint32_t n = usec << 3;
#endif
	asm volatile(
		"L_%=_delayMicroseconds:"		"\n\t"
		"subs   %0, #1"				"\n\t"
		"bne    L_%=_delayMicroseconds"		"\n"
		: "+r" (n) :
	);
}


void yield(void) __attribute__ ((weak));

uint32_t micros(void);

void delay(uint32_t ms);

#endif