// Process and report status one line of incoming serial data. Performs an initial filtering // by removing spaces and comments and capitalizing all letters. void protocol_process() { uint8_t c; while((c = serial_read()) != SERIAL_NO_DATA) { if ((c == '\n') || (c == '\r')) { // End of line reached // Runtime command check point before executing line. Prevent any furthur line executions. // NOTE: If there is no line, this function should quickly return to the main program when // the buffer empties of non-executable data. protocol_execute_runtime(); if (sys.abort) { return; // Bail to main program upon system abort } if (char_counter > 0) {// Line is complete. Then execute! line[char_counter] = 0; // Terminate string report_status_message(protocol_execute_line(line)); } else { // Empty or comment line. Skip block. report_status_message(STATUS_OK); // Send status message for syncing purposes. } protocol_reset_line_buffer(); } else { if (iscomment) { // Throw away all comment characters if (c == ')') { // End of comment. Resume line. iscomment = false; } } else { if (c <= ' ') { // Throw away whitepace and control characters } else if (c == '/') { // Block delete not supported. Ignore character. } else if (c == '(') { // Enable comments flag and ignore all characters until ')' or EOL. iscomment = true; } else if (char_counter >= LINE_BUFFER_SIZE-1) { // Report line buffer overflow and reset report_status_message(STATUS_OVERFLOW); protocol_reset_line_buffer(); } else if (c >= 'a' && c <= 'z') { // Upcase lowercase line[char_counter++] = c-'a'+'A'; } else { line[char_counter++] = c; } } } } }
void protocol_init() { protocol_reset_line_buffer(); report_init_message(); // Welcome message PINOUT_DDR &= ~(PINOUT_MASK); // Set as input pins PINOUT_PORT |= PINOUT_MASK; // Enable internal pull-up resistors. Normal high operation. PINOUT_PCMSK |= PINOUT_MASK; // Enable specific pins of the Pin Change Interrupt PCICR |= (1 << PINOUT_INT); // Enable Pin Change Interrupt }
void protocol_init() { protocol_reset_line_buffer(); report_init_message(); // Welcome message //========================================== // PINOUT_DDR &= ~(PINOUT_MASK); // Set as input pins //引脚设置为输入 // PINOUT_PORT |= PINOUT_MASK; // Enable internal pull-up resistors. Normal high operation. //预上拉 /*---------HW_GPIO_Init()---------*/ // PINOUT_PCMSK |= PINOUT_MASK; // Enable specific pins of the Pin Change Interrupt //打开对应引脚的PCI中断 // PCICR |= (1 << PINOUT_INT); // Enable Pin Change Interrupt //使能C口的PCI中断 /*---------HW_EXTI_Init()---------*/ //========================================== }