Ver código fonte

picadae/ctrl/Makefile,main.c : Added code to allow ATMega2560 as target.

master
kevin.larke 4 anos atrás
pai
commit
db1ab31279
2 arquivos alterados com 38 adições e 29 exclusões
  1. 27
    2
      control/ctrl/Makefile
  2. 11
    27
      control/ctrl/main.c

+ 27
- 2
control/ctrl/Makefile Ver arquivo

@@ -2,14 +2,39 @@ ifndef TTY
2 2
 TTY=/dev/ttyACM0
3 3
 endif
4 4
 
5
+MMCU=atmega328
6
+#MMCU=atmega2560
7
+
8
+ifeq ($(MMCU),atmega328)
9
+PROG_MMCU=atmega328p
10
+PROG_DEV=arduino
11
+AVRD_CONF=
12
+DISABLE_AUTO_ERASE=
13
+SKIP_CHECKS=-FV
14
+endif
15
+
16
+ifeq ($(MMCU),atmega2560)
17
+PROG_MMCU=$(MMCU)
18
+PROG_DEV=wiring
19
+AVRD_CONF=-C/etc/avrdude/avrdude.conf
20
+DISABLE_AUTO_ERASE=-D
21
+SKIP_CHECKS=-FV
22
+endif
23
+
24
+
25
+
5 26
 # compiler flags:
6 27
 # -Os                : optimize size
7 28
 # -DF_CPU=16000000UL : define F_CPU as 16Mghz
8 29
 # -mmcu=atmega328p   : target MCU
30
+# -F                 : skip device signature read
31
+# -V                 : disable automatic verify step
32
+# -v                 : enable verbose output
33
+# -D                 : disable auto erase flash
9 34
 
10 35
 main.hex : main.c
11 36
 	# compile to object file (optimize for size)
12
-	avr-gcc -Os -DF_CPU=16000000UL -mmcu=atmega328p  -o main.elf main.c twi.c
37
+	avr-gcc -Os -DF_CPU=16000000UL -mmcu=$(MMCU)  -o main.elf main.c twi.c
13 38
 	# link as ELF binary
14 39
 	#avr-gcc -mmcu=atmega328p main.o -o main.elf
15 40
 	# convert ELF format to an IHEX format as used by avrdude
@@ -17,7 +42,7 @@ main.hex : main.c
17 42
 
18 43
 
19 44
 burn:
20
-	avrdude -F -V -c arduino -p ATMEGA328P -P $(TTY) -b 115200 -U flash:w:main.hex
45
+	avrdude $(SKIP_CHECKS) -v $(AVRD_CONF) -c$(PROG_DEV) -p$(PROG_MMCU) -P$(TTY) -b 115200 $(DISABLE_AUTO_ERASE) -U flash:w:main.hex:i
21 46
 
22 47
 clean :
23 48
 	rm main.o twi.o main.elf main.hex

+ 11
- 27
control/ctrl/main.c Ver arquivo

@@ -10,6 +10,16 @@
10 10
 
11 11
 #include "twi.h"
12 12
 
13
+#define ICP_PRE_SCALE (4)
14
+#if defined(__AVR_ATmega2560__)
15
+#define SERIAL_RX_ISR USART0_RX_vect
16
+#elif defined(__AVR_ATmega328__)
17
+#define SERIAL_RX_ISR USART_RX_vect
18
+#else
19
+#error Unknown target processor
20
+#endif
21
+
22
+
13 23
 //------------------------------------------------------------------------------
14 24
 
15 25
 #define SER_BUF_N (16)  // size of receive buffer
@@ -102,7 +112,7 @@ void i2c_init()
102 112
   twi_init();
103 113
 }
104 114
 
105
-ISR(USART_RX_vect)
115
+ISR(SERIAL_RX_ISR)
106 116
 {
107 117
   // receive the incoming byte
108 118
   ser_buf[ ser_buf_i_idx ] = uart_getchar();
@@ -112,25 +122,6 @@ ISR(USART_RX_vect)
112 122
 }
113 123
 
114 124
 
115
-//--------------------------------------------------------------------------------------------------
116
-static volatile int timerFl = 0;
117
-  
118
-
119
-ISR(TIMER1_COMPA_vect)
120
-{
121
-  timerFl = 1;
122
-}
123
-
124
-void timer_init(void)
125
-{
126
-  TCCR1A = 0;              // set timer control registers to default
127
-  TCCR1B = 0;              // 
128
-  OCR1A = 15624;           // 1 Hz = 16Mghz / (1024 * 15624)
129
-  TCCR1B |= (1 << WGM12);  // CTC mode on
130
-  TCCR1B |= (1 << CS10);   // Set CS10 and CS12 bits for 1024 prescaler:
131
-  TCCR1B |= (1 << CS12);   // 
132
-  TIMSK1 |= (1 << OCIE1A); // enable timer compare interrupt  
133
-}
134 125
 
135 126
 //--------------------------------------------------------------------------------------------------
136 127
 
@@ -156,7 +147,6 @@ int main (void)
156 147
 
157 148
   DDRB |= _BV(DDB5);  // set led pin for output
158 149
   
159
-  timer_init(); // setup the timer
160 150
   uart_init();  // setup UART data format and baud rate
161 151
   i2c_init();
162 152
   sei();        // re-enable interrupts
@@ -165,12 +155,6 @@ int main (void)
165 155
   
166 156
   for(;;)
167 157
   {
168
-    if( timerFl )
169
-    {
170
-      //PORTB ^= _BV(PORTB5);   //  toggle LED
171
-      
172
-      timerFl = 0;
173
-    }
174 158
     
175 159
     // if there are bytes waiting in the serial buffer
176 160
     if( ser_buf_o_idx != ser_buf_i_idx )

Carregando…
Cancelar
Salvar