All pastes #107661 Raw Edit

Anonymous

public text v1 · immutable
#107661 ·published 2006-07-31 02:55 UTC
rendered paste body
   1               		.file	"main.c"
   2               		.arch atmega16
   3               	__SREG__ = 0x3f
   4               	__SP_H__ = 0x3e
   5               	__SP_L__ = 0x3d
   6               	__tmp_reg__ = 0
   7               	__zero_reg__ = 1
   8               		.global __do_copy_data
   9               		.global __do_clear_bss
  11               		.text
  12               	.Ltext0:
  77               	.global	__vector_8
  79               	__vector_8:
   1:main.c        **** #include <avr/io.h>
   2:main.c        **** #include <avr/interrupt.h>
   3:main.c        **** #include <util/delay.h>
   4:main.c        **** #include <stdlib.h>
   5:main.c        **** #include "timer.h"
   6:main.c        **** #include "serial_coms.h"
   7:main.c        **** #include "gyro.h"
   8:main.c        **** #include "encoder.h"
   9:main.c        **** #include "data_packet.h"
  10:main.c        **** #include "globals.h"
  11:main.c        **** 
  12:main.c        **** // Flag that is set in an overflow timer. The ISR is then
  13:main.c        **** // executed in the main loop and flag reset.
  14:main.c        **** unsigned char run_timer1_isr;
  15:main.c        **** 
  16:main.c        **** /*******************************************************************************
  17:main.c        **** *
  18:main.c        **** *	FUNCTION:		SIGNAL(SIG_INTERRUPT0)
  19:main.c        **** *
  20:main.c        **** *	PURPOSE:		This is the interrupt service routine (ISR) for external
  21:main.c        **** *                           		interrupt 0 (left encoder, rising edge.)
  22:main.c        **** *
  23:main.c        **** *	CALLED FROM:	Rising edge of INT0
  24:main.c        **** *
  25:main.c        **** *	PARAMETERS:		Nothing.
  26:main.c        **** *
  27:main.c        **** *	RETURNS:		Nothing.
  28:main.c        **** *
  29:main.c        **** *	COMMENTS:		Nothing.
  30:main.c        **** *
  31:main.c        **** *******************************************************************************/
  32:main.c        **** ISR(SIG_INTERRUPT0)
  33:main.c        **** {
  34:main.c        **** 	// Run the ISR that determines direction and updates
  35:main.c        **** 	// the correct variable
  36:main.c        **** 	Left_Encoder_ISR();
  37:main.c        **** }
  38:main.c        **** 
  39:main.c        **** /*******************************************************************************
  40:main.c        **** *
  41:main.c        **** *	FUNCTION:		SIGNAL(SIG_INTERRUPT1)
  42:main.c        **** *
  43:main.c        **** *	PURPOSE:		This is the interrupt service routine (ISR) for external
  44:main.c        **** *                           		interrupt 1 (right encoder, rising edge.)
  45:main.c        **** *
  46:main.c        **** *	CALLED FROM:	Rising edge of INT1
  47:main.c        **** *
  48:main.c        **** *	PARAMETERS:		Nothing.
  49:main.c        **** *
  50:main.c        **** *	RETURNS:		Nothing.
  51:main.c        **** *
  52:main.c        **** *	COMMENTS:		Nothing.
  53:main.c        **** *
  54:main.c        **** *******************************************************************************/
  55:main.c        **** ISR(SIG_INTERRUPT1)
  56:main.c        **** {
  57:main.c        **** 	// Run the ISR that determines direction and updates
  58:main.c        **** 	// the correct variable
  59:main.c        **** 	Right_Encoder_ISR();
  60:main.c        **** }
  61:main.c        **** 
  62:main.c        **** 
  63:main.c        **** /*******************************************************************************
  64:main.c        **** *
  65:main.c        **** *	FUNCTION:		SIGNAL(SIG_OVERFLOW1)
  66:main.c        **** *
  67:main.c        **** *	PURPOSE:		This is the interrupt service routine (ISR) for timer1
  68:main.c        **** *					overflow. It is run at approximately 120MHz thanks to
  69:main.c        **** *					a prescaler and register loading.
  70:main.c        **** *
  71:main.c        **** *	CALLED FROM:	Timer1 overflow
  72:main.c        **** *
  73:main.c        **** *	PARAMETERS:		Nothing.
  74:main.c        **** *
  75:main.c        **** *	RETURNS:		Nothing.
  76:main.c        **** *
  77:main.c        **** *	COMMENTS:		Nothing.
  78:main.c        **** *
  79:main.c        **** *******************************************************************************/
  80:main.c        **** ISR(SIG_OVERFLOW1)
  81:main.c        **** {
  81               	.LM0:
  82               	/* prologue: frame size=0 */
  83 0000 1F92      		push __zero_reg__
  84 0002 0F92      		push __tmp_reg__
  85 0004 0FB6      		in __tmp_reg__,__SREG__
  86 0006 0F92      		push __tmp_reg__
  87 0008 1124      		clr __zero_reg__
  88 000a 8F93      		push r24
  89               	/* prologue end (size=6) */
  82:main.c        **** 	// Set a flag saying that the timer has overflowed
  83:main.c        **** 	// and we need to run the ISR
  84:main.c        **** 	run_timer1_isr	=	TRUE;
  91               	.LM1:
  92 000c 81E0      		ldi r24,lo8(1)
  93 000e 8093 0000 		sts run_timer1_isr,r24
  94               	/* epilogue: frame size=0 */
  95 0012 8F91      		pop r24
  96 0014 0F90      		pop __tmp_reg__
  97 0016 0FBE      		out __SREG__,__tmp_reg__
  98 0018 0F90      		pop __tmp_reg__
  99 001a 1F90      		pop __zero_reg__
 100 001c 1895      		reti
 101               	/* epilogue end (size=6) */
 102               	/* function __vector_8 size 15 (3) */
 104               	.Lscope0:
 105               		.data
 106               	.LC0:
 107 0000 4156 5220 		.string	"AVR board initialized...\r\n"
 107      626F 6172 
 107      6420 696E 
 107      6974 6961 
 107      6C69 7A65 
 108               		.text
 110               	.global	main
 112               	main:
  85:main.c        **** }
  86:main.c        **** 
  87:main.c        **** /*******************************************************************************
  88:main.c        **** *
  89:main.c        **** *	FUNCTION:		main()
  90:main.c        **** *
  91:main.c        **** *	PURPOSE:		This is the main function through which all other functions
  92:main.c        **** *			        	run. This is run once and then the while(1) is run until
  93:main.c        **** *			        	power is removed from the controller.
  94:main.c        **** *
  95:main.c        **** *	CALLED FROM:	Nothing.
  96:main.c        **** *
  97:main.c        **** *	PARAMETERS:		Nothing.
  98:main.c        **** *
  99:main.c        **** *	RETURNS:		Nothing.
 100:main.c        **** *
 101:main.c        **** *	COMMENTS:		Nothing.
 102:main.c        **** *
 103:main.c        **** *******************************************************************************/
 104:main.c        **** int main(void)
 105:main.c        **** {
 114               	.LM2:
 115               	/* prologue: frame size=0 */
 116 001e C0E0      		ldi r28,lo8(__stack - 0)
 117 0020 D0E0      		ldi r29,hi8(__stack - 0)
 118 0022 DEBF      		out __SP_H__,r29
 119 0024 CDBF      		out __SP_L__,r28
 120               	/* prologue end (size=4) */
 106:main.c        **** 
 107:main.c        **** 	// Initialize the serial port
 108:main.c        **** 	USART_Init();
 122               	.LM3:
 123 0026 0E94 0000 		call USART_Init
 109:main.c        **** 	
 110:main.c        **** 	// Initialize encoder data
 111:main.c        **** 	Encoders_Init();
 125               	.LM4:
 126 002a 0E94 0000 		call Encoders_Init
 112:main.c        **** 
 113:main.c        **** 	// Initialize gyros
 114:main.c        **** 	Gyro_Init();
 128               	.LM5:
 129 002e 0E94 0000 		call Gyro_Init
 115:main.c        **** 
 116:main.c        **** 	// Initialize timers
 117:main.c        **** 	Timer_Init();
 131               	.LM6:
 132 0032 0E94 0000 		call Timer_Init
 118:main.c        **** 
 119:main.c        **** 	// Enable global interrupts, sets l bit of SREG [334]
 120:main.c        **** 	sei();
 134               	.LM7:
 135               	/* #APP */
 136 0036 7894      		sei
 121:main.c        **** 
 122:main.c        **** 	// Write Data Direction Register A a logical 0 to set
 123:main.c        **** 	// it as input. This is used for the switches that
 124:main.c        **** 	// toggle debug mode on/off as well as the ADC
 125:main.c        **** 	// for the gyro. [51]
 126:main.c        **** 	DDRA	=	0x00;
 138               	.LM8:
 139               	/* #NOAPP */
 140 0038 1ABA      		out 58-0x20,__zero_reg__
 127:main.c        **** 
 128:main.c        **** 	// Write Data Direction Register B a logical 1 to set
 129:main.c        **** 	// it as output. This port drives the LEDs that
 130:main.c        **** 	// indicate whether debug mode is on or off. [51]
 131:main.c        **** 	DDRB	=	0xFF;
 142               	.LM9:
 143 003a 8FEF      		ldi r24,lo8(-1)
 144 003c 87BB      		out 55-0x20,r24
 132:main.c        **** 
 133:main.c        **** 	// By default have the LEDs off
 134:main.c        **** 	PORTB	=	0xFF;
 146               	.LM10:
 147 003e 88BB      		out 56-0x20,r24
 135:main.c        **** 
 136:main.c        **** 	// Initialization message
 137:main.c        **** 	print("AVR board initialized...\r\n");
 149               	.LM11:
 150 0040 80E0      		ldi r24,lo8(.LC0)
 151 0042 90E0      		ldi r25,hi8(.LC0)
 152 0044 0E94 0000 		call print
 153 0048 01C0      		rjmp .L4
 154               	.L5:
 156               	.LM12:
 157 004a 102F      		mov r17,r16
 158               	.L4:
 159               	.LBB2:
 138:main.c        **** 
 139:main.c        **** 	// Endless loop
 140:main.c        **** 	while(1)
 141:main.c        **** 	{
 142:main.c        **** 
 143:main.c        **** 		// These values hold the values of the button and
 144:main.c        **** 		// the flag thats set when it's decided that it is
 145:main.c        **** 		// a valid fresh hit and not the user just holding
 146:main.c        **** 		// down the button.
 147:main.c        **** 		char button_value, button_push_valid, debug_sw_prev;
 148:main.c        **** 
 149:main.c        **** 		button_value	=	(PINA & 0b00000001)	==	0;
 161               	.LM13:
 162 004c 89B3      		in r24,57-0x20
 163 004e 8095      		com r24
 150:main.c        **** 
 151:main.c        **** 		// Make sure that the user isn't just holding down
 152:main.c        **** 		// the button
 153:main.c        **** 		button_push_valid	=	button_value && !debug_sw_prev;
 165               	.LM14:
 166 0050 082F      		mov r16,r24
 167 0052 0170      		andi r16,lo8(1)
 168 0054 80FF      		sbrs r24,0
 169 0056 0FC0      		rjmp .L6
 170 0058 1123      		tst r17
 171 005a 69F4      		brne .L6
 154:main.c        **** 
 155:main.c        **** 		// Set the previous value to the current value, to
 156:main.c        **** 		// be used in the next loop.
 157:main.c        **** 		debug_sw_prev	=	button_value;
 158:main.c        **** 		
 159:main.c        **** 		// If this is a valid (not noise/held down) push
 160:main.c        **** 		if(button_push_valid)
 161:main.c        **** 		{
 162:main.c        **** 			// Flip flop modes
 163:main.c        **** 			if(debug_mode == TRUE)
 173               	.LM15:
 174 005c 8091 0000 		lds r24,debug_mode
 175 0060 8130      		cpi r24,lo8(1)
 176 0062 29F4      		brne .L9
 164:main.c        **** 			{
 165:main.c        **** 				// Lights off = debug mode off
 166:main.c        **** 				debug_mode	=	FALSE;
 178               	.LM16:
 179 0064 1092 0000 		sts debug_mode,__zero_reg__
 167:main.c        **** 				PORTB		=	0xFF;
 181               	.LM17:
 182 0068 8FEF      		ldi r24,lo8(-1)
 183 006a 88BB      		out 56-0x20,r24
 184 006c 04C0      		rjmp .L6
 185               	.L9:
 168:main.c        **** 			}
 169:main.c        **** 			else
 170:main.c        **** 			{
 171:main.c        **** 				// Lights on = debug mode on
 172:main.c        **** 				debug_mode	=	TRUE;
 187               	.LM18:
 188 006e 81E0      		ldi r24,lo8(1)
 189 0070 8093 0000 		sts debug_mode,r24
 173:main.c        **** 				PORTB		=	0x00;
 191               	.LM19:
 192 0074 18BA      		out 56-0x20,__zero_reg__
 193               	.L6:
 174:main.c        **** 			}
 175:main.c        **** 
 176:main.c        **** 		}
 177:main.c        **** 		
 178:main.c        **** 		// If the interrupt tripped, run the ISR.
 179:main.c        **** 		// We run it in the main loop as to not
 180:main.c        **** 		// miss as many encoder ticks.
 181:main.c        **** 		if(run_timer1_isr	==	TRUE)
 195               	.LM20:
 196 0076 8091 0000 		lds r24,run_timer1_isr
 197 007a 8130      		cpi r24,lo8(1)
 198 007c 31F7      		brne .L5
 182:main.c        **** 		{
 183:main.c        **** 			USART_Transmit(0x00);
 200               	.LM21:
 201 007e 80E0      		ldi r24,lo8(0)
 202 0080 0E94 0000 		call USART_Transmit
 184:main.c        **** 			// We sample the gyro every time 
 185:main.c        **** 			// (120Hz)
 186:main.c        **** 			Sample_Gyro();
 204               	.LM22:
 205 0084 0E94 0000 		call Sample_Gyro
 187:main.c        **** 			
 188:main.c        **** 			// Send a data packet every 3 times
 189:main.c        **** 			// (40Hz)
 190:main.c        **** 			if(packet_limiter	>=	3)
 207               	.LM23:
 208 0088 8091 0000 		lds r24,packet_limiter
 209 008c 8330      		cpi r24,lo8(3)
 210 008e 58F0      		brlo .L12
 191:main.c        **** 			{
 192:main.c        **** 				// If we are currently in debug mode, send a
 193:main.c        **** 				// packet that is easier for humans to read.
 194:main.c        **** 				// Else send the normal, RC optimized, packet.
 195:main.c        **** 				if(debug_mode == TRUE)
 212               	.LM24:
 213 0090 8091 0000 		lds r24,debug_mode
 214 0094 8130      		cpi r24,lo8(1)
 215 0096 19F4      		brne .L14
 196:main.c        **** 				{
 197:main.c        **** 					Send_Debug_Packet();
 217               	.LM25:
 218 0098 0E94 0000 		call Send_Debug_Packet
 219 009c 02C0      		rjmp .L16
 220               	.L14:
 198:main.c        **** 				}
 199:main.c        **** 				else
 200:main.c        **** 				{
 201:main.c        **** 					Send_RC_Packet();
 222               	.LM26:
 223 009e 0E94 0000 		call Send_RC_Packet
 224               	.L16:
 202:main.c        **** 				}
 203:main.c        **** 				
 204:main.c        **** 				// Reset the packet limiter
 205:main.c        **** 				packet_limiter	=	0;
 226               	.LM27:
 227 00a2 1092 0000 		sts packet_limiter,__zero_reg__
 228               	.L12:
 206:main.c        **** 			}
 207:main.c        **** 			
 208:main.c        **** 			// Reload the timer value so we can
 209:main.c        **** 			// control the interrupt frequency
 210:main.c        **** 			TCNT1	=	T1_LOAD;
 230               	.LM28:
 231 00a6 83E7      		ldi r24,lo8(-8333)
 232 00a8 9FED      		ldi r25,hi8(-8333)
 233 00aa 9DBD      		out (76)+1-0x20,r25
 234 00ac 8CBD      		out 76-0x20,r24
 211:main.c        **** 			
 212:main.c        **** 			// Increment the limiter
 213:main.c        **** 			packet_limiter++;
 236               	.LM29:
 237 00ae 8091 0000 		lds r24,packet_limiter
 238 00b2 8F5F      		subi r24,lo8(-(1))
 239 00b4 8093 0000 		sts packet_limiter,r24
 240 00b8 C8CF      		rjmp .L5
 241               	.LBE2:
 242               	/* epilogue: frame size=0 */
 243               	/* epilogue: noreturn */
 244               	/* epilogue end (size=0) */
 245               	/* function main size 79 (75) */
 251               	.Lscope1:
 253               	.global	__vector_2
 255               	__vector_2:
 257               	.LM30:
 258               	/* prologue: frame size=0 */
 259 00ba 1F92      		push __zero_reg__
 260 00bc 0F92      		push __tmp_reg__
 261 00be 0FB6      		in __tmp_reg__,__SREG__
 262 00c0 0F92      		push __tmp_reg__
 263 00c2 1124      		clr __zero_reg__
 264 00c4 2F93      		push r18
 265 00c6 3F93      		push r19
 266 00c8 4F93      		push r20
 267 00ca 5F93      		push r21
 268 00cc 6F93      		push r22
 269 00ce 7F93      		push r23
 270 00d0 8F93      		push r24
 271 00d2 9F93      		push r25
 272 00d4 AF93      		push r26
 273 00d6 BF93      		push r27
 274 00d8 EF93      		push r30
 275 00da FF93      		push r31
 276               	/* prologue end (size=17) */
 278               	.LM31:
 279 00dc 0E94 0000 		call Right_Encoder_ISR
 280               	/* epilogue: frame size=0 */
 281 00e0 FF91      		pop r31
 282 00e2 EF91      		pop r30
 283 00e4 BF91      		pop r27
 284 00e6 AF91      		pop r26
 285 00e8 9F91      		pop r25
 286 00ea 8F91      		pop r24
 287 00ec 7F91      		pop r23
 288 00ee 6F91      		pop r22
 289 00f0 5F91      		pop r21
 290 00f2 4F91      		pop r20
 291 00f4 3F91      		pop r19
 292 00f6 2F91      		pop r18
 293 00f8 0F90      		pop __tmp_reg__
 294 00fa 0FBE      		out __SREG__,__tmp_reg__
 295 00fc 0F90      		pop __tmp_reg__
 296 00fe 1F90      		pop __zero_reg__
 297 0100 1895      		reti
 298               	/* epilogue end (size=17) */
 299               	/* function __vector_2 size 36 (2) */
 301               	.Lscope2:
 303               	.global	__vector_1
 305               	__vector_1:
 307               	.LM32:
 308               	/* prologue: frame size=0 */
 309 0102 1F92      		push __zero_reg__
 310 0104 0F92      		push __tmp_reg__
 311 0106 0FB6      		in __tmp_reg__,__SREG__
 312 0108 0F92      		push __tmp_reg__
 313 010a 1124      		clr __zero_reg__
 314 010c 2F93      		push r18
 315 010e 3F93      		push r19
 316 0110 4F93      		push r20
 317 0112 5F93      		push r21
 318 0114 6F93      		push r22
 319 0116 7F93      		push r23
 320 0118 8F93      		push r24
 321 011a 9F93      		push r25
 322 011c AF93      		push r26
 323 011e BF93      		push r27
 324 0120 EF93      		push r30
 325 0122 FF93      		push r31
 326               	/* prologue end (size=17) */
 328               	.LM33:
 329 0124 0E94 0000 		call Left_Encoder_ISR
 330               	/* epilogue: frame size=0 */
 331 0128 FF91      		pop r31
 332 012a EF91      		pop r30
 333 012c BF91      		pop r27
 334 012e AF91      		pop r26
 335 0130 9F91      		pop r25
 336 0132 8F91      		pop r24
 337 0134 7F91      		pop r23
 338 0136 6F91      		pop r22
 339 0138 5F91      		pop r21
 340 013a 4F91      		pop r20
 341 013c 3F91      		pop r19
 342 013e 2F91      		pop r18
 343 0140 0F90      		pop __tmp_reg__
 344 0142 0FBE      		out __SREG__,__tmp_reg__
 345 0144 0F90      		pop __tmp_reg__
 346 0146 1F90      		pop __zero_reg__
 347 0148 1895      		reti
 348               	/* epilogue end (size=17) */
 349               	/* function __vector_1 size 36 (2) */
 351               	.Lscope3:
 352               		.lcomm debug_mode,1
 353               		.lcomm packet_limiter,1
 354               		.comm temp,20,1
 355               		.comm run_timer1_isr,1,1
 361               	.Letext0:
 362               	/* File "main.c": code  166 = 0x00a6 (  82), prologues  44, epilogues  40 */
DEFINED SYMBOLS
                            *ABS*:00000000 main.c
     /tmp/ccDlIpWb.s:3      *ABS*:0000003f __SREG__
     /tmp/ccDlIpWb.s:4      *ABS*:0000003e __SP_H__
     /tmp/ccDlIpWb.s:5      *ABS*:0000003d __SP_L__
     /tmp/ccDlIpWb.s:6      *ABS*:00000000 __tmp_reg__
     /tmp/ccDlIpWb.s:7      *ABS*:00000001 __zero_reg__
     /tmp/ccDlIpWb.s:79     .text:00000000 __vector_8
                            *COM*:00000001 run_timer1_isr
     /tmp/ccDlIpWb.s:112    .text:0000001e main
                             .bss:00000000 debug_mode
     /tmp/ccDlIpWb.s:352    .bss:00000001 packet_limiter
     /tmp/ccDlIpWb.s:255    .text:000000ba __vector_2
     /tmp/ccDlIpWb.s:305    .text:00000102 __vector_1
                            *COM*:00000014 temp

UNDEFINED SYMBOLS
__do_copy_data
__do_clear_bss
__stack
USART_Init
Encoders_Init
Gyro_Init
Timer_Init
print
USART_Transmit
Sample_Gyro
Send_Debug_Packet
Send_RC_Packet
Right_Encoder_ISR
Left_Encoder_ISR