Browse Source

clean up the code a bit

cat got fat and i needed different timing lol
master
dave 1 year ago
parent
commit
4646817d7e
5 changed files with 76 additions and 636 deletions
  1. +10
    -0
      .gitignore
  2. +8
    -1
      libs/serialdebug.c
  3. +0
    -595
      libs/serialdebug.lst
  4. BIN
      libs/serialdebug.o
  5. +58
    -40
      main.c

+ 10
- 0
.gitignore View File

@@ -0,0 +1,10 @@
/.dep/
*.eep
*.elf
*.hex
*.lss
*.lst
*.map
*.o
*.sym
__*

+ 8
- 1
libs/serialdebug.c View File

@@ -61,8 +61,15 @@ void dbg_putstring_nl(char string[]) {
}

void dbg_putint(unsigned int num) {
// Create string representing int and print to serial
// Create string representing an int and print to serial
char c[7];
itoa(num, c, 10);
dbg_putstring(c);
}

void dbg_putlong(long num) {
// Create string representing a long int and print to serial
char c[16];
ltoa(num, c, 10);
dbg_putstring(c);
}

+ 0
- 595
libs/serialdebug.lst View File

@@ -1,595 +0,0 @@
1 .file "serialdebug.c"
2 __SP_H__ = 0x3e
3 __SP_L__ = 0x3d
4 __SREG__ = 0x3f
5 __tmp_reg__ = 0
6 __zero_reg__ = 1
7 .text
8 .Ltext0:
9 .cfi_sections .debug_frame
10 .global usart_putchar
12 usart_putchar:
13 .LFB8:
14 .file 1 "libs/serialdebug.c"
1:libs/serialdebug.c **** #include <libs/serialdebug.h>
2:libs/serialdebug.c ****
3:libs/serialdebug.c **** #if SERIALDEBUG_USE_INTS
4:libs/serialdebug.c **** #include <avr/interrupt.h>
5:libs/serialdebug.c **** #endif
6:libs/serialdebug.c ****
7:libs/serialdebug.c **** void serial_configure(void) {
8:libs/serialdebug.c **** // Configure serial output
9:libs/serialdebug.c **** SERIALDEBUG_SOFT_TX_PORT |= (1<<SERIALDEBUG_SOFT_TX_BIT);
10:libs/serialdebug.c **** SERIALDEBUG_SOFT_TX_DDR |= (1<<SERIALDEBUG_SOFT_TX_BIT);
11:libs/serialdebug.c **** fdev_setup_stream(&serialdebug_usartout, usart_putchar, NULL, _FDEV_SETUP_WRITE);
12:libs/serialdebug.c **** stdout = &serialdebug_usartout;
13:libs/serialdebug.c **** }
14:libs/serialdebug.c ****
15:libs/serialdebug.c **** int usart_putchar (char c, FILE *stream) {
15 .loc 1 15 0
16 .cfi_startproc
17 .LVL0:
18 /* prologue: function */
19 /* frame size = 0 */
20 /* stack size = 0 */
21 .L__stack_usage = 0
16:libs/serialdebug.c **** #if SERIALDEBUG_USE_INTS
17:libs/serialdebug.c **** cli();
18:libs/serialdebug.c **** #endif
19:libs/serialdebug.c **** // Print 1 char to serial
20:libs/serialdebug.c **** uint8_t bit_mask;
21:libs/serialdebug.c ****
22:libs/serialdebug.c **** // start bit
23:libs/serialdebug.c **** SERIALDEBUG_SOFT_TX_PORT &= ~(1<<SERIALDEBUG_SOFT_TX_BIT);
22 .loc 1 23 0
23 0000 DE98 cbi 0x1b,6
24 .LVL1:
25 .LBB8:
26 .LBB9:
27 .file 2 "/usr/local/CrossPack-AVR-20131216/avr/include/util/delay.h"
1:/usr/local/CrossPack-AVR-20131216/avr/include/util/delay.h **** /* Copyright (c) 2002, Marek Michalkiewicz
2:/usr/local/CrossPack-AVR-20131216/avr/include/util/delay.h **** Copyright (c) 2004,2005,2007 Joerg Wunsch
3:/usr/local/CrossPack-AVR-20131216/avr/include/util/delay.h **** Copyright (c) 2007 Florin-Viorel Petrov
4:/usr/local/CrossPack-AVR-20131216/avr/include/util/delay.h **** All rights reserved.
5:/usr/local/CrossPack-AVR-20131216/avr/include/util/delay.h ****
6:/usr/local/CrossPack-AVR-20131216/avr/include/util/delay.h **** Redistribution and use in source and binary forms, with or without
7:/usr/local/CrossPack-AVR-20131216/avr/include/util/delay.h **** modification, are permitted provided that the following conditions are met:
8:/usr/local/CrossPack-AVR-20131216/avr/include/util/delay.h ****
9:/usr/local/CrossPack-AVR-20131216/avr/include/util/delay.h **** * Redistributions of source code must retain the above copyright
10:/usr/local/CrossPack-AVR-20131216/avr/include/util/delay.h **** notice, this list of conditions and the following disclaimer.
11:/usr/local/CrossPack-AVR-20131216/avr/include/util/delay.h ****
12:/usr/local/CrossPack-AVR-20131216/avr/include/util/delay.h **** * Redistributions in binary form must reproduce the above copyright
13:/usr/local/CrossPack-AVR-20131216/avr/include/util/delay.h **** notice, this list of conditions and the following disclaimer in
14:/usr/local/CrossPack-AVR-20131216/avr/include/util/delay.h **** the documentation and/or other materials provided with the
15:/usr/local/CrossPack-AVR-20131216/avr/include/util/delay.h **** distribution.
16:/usr/local/CrossPack-AVR-20131216/avr/include/util/delay.h ****
17:/usr/local/CrossPack-AVR-20131216/avr/include/util/delay.h **** * Neither the name of the copyright holders nor the names of
18:/usr/local/CrossPack-AVR-20131216/avr/include/util/delay.h **** contributors may be used to endorse or promote products derived
19:/usr/local/CrossPack-AVR-20131216/avr/include/util/delay.h **** from this software without specific prior written permission.
20:/usr/local/CrossPack-AVR-20131216/avr/include/util/delay.h ****
21:/usr/local/CrossPack-AVR-20131216/avr/include/util/delay.h **** THIS SOFTWARE IS PROVIDED BY THE COPYRIGHT HOLDERS AND CONTRIBUTORS "AS IS"
22:/usr/local/CrossPack-AVR-20131216/avr/include/util/delay.h **** AND ANY EXPRESS OR IMPLIED WARRANTIES, INCLUDING, BUT NOT LIMITED TO, THE
23:/usr/local/CrossPack-AVR-20131216/avr/include/util/delay.h **** IMPLIED WARRANTIES OF MERCHANTABILITY AND FITNESS FOR A PARTICULAR PURPOSE
24:/usr/local/CrossPack-AVR-20131216/avr/include/util/delay.h **** ARE DISCLAIMED. IN NO EVENT SHALL THE COPYRIGHT OWNER OR CONTRIBUTORS BE
25:/usr/local/CrossPack-AVR-20131216/avr/include/util/delay.h **** LIABLE FOR ANY DIRECT, INDIRECT, INCIDENTAL, SPECIAL, EXEMPLARY, OR
26:/usr/local/CrossPack-AVR-20131216/avr/include/util/delay.h **** CONSEQUENTIAL DAMAGES (INCLUDING, BUT NOT LIMITED TO, PROCUREMENT OF
27:/usr/local/CrossPack-AVR-20131216/avr/include/util/delay.h **** SUBSTITUTE GOODS OR SERVICES; LOSS OF USE, DATA, OR PROFITS; OR BUSINESS
28:/usr/local/CrossPack-AVR-20131216/avr/include/util/delay.h **** INTERRUPTION) HOWEVER CAUSED AND ON ANY THEORY OF LIABILITY, WHETHER IN
29:/usr/local/CrossPack-AVR-20131216/avr/include/util/delay.h **** CONTRACT, STRICT LIABILITY, OR TORT (INCLUDING NEGLIGENCE OR OTHERWISE)
30:/usr/local/CrossPack-AVR-20131216/avr/include/util/delay.h **** ARISING IN ANY WAY OUT OF THE USE OF THIS SOFTWARE, EVEN IF ADVISED OF THE
31:/usr/local/CrossPack-AVR-20131216/avr/include/util/delay.h **** POSSIBILITY OF SUCH DAMAGE. */
32:/usr/local/CrossPack-AVR-20131216/avr/include/util/delay.h ****
33:/usr/local/CrossPack-AVR-20131216/avr/include/util/delay.h **** /* $Id$ */
34:/usr/local/CrossPack-AVR-20131216/avr/include/util/delay.h ****
35:/usr/local/CrossPack-AVR-20131216/avr/include/util/delay.h **** #ifndef _UTIL_DELAY_H_
36:/usr/local/CrossPack-AVR-20131216/avr/include/util/delay.h **** #define _UTIL_DELAY_H_ 1
37:/usr/local/CrossPack-AVR-20131216/avr/include/util/delay.h ****
38:/usr/local/CrossPack-AVR-20131216/avr/include/util/delay.h **** #ifndef __HAS_DELAY_CYCLES
39:/usr/local/CrossPack-AVR-20131216/avr/include/util/delay.h **** #define __HAS_DELAY_CYCLES 1
40:/usr/local/CrossPack-AVR-20131216/avr/include/util/delay.h **** #endif
41:/usr/local/CrossPack-AVR-20131216/avr/include/util/delay.h ****
42:/usr/local/CrossPack-AVR-20131216/avr/include/util/delay.h **** #include <inttypes.h>
43:/usr/local/CrossPack-AVR-20131216/avr/include/util/delay.h **** #include <util/delay_basic.h>
44:/usr/local/CrossPack-AVR-20131216/avr/include/util/delay.h **** #include <math.h>
45:/usr/local/CrossPack-AVR-20131216/avr/include/util/delay.h ****
46:/usr/local/CrossPack-AVR-20131216/avr/include/util/delay.h **** /** \file */
47:/usr/local/CrossPack-AVR-20131216/avr/include/util/delay.h **** /** \defgroup util_delay <util/delay.h>: Convenience functions for busy-wait delay loops
48:/usr/local/CrossPack-AVR-20131216/avr/include/util/delay.h **** \code
49:/usr/local/CrossPack-AVR-20131216/avr/include/util/delay.h **** #define F_CPU 1000000UL // 1 MHz
50:/usr/local/CrossPack-AVR-20131216/avr/include/util/delay.h **** //#define F_CPU 14.7456E6
51:/usr/local/CrossPack-AVR-20131216/avr/include/util/delay.h **** #include <util/delay.h>
52:/usr/local/CrossPack-AVR-20131216/avr/include/util/delay.h **** \endcode
53:/usr/local/CrossPack-AVR-20131216/avr/include/util/delay.h ****
54:/usr/local/CrossPack-AVR-20131216/avr/include/util/delay.h **** \note As an alternative method, it is possible to pass the
55:/usr/local/CrossPack-AVR-20131216/avr/include/util/delay.h **** F_CPU macro down to the compiler from the Makefile.
56:/usr/local/CrossPack-AVR-20131216/avr/include/util/delay.h **** Obviously, in that case, no \c \#define statement should be
57:/usr/local/CrossPack-AVR-20131216/avr/include/util/delay.h **** used.
58:/usr/local/CrossPack-AVR-20131216/avr/include/util/delay.h ****
59:/usr/local/CrossPack-AVR-20131216/avr/include/util/delay.h **** The functions in this header file are wrappers around the basic
60:/usr/local/CrossPack-AVR-20131216/avr/include/util/delay.h **** busy-wait functions from <util/delay_basic.h>. They are meant as
61:/usr/local/CrossPack-AVR-20131216/avr/include/util/delay.h **** convenience functions where actual time values can be specified
62:/usr/local/CrossPack-AVR-20131216/avr/include/util/delay.h **** rather than a number of cycles to wait for. The idea behind is
63:/usr/local/CrossPack-AVR-20131216/avr/include/util/delay.h **** that compile-time constant expressions will be eliminated by
64:/usr/local/CrossPack-AVR-20131216/avr/include/util/delay.h **** compiler optimization so floating-point expressions can be used
65:/usr/local/CrossPack-AVR-20131216/avr/include/util/delay.h **** to calculate the number of delay cycles needed based on the CPU
66:/usr/local/CrossPack-AVR-20131216/avr/include/util/delay.h **** frequency passed by the macro F_CPU.
67:/usr/local/CrossPack-AVR-20131216/avr/include/util/delay.h ****
68:/usr/local/CrossPack-AVR-20131216/avr/include/util/delay.h **** \note In order for these functions to work as intended, compiler
69:/usr/local/CrossPack-AVR-20131216/avr/include/util/delay.h **** optimizations <em>must</em> be enabled, and the delay time
70:/usr/local/CrossPack-AVR-20131216/avr/include/util/delay.h **** <em>must</em> be an expression that is a known constant at
71:/usr/local/CrossPack-AVR-20131216/avr/include/util/delay.h **** compile-time. If these requirements are not met, the resulting
72:/usr/local/CrossPack-AVR-20131216/avr/include/util/delay.h **** delay will be much longer (and basically unpredictable), and
73:/usr/local/CrossPack-AVR-20131216/avr/include/util/delay.h **** applications that otherwise do not use floating-point calculations
74:/usr/local/CrossPack-AVR-20131216/avr/include/util/delay.h **** will experience severe code bloat by the floating-point library
75:/usr/local/CrossPack-AVR-20131216/avr/include/util/delay.h **** routines linked into the application.
76:/usr/local/CrossPack-AVR-20131216/avr/include/util/delay.h ****
77:/usr/local/CrossPack-AVR-20131216/avr/include/util/delay.h **** The functions available allow the specification of microsecond, and
78:/usr/local/CrossPack-AVR-20131216/avr/include/util/delay.h **** millisecond delays directly, using the application-supplied macro
79:/usr/local/CrossPack-AVR-20131216/avr/include/util/delay.h **** F_CPU as the CPU clock frequency (in Hertz).
80:/usr/local/CrossPack-AVR-20131216/avr/include/util/delay.h ****
81:/usr/local/CrossPack-AVR-20131216/avr/include/util/delay.h **** */
82:/usr/local/CrossPack-AVR-20131216/avr/include/util/delay.h ****
83:/usr/local/CrossPack-AVR-20131216/avr/include/util/delay.h **** #if !defined(__DOXYGEN__)
84:/usr/local/CrossPack-AVR-20131216/avr/include/util/delay.h **** static inline void _delay_us(double __us) __attribute__((always_inline));
85:/usr/local/CrossPack-AVR-20131216/avr/include/util/delay.h **** static inline void _delay_ms(double __ms) __attribute__((always_inline));
86:/usr/local/CrossPack-AVR-20131216/avr/include/util/delay.h **** #endif
87:/usr/local/CrossPack-AVR-20131216/avr/include/util/delay.h ****
88:/usr/local/CrossPack-AVR-20131216/avr/include/util/delay.h **** #ifndef F_CPU
89:/usr/local/CrossPack-AVR-20131216/avr/include/util/delay.h **** /* prevent compiler error by supplying a default */
90:/usr/local/CrossPack-AVR-20131216/avr/include/util/delay.h **** # warning "F_CPU not defined for <util/delay.h>"
91:/usr/local/CrossPack-AVR-20131216/avr/include/util/delay.h **** # define F_CPU 1000000UL
92:/usr/local/CrossPack-AVR-20131216/avr/include/util/delay.h **** #endif
93:/usr/local/CrossPack-AVR-20131216/avr/include/util/delay.h ****
94:/usr/local/CrossPack-AVR-20131216/avr/include/util/delay.h **** #ifndef __OPTIMIZE__
95:/usr/local/CrossPack-AVR-20131216/avr/include/util/delay.h **** # warning "Compiler optimizations disabled; functions from <util/delay.h> won't work as designed"
96:/usr/local/CrossPack-AVR-20131216/avr/include/util/delay.h **** #endif
97:/usr/local/CrossPack-AVR-20131216/avr/include/util/delay.h ****
98:/usr/local/CrossPack-AVR-20131216/avr/include/util/delay.h **** #if __HAS_DELAY_CYCLES && defined(__OPTIMIZE__) && \
99:/usr/local/CrossPack-AVR-20131216/avr/include/util/delay.h **** !defined(__DELAY_BACKWARD_COMPATIBLE__) && \
100:/usr/local/CrossPack-AVR-20131216/avr/include/util/delay.h **** __STDC_HOSTED__
101:/usr/local/CrossPack-AVR-20131216/avr/include/util/delay.h **** # include <math.h>
102:/usr/local/CrossPack-AVR-20131216/avr/include/util/delay.h **** #endif
103:/usr/local/CrossPack-AVR-20131216/avr/include/util/delay.h ****
104:/usr/local/CrossPack-AVR-20131216/avr/include/util/delay.h **** /**
105:/usr/local/CrossPack-AVR-20131216/avr/include/util/delay.h **** \ingroup util_delay
106:/usr/local/CrossPack-AVR-20131216/avr/include/util/delay.h ****
107:/usr/local/CrossPack-AVR-20131216/avr/include/util/delay.h **** Perform a delay of \c __ms milliseconds, using _delay_loop_2().
108:/usr/local/CrossPack-AVR-20131216/avr/include/util/delay.h ****
109:/usr/local/CrossPack-AVR-20131216/avr/include/util/delay.h **** The macro F_CPU is supposed to be defined to a
110:/usr/local/CrossPack-AVR-20131216/avr/include/util/delay.h **** constant defining the CPU clock frequency (in Hertz).
111:/usr/local/CrossPack-AVR-20131216/avr/include/util/delay.h ****
112:/usr/local/CrossPack-AVR-20131216/avr/include/util/delay.h **** The maximal possible delay is 262.14 ms / F_CPU in MHz.
113:/usr/local/CrossPack-AVR-20131216/avr/include/util/delay.h ****
114:/usr/local/CrossPack-AVR-20131216/avr/include/util/delay.h **** When the user request delay which exceed the maximum possible one,
115:/usr/local/CrossPack-AVR-20131216/avr/include/util/delay.h **** _delay_ms() provides a decreased resolution functionality. In this
116:/usr/local/CrossPack-AVR-20131216/avr/include/util/delay.h **** mode _delay_ms() will work with a resolution of 1/10 ms, providing
117:/usr/local/CrossPack-AVR-20131216/avr/include/util/delay.h **** delays up to 6.5535 seconds (independent from CPU frequency). The
118:/usr/local/CrossPack-AVR-20131216/avr/include/util/delay.h **** user will not be informed about decreased resolution.
119:/usr/local/CrossPack-AVR-20131216/avr/include/util/delay.h ****
120:/usr/local/CrossPack-AVR-20131216/avr/include/util/delay.h **** If the avr-gcc toolchain has __builtin_avr_delay_cycles(unsigned long)
121:/usr/local/CrossPack-AVR-20131216/avr/include/util/delay.h **** support, maximal possible delay is 4294967.295 ms/ F_CPU in MHz. For
122:/usr/local/CrossPack-AVR-20131216/avr/include/util/delay.h **** values greater than the maximal possible delay, overflows results in
123:/usr/local/CrossPack-AVR-20131216/avr/include/util/delay.h **** no delay i.e., 0ms.
124:/usr/local/CrossPack-AVR-20131216/avr/include/util/delay.h ****
125:/usr/local/CrossPack-AVR-20131216/avr/include/util/delay.h **** Conversion of __us into clock cycles may not always result in integer.
126:/usr/local/CrossPack-AVR-20131216/avr/include/util/delay.h **** By default, the clock cycles rounded up to next integer. This ensures that
127:/usr/local/CrossPack-AVR-20131216/avr/include/util/delay.h **** the user gets atleast __us microseconds of delay.
128:/usr/local/CrossPack-AVR-20131216/avr/include/util/delay.h ****
129:/usr/local/CrossPack-AVR-20131216/avr/include/util/delay.h **** Alternatively, user can define __DELAY_ROUND_DOWN__ and __DELAY_ROUND_CLOSEST__
130:/usr/local/CrossPack-AVR-20131216/avr/include/util/delay.h **** to round down and round to closest integer.
131:/usr/local/CrossPack-AVR-20131216/avr/include/util/delay.h ****
132:/usr/local/CrossPack-AVR-20131216/avr/include/util/delay.h **** Note: The new implementation of _delay_ms(double __ms) with
133:/usr/local/CrossPack-AVR-20131216/avr/include/util/delay.h **** __builtin_avr_delay_cycles(unsigned long) support is not backward compatible.
134:/usr/local/CrossPack-AVR-20131216/avr/include/util/delay.h **** User can define __DELAY_BACKWARD_COMPATIBLE__ to get a backward compatible delay.
135:/usr/local/CrossPack-AVR-20131216/avr/include/util/delay.h **** Also, the backward compatible
136:/usr/local/CrossPack-AVR-20131216/avr/include/util/delay.h **** algorithm will be chosen if the code is compiled in a <em>freestanding
137:/usr/local/CrossPack-AVR-20131216/avr/include/util/delay.h **** environment</em> (GCC option \c -ffreestanding), as the math functions
138:/usr/local/CrossPack-AVR-20131216/avr/include/util/delay.h **** required for rounding are not available to the compiler then.
139:/usr/local/CrossPack-AVR-20131216/avr/include/util/delay.h ****
140:/usr/local/CrossPack-AVR-20131216/avr/include/util/delay.h **** */
141:/usr/local/CrossPack-AVR-20131216/avr/include/util/delay.h **** void
142:/usr/local/CrossPack-AVR-20131216/avr/include/util/delay.h **** _delay_ms(double __ms)
143:/usr/local/CrossPack-AVR-20131216/avr/include/util/delay.h **** {
144:/usr/local/CrossPack-AVR-20131216/avr/include/util/delay.h **** double __tmp ;
145:/usr/local/CrossPack-AVR-20131216/avr/include/util/delay.h **** #if __HAS_DELAY_CYCLES && defined(__OPTIMIZE__) && \
146:/usr/local/CrossPack-AVR-20131216/avr/include/util/delay.h **** !defined(__DELAY_BACKWARD_COMPATIBLE__) && \
147:/usr/local/CrossPack-AVR-20131216/avr/include/util/delay.h **** __STDC_HOSTED__
148:/usr/local/CrossPack-AVR-20131216/avr/include/util/delay.h **** uint32_t __ticks_dc;
149:/usr/local/CrossPack-AVR-20131216/avr/include/util/delay.h **** extern void __builtin_avr_delay_cycles(unsigned long);
150:/usr/local/CrossPack-AVR-20131216/avr/include/util/delay.h **** __tmp = ((F_CPU) / 1e3) * __ms;
151:/usr/local/CrossPack-AVR-20131216/avr/include/util/delay.h ****
152:/usr/local/CrossPack-AVR-20131216/avr/include/util/delay.h **** #if defined(__DELAY_ROUND_DOWN__)
153:/usr/local/CrossPack-AVR-20131216/avr/include/util/delay.h **** __ticks_dc = (uint32_t)fabs(__tmp);
154:/usr/local/CrossPack-AVR-20131216/avr/include/util/delay.h ****
155:/usr/local/CrossPack-AVR-20131216/avr/include/util/delay.h **** #elif defined(__DELAY_ROUND_CLOSEST__)
156:/usr/local/CrossPack-AVR-20131216/avr/include/util/delay.h **** __ticks_dc = (uint32_t)(fabs(__tmp)+0.5);
157:/usr/local/CrossPack-AVR-20131216/avr/include/util/delay.h ****
158:/usr/local/CrossPack-AVR-20131216/avr/include/util/delay.h **** #else
159:/usr/local/CrossPack-AVR-20131216/avr/include/util/delay.h **** //round up by default
160:/usr/local/CrossPack-AVR-20131216/avr/include/util/delay.h **** __ticks_dc = (uint32_t)(ceil(fabs(__tmp)));
161:/usr/local/CrossPack-AVR-20131216/avr/include/util/delay.h **** #endif
162:/usr/local/CrossPack-AVR-20131216/avr/include/util/delay.h ****
163:/usr/local/CrossPack-AVR-20131216/avr/include/util/delay.h **** __builtin_avr_delay_cycles(__ticks_dc);
164:/usr/local/CrossPack-AVR-20131216/avr/include/util/delay.h ****
165:/usr/local/CrossPack-AVR-20131216/avr/include/util/delay.h **** #else
166:/usr/local/CrossPack-AVR-20131216/avr/include/util/delay.h **** uint16_t __ticks;
167:/usr/local/CrossPack-AVR-20131216/avr/include/util/delay.h **** __tmp = ((F_CPU) / 4e3) * __ms;
168:/usr/local/CrossPack-AVR-20131216/avr/include/util/delay.h **** if (__tmp < 1.0)
169:/usr/local/CrossPack-AVR-20131216/avr/include/util/delay.h **** __ticks = 1;
170:/usr/local/CrossPack-AVR-20131216/avr/include/util/delay.h **** else if (__tmp > 65535)
171:/usr/local/CrossPack-AVR-20131216/avr/include/util/delay.h **** {
172:/usr/local/CrossPack-AVR-20131216/avr/include/util/delay.h **** // __ticks = requested delay in 1/10 ms
173:/usr/local/CrossPack-AVR-20131216/avr/include/util/delay.h **** __ticks = (uint16_t) (__ms * 10.0);
174:/usr/local/CrossPack-AVR-20131216/avr/include/util/delay.h **** while(__ticks)
175:/usr/local/CrossPack-AVR-20131216/avr/include/util/delay.h **** {
176:/usr/local/CrossPack-AVR-20131216/avr/include/util/delay.h **** // wait 1/10 ms
177:/usr/local/CrossPack-AVR-20131216/avr/include/util/delay.h **** _delay_loop_2(((F_CPU) / 4e3) / 10);
178:/usr/local/CrossPack-AVR-20131216/avr/include/util/delay.h **** __ticks --;
179:/usr/local/CrossPack-AVR-20131216/avr/include/util/delay.h **** }
180:/usr/local/CrossPack-AVR-20131216/avr/include/util/delay.h **** return;
181:/usr/local/CrossPack-AVR-20131216/avr/include/util/delay.h **** }
182:/usr/local/CrossPack-AVR-20131216/avr/include/util/delay.h **** else
183:/usr/local/CrossPack-AVR-20131216/avr/include/util/delay.h **** __ticks = (uint16_t)__tmp;
184:/usr/local/CrossPack-AVR-20131216/avr/include/util/delay.h **** _delay_loop_2(__ticks);
185:/usr/local/CrossPack-AVR-20131216/avr/include/util/delay.h **** #endif
186:/usr/local/CrossPack-AVR-20131216/avr/include/util/delay.h **** }
187:/usr/local/CrossPack-AVR-20131216/avr/include/util/delay.h ****
188:/usr/local/CrossPack-AVR-20131216/avr/include/util/delay.h **** /**
189:/usr/local/CrossPack-AVR-20131216/avr/include/util/delay.h **** \ingroup util_delay
190:/usr/local/CrossPack-AVR-20131216/avr/include/util/delay.h ****
191:/usr/local/CrossPack-AVR-20131216/avr/include/util/delay.h **** Perform a delay of \c __us microseconds, using _delay_loop_1().
192:/usr/local/CrossPack-AVR-20131216/avr/include/util/delay.h ****
193:/usr/local/CrossPack-AVR-20131216/avr/include/util/delay.h **** The macro F_CPU is supposed to be defined to a
194:/usr/local/CrossPack-AVR-20131216/avr/include/util/delay.h **** constant defining the CPU clock frequency (in Hertz).
195:/usr/local/CrossPack-AVR-20131216/avr/include/util/delay.h ****
196:/usr/local/CrossPack-AVR-20131216/avr/include/util/delay.h **** The maximal possible delay is 768 us / F_CPU in MHz.
197:/usr/local/CrossPack-AVR-20131216/avr/include/util/delay.h ****
198:/usr/local/CrossPack-AVR-20131216/avr/include/util/delay.h **** If the user requests a delay greater than the maximal possible one,
199:/usr/local/CrossPack-AVR-20131216/avr/include/util/delay.h **** _delay_us() will automatically call _delay_ms() instead. The user
200:/usr/local/CrossPack-AVR-20131216/avr/include/util/delay.h **** will not be informed about this case.
201:/usr/local/CrossPack-AVR-20131216/avr/include/util/delay.h ****
202:/usr/local/CrossPack-AVR-20131216/avr/include/util/delay.h **** If the avr-gcc toolchain has __builtin_avr_delay_cycles(unsigned long)
203:/usr/local/CrossPack-AVR-20131216/avr/include/util/delay.h **** support, maximal possible delay is 4294967.295 us/ F_CPU in MHz. For
204:/usr/local/CrossPack-AVR-20131216/avr/include/util/delay.h **** values greater than the maximal possible delay, overflow results in
205:/usr/local/CrossPack-AVR-20131216/avr/include/util/delay.h **** no delay i.e., 0us.
206:/usr/local/CrossPack-AVR-20131216/avr/include/util/delay.h ****
207:/usr/local/CrossPack-AVR-20131216/avr/include/util/delay.h **** Conversion of __us into clock cycles may not always result in integer.
208:/usr/local/CrossPack-AVR-20131216/avr/include/util/delay.h **** By default, the clock cycles rounded up to next integer. This ensures that
209:/usr/local/CrossPack-AVR-20131216/avr/include/util/delay.h **** the user gets atleast __us microseconds of delay.
210:/usr/local/CrossPack-AVR-20131216/avr/include/util/delay.h ****
211:/usr/local/CrossPack-AVR-20131216/avr/include/util/delay.h **** Alternatively, user can define __DELAY_ROUND_DOWN__ and __DELAY_ROUND_CLOSEST__
212:/usr/local/CrossPack-AVR-20131216/avr/include/util/delay.h **** to round down and round to closest integer.
213:/usr/local/CrossPack-AVR-20131216/avr/include/util/delay.h ****
214:/usr/local/CrossPack-AVR-20131216/avr/include/util/delay.h **** Note: The new implementation of _delay_us(double __us) with
215:/usr/local/CrossPack-AVR-20131216/avr/include/util/delay.h **** __builtin_avr_delay_cycles(unsigned long) support is not backward compatible.
216:/usr/local/CrossPack-AVR-20131216/avr/include/util/delay.h **** User can define __DELAY_BACKWARD_COMPATIBLE__ to get a backward compatible delay.
217:/usr/local/CrossPack-AVR-20131216/avr/include/util/delay.h **** Also, the backward compatible
218:/usr/local/CrossPack-AVR-20131216/avr/include/util/delay.h **** algorithm will be chosen if the code is compiled in a <em>freestanding
219:/usr/local/CrossPack-AVR-20131216/avr/include/util/delay.h **** environment</em> (GCC option \c -ffreestanding), as the math functions
220:/usr/local/CrossPack-AVR-20131216/avr/include/util/delay.h **** required for rounding are not available to the compiler then.
221:/usr/local/CrossPack-AVR-20131216/avr/include/util/delay.h ****
222:/usr/local/CrossPack-AVR-20131216/avr/include/util/delay.h **** */
223:/usr/local/CrossPack-AVR-20131216/avr/include/util/delay.h **** void
224:/usr/local/CrossPack-AVR-20131216/avr/include/util/delay.h **** _delay_us(double __us)
225:/usr/local/CrossPack-AVR-20131216/avr/include/util/delay.h **** {
226:/usr/local/CrossPack-AVR-20131216/avr/include/util/delay.h **** double __tmp ;
227:/usr/local/CrossPack-AVR-20131216/avr/include/util/delay.h **** #if __HAS_DELAY_CYCLES && defined(__OPTIMIZE__) && \
228:/usr/local/CrossPack-AVR-20131216/avr/include/util/delay.h **** !defined(__DELAY_BACKWARD_COMPATIBLE__) && \
229:/usr/local/CrossPack-AVR-20131216/avr/include/util/delay.h **** __STDC_HOSTED__
230:/usr/local/CrossPack-AVR-20131216/avr/include/util/delay.h **** uint32_t __ticks_dc;
231:/usr/local/CrossPack-AVR-20131216/avr/include/util/delay.h **** extern void __builtin_avr_delay_cycles(unsigned long);
232:/usr/local/CrossPack-AVR-20131216/avr/include/util/delay.h **** __tmp = ((F_CPU) / 1e6) * __us;
233:/usr/local/CrossPack-AVR-20131216/avr/include/util/delay.h ****
234:/usr/local/CrossPack-AVR-20131216/avr/include/util/delay.h **** #if defined(__DELAY_ROUND_DOWN__)
235:/usr/local/CrossPack-AVR-20131216/avr/include/util/delay.h **** __ticks_dc = (uint32_t)fabs(__tmp);
236:/usr/local/CrossPack-AVR-20131216/avr/include/util/delay.h ****
237:/usr/local/CrossPack-AVR-20131216/avr/include/util/delay.h **** #elif defined(__DELAY_ROUND_CLOSEST__)
238:/usr/local/CrossPack-AVR-20131216/avr/include/util/delay.h **** __ticks_dc = (uint32_t)(fabs(__tmp)+0.5);
239:/usr/local/CrossPack-AVR-20131216/avr/include/util/delay.h ****
240:/usr/local/CrossPack-AVR-20131216/avr/include/util/delay.h **** #else
241:/usr/local/CrossPack-AVR-20131216/avr/include/util/delay.h **** //round up by default
242:/usr/local/CrossPack-AVR-20131216/avr/include/util/delay.h **** __ticks_dc = (uint32_t)(ceil(fabs(__tmp)));
243:/usr/local/CrossPack-AVR-20131216/avr/include/util/delay.h **** #endif
244:/usr/local/CrossPack-AVR-20131216/avr/include/util/delay.h ****
245:/usr/local/CrossPack-AVR-20131216/avr/include/util/delay.h **** __builtin_avr_delay_cycles(__ticks_dc);
28 .loc 2 245 0
29 0002 EFEC ldi r30,lo8(207)
30 0004 F0E0 ldi r31,hi8(207)
31 0006 3197 1: sbiw r30,1
32 0008 01F4 brne 1b
33 000a 00C0 rjmp .
34 000c 0000 nop
35 .LVL2:
36 000e 28E0 ldi r18,lo8(8)
37 0010 30E0 ldi r19,0
38 .LBE9:
39 .LBE8:
24:libs/serialdebug.c **** _delay_us(SERIALDEBUG_MICROSECONDS_PER_BIT);
25:libs/serialdebug.c ****
26:libs/serialdebug.c **** // data bits
27:libs/serialdebug.c **** for (bit_mask=0x01; bit_mask; bit_mask<<=1) {
40 .loc 1 27 0
41 0012 91E0 ldi r25,lo8(1)
42 .LVL3:
43 .L5:
28:libs/serialdebug.c **** if (c & bit_mask) {
44 .loc 1 28 0
45 0014 492F mov r20,r25
46 0016 4823 and r20,r24
47 0018 01F0 breq .L2
29:libs/serialdebug.c **** SERIALDEBUG_SOFT_TX_PORT |= (1<<SERIALDEBUG_SOFT_TX_BIT);
48 .loc 1 29 0
49 001a DE9A sbi 0x1b,6
50 001c 00C0 rjmp .L3
51 .L2:
30:libs/serialdebug.c **** }
31:libs/serialdebug.c **** else {
32:libs/serialdebug.c **** SERIALDEBUG_SOFT_TX_PORT &= ~(1<<SERIALDEBUG_SOFT_TX_BIT);
52 .loc 1 32 0
53 001e DE98 cbi 0x1b,6
54 .L3:
55 .LVL4:
56 .LBB10:
57 .LBB11:
58 .loc 2 245 0
59 0020 EFEC ldi r30,lo8(207)
60 0022 F0E0 ldi r31,hi8(207)
61 0024 3197 1: sbiw r30,1
62 0026 01F4 brne 1b
63 0028 00C0 rjmp .
64 002a 0000 nop
65 .LBE11:
66 .LBE10:
27:libs/serialdebug.c **** for (bit_mask=0x01; bit_mask; bit_mask<<=1) {
67 .loc 1 27 0
68 002c 990F lsl r25
69 .LVL5:
70 002e 2150 subi r18,1
71 0030 3109 sbc r19,__zero_reg__
72 0032 2115 cp r18,__zero_reg__
73 0034 3105 cpc r19,__zero_reg__
74 0036 01F4 brne .L5
33:libs/serialdebug.c **** }
34:libs/serialdebug.c **** _delay_us(SERIALDEBUG_MICROSECONDS_PER_BIT);
35:libs/serialdebug.c **** }
36:libs/serialdebug.c ****
37:libs/serialdebug.c **** // stop bit(s)
38:libs/serialdebug.c **** SERIALDEBUG_SOFT_TX_PORT |= (1<<SERIALDEBUG_SOFT_TX_BIT);
75 .loc 1 38 0
76 0038 DE9A sbi 0x1b,6
77 .LVL6:
78 .LBB12:
79 .LBB13:
80 .loc 2 245 0
81 003a EFEC ldi r30,lo8(207)
82 003c F0E0 ldi r31,hi8(207)
83 003e 3197 1: sbiw r30,1
84 0040 01F4 brne 1b
85 0042 00C0 rjmp .
86 0044 0000 nop
87 .LBE13:
88 .LBE12:
39:libs/serialdebug.c **** _delay_us(SERIALDEBUG_MICROSECONDS_PER_BIT * SERIALDEBUG_STOP_BITS);
40:libs/serialdebug.c ****
41:libs/serialdebug.c **** #if SERIALDEBUG_USE_INTS
42:libs/serialdebug.c **** sei();
43:libs/serialdebug.c **** #endif
44:libs/serialdebug.c ****
45:libs/serialdebug.c **** return c;
46:libs/serialdebug.c ****
47:libs/serialdebug.c **** }
89 .loc 1 47 0
90 0046 90E0 ldi r25,0
91 .LVL7:
92 0048 0895 ret
93 .cfi_endproc
94 .LFE8:
96 .global serial_configure
98 serial_configure:
99 .LFB7:
7:libs/serialdebug.c **** void serial_configure(void) {
100 .loc 1 7 0
101 .cfi_startproc
102 /* prologue: function */
103 /* frame size = 0 */
104 /* stack size = 0 */
105 .L__stack_usage = 0
9:libs/serialdebug.c **** SERIALDEBUG_SOFT_TX_PORT |= (1<<SERIALDEBUG_SOFT_TX_BIT);
106 .loc 1 9 0
107 004a DE9A sbi 0x1b,6
10:libs/serialdebug.c **** SERIALDEBUG_SOFT_TX_DDR |= (1<<SERIALDEBUG_SOFT_TX_BIT);
108 .loc 1 10 0
109 004c D69A sbi 0x1a,6
11:libs/serialdebug.c **** fdev_setup_stream(&serialdebug_usartout, usart_putchar, NULL, _FDEV_SETUP_WRITE);
110 .loc 1 11 0
111 004e 80E0 ldi r24,lo8(gs(usart_putchar))
112 0050 90E0 ldi r25,hi8(gs(usart_putchar))
113 0052 9093 0000 sts serialdebug_usartout+8+1,r25
114 0056 8093 0000 sts serialdebug_usartout+8,r24
115 005a 1092 0000 sts serialdebug_usartout+10+1,__zero_reg__
116 005e 1092 0000 sts serialdebug_usartout+10,__zero_reg__
117 0062 82E0 ldi r24,lo8(2)
118 0064 8093 0000 sts serialdebug_usartout+3,r24
119 0068 1092 0000 sts serialdebug_usartout+12+1,__zero_reg__
120 006c 1092 0000 sts serialdebug_usartout+12,__zero_reg__
12:libs/serialdebug.c **** stdout = &serialdebug_usartout;
121 .loc 1 12 0
122 0070 80E0 ldi r24,lo8(serialdebug_usartout)
123 0072 90E0 ldi r25,hi8(serialdebug_usartout)
124 0074 9093 0000 sts __iob+2+1,r25
125 0078 8093 0000 sts __iob+2,r24
126 007c 0895 ret
127 .cfi_endproc
128 .LFE7:
130 .global dbg_putstring
132 dbg_putstring:
133 .LFB9:
48:libs/serialdebug.c ****
49:libs/serialdebug.c **** void dbg_putstring(char string[]) {
134 .loc 1 49 0
135 .cfi_startproc
136 .LVL8:
137 007e CF93 push r28
138 .LCFI0:
139 .cfi_def_cfa_offset 3
140 .cfi_offset 28, -2
141 0080 DF93 push r29
142 .LCFI1:
143 .cfi_def_cfa_offset 4
144 .cfi_offset 29, -3
145 /* prologue: function */
146 /* frame size = 0 */
147 /* stack size = 2 */
148 .L__stack_usage = 2
149 0082 EC01 movw r28,r24
150 .LVL9:
151 .L9:
50:libs/serialdebug.c **** // Print a string of arbitrary length to serial
51:libs/serialdebug.c **** int i=0;
52:libs/serialdebug.c **** while (string[i] != '\0') {
152 .loc 1 52 0 discriminator 1
153 0084 8991 ld r24,Y+
154 .LVL10:
155 0086 8823 tst r24
156 0088 01F0 breq .L11
53:libs/serialdebug.c **** usart_putchar(string[i], &serialdebug_usartout);
157 .loc 1 53 0
158 008a 60E0 ldi r22,lo8(serialdebug_usartout)
159 008c 70E0 ldi r23,hi8(serialdebug_usartout)
160 008e 00D0 rcall usart_putchar
161 .LVL11:
162 0090 00C0 rjmp .L9
163 .LVL12:
164 .L11:
165 /* epilogue start */
54:libs/serialdebug.c **** i++;
55:libs/serialdebug.c **** }
56:libs/serialdebug.c **** }
166 .loc 1 56 0
167 0092 DF91 pop r29
168 0094 CF91 pop r28
169 .LVL13:
170 0096 0895 ret
171 .cfi_endproc
172 .LFE9:
174 .section .rodata.str1.1,"aMS",@progbits,1
175 .LC0:
176 0000 0A00 .string "\n"
177 .text
178 .global dbg_putstring_nl
180 dbg_putstring_nl:
181 .LFB10:
57:libs/serialdebug.c ****
58:libs/serialdebug.c **** void dbg_putstring_nl(char string[]) {
182 .loc 1 58 0
183 .cfi_startproc
184 .LVL14:
185 /* prologue: function */
186 /* frame size = 0 */
187 /* stack size = 0 */
188 .L__stack_usage = 0
59:libs/serialdebug.c **** if(string) dbg_putstring(string);
189 .loc 1 59 0
190 0098 0097 sbiw r24,0
191 009a 01F0 breq .L13
192 .loc 1 59 0 is_stmt 0 discriminator 1
193 009c 00D0 rcall dbg_putstring
194 .LVL15:
195 .L13:
60:libs/serialdebug.c **** dbg_putstring("\n");
196 .loc 1 60 0 is_stmt 1
197 009e 80E0 ldi r24,lo8(.LC0)
198 00a0 90E0 ldi r25,hi8(.LC0)
199 00a2 00C0 rjmp dbg_putstring
200 .LVL16:
201 .cfi_endproc
202 .LFE10:
204 .global dbg_putint
206 dbg_putint:
207 .LFB11:
61:libs/serialdebug.c **** }
62:libs/serialdebug.c ****
63:libs/serialdebug.c **** void dbg_putint(unsigned int num) {
208 .loc 1 63 0
209 .cfi_startproc
210 .LVL17:
211 00a4 CF93 push r28
212 .LCFI2:
213 .cfi_def_cfa_offset 3
214 .cfi_offset 28, -2
215 00a6 DF93 push r29
216 .LCFI3:
217 .cfi_def_cfa_offset 4
218 .cfi_offset 29, -3
219 00a8 CDB7 in r28,__SP_L__
220 00aa DEB7 in r29,__SP_H__
221 .LCFI4:
222 .cfi_def_cfa_register 28
223 00ac 2797 sbiw r28,7
224 .LCFI5:
225 .cfi_def_cfa_offset 11
226 00ae 0FB6 in __tmp_reg__,__SREG__
227 00b0 F894 cli
228 00b2 DEBF out __SP_H__,r29
229 00b4 0FBE out __SREG__,__tmp_reg__
230 00b6 CDBF out __SP_L__,r28
231 /* prologue: function */
232 /* frame size = 7 */
233 /* stack size = 9 */
234 .L__stack_usage = 9
64:libs/serialdebug.c **** // Create string representing int and print to serial
65:libs/serialdebug.c **** char c[7];
66:libs/serialdebug.c **** itoa(num, c, 10);
235 .loc 1 66 0
236 00b8 4AE0 ldi r20,lo8(10)
237 00ba 50E0 ldi r21,0
238 00bc BE01 movw r22,r28
239 00be 6F5F subi r22,-1
240 00c0 7F4F sbci r23,-1
241 00c2 00D0 rcall itoa
242 .LVL18:
67:libs/serialdebug.c **** dbg_putstring(c);
243 .loc 1 67 0
244 00c4 CE01 movw r24,r28
245 00c6 0196 adiw r24,1
246 00c8 00D0 rcall dbg_putstring
247 .LVL19:
248 /* epilogue start */
68:libs/serialdebug.c **** }
249 .loc 1 68 0
250 00ca 2796 adiw r28,7
251 00cc 0FB6 in __tmp_reg__,__SREG__
252 00ce F894 cli
253 00d0 DEBF out __SP_H__,r29
254 00d2 0FBE out __SREG__,__tmp_reg__
255 00d4 CDBF out __SP_L__,r28
256 00d6 DF91 pop r29
257 00d8 CF91 pop r28
258 00da 0895 ret
259 .cfi_endproc
260 .LFE11:
262 .local serialdebug_usartout
263 .comm serialdebug_usartout,14,1
264 .Letext0:
265 .file 3 "/usr/local/CrossPack-AVR-20131216/avr/include/stdint.h"
266 .file 4 "/usr/local/CrossPack-AVR-20131216/avr/include/stdio.h"
267 .file 5 "./libs/serialdebug.h"
DEFINED SYMBOLS
*ABS*:00000000 serialdebug.c
/var/folders/wx/jhklkzmx1jjffh5wq3y2p3lc0000gn/T//cclDgkOy.s:2 *ABS*:0000003e __SP_H__
/var/folders/wx/jhklkzmx1jjffh5wq3y2p3lc0000gn/T//cclDgkOy.s:3 *ABS*:0000003d __SP_L__
/var/folders/wx/jhklkzmx1jjffh5wq3y2p3lc0000gn/T//cclDgkOy.s:4 *ABS*:0000003f __SREG__
/var/folders/wx/jhklkzmx1jjffh5wq3y2p3lc0000gn/T//cclDgkOy.s:5 *ABS*:00000000 __tmp_reg__
/var/folders/wx/jhklkzmx1jjffh5wq3y2p3lc0000gn/T//cclDgkOy.s:6 *ABS*:00000001 __zero_reg__
/var/folders/wx/jhklkzmx1jjffh5wq3y2p3lc0000gn/T//cclDgkOy.s:12 .text:00000000 usart_putchar
/var/folders/wx/jhklkzmx1jjffh5wq3y2p3lc0000gn/T//cclDgkOy.s:98 .text:0000004a serial_configure
.bss:00000000 serialdebug_usartout
/var/folders/wx/jhklkzmx1jjffh5wq3y2p3lc0000gn/T//cclDgkOy.s:132 .text:0000007e dbg_putstring
/var/folders/wx/jhklkzmx1jjffh5wq3y2p3lc0000gn/T//cclDgkOy.s:180 .text:00000098 dbg_putstring_nl
/var/folders/wx/jhklkzmx1jjffh5wq3y2p3lc0000gn/T//cclDgkOy.s:206 .text:000000a4 dbg_putint

UNDEFINED SYMBOLS
__iob
itoa
__do_copy_data
__do_clear_bss

BIN
libs/serialdebug.o View File


+ 58
- 40
main.c View File

@@ -8,40 +8,53 @@
#include <avr/sleep.h>
#include <avr/wdt.h>

// User settings
#define HOUR 3600
// I wanted each block of time to be 45 mins, but my chip's clock is slow
// 40 should roughly scale to 45
#define BLOCK_MINS 40
// How long to pour for
#define DISPENSE_MS 12000
/* User settings */

/*
// How long between feedings is calculated as follows:
// BLOCK_BASE + ($setting * BLOCK_STEP)
// All units are minutes.
// $setting is the 0-15 value read from the speed knob

#define BLOCK_BASE 360
#define BLOCK_STEP 27 // I wanted 30 mins but my chip's clock is off

vcc [1 14] gnd
[2 13] input speed_0
[3 12] input speed_1
rst [4 11] input speed_2
INT/input feed button [5 10] input speed_3
motor [6 9]
debug serial [7 8]
*/
// How long to pour for, in milliseconds
// Cannot be larger than an unsigned int
#define DISPENSE_MS 12000

// Ports
// When the device boots, it wiggles the motor to notify the user that is is alive.
// These settings control the length and spacing of the pulses, in milliseconds
#define WAKEUP_PULSE 100
#define WAKEUP_BETWEEN 75
#define NUM_PULSES 6

/* Ports configuration */

// Attiny84 pin layout:
// vcc [1 14] gnd
// PB0 [2 13] PA0 input speed_0
// PB1 [3 12] PA1 input speed_1
// rst PB3 [4 11] PA2 input speed_2
// INT/input feed button PB2 [5 10] PA3 input speed_3
// motor control PA7 [6 9] PA4
// debug serial PA6 [7 8] PA5 dial/motor enable

// Motor control
#define FEED_DDR DDRA
#define FEED_PORT PORTA
#define FEED_BIT PA7

// Dial/motor enable
#define PWRON_DDR DDRA
#define PWRON_PORT PORTA
#define PWRON_BIT PA5

// Force-feed input button - must be an interrupt pin
#define FORCE_DDR DDRB
#define FORCE_PORT PINB
#define FORCE_BIT PB2

// Dial inputs - NIBBLE0 is MSB
#define NIBBLE0_DDR DDRA
#define NIBBLE0_PORT PINA
#define NIBBLE0_BIT PA0
@@ -69,7 +82,7 @@ void motor_off(void) {
CLEAR_BIT(FEED_PORT, FEED_BIT);
}

void dispense(int ms) {
void dispense(unsigned int ms) {
// Activate motor for X ms
motor_on();
while(ms > 0) {
@@ -89,9 +102,6 @@ void pwr_off(void) {
CLEAR_BIT(PWRON_PORT, PWRON_BIT);
}

#define WAKEUP_PULSE 100
#define WAKEUP_BETWEEN 75

void bootpulse(void) {
// Pulse the motor quickly
motor_on();
@@ -101,9 +111,9 @@ void bootpulse(void) {
}

void wakeup(void) {
// Perform
// Notify the user the device is alive
motor_on();
for(int i=0;i<6;i++) bootpulse();
for(int i=0;i<NUM_PULSES;i++) bootpulse();
motor_off();
}

@@ -111,9 +121,6 @@ void delay_s(int seconds) {
while(seconds-- > 0) {
for (int i = 0; i < 10; i++)
_delay_ms(100);
#ifdef __DEBUG__
dbg_putstring("Wait...\n");
#endif
}
}

@@ -124,6 +131,11 @@ uint8_t get_speed() {
speed |= (IS_SET(NIBBLE2_PORT,NIBBLE2_BIT) << 1);
speed |= (IS_SET(NIBBLE1_PORT,NIBBLE1_BIT) << 2);
speed |= (IS_SET(NIBBLE0_PORT,NIBBLE0_BIT) << 3);
#ifdef __DEBUG__
dbg_putstring("read setting: ");
dbg_putint(speed);
dbg_putstring("\r\n");
#endif
return speed;
}

@@ -143,10 +155,10 @@ void setup() {
cli(); //disable global interrupts

// Set ISC01= 1 and ISC00 = 0 to generate an external interrupt request
// on any change of INT0
// on any change of INT0 (which is on PB2 on an attiny84)
SET_BIT(MCUCR,ISC00);
SET_BIT(MCUCR,ISC01);
//enable external interrupt request 0
// enable external interrupt request 0
SET_BIT(GIMSK,INT0);

// disable ADC (saves power)
@@ -183,7 +195,7 @@ ISR (WDT_vect) {
//external interrupt ISR (for INT0 pin)
ISR(INT0_vect) {
#ifdef __DEBUG__
dbg_putstring("AYE MATEY\n");
dbg_putstring("Woken from manual interrupt\r\n");
#endif
pwr_on();
while(IS_SET(FORCE_PORT, FORCE_BIT)) {
@@ -200,7 +212,7 @@ int main(void) {

#ifdef __DEBUG__
serial_configure();
dbg_putstring("\n\n");
dbg_putstring(".\r\n\r\n\r\n\r\n\r\nCatFeeder v1.2 Booted!\r\n = ^_^ =\r\n\r\n");
#endif

// Configure the mcu
@@ -210,33 +222,39 @@ int main(void) {
pwr_on();
wakeup();
pwr_off();

delay_s(1);

while (1) {
if (seconds_since_last_spin % 10 == 0) {
// Power on the input dial, delay while it warms up
pwr_on();
_delay_ms(1); // Let input pins warm up
_delay_ms(1);

// speed can be 0-15
// delay = 2hrs + speed * .75h
// range of 1hr to 12hrs25m
// read delay setting, speed can be 0-15
uint8_t speed = get_speed();
long sleep_max = HOUR + (BLOCK_MINS * 60 * speed); // 45 mins per unit of speed

long to_go = sleep_max - seconds_since_last_spin;
// Calculate how long since the last feeding the next one will be
long feed_internal = 60L * ((long)BLOCK_BASE + ((long)BLOCK_STEP * (long)speed));

// This many seconds until the next feeding
long to_go = feed_internal - seconds_since_last_spin;

#ifdef __DEBUG__
dbg_putstring("calculated feed_internal: ");
dbg_putlong(feed_internal);
dbg_putstring("s\r\n");

dbg_putstring("Mins to sleep: ");
dbg_putint((unsigned int)sleep_max/60);
dbg_putstring("\n");
dbg_putint((unsigned int)feed_internal/60);
dbg_putstring("\r\n");
dbg_putstring("Mins to go: ");
dbg_putint((unsigned int)to_go/60);
dbg_putstring("\n\n");
dbg_putstring("\r\n\n");
#endif

// If it's been long enough, do the thing
if(to_go <= 0) {
dbg_putstring("dispensing now\r\n");
dispense(DISPENSE_MS);
seconds_since_last_spin = 0;
}


Loading…
Cancel
Save