// Define Interrupt Service Routine for Port #2 // name of function is predefined void PIOINT2_IRQHandler(void) { if (LPC_GPIO2->RIS & (1 << 6)) { //read raw interrupt status safe_increment((uint32_t * ) & encoder_1_count); LPC_GPIO2->IC = (1 << 6); //clear edge detection } else if (LPC_GPIO2->RIS & (1 << 11)) { safe_increment((uint32_t * ) & encoder_0_count); LPC_GPIO2->IC = (1 << 11); //clear edge detection } }
int parse(int params_count, char * params[], char * commands[]) { int i; for (i = 0; i < COMMAND_COUNT; i++) { commands[i] = malloc(BUFF_SIZE); memset(commands[i],0,BUFF_SIZE); } char buf[2]; int index = -1; for (i = 0; i < params_count; i++) { if (strcmp(params[i], "<")==0 || strcmp(params[i], ">")==0 || strcmp(params[i], ">>")==0) { index = safe_increment(index); strcat(commands[index], params[i]); index = safe_increment(index); } else { if (index == -1) { index = safe_increment(index); } strcat(commands[index], params[i]); strcat(commands[index], " "); } } if (strlen(commands[2]) > 1) { my_sbstr1(commands[2]); } if (strlen(commands[4]) > 1) { my_sbstr1(commands[4]); } //check command correctness(correct commands: cmd > file, cmd >> file, cmd < file, cmd < file > file) if (strcmp(commands[1], ">") != 0 && strcmp(commands[1], ">>") != 0 && strcmp(commands[1], "<") != 0) return -1; if (strcmp(commands[1], ">") == 0 || strcmp(commands[1], ">>") == 0) { if (strcmp(commands[3], "\0") != 0) return -1; } if (strcmp(commands[1], "<") == 0 ) { if (strcmp(commands[3], "\0") != 0 && strcmp(commands[3], ">") != 0 && strcmp(commands[3], ">>") != 0) return -1; } return 0; }