mirror of
https://github.com/logicog/RTLPlayground.git
synced 2026-08-30 14:52:51 +08:00
Merge pull request #195 from logicog/fix_config_reading
Fix reading configuration over flash block boundaries
This commit is contained in:
+37
-15
@@ -70,6 +70,8 @@ __xdata signed char cmd_words_b[N_WORDS];
|
||||
__xdata uint8_t cmd_history[CMD_HISTORY_SIZE];
|
||||
__xdata uint16_t cmd_history_ptr;
|
||||
|
||||
// Error set by commands
|
||||
__xdata uint8_t err_status;
|
||||
|
||||
inline uint8_t isletter(uint8_t l)
|
||||
{
|
||||
@@ -1172,6 +1174,7 @@ uint8_t cmd_tokenize(void) __banked
|
||||
print_string_x(&cmd_buffer[0]);
|
||||
write_char('<'); write_char('\n');
|
||||
#endif
|
||||
err_status = ERR_OK;
|
||||
line_ptr = 0;
|
||||
is_white = 1;
|
||||
uint8_t word = 0;
|
||||
@@ -1189,11 +1192,14 @@ uint8_t cmd_tokenize(void) __banked
|
||||
line_ptr++;
|
||||
if (word >= N_WORDS - 1) {
|
||||
print_string("\ntoo many arguments, truncated");
|
||||
err_status = ERR_TOO_MANY_ARGUMENTS;
|
||||
return 1;
|
||||
}
|
||||
}
|
||||
if (line_ptr == CMD_BUF_SIZE - 1)
|
||||
if (line_ptr == CMD_BUF_SIZE - 1) {
|
||||
err_status = ERR_CMD_TOO_LONG;
|
||||
return 1;
|
||||
}
|
||||
cmd_words_b[word++] = line_ptr;
|
||||
cmd_words_b[word++] = -1;
|
||||
|
||||
@@ -1481,15 +1487,20 @@ void clear_command_history(void) __banked
|
||||
|
||||
#define FLASH_READ_BURST_SIZE 0x100
|
||||
#define PASSWORD "1234"
|
||||
|
||||
#if CONFIG_LEN % FLASH_READ_BURST_SIZE
|
||||
#error "CONFIG_LEN not a multiple of FLASH_READ_BURST_SIZE"
|
||||
#endif
|
||||
void execute_config(void) __banked
|
||||
{
|
||||
__xdata uint32_t pos = CONFIG_START;
|
||||
__xdata uint16_t len_left = CONFIG_LEN;
|
||||
__xdata uint8_t pages_left = CONFIG_LEN / FLASH_READ_BURST_SIZE;
|
||||
|
||||
// Set default password, it can be overwritten in the configuration file
|
||||
strtox(passwd, PASSWORD);
|
||||
save_cmd = 0;
|
||||
|
||||
uint8_t cmd_idx = 0;
|
||||
do {
|
||||
flash_region.addr = pos;
|
||||
flash_region.len = FLASH_READ_BURST_SIZE;
|
||||
@@ -1498,24 +1509,35 @@ void execute_config(void) __banked
|
||||
__xdata uint8_t cfg_idx = 0;
|
||||
uint8_t c = 0;
|
||||
do {
|
||||
for (uint8_t cmd_idx = 0; cmd_idx < (CMD_BUF_SIZE - 1); cmd_idx++) {
|
||||
c = flash_buf[cfg_idx++];
|
||||
if (c == 0 || c == '\n') {
|
||||
cmd_buffer[cmd_idx] = '\0';
|
||||
if (cmd_idx && !cmd_tokenize())
|
||||
cmd_parser();
|
||||
if (c == 0)
|
||||
if (cmd_idx >= (CMD_BUF_SIZE - 1)) {
|
||||
cmd_buffer[cmd_idx] = '\0';
|
||||
print_string("ERROR: Command too long: ");
|
||||
print_string_x(cmd_buffer);
|
||||
write_char('\n');
|
||||
err_status = ERR_CMD_TOO_LONG;
|
||||
goto config_done;
|
||||
}
|
||||
c = flash_buf[cfg_idx++];
|
||||
if (c == 0 || c == '\n') {
|
||||
cmd_buffer[cmd_idx] = '\0';
|
||||
if (cmd_idx && !cmd_tokenize()) {
|
||||
cmd_parser();
|
||||
if (err_status)
|
||||
goto config_done;
|
||||
break;
|
||||
}
|
||||
|
||||
cmd_buffer[cmd_idx] = c;
|
||||
if (c == 0)
|
||||
goto config_done;
|
||||
cmd_idx = 0;
|
||||
continue;
|
||||
}
|
||||
} while(cfg_idx);
|
||||
|
||||
len_left -= FLASH_READ_BURST_SIZE;
|
||||
cmd_buffer[cmd_idx] = c;
|
||||
cmd_idx++;
|
||||
} while (cfg_idx);
|
||||
|
||||
pages_left--;
|
||||
pos += FLASH_READ_BURST_SIZE;
|
||||
} while(len_left);
|
||||
} while(pages_left);
|
||||
|
||||
config_done:
|
||||
// Start saving commands to cmd_history
|
||||
|
||||
Reference in New Issue
Block a user