Пример #1
0
/*	Initialise the serial connection on the QR-side
 *	Author: Maurijn Neumann
 */
int serial_init() {
	//Declare variables
	unsigned char c;
	
	//Setup interrupts (recv)
	SET_INTERRUPT_VECTOR(INTERRUPT_PRIMARY_RX, &isr_serial_rx);
	SET_INTERRUPT_PRIORITY(INTERRUPT_PRIMARY_RX, 20);
	
	//There may yet be data in the internal buffer, empty to prevent unscheduled interrupts
	while (X32_serial_status & 0x02)
		//Emtpy through reading
		c = X32_serial_data;

	//Setup interrupts (send)
	SET_INTERRUPT_VECTOR(INTERRUPT_PRIMARY_TX, &isr_serial_tx);
	SET_INTERRUPT_PRIORITY(INTERRUPT_PRIMARY_TX, 15);

	//Clear buffers
	serial_buffer_recv_base = 0;
	serial_buffer_recv_top = 0;
	serial_buffer_send_base = 0;
	serial_buffer_send_top = 0;
	
	//Enable  interrupts
	ENABLE_INTERRUPT(INTERRUPT_PRIMARY_RX);
	ENABLE_INTERRUPT(INTERRUPT_PRIMARY_TX);

	//Communication is setup correctly
	X32_leds |= COMM_LED;

	return 0;
}
Пример #2
0
/* main entry point */
int main() {
	int time, iterations;

	/* make the code somewhat faster when running in the sim */
	if (STATE_SIMULATOR) {
		/* set timer 1 period to 5 seconds */
		peripherals[PERIPHERAL_TIMER1_PERIOD] = 100*CLOCKS_PER_MS;
		/* set timer 2 period to 7 seconds */
		peripherals[PERIPHERAL_TIMER2_PERIOD] = 140*CLOCKS_PER_MS;
		printf("Running in simulation mode!\n");
	} else {
		/* set timer 1 period to 5 seconds */
		peripherals[PERIPHERAL_TIMER1_PERIOD] = 5000*CLOCKS_PER_MS;
		/* set timer 2 period to 7 seconds */
		peripherals[PERIPHERAL_TIMER2_PERIOD] = 7000*CLOCKS_PER_MS;
	}
	
	/* set interrupt addresses & priorities */
	/* note: the priority MUST be > 1, larger means higher prio */
	SET_INTERRUPT_VECTOR(INTERRUPT_TIMER1, &int_timer1);
	SET_INTERRUPT_PRIORITY(INTERRUPT_TIMER1, 50);
	SET_INTERRUPT_VECTOR(INTERRUPT_TIMER2, &int_timer2);
	SET_INTERRUPT_PRIORITY(INTERRUPT_TIMER2, 40);
	SET_INTERRUPT_VECTOR(INTERRUPT_PRIMARY_RX, &int_com1_in);
	SET_INTERRUPT_PRIORITY(INTERRUPT_PRIMARY_RX, 30);
	SET_INTERRUPT_VECTOR(INTERRUPT_PRIMARY_TX, &int_com1_out);
	SET_INTERRUPT_PRIORITY(INTERRUPT_PRIMARY_TX, 20);
#ifdef INTERRUPT_SECONDARY_RX
	SET_INTERRUPT_VECTOR(INTERRUPT_SECONDARY_RX, &int_com2_in);
	SET_INTERRUPT_PRIORITY(INTERRUPT_SECONDARY_RX, 30);
#endif
#ifdef INTERRUPT_SECONDARY_TX
	SET_INTERRUPT_VECTOR(INTERRUPT_SECONDARY_TX, &int_com2_out);
	SET_INTERRUPT_PRIORITY(INTERRUPT_SECONDARY_TX, 20);
#endif
	SET_INTERRUPT_VECTOR(INTERRUPT_BUTTONS, &int_buttons);
	SET_INTERRUPT_PRIORITY(INTERRUPT_BUTTONS, 10);
	SET_INTERRUPT_VECTOR(INTERRUPT_SWITCHES, &int_switches);
	SET_INTERRUPT_PRIORITY(INTERRUPT_SWITCHES, 10);

	/* enable interrupts */
	ENABLE_INTERRUPT(INTERRUPT_TIMER1);
	ENABLE_INTERRUPT(INTERRUPT_TIMER2);
	ENABLE_INTERRUPT(INTERRUPT_PRIMARY_RX);
	//ENABLE_INTERRUPT(INTERRUPT_PRIMARY_TX);
#ifdef INTERRUPT_SECONDARY_RX
	ENABLE_INTERRUPT(INTERRUPT_SECONDARY_RX);
#endif
#ifdef INTERRUPT_SECONDARY_TX
	//ENABLE_INTERRUPT(INTERRUPT_SECONDARY_TX);
#endif
	ENABLE_INTERRUPT(INTERRUPT_BUTTONS);
	ENABLE_INTERRUPT(INTERRUPT_SWITCHES);
	/* this is the global 'turn all interrupts on/off interrupt',
			when it's off, no interrupt will ever trigger, when it's
			on, all enabled interrupts may trigger */
	ENABLE_INTERRUPT(INTERRUPT_GLOBAL);

	/* run idle loop, print "IDLE LOOP" each 1000 iterations */
	time = iterations = 0;
	while(!quit) {
		if ((STATE_SIMULATOR && X32_MS_CLOCK - time > 50) || X32_MS_CLOCK - time > 1000) {
			printf("IDLE LOOP: %d iterations/sec\r\n", iterations);
			iterations = 0;
			time = X32_MS_CLOCK;
		}
		iterations++;
	}
	
	/* disable interrupts */
	DISABLE_INTERRUPT(INTERRUPT_GLOBAL);
	DISABLE_INTERRUPT(INTERRUPT_TIMER1);
	DISABLE_INTERRUPT(INTERRUPT_TIMER2);
	DISABLE_INTERRUPT(INTERRUPT_PRIMARY_RX);
	DISABLE_INTERRUPT(INTERRUPT_PRIMARY_TX);
#ifdef INTERRUPT_SECONDARY_RX
	DISABLE_INTERRUPT(INTERRUPT_SECONDARY_RX);
#endif
#ifdef INTERRUPT_SECONDARY_TX
	DISABLE_INTERRUPT(INTERRUPT_SECONDARY_TX);
#endif
	DISABLE_INTERRUPT(INTERRUPT_BUTTONS);
	DISABLE_INTERRUPT(INTERRUPT_SWITCHES);

	return 0;
}