Beispiel #1
0
int main()
{
	/*
	 * Initialize the SYSTICK timer
	 */
	systick_init();

	/*
	 * Demonstrate use of LED.h/LED.c - modifies hardware registers using C
	 */
	LED_init();
	LED_update(LED_BLUE_ON);
	LED_update(LED_BLUE_OFF);
	LED_update(LED_RED_ON | LED_BLUE_ON | LED_ORANGE_ON | LED_GREEN_ON );

	/*
	 * Demonstrate use of in-line assembly - enable interrupts
	 */
	__asm ("  cpsie i \n" );


	/* Initialize the USART for 9600, 8N1, send '!' - calls into USART2.S */
	/* NOTE: must set USART2 interrupt config register to enable TX/RX interrupts */
	USART2_init();
	USART2_send('!');

	uint32_t test_val = 785904457;
	printHex(785904457);

	/* Wait here forever */
	while(1);

	/* We'll never reach this line */
	return 0;
}
Beispiel #2
0
void __attribute__ ((interrupt)) USART3_handler(void) {
	char c = USART3_recv(); // Always immediately read the input

	switch (mode_state) {
	case CONFIGURE_S: // In configure, pass to console
	{
		USART2_send(c);
		break;
	}

	case CLIENT_S:
	case COMMAND_S: // Intentional fall-through - these do the same thing
	{
		/* Read in consecutive bytes of the message */
		*(((char*)&recv_msg)+recv_offset) = c;
		recv_offset++;

		/* When we get the full message, set a flag for it
		 * to print in the main loop, and clear the recv_offset
		 * and waiting_to_recv_packet flag
		 */
		if (recv_offset == sizeof(Update_resp_t)) {
			received_new_packet = 1;
			recv_offset = 0;
			waiting_to_recv_packet = 0;
		}
		break;
	}
	default:
		break;
	}
}
Beispiel #3
0
/*
 * void printHex(uint32_t value):
 *
 * Prints the hexadecimal representation of value.
 */
void printHex(uint32_t value){
	//Print out 0x
	uint8_t zero = 48;
	USART2_send(48);
	uint8_t x = 120;
	USART2_send(x);

	static char hex_digits[] = "0123456789ABCDEF";

	//Print out the hexadecimal representation of the number
	uint32_t mask = 0xF0000000;
	int i;
	for( i = 7; i >= 0; i-- ){
		//Mask out all but the highest 4 bits
		uint32_t masked_value = value & mask;
		//Shift off all but the highest 4 bits
		masked_value = masked_value >> 4*i;
		mask = mask >> 4;
		//Print out the hexadecimal representation of the value
		USART2_send(hex_digits[masked_value]);
	}
}
Beispiel #4
0
void __attribute__ ((interrupt)) USART2_handler(void) {
	char c = USART2_recv(); // Always immediately read the input


	switch (mode_state) {
	case CONFIGURE_S: // In configure mode, pass it along to the WiFly
		USART3_send(c);
		break;
	default: // Other modes just echo back input
		USART2_send(c);
		break;
	}
}
Beispiel #5
0
/*
 * The USART2 Interrupt Service Routine
 */
void __attribute__ ((interrupt)) USART2_handler(void)
{
	/* This code receives input from the USART2
	 * interface and repeats it back to the user
	 * on the same interface.
	 */
	uint8_t c = USART2_recv();
	USART2_send(c);

	//Check if the input was one of our commands:
	//h - history
	if(c == 'h'){
		//Print the history
	}
	if(c == 'a'){
		//Print the average of the history
	}

}