annotate Lib/delay.h @ 308:ab4515606277

Fix whitespace Use a consistent standard - Tabs in front for indenting, spaces after for anything else. This way everything stays nice and lined up while also letting users change there prefered indent level. Most of the new files from Haata where already in this format.
author Rowan Decker <Smasher816@gmail.com>
date Sun, 08 Mar 2015 18:40:01 -0700
parents 6ac92b8614c0
children 772f9bea482b
Ignore whitespace changes - Everywhere: Within whitespace: At end of lines:
rev   line source
192
6ac92b8614c0 Fixing RAM calculator and reduced actual SRAM usage
Jacob Alexander <haata@kiibohd.com>
parents: 70
diff changeset
1 /* Teensyduino Core Library
6ac92b8614c0 Fixing RAM calculator and reduced actual SRAM usage
Jacob Alexander <haata@kiibohd.com>
parents: 70
diff changeset
2 * http://www.pjrc.com/teensy/
6ac92b8614c0 Fixing RAM calculator and reduced actual SRAM usage
Jacob Alexander <haata@kiibohd.com>
parents: 70
diff changeset
3 * Copyright (c) 2013 PJRC.COM, LLC.
6ac92b8614c0 Fixing RAM calculator and reduced actual SRAM usage
Jacob Alexander <haata@kiibohd.com>
parents: 70
diff changeset
4 * Modifications by Jacob Alexander 2013-2014
6ac92b8614c0 Fixing RAM calculator and reduced actual SRAM usage
Jacob Alexander <haata@kiibohd.com>
parents: 70
diff changeset
5 *
6ac92b8614c0 Fixing RAM calculator and reduced actual SRAM usage
Jacob Alexander <haata@kiibohd.com>
parents: 70
diff changeset
6 * Permission is hereby granted, free of charge, to any person obtaining
6ac92b8614c0 Fixing RAM calculator and reduced actual SRAM usage
Jacob Alexander <haata@kiibohd.com>
parents: 70
diff changeset
7 * a copy of this software and associated documentation files (the
6ac92b8614c0 Fixing RAM calculator and reduced actual SRAM usage
Jacob Alexander <haata@kiibohd.com>
parents: 70
diff changeset
8 * "Software"), to deal in the Software without restriction, including
6ac92b8614c0 Fixing RAM calculator and reduced actual SRAM usage
Jacob Alexander <haata@kiibohd.com>
parents: 70
diff changeset
9 * without limitation the rights to use, copy, modify, merge, publish,
6ac92b8614c0 Fixing RAM calculator and reduced actual SRAM usage
Jacob Alexander <haata@kiibohd.com>
parents: 70
diff changeset
10 * distribute, sublicense, and/or sell copies of the Software, and to
6ac92b8614c0 Fixing RAM calculator and reduced actual SRAM usage
Jacob Alexander <haata@kiibohd.com>
parents: 70
diff changeset
11 * permit persons to whom the Software is furnished to do so, subject to
6ac92b8614c0 Fixing RAM calculator and reduced actual SRAM usage
Jacob Alexander <haata@kiibohd.com>
parents: 70
diff changeset
12 * the following conditions:
6ac92b8614c0 Fixing RAM calculator and reduced actual SRAM usage
Jacob Alexander <haata@kiibohd.com>
parents: 70
diff changeset
13 *
6ac92b8614c0 Fixing RAM calculator and reduced actual SRAM usage
Jacob Alexander <haata@kiibohd.com>
parents: 70
diff changeset
14 * 1. The above copyright notice and this permission notice shall be
6ac92b8614c0 Fixing RAM calculator and reduced actual SRAM usage
Jacob Alexander <haata@kiibohd.com>
parents: 70
diff changeset
15 * included in all copies or substantial portions of the Software.
6ac92b8614c0 Fixing RAM calculator and reduced actual SRAM usage
Jacob Alexander <haata@kiibohd.com>
parents: 70
diff changeset
16 *
6ac92b8614c0 Fixing RAM calculator and reduced actual SRAM usage
Jacob Alexander <haata@kiibohd.com>
parents: 70
diff changeset
17 * 2. If the Software is incorporated into a build system that allows
6ac92b8614c0 Fixing RAM calculator and reduced actual SRAM usage
Jacob Alexander <haata@kiibohd.com>
parents: 70
diff changeset
18 * selection among a list of target devices, then similar target
6ac92b8614c0 Fixing RAM calculator and reduced actual SRAM usage
Jacob Alexander <haata@kiibohd.com>
parents: 70
diff changeset
19 * devices manufactured by PJRC.COM must be included in the list of
6ac92b8614c0 Fixing RAM calculator and reduced actual SRAM usage
Jacob Alexander <haata@kiibohd.com>
parents: 70
diff changeset
20 * target devices and selectable in the same manner.
6ac92b8614c0 Fixing RAM calculator and reduced actual SRAM usage
Jacob Alexander <haata@kiibohd.com>
parents: 70
diff changeset
21 *
6ac92b8614c0 Fixing RAM calculator and reduced actual SRAM usage
Jacob Alexander <haata@kiibohd.com>
parents: 70
diff changeset
22 * THE SOFTWARE IS PROVIDED "AS IS", WITHOUT WARRANTY OF ANY KIND,
6ac92b8614c0 Fixing RAM calculator and reduced actual SRAM usage
Jacob Alexander <haata@kiibohd.com>
parents: 70
diff changeset
23 * EXPRESS OR IMPLIED, INCLUDING BUT NOT LIMITED TO THE WARRANTIES OF
6ac92b8614c0 Fixing RAM calculator and reduced actual SRAM usage
Jacob Alexander <haata@kiibohd.com>
parents: 70
diff changeset
24 * MERCHANTABILITY, FITNESS FOR A PARTICULAR PURPOSE AND
6ac92b8614c0 Fixing RAM calculator and reduced actual SRAM usage
Jacob Alexander <haata@kiibohd.com>
parents: 70
diff changeset
25 * NONINFRINGEMENT. IN NO EVENT SHALL THE AUTHORS OR COPYRIGHT HOLDERS
6ac92b8614c0 Fixing RAM calculator and reduced actual SRAM usage
Jacob Alexander <haata@kiibohd.com>
parents: 70
diff changeset
26 * BE LIABLE FOR ANY CLAIM, DAMAGES OR OTHER LIABILITY, WHETHER IN AN
6ac92b8614c0 Fixing RAM calculator and reduced actual SRAM usage
Jacob Alexander <haata@kiibohd.com>
parents: 70
diff changeset
27 * ACTION OF CONTRACT, TORT OR OTHERWISE, ARISING FROM, OUT OF OR IN
6ac92b8614c0 Fixing RAM calculator and reduced actual SRAM usage
Jacob Alexander <haata@kiibohd.com>
parents: 70
diff changeset
28 * CONNECTION WITH THE SOFTWARE OR THE USE OR OTHER DEALINGS IN THE
6ac92b8614c0 Fixing RAM calculator and reduced actual SRAM usage
Jacob Alexander <haata@kiibohd.com>
parents: 70
diff changeset
29 * SOFTWARE.
6ac92b8614c0 Fixing RAM calculator and reduced actual SRAM usage
Jacob Alexander <haata@kiibohd.com>
parents: 70
diff changeset
30 */
70
23600aaa5e15 Adding initial Teensy 3 support, compiles, but not fully functional yet.
Jacob Alexander <triplehaata@gmail.com>
parents:
diff changeset
31
23600aaa5e15 Adding initial Teensy 3 support, compiles, but not fully functional yet.
Jacob Alexander <triplehaata@gmail.com>
parents:
diff changeset
32 #ifndef __DELAY_H
23600aaa5e15 Adding initial Teensy 3 support, compiles, but not fully functional yet.
Jacob Alexander <triplehaata@gmail.com>
parents:
diff changeset
33 #define __DELAY_H
23600aaa5e15 Adding initial Teensy 3 support, compiles, but not fully functional yet.
Jacob Alexander <triplehaata@gmail.com>
parents:
diff changeset
34
192
6ac92b8614c0 Fixing RAM calculator and reduced actual SRAM usage
Jacob Alexander <haata@kiibohd.com>
parents: 70
diff changeset
35 // ----- System Includes -----
6ac92b8614c0 Fixing RAM calculator and reduced actual SRAM usage
Jacob Alexander <haata@kiibohd.com>
parents: 70
diff changeset
36
70
23600aaa5e15 Adding initial Teensy 3 support, compiles, but not fully functional yet.
Jacob Alexander <triplehaata@gmail.com>
parents:
diff changeset
37 #include <stdint.h>
23600aaa5e15 Adding initial Teensy 3 support, compiles, but not fully functional yet.
Jacob Alexander <triplehaata@gmail.com>
parents:
diff changeset
38
192
6ac92b8614c0 Fixing RAM calculator and reduced actual SRAM usage
Jacob Alexander <haata@kiibohd.com>
parents: 70
diff changeset
39
6ac92b8614c0 Fixing RAM calculator and reduced actual SRAM usage
Jacob Alexander <haata@kiibohd.com>
parents: 70
diff changeset
40
6ac92b8614c0 Fixing RAM calculator and reduced actual SRAM usage
Jacob Alexander <haata@kiibohd.com>
parents: 70
diff changeset
41 // ----- Macros -----
6ac92b8614c0 Fixing RAM calculator and reduced actual SRAM usage
Jacob Alexander <haata@kiibohd.com>
parents: 70
diff changeset
42
70
23600aaa5e15 Adding initial Teensy 3 support, compiles, but not fully functional yet.
Jacob Alexander <triplehaata@gmail.com>
parents:
diff changeset
43 // Convenience Macros, for delay compatibility with AVR-GCC
23600aaa5e15 Adding initial Teensy 3 support, compiles, but not fully functional yet.
Jacob Alexander <triplehaata@gmail.com>
parents:
diff changeset
44 #define _delay_ms(val) delay( val )
23600aaa5e15 Adding initial Teensy 3 support, compiles, but not fully functional yet.
Jacob Alexander <triplehaata@gmail.com>
parents:
diff changeset
45 #define _delay_us(val) delayMicroseconds( val )
23600aaa5e15 Adding initial Teensy 3 support, compiles, but not fully functional yet.
Jacob Alexander <triplehaata@gmail.com>
parents:
diff changeset
46
23600aaa5e15 Adding initial Teensy 3 support, compiles, but not fully functional yet.
Jacob Alexander <triplehaata@gmail.com>
parents:
diff changeset
47
192
6ac92b8614c0 Fixing RAM calculator and reduced actual SRAM usage
Jacob Alexander <haata@kiibohd.com>
parents: 70
diff changeset
48
6ac92b8614c0 Fixing RAM calculator and reduced actual SRAM usage
Jacob Alexander <haata@kiibohd.com>
parents: 70
diff changeset
49 // ----- Functions -----
6ac92b8614c0 Fixing RAM calculator and reduced actual SRAM usage
Jacob Alexander <haata@kiibohd.com>
parents: 70
diff changeset
50
70
23600aaa5e15 Adding initial Teensy 3 support, compiles, but not fully functional yet.
Jacob Alexander <triplehaata@gmail.com>
parents:
diff changeset
51 // the systick interrupt is supposed to increment this at 1 kHz rate
23600aaa5e15 Adding initial Teensy 3 support, compiles, but not fully functional yet.
Jacob Alexander <triplehaata@gmail.com>
parents:
diff changeset
52 extern volatile uint32_t systick_millis_count;
23600aaa5e15 Adding initial Teensy 3 support, compiles, but not fully functional yet.
Jacob Alexander <triplehaata@gmail.com>
parents:
diff changeset
53
23600aaa5e15 Adding initial Teensy 3 support, compiles, but not fully functional yet.
Jacob Alexander <triplehaata@gmail.com>
parents:
diff changeset
54 static inline uint32_t millis(void) __attribute__((always_inline, unused));
23600aaa5e15 Adding initial Teensy 3 support, compiles, but not fully functional yet.
Jacob Alexander <triplehaata@gmail.com>
parents:
diff changeset
55 static inline uint32_t millis(void)
23600aaa5e15 Adding initial Teensy 3 support, compiles, but not fully functional yet.
Jacob Alexander <triplehaata@gmail.com>
parents:
diff changeset
56 {
23600aaa5e15 Adding initial Teensy 3 support, compiles, but not fully functional yet.
Jacob Alexander <triplehaata@gmail.com>
parents:
diff changeset
57 return systick_millis_count; // single aligned 32 bit is atomic;
23600aaa5e15 Adding initial Teensy 3 support, compiles, but not fully functional yet.
Jacob Alexander <triplehaata@gmail.com>
parents:
diff changeset
58 }
23600aaa5e15 Adding initial Teensy 3 support, compiles, but not fully functional yet.
Jacob Alexander <triplehaata@gmail.com>
parents:
diff changeset
59
23600aaa5e15 Adding initial Teensy 3 support, compiles, but not fully functional yet.
Jacob Alexander <triplehaata@gmail.com>
parents:
diff changeset
60
23600aaa5e15 Adding initial Teensy 3 support, compiles, but not fully functional yet.
Jacob Alexander <triplehaata@gmail.com>
parents:
diff changeset
61 static inline void delayMicroseconds(uint32_t) __attribute__((always_inline, unused));
23600aaa5e15 Adding initial Teensy 3 support, compiles, but not fully functional yet.
Jacob Alexander <triplehaata@gmail.com>
parents:
diff changeset
62 static inline void delayMicroseconds(uint32_t usec)
23600aaa5e15 Adding initial Teensy 3 support, compiles, but not fully functional yet.
Jacob Alexander <triplehaata@gmail.com>
parents:
diff changeset
63 {
23600aaa5e15 Adding initial Teensy 3 support, compiles, but not fully functional yet.
Jacob Alexander <triplehaata@gmail.com>
parents:
diff changeset
64 #if F_CPU == 96000000
23600aaa5e15 Adding initial Teensy 3 support, compiles, but not fully functional yet.
Jacob Alexander <triplehaata@gmail.com>
parents:
diff changeset
65 uint32_t n = usec << 5;
23600aaa5e15 Adding initial Teensy 3 support, compiles, but not fully functional yet.
Jacob Alexander <triplehaata@gmail.com>
parents:
diff changeset
66 #elif F_CPU == 48000000
23600aaa5e15 Adding initial Teensy 3 support, compiles, but not fully functional yet.
Jacob Alexander <triplehaata@gmail.com>
parents:
diff changeset
67 uint32_t n = usec << 4;
23600aaa5e15 Adding initial Teensy 3 support, compiles, but not fully functional yet.
Jacob Alexander <triplehaata@gmail.com>
parents:
diff changeset
68 #elif F_CPU == 24000000
23600aaa5e15 Adding initial Teensy 3 support, compiles, but not fully functional yet.
Jacob Alexander <triplehaata@gmail.com>
parents:
diff changeset
69 uint32_t n = usec << 3;
23600aaa5e15 Adding initial Teensy 3 support, compiles, but not fully functional yet.
Jacob Alexander <triplehaata@gmail.com>
parents:
diff changeset
70 #endif
23600aaa5e15 Adding initial Teensy 3 support, compiles, but not fully functional yet.
Jacob Alexander <triplehaata@gmail.com>
parents:
diff changeset
71 asm volatile(
308
ab4515606277 Fix whitespace
Rowan Decker <Smasher816@gmail.com>
parents: 192
diff changeset
72 "L_%=_delayMicroseconds:" "\n\t"
ab4515606277 Fix whitespace
Rowan Decker <Smasher816@gmail.com>
parents: 192
diff changeset
73 "subs %0, #1" "\n\t"
ab4515606277 Fix whitespace
Rowan Decker <Smasher816@gmail.com>
parents: 192
diff changeset
74 "bne L_%=_delayMicroseconds" "\n"
70
23600aaa5e15 Adding initial Teensy 3 support, compiles, but not fully functional yet.
Jacob Alexander <triplehaata@gmail.com>
parents:
diff changeset
75 : "+r" (n) :
23600aaa5e15 Adding initial Teensy 3 support, compiles, but not fully functional yet.
Jacob Alexander <triplehaata@gmail.com>
parents:
diff changeset
76 );
23600aaa5e15 Adding initial Teensy 3 support, compiles, but not fully functional yet.
Jacob Alexander <triplehaata@gmail.com>
parents:
diff changeset
77 }
23600aaa5e15 Adding initial Teensy 3 support, compiles, but not fully functional yet.
Jacob Alexander <triplehaata@gmail.com>
parents:
diff changeset
78
23600aaa5e15 Adding initial Teensy 3 support, compiles, but not fully functional yet.
Jacob Alexander <triplehaata@gmail.com>
parents:
diff changeset
79
23600aaa5e15 Adding initial Teensy 3 support, compiles, but not fully functional yet.
Jacob Alexander <triplehaata@gmail.com>
parents:
diff changeset
80 void yield(void) __attribute__ ((weak));
23600aaa5e15 Adding initial Teensy 3 support, compiles, but not fully functional yet.
Jacob Alexander <triplehaata@gmail.com>
parents:
diff changeset
81
23600aaa5e15 Adding initial Teensy 3 support, compiles, but not fully functional yet.
Jacob Alexander <triplehaata@gmail.com>
parents:
diff changeset
82 uint32_t micros(void);
23600aaa5e15 Adding initial Teensy 3 support, compiles, but not fully functional yet.
Jacob Alexander <triplehaata@gmail.com>
parents:
diff changeset
83
23600aaa5e15 Adding initial Teensy 3 support, compiles, but not fully functional yet.
Jacob Alexander <triplehaata@gmail.com>
parents:
diff changeset
84 void delay(uint32_t ms);
23600aaa5e15 Adding initial Teensy 3 support, compiles, but not fully functional yet.
Jacob Alexander <triplehaata@gmail.com>
parents:
diff changeset
85
23600aaa5e15 Adding initial Teensy 3 support, compiles, but not fully functional yet.
Jacob Alexander <triplehaata@gmail.com>
parents:
diff changeset
86 #endif
23600aaa5e15 Adding initial Teensy 3 support, compiles, but not fully functional yet.
Jacob Alexander <triplehaata@gmail.com>
parents:
diff changeset
87