/**
	 * Writes a formatted c string.
	 * Works like printf is expected to work
	 * except it uses a static buffer of size
	 * UART[n]_PRNT_BUFF_SIZE to store the intermediate
	 * string in.
	 */
	int usart0_printf(const char *str, ...){
		if(str == NULL) return -1;

		char buffer[UART0_PRNT_BUFF_SIZE] = {'\0'}; // Warning this might overflow on long str
		va_list args;
		int rc_vsprintf;
		int rc_tx;

		va_start(args, str);
		if((rc_vsprintf = vsnprintf(buffer, UART0_PRNT_BUFF_SIZE, str, args)) < 0){
			return rc_vsprintf; // vsprintf return a negative value on err
		}
		va_end(args);

		if((rc_tx = usart0_puts(buffer)) != rc_vsprintf){
			return -1; // We haven't send the same amount as sprintf wrote the the buffer
		}

		if(rc_tx > UART0_PRNT_BUFF_SIZE) return -UART0_PRNT_BUFF_SIZE; // if buffer overflow

		return rc_tx;
	}
Example #2
0
int main(void) {

#ifdef USART_DEBUG
	usart0_init();
#endif

	init_pwm();
	ir_init();
	control_init();
	fe_init();
	
	sei();

#ifdef USART_DEBUG
	usart0_puts("Initialized\n\r");
#endif

	while (1) {
		ir_handler();
		control_handler();
		pwm_handler();
		fe_handler();
	}
}