unsigned long command[5]; unsigned long result[5]; typedef void (*IAP)(uint32_t [], uint32_t []); IAP iap_entry2 = (IAP)0x1fff1ff1; void ReinvokeISP(void) { LPC_SYSCON->SYSAHBCLKCTRL |= 0x04000; LPC_SYSCON->SYSAHBCLKCTRL |= 0x00400; LPC_SYSCON->SYSAHBCLKCTRL |= 0x00040; LPC_SYSCON->SYSAHBCLKCTRL |= 0x10000; LPC_SYSCON->SYSAHBCLKDIV = 1; command[0] = 57; __set_MSP(*((uint32_t *) 0x1FFF0000)); /* inline asm function */ iap_entry2(command, result); } int main(void) { uint32_t temp = 0; LPC_SYSCON->SYSAHBCLKCTRL |= (1 << 6); LPC_IOCON->R_PIO0_11 = 0x91; LPC_IOCON->R_PIO1_0 = 0x81; LPC_IOCON->R_PIO1_1 = 0x81; LPC_IOCON->R_PIO1_2 = 0x81; GPIOSetDir(PORT1, 2, 0); /*The while is to check the entrance several times and delay the startup a bit in case the power doesn't get on time to the line*/ while (temp++ < 100000) if ((GPIOGetValue(PORT1, 2) == 1)) { ReinvokeISP(); } //...... Main continues, but it's not supposed to get here if PIO1_2 == 1 //It continues with the normal code independently of PIO1_2 being 0 or 1 } |