borgware-2d/util.c

63 lines
1.2 KiB
C
Raw Normal View History

2009-02-19 01:06:09 +00:00
#include "config.h"
#include <avr/io.h>
#include <setjmp.h>
2011-05-09 20:54:01 +00:00
#ifdef JOYSTICK_SUPPORT
# include "joystick/joystick.h"
#endif
//this buffer is declared in main
extern jmp_buf newmode_jmpbuf;
#ifdef CAN_SUPPORT
# include "can/borg_can.h"
#endif
void wait(int ms){
/* TCCR2: FOC2 WGM20 COM21 COM20 WGM21 CS22 CS21 CS20
CS22 CS21 CS20
0 0 0 stop
0 0 1 clk
0 1 0 clk/8
0 1 1 clk/32
1 0 0 clk/64
1 0 1 clk/128
1 1 0 clk/256
1 1 1 clk/1024
*/
2009-07-09 13:37:11 +00:00
//TCCR2 = 0x0D; //CTC Mode, clk/128
//OCR2 = (F_CPU/128000); //1000Hz
2009-07-09 13:37:11 +00:00
TCCR1B = (1<<WGM12) | 4;//CTC Mode, clk/256
OCR1A = (F_CPU/256000); //1000Hz
for(;ms>0;ms--){
#ifdef CAN_SUPPORT
bcan_process_messages();
#endif
#ifdef JOYSTICK_SUPPORT
if (waitForFire) {
//PORTJOYGND &= ~(1<<BITJOY0);
//PORTJOYGND &= ~(1<<BITJOY1);
if (JOYISFIRE) {
longjmp(newmode_jmpbuf, 43);
}
}
#endif
#if defined (__AVR_ATmega644P__) || defined (__AVR_ATmega644__)
2010-01-29 01:06:50 +00:00
while(!(TIFR1&(1<<OCF1A))); //wait for compare match flag
TIFR1=(1<<OCF1A); //reset flag
#else
2009-07-09 13:37:11 +00:00
while(!(TIFR&(1<<OCF1A))); //wait for compare match flag
TIFR=(1<<OCF1A); //reset flag
2010-01-29 01:06:50 +00:00
#endif
}
}