Altera_Forum
Honored Contributor
12 years agoCan't get my do while loop to repeat
Here is a sample of my code, I'm trying to make a prompt for a user enter 1 for reset test, 2 to do something later, and 3 to exit. After pressing 1 the reset code executes, the code should then reask the user to input 1, 2 or 3; only after pressing 3 should the code exit. The reset code executes perfectly, but I can't get the prompt to repeat. My variable 'c' is declared as int, and 'quit' is declared as u8. I wanted to declare 'quit' as bool or boolean, but my compiler didn't recognize bool.
do { c=0; TestFailed = 0; TestSuccess = 0; alt_printf("Enter 1 for reset test, 2 for ???, and 3 to exit"); c = alt_getchar(); alt_printf("You chose %s\n", c); switch(c) { case '1': alt_printf("Reset Test\n"); alt_printf("Entering reset loop with %x resets. \n", num_results); for (ii = 0; ii < num_resets; ii++) { //Reset the core through reg read mod write to bit 4. iprop_dev_portreset((u32*)DEV_BUS_SLAVE_BASE); //poll on bit 5 of ADI_DEV_CORE_STATUS every 1 ms for when device is up and running timeout after 20ms rc = iprop_wait_reg((u32*)(DEV_BUS_SLAVE_BASE + ADI_OFFSET + ADI_DEV_CORE_STATUS), 0x20, //only look at bit 5 0x00, //if bit-1 ==1, we're phy-ready 1, //wait 1us between register reads 100000); //~100ms read = Iprop_RegRead32((u32*)DEV_BUS_SLAVE_BASE, ADI_OFFSET + ADI_DEV_CORE_STATUS); if ((rc & 0x20) == DEV_STATUS_PHYRDY) { TestSuccess = TestSuccess + 1; } else { TestFailed = TestFailed + 1; } //sleep to allow the drive to send an initial d2h percent_done = ii/(num_resets/10); if (ii%(num_resets/10) == 0) { alt_printf("%x0%% Done\n", percent_done); } usleep(10); } alt_printf("Test Completed\n"); alt_printf("Successful Results: %x ", TestSucccess); alt_printf("Failed Resets: %x ", TestFailed); while(1) { } return 0; break; case '2': alt_printf("???"); while(1) { } return 0; break; case '3': alt_printf("Exiting"); quit = 0xFF; while(1) { } return 0; break; default: alt_printf("Invalid entry %s", c); while(1) { } return 0; break; } }while (!quit);