OpenCores
URL https://opencores.org/ocsvn/s6soc/s6soc/trunk

Subversion Repositories s6soc

[/] [s6soc/] [trunk/] [sw/] [zipos/] [doorbell.c] - Diff between revs 29 and 39

Go to most recent revision | Show entire file | Details | Blame | View Log

Rev 29 Rev 39
Line 337... Line 337...
                        // Seconds records the number of seconds since the
                        // Seconds records the number of seconds since the
                        // button was last pressed.
                        // button was last pressed.
                        int     seconds = 0;
                        int     seconds = 0;
 
 
                        // Check time: should we turn our light on or not?
                        // Check time: should we turn our light on or not?
                        belllight(rtcclock);
                        belllight((volatile unsigned)rtcclock);
                        const int *sptr = sound_data;
                        const int *sptr = sound_data;
                        // uartchr('N');
                        // uartchr('N');
                        while(sptr < &sound_data[NSAMPLE_WORDS]) {
                        while(sptr < &sound_data[NSAMPLE_WORDS]) {
                                int     len = &sound_data[NSAMPLE_WORDS]-sptr;
                                int     len = &sound_data[NSAMPLE_WORDS]-sptr;
                                if (len > 256)
                                if (len > 256)
Line 366... Line 366...
                                                post(SWINT_DOORBELL);
                                                post(SWINT_DOORBELL);
#endif
#endif
                                        }
                                        }
                                } else if (event&SWINT_PPS) {
                                } else if (event&SWINT_PPS) {
                                        seconds++;
                                        seconds++;
                                        belllight(rtcclock);
                                        belllight((volatile unsigned)rtcclock);
#ifndef MENU_TASK
#ifndef MENU_TASK
                                        showbell(when);
                                        showbell(when);
#endif
#endif
                                }
                                }
                        }
                        }
Line 379... Line 379...
                        // we have yet to return to normal--the light is still
                        // we have yet to return to normal--the light is still
                        // on.
                        // on.
                        while((seconds < HALF_HOUR_S)&&
                        while((seconds < HALF_HOUR_S)&&
                                (((event=wait(INT_BUTTON|SWINT_PPS,-1))&INT_BUTTON)==0)) {
                                (((event=wait(INT_BUTTON|SWINT_PPS,-1))&INT_BUTTON)==0)) {
                                seconds++;
                                seconds++;
                                belllight(rtcclock);
                                belllight((volatile unsigned)rtcclock);
#ifndef MENU_TASK
#ifndef MENU_TASK
                                showbell(when);
                                showbell(when);
#endif
#endif
                        }
                        }
                        if (event&INT_BUTTON) {
                        if (event&INT_BUTTON) {
Line 517... Line 517...
                                }
                                }
                        }
                        }
                } while(0==(event&INT_KEYPAD));
                } while(0==(event&INT_KEYPAD));
        }
        }
 
 
 
        // Here's the trick here: without semaphores, we can't prevent a 
 
        // race condition on the clock.  It may be that the clock simulator
 
        // has read the clock value and is in the process of updating it, only
 
        // to have our task swapped in.  The risk here is that the RTC simulator
 
        // will write the updated value after we update our value here.  If it
 
        // does that, it will then set the SWINT_PPS interrupt.  So let's clear
 
        // this interrupt and then set our clock.  If the interrupt then
 
        // takes place in short order, we'll set the clock again.  That way,
 
        // if the RTC device was in the process of setting the clock, and then
 
        // sets it, we can adjust it again.
 
        //
 
        // Of course ... this won't work if it takes the clock longer than 
 
        // a millisecond to finish setting the clock ... but this is such a
 
        // rare race condition, and the consequences so minor, that this will
 
        // probably continue to work for now.
        clear(SWINT_PPS);
        clear(SWINT_PPS);
        rtcclock = newclock;
        rtcclock = newclock;
        if (wait(SWINT_PPS, 1))
        if (wait(SWINT_PPS, 1))
                rtcclock = newclock;
                rtcclock = newclock;
}
}
Line 614... Line 629...
        // Start by initializing the display to GT Gisselquist\nTechnology
        // Start by initializing the display to GT Gisselquist\nTechnology
        // write(KFD_STDOUT, disp_build_backslash,sizeof(disp_build_backslash));
        // write(KFD_STDOUT, disp_build_backslash,sizeof(disp_build_backslash));
        // write(KFD_STDOUT, disp_build_gtlogo, sizeof(disp_build_gtlogo));
        // write(KFD_STDOUT, disp_build_gtlogo, sizeof(disp_build_gtlogo));
        // write(KFD_STDOUT, disp_reset_data, sizeof(disp_reset_data));
        // write(KFD_STDOUT, disp_reset_data, sizeof(disp_reset_data));
        // write(KFD_STDOUT, disp_gtech_data, sizeof(disp_gtech_data));
        // write(KFD_STDOUT, disp_gtech_data, sizeof(disp_gtech_data));
        IOSPACE *sys = (IOSPACE *)IOADDR;
        // IOSPACE      *sys = (IOSPACE *)IOADDR;
        unsigned belltime = 0, when;
        unsigned belltime = 0, when;
 
 
 
 
        when = rtcclock;
        when = (volatile unsigned)rtcclock;
        while(1) {
        while(1) {
                int     event;
                int     event;
                // Initial state: doorbell is not ringing.  In this state, we
                // Initial state: doorbell is not ringing.  In this state, we
                // can wait forever for an event
                // can wait forever for an event
                sys->io_spio = 0x080; // Turn our light off
 
                event = wait(SWINT_DOORBELL|SWINT_PPS|INT_KEYPAD,-1);
                event = wait(SWINT_DOORBELL|SWINT_PPS|INT_KEYPAD,-1);
                if (event & SWINT_DOORBELL) {
                if (event & SWINT_DOORBELL) {
                        showbell(when);
                        showbell(when);
                        belltime = time();
                        belltime = time();
                } else if (event & SWINT_PPS) {
                } else if (event & SWINT_PPS) {
                        unsigned        now = time();
                        unsigned        now = time();
                        if ((now-belltime)<HALF_HOUR_S)
                        if ((now-belltime)<HALF_HOUR_S)
                                showbell(when);
                                showbell(when);
                        else {
                        else {
                                when = rtcclock;
                                when = (volatile unsigned)rtcclock;
                                shownow(when);
                                shownow(when);
                        }
                        }
                }
                }
 
 
                if (event & INT_KEYPAD) {
                if (event & INT_KEYPAD) {
                        int     key;
                        int     key;
                        key = menu_readkey();
                        key = menu_readkey();
                        switch(key) {
                        switch(key) {
                                case 10: time_menu();
                                case 10: time_menu();
                                        when = rtcclock;
                                        when = (volatile unsigned)rtcclock;
                                        break;
                                        break;
                                case 11: dawn_menu(); break;
                                case 11: dawn_menu(); break;
                                case 12: dusk_menu(); break;
                                case 12: dusk_menu(); break;
                                default:
                                default:
                                        unknown_menu();
                                        unknown_menu();

powered by: WebSVN 2.1.0

© copyright 1999-2024 OpenCores.org, equivalent to Oliscience, all rights reserved. OpenCores®, registered trademark.