/* generate.c Version 2.0 2/3/2000 * * Simple version for customization. * * This program generates data in the format expected by the frame * data decoder. */ /******** Change the next line to indicate your team letter **********/ #define MY_TEAM 'B' /**** Change the next line to indicate a different team letter *******/ /**** N.B. If your frame size is 16 bits do not select a *******/ /**** team here letter beyond 'G' *******/ #define OTHER_TEAM 'D' #define BROAD_MASK 1 #define BROAD_VAL 1 #define STROBE_MASK 2 #define STROBE_VAL 2 #define SHORT_MASK 128 #define SHORT_VAL 128 #define BASE_TEAM ('A' - 1) #include "iodevs.h" #include "trap.h" #include "stdio.h" static int frame[32]; /* * Routine to write an 8-bit pattern to the LEDs */ void SetLeds( int v ) { *LEDS = v; /* LEDS defined in iodevs.h */ } /* * Routine to read an 8-bit pattern from the switches * and check against known mask and value */ int CheckSwitches(mask,value) int mask,value; { int switches; switches = *SWITCHES; /* SWITCHES defined in iodevs.h */ return ((switches & mask) == value); } /* * Routine to generate a new frame */ void makeFrame( frame_data, station_address, frame_number, frame_align_word ) int frame_data, station_address, frame_number, frame_align_word; { int i; for ( i = 0; i < 6; i++ ) frame[i+0] = (frame_align_word >> i) & 1; /* 7 bit character data */ for ( i = 0; i < 7; i++ ) frame[i+6] = (frame_data >> i) & 1; /* 5 bit station address */ for ( i = 0; i < 5; i++ ) frame[i+13] = (station_address >> i) & 1; /* 4 bit frame number */ for ( i = 0; i < 4; i++ ) frame[i+18] = (frame_number >> i) & 1; frame[22+0] = (frame[ 6]+frame[ 7]+frame[ 8]+frame[ 9]+1) % 2; /*P0*/ frame[22+1] = (frame[10]+frame[11]+frame[12]+frame[13]+1) % 2; /*P1*/ frame[22+2] = (frame[14]+frame[15]+frame[16]+frame[17]+1) % 2; /*P2*/ frame[22+3] = (frame[18]+frame[19]+frame[20]+frame[21]+1) % 2; /*P3*/ frame[22+4] = (frame[ 6]+frame[10]+frame[14]+frame[18]+1) % 2; /*P4*/ frame[22+5] = (frame[ 7]+frame[11]+frame[15]+frame[19]+1) % 2; /*P5*/ frame[22+6] = (frame[ 8]+frame[12]+frame[16]+frame[20]+1) % 2; /*P6*/ frame[22+7] = (frame[ 9]+frame[13]+frame[17]+frame[21]+1) % 2; /*P7*/ frame[22+8] = (frame[22]+frame[23]+frame[24]+frame[25]+ frame[26]+frame[27]+frame[28]+frame[29]) % 2; /*P8*/ frame[31] = (frame[30]+1) % 2; /* not P8*/ } void makeNextFrame() { static int FAW = 13; static char broadcast_message [] = "Broadcast Test.\r"; static int my_team = MY_TEAM - BASE_TEAM; static int address = MY_TEAM - BASE_TEAM; static char my_message [] = "Message for Me!\r"; static int other_team = OTHER_TEAM - BASE_TEAM; static char other_message [] = "_______________\r"; static int broadcast = 1; static int symbol = 0; if ( broadcast == 1 ) { makeFrame(broadcast_message[symbol], 0, symbol, FAW); symbol = (symbol + 1) % 16; if (symbol == 0) if (! CheckSwitches( BROAD_MASK, BROAD_VAL )) broadcast = 0; } else { if (address == my_team) { makeFrame(my_message[symbol], my_team, symbol, FAW); address = other_team; } else { makeFrame(other_message[symbol], other_team, symbol, FAW); address = my_team; symbol = (symbol + 1) % 16; if (symbol == 0) broadcast = 1; } } } /* * The timer interrupt handler */ void TimerInt( void ) { static int count = 0; int frame_bit; int strobe_bits; SetLeds( count ); /* Show some action on LEDs */ PIT_1[TSR] = 1; /* Clear the IRQ before returning */ frame_bit = frame[count]; strobe_bits = 0; if (CheckSwitches( STROBE_MASK, STROBE_VAL )) { if ( count == 6 ) strobe_bits = 1; /* Strobe_6 at PortA[1]*/ else if ( count == 5 ) strobe_bits = 2; /* Strobe_5 at PortA[2]*/ else if ( count == 4 ) strobe_bits = 4; /* Strobe_4 at PortA[3]*/ } PIT_2[PADR] = frame_bit + 2 * strobe_bits; if (CheckSwitches( SHORT_MASK, SHORT_VAL )) count = (count + 1) % 16; /* ignore second half of frame */ else count = (count + 1) % 32; if (count == 0) makeNextFrame(); } int main( void ) { /* set initial frame contents */ makeNextFrame(); /* * Set up timer control register. Bits set as follows: * b7..5 = 11i Auto-vectored interrupts, * b7..5 = 01X Square wave generate on TOUT, * b4 = 0 Periodic reloads from preload register * b4 = 1 No reload on zero detect, just keep counting * b2..1 = 00 Prescaler divides CLK by 32. * b0 is run/~halt * b0 = 0 Timer halted * b1 = 1 Timer running */ /* * Set up PIT1 timer control register. Bits set as follows: * b7..5 = 11i Auto-vectored interrupts, * i=1 for enabled, 0 for disabled * b4 = 0 Periodic reloads from preload register * b2..1 = 00 Prescaler divides CLK by 32. * b0 is run/~halt * b0 = 0 Timer halted * b1 = 1 Timer running */ PIT_1[TCR] = 0xC0; PIT_1[CPRH] = 0x00; /* Set counter preload to 0x000103 */ PIT_1[CPRM] = 0x01; /* Causes interrupts 1/1202 secs */ PIT_1[CPRL] = 0x03; /* Prescaler used, & CLKIN = 10MHz */ /* * Set up PIT2 timer control register. Bits set as follows: * b7..5 = 01X Square wave generate on TOUT, * b4 = 0 Periodic reloads from preload register * b2..1 = 00 Prescaler divides CLK by 32. * b0 is run/~halt * b0 = 0 Timer halted * b1 = 1 Timer running */ PIT_2[TCR] = 0x40; PIT_2[CPRH] = 0x00; /* Set counter preload to 0x000081 */ PIT_2[CPRM] = 0x00; /* Causes 1202 Hz square wave */ PIT_2[CPRL] = 0x81; /* Prescaler used, & CLKIN = 10MHz */ PIT_2[PADDR] = 0xFF; /* PI/T 2 Port A for output */ PIT_2[PCDDR] = 0x00; /* PI/T 2 Port C for input */ /* Install the interrupt handler function */ SetIrqFunction( TimerInt, PIT_1_TIRQ ); /* Start PI/T 2 timer as Clock source */ PIT_2[TCR] = 0x41; /* Start timer */ /* Wait on rising edge of PI/T 2 timer */ while ((PIT_2[PCDR] & 8) == 8){} while ((PIT_2[PCDR] & 8) == 0){} PIT_1[TCR] = 0xE1; /* Enable interrupts and start timer */ return 1; /* Terminate leaving timers and interrupts doing the work */ }