Skip to content

Commit 23a5ccd

Browse files
committed
Add start address argument for adm command.
This removes the need to send a separate `cls` before doing `adm` commands.
1 parent bdf5009 commit 23a5ccd

File tree

2 files changed

+12
-7
lines changed

2 files changed

+12
-7
lines changed

README.md

Lines changed: 3 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -59,8 +59,9 @@ These commands must be run when the running status is `STOPPED`.
5959
* `get <address (in hex)>` - Gets instruction at address. Returns output word and number of clock cycles separated by a space, in same format as `set`.
6060
* `run` - Used to hardware start a programmed sequence (ie waits for external trigger before processing first instruction).
6161
* `swr` - Used to software start a programmed sequence (ie do not wait for a hardware trigger at sequence start).
62-
* `adm <number of instructions (in hex)>` - Enters mode for adding pulse instructions in binary.
63-
* The number of instructions must be specified with the command. The Pi Pico will then wait for that enough bytes to fill that many instructions (6 times the number of instructions) to be read, and will not respond during this time unless there is an error. This mode can not be be terminated until that many bytes are read.
62+
* `adm <starting instruction address (in hex)> <number of instructions (in hex)>` - Enters mode for adding pulse instructions in binary.
63+
* This command over-writes any existing instructions in memory. The starting instruction address specifies where to insert the block of instructions. This is generally set to 0 to write a complete instruction set from scratch.
64+
* The number of instructions must be specified with the command. The Pi Pico will then wait for enough bytes (6 times the number of instructions) to be read, and will not respond during this time unless there is an error. This mode can not be be terminated until that many bytes are read.
6465
* Each instruction is specified by a 16 bit unsigned integer (little Endian, output 15 is most significant) specifying the state of the outputs and a 32 bit unsigned integer (little Endian) specifying the number of clock cycles.
6566
* The number of clock cycles sets how long this state is held before the next instruction.
6667
* If the number of clock cycles is 0, this indicates an indefinite wait.

prawn_do/prawn_do.c

Lines changed: 9 additions & 5 deletions
Original file line numberDiff line numberDiff line change
@@ -519,18 +519,22 @@ int main(){
519519
// Add many command: read in a fixed number of binary integers without separation,
520520
// append to command array
521521
else if(strncmp(serial_buf, "adm", 3) == 0){
522-
// Get how many instructions this adm command contains
522+
// Get how many instructions this adm command contains and where to insert them
523+
uint32_t start_addr;
523524
uint32_t inst_count;
524-
int parsed = sscanf(serial_buf, "%*s %x", &inst_count);
525-
if(parsed < 1){
525+
int parsed = sscanf(serial_buf, "%*s %x %x", &start_addr, &inst_count);
526+
if(parsed < 2){
526527
fast_serial_printf("Invalid request\r\n");
527528
}
528529

529530
// Check that the instructions will fit in the do_cmds array
530-
if(inst_count + do_cmd_count >= MAX_DO_CMDS - 3){
531-
fast_serial_printf("Too many DO commands (%d + %d). Please use resources more efficiently or increase MAX_DO_CMDS and recompile.\r\n", do_cmd_count, inst_count);
531+
if(inst_count + start_addr >= MAX_DO_CMDS - 3){
532+
fast_serial_printf("Invalid address and/or too many instructions (%d + %d).\r\n", start_addr, inst_count);
532533
}
533534

535+
// reset do_cmd_count to start_address
536+
do_cmd_count = start_addr * 2;
537+
534538
// It takes 6 bytes to describe an instruction: 2 bytes for values, 4 bytes for time
535539
uint32_t inst_per_buffer = SERIAL_BUFFER_SIZE / 6;
536540
// In this loop, we read nearly full serial buffers and load them into do_cmds.

0 commit comments

Comments
 (0)