Serial I/O API for Robolocust control program running on iRobot Create Command Module. More...
#include "LoIO.h"
#include "LoTimer.h"
#include "LoOpenInterface.h"
#include <avr/io.h>
#include <avr/interrupt.h>
Go to the source code of this file.
Functions | |
void | lo_init_comm () |
Set up the serial port. | |
void | lo_reset_baud (int baud_rate) |
Reset communication speed on both Create robot and Command Module. | |
void | lo_clear_buffers (void) |
Flush the RX and TX buffers. | |
void | lo_tx (char byte) |
Transmit a byte over the serial port. | |
unsigned char | lo_rx (char *buf, unsigned char n, unsigned int timeout) |
char | lo_rx1 (unsigned int timeout) |
void | lo_io_to_usb () |
void | lo_io_to_create () |
char | lo_io_error () |
Variables | |
static char | g_io_error |
Serial I/O API for Robolocust control program running on iRobot Create Command Module.
This file defines the functions for serial port I/O needed by the Robolocust iRobot Create Command Module control program.
Definition in file LoIO.c.
char lo_io_error | ( | void | ) |
Retrieve current I/O status. After each I/O operation, clients should use this function to check for errors.
Definition at line 241 of file LoIO.c.
Referenced by lo_sensors().
void lo_io_to_usb | ( | void | ) |
Since the Command Module has only one USART, it needs to be switched between talking to the USB port and the iRobot Create's serial port.
Usually, the low-level Robolocust control program that runs on the command module will listen for incoming high-level motor commands over the USB port. But every time it needs to actually execute one of those commands, it will have to switch the USART to talk to the Create's serial port and then back again to continue listening to the higher layers of the Robolocust controller.
These functions switch the USART between the Command Module's USB port and the Create's serial port.
Definition at line 224 of file LoIO.c.
References lo_wait().
void lo_reset_baud | ( | int | baud_rate | ) |
Reset communication speed on both Create robot and Command Module.
Definition at line 75 of file LoIO.c.
References lo_tx(), lo_wait(), and LOBOT_OI_CMD_BAUD.
unsigned char lo_rx | ( | char * | buf, | |
unsigned char | n, | |||
unsigned int | timeout | |||
) |
Receive the specified number of bytes over the serial port, waiting a maximum number of milliseconds before giving up. If the timeout is zero, wait forever for the data to come in.
The function returns the number of bytes successfully read.
Clients should setup a large enough buffer to accommodate the amount of data they require and check the return value before using the data in the buffer. If the number of bytes read is less than the number requested, clients can query the I/O error to see what went wrong.
NOTE: Since we're using 8-bit integers, only a maximum of 255 bytes can be retrieved at one time. For the purposes of this control program, that number is more than enough.
Definition at line 182 of file LoIO.c.
References lo_setup_timer(), and lo_timer_is_running().
Referenced by lo_backup(), lo_rx1(), lo_sensors(), and lo_spin().
char lo_rx1 | ( | unsigned int | timeout | ) |
Receive a single byte over the serial port, waiting a maximum number of milliseconds before giving up. If the timeout is zero, wait forever for the data byte to come in.
Clients should check the I/O error flag before using the byte returned by this function.
Definition at line 215 of file LoIO.c.
References lo_rx().
void lo_tx | ( | char | byte | ) |
Transmit a byte over the serial port.
Definition at line 159 of file LoIO.c.
Referenced by lo_backup(), lo_beep(), lo_init_beeps(), lo_reset_baud(), lo_send_bumps(), lo_send_cliffs(), lo_send_remote(), lo_send_sensors(), lo_send_wheel_drops(), lo_sensors(), and lo_spin().