main
Default mainpagebasic-rtt-projectmain
Description Source Call Graph
Start Line: 243
int main(void)
{
    unsigned char c;

    // Enable DBGU
    TRACE_CONFIGURE(DBGU_STANDARD, 115200, BOARD_MCK);
    printf("-- Basic RTT Project %s --\n\r", SOFTPACK_VERSION);
    printf("-- %s\n\r", BOARD_NAME);
    printf("-- Compiled: %s %s --\n\r", __DATE__, __TIME__);

    // Configure RTT
    ConfigureRtt();

    // Initialize state machine
    state = STATE_MAINMENU;
    alarmed = 0;
    RefreshDisplay();

    // User input loop
    while (1) { 

        // Wait for user input
        c = DBGU_GetChar();

        // Main menu mode
        if (state == STATE_MAINMENU) {

            // Reset timer
            if (c == 'r') {

                ConfigureRtt();
                RefreshDisplay();
            }
            // Set alarm
            else if (c == 's') {

                state = STATE_SETALARM;
                newAlarm = 0;
                RefreshDisplay();
            }
            // Clear alarm
            else if ((c == 'c') && alarmed) {

                alarmed = 0;
                RefreshDisplay();
            }
        }
        // Set alarm mode
        else if (state == STATE_SETALARM) {

            // Number
            if ((c >= '0') && (c <= '9')) {

                newAlarm = newAlarm * 10 + c - '0';
                RefreshDisplay();
            }
            // Backspace
            else if (c == 8) {

                newAlarm /= 10;
                RefreshDisplay();
            }
            // Enter key
            else if (c == 13) {

                // Avoid newAlarm = 0 case
                if (newAlarm != 0) {

                    RTT_SetAlarm(AT91C_BASE_RTTC, newAlarm);
                }
               
                state = STATE_MAINMENU;
                RefreshDisplay();
            }
        }
    }
}