void vUART1Task(void *p) { unsigned int v=0; const portTickType xDelay = 10 / portTICK_RATE_MS; ( void ) p; while (1) { if(g_u1char_available) { g_u1char_available=0; if(u1_ack == 1) { printf("ACK"); } else { printf("NACK"); } printf(", adr: "); print_hex_byte(u1_adr); printf(", dat: "); print_hex_byte(u1_dat); puts(""); } vTaskDelay( xDelay ); v++; } }
/** * M100 D * Dump the free memory block from __brkval to the stack pointer. * malloc() eats memory from the start of the block and the stack grows * up from the bottom of the block. Solid test bytes indicate nothing has * used that memory yet. There should not be anything but test bytes within * the block. If so, it may indicate memory corruption due to a bad pointer. * Unexpected bytes are flagged in the right column. */ void dump_free_memory(const char *ptr, const char *sp) { // // Start and end the dump on a nice 16 byte boundary // (even though the values are not 16-byte aligned). // ptr = (char *)((uint16_t)ptr & 0xFFF0); // Align to 16-byte boundary sp = (char *)((uint16_t)sp | 0x000F); // Align sp to the 15th byte (at or above sp) // Dump command main loop while (ptr < sp) { print_hex_word((uint16_t)ptr); // Print the address SERIAL_CHAR(':'); for (uint8_t i = 0; i < 16; i++) { // and 16 data bytes if (i == 8) SERIAL_CHAR('-'); print_hex_byte(ptr[i]); SERIAL_CHAR(' '); } safe_delay(25); SERIAL_CHAR('|'); // Point out non test bytes for (uint8_t i = 0; i < 16; i++) { char ccc = (char)ptr[i]; // cast to char before automatically casting to char on assignment, in case the compiler is broken if (&ptr[i] >= (const char*)command_queue && &ptr[i] < (const char*)(command_queue + sizeof(command_queue))) { // Print out ASCII in the command buffer area if (!WITHIN(ccc, ' ', 0x7E)) ccc = ' '; } else { // If not in the command buffer area, flag bytes that don't match the test byte ccc = (ccc == TEST_BYTE) ? ' ' : '?'; } SERIAL_CHAR(ccc); } SERIAL_EOL(); ptr += 16; safe_delay(25); idle(); } }
// If it's not a data byte, beeps, backs up one, and returns true. char check_data_byte(char byte) { if(is_data(byte)) return 0; play("o3c"); clear(); print("Bad data"); lcd_goto_xy(0,1); print_hex_byte(byte); previous_byte(); return 1; }
void dump_bkod() { opcode_type opcode; int i, line; char text[50000]; char opcode_char; static int last_line = 0; // printf("at %08X\n",index); inst_start = index; line = find_linenum(index); if (line != last_line) { printf("*** Line %d\n", line); last_line = line; } opcode_char = get_byte(); memcpy(&opcode,&opcode_char,1); /* opcode = (opcode_type)get_byte(); can't get to compile */ switch (opcode.command) { case UNARY_ASSIGN : dump_unary_assign(opcode,text); break; case BINARY_ASSIGN : dump_binary_assign(opcode,text); break; case GOTO : dump_goto(opcode,text); break; case CALL : dump_call(opcode,text); break; case RETURN : dump_return(opcode,text); break; case DEBUG_LINE : dump_debug_line(opcode,text); break; default : sprintf(text,"INVALID"); break; } if (dump_hex) { printf("BKOD raw: "); for (i=0;i<index-inst_start;i++) print_hex_byte(file_mem[inst_start+i]); printf("\n"); } printf("@%08X: ",inst_start); printf("%s\n",text); }
/** * URL-encode a string. * * @param dst buffer to receive result or NULL to calculate * the lengths of encoded string * @param filename the file name * @return the length of the result string */ int urlencode(char *dst, const char *name) { const char *start; if (!dst) { int len; for (len = 0; *name; name++) len += (IS_GOOD_URL_CHAR(*name) ? 1 : 3); return len; } /* encode URL as specified by RFC 1738 */ for (start = dst; *name; name++) { if ( IS_GOOD_URL_CHAR(*name) ) { *dst++ = *name; } else { *dst++ = '%'; dst = print_hex_byte(dst, *name, 'A'); } } *dst = 0; return (int)(dst - start); }
void vUART2Task(void *p) { unsigned int v=0; const portTickType xDelay = 10 / portTICK_RATE_MS; ( void ) p; while (1) { int c = getchar2_nb(); if(c > 0) { printf("u2 read: "); print_hex_byte(c); puts(""); } vTaskDelay( xDelay ); v++; } }
int main() { pololu_3pi_init(2000); play_mode(PLAY_CHECK); clear(); // start receiving data at 115.2 kbaud serial_set_baud_rate(115200); serial_receive_ring(buffer, 100); while(1) { // wait for a command char command = read_next_byte(); // The list of commands is below: add your own simply by // choosing a command byte and introducing another case // statement. switch(command) { case (char)0x00: // silent error - probable master resetting break; case (char)0x81: send_signature(); break; case (char)0x86: send_raw_sensor_values(); break; case (char)0x87: send_calibrated_sensor_values(1); break; case (char)0xB0: send_trimpot(); break; case (char)0xB1: send_battery_millivolts(); break; case (char)0xB3: do_play(); break; case (char)0xB4: calibrate_line_sensors(IR_EMITTERS_ON); send_calibrated_sensor_values(1); break; case (char)0xB5: line_sensors_reset_calibration(); break; case (char)0xB6: send_line_position(); break; case (char)0xB7: do_clear(); break; case (char)0xB8: do_print(); break; case (char)0xB9: do_lcd_goto_xy(); break; case (char)0xBA: auto_calibrate(); break; case (char)0xBB: set_pid(); break; case (char)0xBC: stop_pid(); break; case (char)0xC1: m1_forward(); break; case (char)0xC2: m1_backward(); break; case (char)0xC5: m2_forward(); break; case (char)0xC6: m2_backward(); break; default: clear(); print("Bad cmd"); lcd_goto_xy(0,1); print_hex_byte(command); play("o7l16crc"); continue; // bad command } } }