uMIDI
The swiss army knife for quick and easy developement of MIDI applications.
|
Implementation of the serial communication module. More...
#include <stdlib.h>
#include <string.h>
#include <avr/pgmspace.h>
#include <avr/wdt.h>
#include "xboot/xbootapi.h"
#include "background_tasks.h"
#include "usb.h"
#include "serial_communication.h"
#include "system.h"
Functions | |
static bool | exec_help (void) |
Handler for the help command. More... | |
static bool | exec_update (const char *const command) |
Handler for the update command. More... | |
static void | execute_command (const char *const command) |
Executes an interactive command. More... | |
static void | print_command_from_history (const int8_t offset) |
Prints out a command from the history. More... | |
static bool | handle_escape_sequence (const char data) |
Handles ANSI escape sequences. More... | |
static void | process_command_char (void) |
Processes a command character. More... | |
static void | process_update_data (void) |
Processes binary data arriving over USB during the update process. More... | |
void | init_serial_communication (const struct serial_command *const commands, uint8_t commands_size) |
void | serial_communication_task (void) |
Main task for USB communication. More... | |
Variables | |
static char | cmd_buffer [100] = "" |
Buffer for incoming commands. More... | |
static uint8_t | cmd_buffer_index = 0 |
Command buffer write index. More... | |
static char | cmd_history [4][100] = {"",} |
Buffer for incoming commands. More... | |
static uint8_t | cmd_history_index = 0 |
Command buffer write index. More... | |
static const struct serial_command * | user_commands |
Array of user-defined commands. More... | |
static uint8_t | user_commands_size |
Number of registered user commands. More... | |
static bool | reset = false |
Device reset flag. More... | |
static bool | update_in_progress = false |
This flag indicates if an update is in progress. More... | |
static uint16_t | update_bytes_pending = 0 |
Number of pending update bytes. More... | |
static uint16_t | num_pages = 0 |
Number of pages required for update. More... | |
static uint16_t | expected_crc = 0 |
CRC of the firmware. More... | |
static uint8_t | page_buffer [SPM_PAGESIZE] = "" |
Buffer for application pages. More... | |
static uint16_t | page_buffer_index = 0 |
Page buffer write index. More... | |
static uint32_t | temp_app_addr = 0 |
Temporary application write address. More... | |
static bool | echo_on = true |
Terminal echo flag. More... | |
Implementation of the serial communication module.
|
inlinestatic |
Handler for the help
command.
|
inlinestatic |
Handler for the update
command.
|
inlinestatic |
Executes an interactive command.
Tries to match the beginning of the supplied string to the registered commands. If a matching command string is found, its handler is invoked. In case no suitable command could be matched, or the executed handler returns a non-zero value, an error message is sent.
command | the full command line as a C-string |
|
static |
Handles ANSI escape sequences.
true
as long as we are in the middle of an escape sequence void init_serial_communication | ( | const struct serial_command *const | commands, |
uint8_t | commands_size | ||
) |
|
inlinestatic |
Prints out a command from the history.
Clears out the last printed command first.
offset | offset of the command to be printed |
|
inlinestatic |
Processes a command character.
If the supplied character is a carriage return, the command line read so far is executed, otherwise the character is simply appended to a (circular!) buffer. If echo_on is set, the character is also immediately sent back to the sender, whereby carriage return characters are replaced by USB_NEWLINE.
|
inlinestatic |
Processes binary data arriving over USB during the update process.
If the supplied character is a carriage return, the command line read so far is executed, otherwise the character is simply appended to a (circular!) buffer.
void serial_communication_task | ( | void | ) |
Main task for USB communication.
This task must be run as a slow or medium speed task in order to enable USB communication and firmware updates. It processes commands arriving on the bus and takes required actions by calling registered handler functions.
|
static |
Buffer for incoming commands.
|
static |
Command buffer write index.
|
static |
Buffer for incoming commands.
|
static |
Command buffer write index.
|
static |
Terminal echo flag.
When this flag is set, received bytes are immediately echoed back to provide a shell-like experience.
|
static |
CRC of the firmware.
|
static |
Number of pages required for update.
|
static |
Buffer for application pages.
|
static |
Page buffer write index.
|
static |
Device reset flag.
This flag is set when the device receives the reset
command. The device will then stop receiving data, send a shutdown message, count down a timeout and reset itself.
|
static |
Temporary application write address.
|
static |
Number of pending update bytes.
|
static |
This flag indicates if an update is in progress.
|
static |
Array of user-defined commands.
|
static |
Number of registered user commands.