示例#1
0
int phantom_console_window_putc(int c)
{
#if TIMED_FLUSH
    phantom_undo_timed_call( &cons_timer );
#endif

#if NET_TIMED_FLUSH
    cancel_net_timer(&cons_upd_timer);
#endif

    switch(c)
    {
    case '\b':
        if(cbufpos > 0) cbufpos--;
        goto noflush;
        //return c;

    case '\t':
        while(cbufpos % 8)
        {
            if(cbufpos >= BUFS)
                break;
            put_buf(' ');
        }
        goto noflush;
        //return c;

    case '\n':
    case '\r':
        put_buf( c );
        goto flush;

    default:
        put_buf( c );
        if( cbufpos >= BUFS )
            goto flush;

noflush:
#if TIMED_FLUSH
        phantom_request_timed_call( &cons_timer, 0 );
#endif

#if NET_TIMED_FLUSH
        set_net_timer(&cons_upd_timer, 100, flush_stdout, 0, 0 );
#endif

        return c;
    }

flush:
    flush_stdout(0);
    return c;
}
示例#2
0
int do_test_timed_call(const char *test_parm)
{
    (void) test_parm;


    printf("Testing timed call undo, must be no echoes:\n");
    called = 0;

    phantom_request_timed_call( &t2, 0 );
    phantom_undo_timed_call(&t2);

    hal_sleep_msec(200); // Twice the time
    test_check_eq(called, 0);


#if DUMPQ
    //dump_timed_call_queue();
#endif


    called = 0;

    printf("Testing timed calls, wait for echoes:\n");

    phantom_request_timed_call( &t1, 0 );
    //test_check_false(called); // it is still possible for this test to fail with correct code!
    phantom_request_timed_call( &t2, 0 );
#if DUMPQ
    //dump_timed_call_queue();
#endif
    phantom_request_timed_call( &t3, 0 );
    phantom_request_timed_call( &t4, 0 );

    //TIMEDCALL_FLAG_AUTOFREE requires call to free from interrupt :(
    //phantom_request_timed_func( echo, msg, 5000, 0 );
    phantom_request_timed_call( &t5, 0 );

#if DUMPQ
    dump_timed_call_queue();
#endif

    // We check for >= (ge) because hal_sleep... can cleep for more than asked, and timed
    // calls are usually quite on time

    hal_sleep_msec(6);
    test_check_ge(called, 1);

    hal_sleep_msec(200); // Have lag of 106 msec, OK?
    test_check_ge(called, 2);

    hal_sleep_msec(2000-100); // Still have lag of 106 msec
    test_check_ge(called, 3);

    hal_sleep_msec(5000-2000); // Have lag of 206 msec
    test_check_ge(called, 4);

    hal_sleep_msec(2500+10000-5000-2000); // Strange - need quite big lag here...
    test_check_ge(called, 5);



    printf("Done testing timed calls\n");
    return 0;
}