static size_t gdbserial_recv ( char *buf, size_t len ) { assert ( len > 0 ); while ( ! uart_data_ready ( &gdbserial_uart ) ) {} buf[0] = uart_receive ( &gdbserial_uart ); return 1; }
/** * Check for character ready to read from serial console * * @ret True Character available to read * @ret False No character available to read */ static int serial_iskey ( void ) { /* Do nothing if we have no UART */ if ( ! serial_console.base ) return 0; /* Check UART */ return uart_data_ready ( &serial_console ); }
/** * Get character from serial console * * @ret character Character read from console */ static int serial_getchar ( void ) { uint8_t data; /* Do nothing if we have no UART */ if ( ! serial_console.base ) return 0; /* Wait for data to be ready */ while ( ! uart_data_ready ( &serial_console ) ) {} /* Receive data */ data = uart_receive ( &serial_console ); /* Strip any high bit and convert DEL to backspace */ data &= 0x7f; if ( data == 0x7f ) data = 0x08; return data; }
void main(void) { /* Initialization functions called below */ ConfigureOscillator(); uart_init(9600); ecan_init(); enable_interrupts(); /* While doing recurring functions */ while(1) { /* Check if UART contains data*/ if(uart_data_ready()) { Message mess; char num = uart_read(); if (num == 'i') { mess.sid = 0x00A; mess.len = 1; uart_write_text("Command Sent (Array Idle)\r\n"); mess.data[0] = 0x00; ecan_send(&mess); } else if (num == 'f') { mess.sid = 0x00A; mess.len = 1; uart_write_text("Command Sent (Array Forward)\r\n"); mess.data[0] = 0x01; ecan_send(&mess); } else if (num == 'b') { mess.sid = 0x00A; mess.len = 1; uart_write_text("Command Sent (Array Backward)\r\n"); mess.data[0] = 0x02; ecan_send(&mess); } else if (num == '0') { mess.sid = 0x007; mess.len = 1; uart_write_text("Command Sent (Motor Speed 0)\r\n"); mess.data[0] = 0x00; ecan_send(&mess); } else if (num == '1') { mess.sid = 0x007; mess.len = 1; uart_write_text("Command Sent (Motor Speed 1)\r\n"); mess.data[0] = 0x01; ecan_send(&mess); } else if (num == '2') { mess.sid = 0x007; mess.len = 1; uart_write_text("Command Sent (Motor Speed 2)\r\n"); mess.data[0] = 0x02; ecan_send(&mess); } else if (num == '3') { mess.sid = 0x007; mess.len = 1; uart_write_text("Command Sent (Motor Speed 3)\r\n"); mess.data[0] = 0x03; ecan_send(&mess); } else if (num == '4') { mess.sid = 0x007; mess.len = 1; uart_write_text("Command Sent (Motor Speed 4)\r\n"); mess.data[0] = 0x04; ecan_send(&mess); } else if (num == '5') { mess.sid = 0x007; mess.len = 1; uart_write_text("Command Sent (Motor Speed 5)\r\n"); mess.data[0] = 0x05; ecan_send(&mess); } else if (num == '6') { mess.sid = 0x007; mess.len = 1; uart_write_text("Command Sent (Motor Speed 6)\r\n"); mess.data[0] = 0x06; ecan_send(&mess); } else if (num == '7') { mess.sid = 0x007; mess.len = 1; uart_write_text("Command Sent (Motor Speed 7)\r\n"); mess.data[0] = 0x07; ecan_send(&mess); } else if (num == '8') { mess.sid = 0x007; mess.len = 1; uart_write_text("Command Sent (Motor Speed 8)\r\n"); mess.data[0] = 0x08; ecan_send(&mess); } else if (num == '9') { mess.sid = 0x007; mess.len = 1; uart_write_text("Command Sent (Motor Speed 9)\r\n"); mess.data[0] = 0x09; ecan_send(&mess); } else if (num == '-') { mess.sid = 0x007; mess.len = 1; uart_write_text("Command Sent (Motor Speed 10)\r\n"); mess.data[0] = 0x0A; ecan_send(&mess); } else if (num == '!') //! brake! { mess.sid = 0x00B; mess.len = 1; uart_write_text("Command Sent (Brake On)\r\n"); mess.data[0] = 0x01; ecan_send(&mess); } else if (num == 'g') //go - brake off { mess.sid = 0x00B; mess.len = 1; uart_write_text("Command Sent (Brake Off)\r\n"); mess.data[0] = 0x00; ecan_send(&mess); } } } }