Ejemplo n.º 1
0
void init_scheduler(void)
{
	int rtc_ticks_per_sec;

	/* get handle to the system realtime clock */
	rtclock = cyg_real_time_clock ();
	rtc_resolution = cyg_clock_get_resolution ( rtclock );
	rtc_ticks_per_sec = rtc_resolution.divisor;
	cyg_clock_to_counter ( rtclock, &rtc_counter );
	
	// Real time clock frequency must be changed in eCos configuration, as there is another
	// macro that depends on its value.
	//fprintf ( stderr, "cyg_realtime_clock() resolution: dividend=%d, \t divisor=%d\n", rtc_resolution.dividend, rtc_resolution.divisor );

	// Create alarms
	cyg_alarm_create ( rtc_counter, alarm_handlerfn_daq,0,&alarm_hdl[0],&alarm_obj[0] );
	cyg_alarm_create ( rtc_counter, alarm_handlerfn_actuators,0,&alarm_hdl[1],&alarm_obj[1] );
	cyg_alarm_create ( rtc_counter, alarm_handlerfn_thread1,0,&alarm_hdl[2],&alarm_obj[2] );

	// Initialize conditional variables
	pthread_cond_init (&trigger_daq, NULL);
	pthread_cond_init (&trigger_actuators, NULL);
	pthread_cond_init (&trigger_thread1, NULL);

	// Start alarms
	// DAQ, executes at t0 + 0.0000
	cyg_alarm_initialize ( alarm_hdl[0], DAQ_OFFSET*rtc_ticks_per_sec, rtc_ticks_per_sec/BASE_HZ );
	
	// ACTUATORS, executes at t0 + 0.014
	cyg_alarm_initialize ( alarm_hdl[1], ACTUATORS_OFFSET*rtc_ticks_per_sec, rtc_ticks_per_sec/BASE_HZ);

	// Thread1, executes at t0 + 0.0130
	cyg_alarm_initialize ( alarm_hdl[2], THREAD1_OFFSET*rtc_ticks_per_sec, rtc_ticks_per_sec/THREAD1_HZ );

}
Ejemplo n.º 2
0
void alarm0_main(void)
{
    int i;
    
    CYG_TEST_INIT();

    // Create the counter
    cyg_counter_create( &counter, &counter_obj );

    // Create the alarms
    cyg_alarm_create( counter,
                      alarmfn0,
                      0,
                      &alarm[0],
                      &alarm_obj[0]);


    cyg_alarm_create( counter,
                      alarmfn1,
                      1,
                      &alarm[1],
                      &alarm_obj[1]);

    cyg_alarm_create( counter,
                      alarmfn2,
                      2,
                      &alarm[2],
                      &alarm_obj[2]);


    // Kick it all off by starting alarm[2]
    cyg_alarm_initialize( alarm[2], 0, 10 );

    // Run the whole thing for 10000 ticks
    for( i = 0; i < 10000; i++ )
        cyg_counter_tick( counter );

    db_printf("alarmfn_called: %d %d %d\n",
                alarmfn_called[0],alarmfn_called[1],alarmfn_called[2]);

    CYG_TEST_CHECK( alarmfn_called[0]==5000, "alarmfn0 not called 5000 times\n");
    CYG_TEST_CHECK( alarmfn_called[1]==2000, "alarmfn1 not called 2000 times\n");
    CYG_TEST_CHECK( alarmfn_called[2]==1001, "alarmfn2 not called 1001 times\n");
    
    CYG_TEST_PASS_FINISH("KAlarm0");
}
Ejemplo n.º 3
0
CECOSTimerHandler::CECOSTimerHandler(){
  cyg_semaphore_init(&m_stSemaphore, 0);

  m_stSystemclockHandle = cyg_real_time_clock();
  cyg_clock_to_counter(m_stSystemclockHandle, &m_stCounterHandle);

  cyg_alarm_create(m_stCounterHandle, timerHandlerFunc, (cyg_addrword_t) 0, &m_stAlarmHandle, &m_stAlarm);
}
Ejemplo n.º 4
0
Archivo: sco.c Proyecto: LucidOne/Rovio
static void sco_sock_init_timer(struct sock *sk)
{
//	init_timer(&sk->timer);
//	sk->timer.function = sco_sock_timeout;
//	sk->timer.data = (unsigned long)sk;
	cyg_clock_to_counter(cyg_real_time_clock(), &sk->h);
    cyg_alarm_create(sk->h, sco_sock_timeout, (cyg_addrword_t)sk, &sk->timeout_alarm_handle, &sk->timeout_alarm);
}
Ejemplo n.º 5
0
void fptest_main( void )
{
    
    CYG_TEST_INIT();

    if( cyg_test_is_simulator )
    {
        run_ticks = RUN_TICKS_SIM;
    }

    CYG_TEST_INFO("Run fptest in cyg_start");
    do_test( fpt3_values, FP3_COUNT, 1000, 0, "start" );
    CYG_TEST_INFO( "cyg_start run done");
    
    cyg_thread_create( BASE_PRI-1,
                       fptest1,
                       0,
                       "fptest1",
                       &stacks[0][0],
                       STACK_SIZE,
                       &thread[0],
                       &thread_struct[0]);

    cyg_thread_resume( thread[0] );

    cyg_thread_create( BASE_PRI,
                       fptest2,
                       1,
                       "fptest2",
                       &stacks[1][0],
                       STACK_SIZE,
                       &thread[1],
                       &thread_struct[1]);

    cyg_thread_resume( thread[1] );

    cyg_thread_create( BASE_PRI,
                       fptest3,
                       2,
                       "fptest3",
                       &stacks[2][0],
                       STACK_SIZE,
                       &thread[2],
                       &thread_struct[2]);

    cyg_thread_resume( thread[2] );

    cyg_alarm_create( cyg_real_time_clock(),
                      alarm_fn,
                      0,
                      &alarm,
                      &alarm_struct );

    cyg_alarm_initialize( alarm, cyg_current_time()+1, 1 );
    
    cyg_scheduler_start();

}
void tcp_hole()
{
	int interval = 30000;
	
	TCP_HOLE_FLAG = 1;
  	
  	/* Attach the timer to the CloseTcpHole clock */
    CloseTcpHole_SysClk = cyg_real_time_clock();

    cyg_clock_to_counter(CloseTcpHole_SysClk, &CloseTcpHole_Counter);

    cyg_alarm_create(CloseTcpHole_Counter, (cyg_alarm_t *)CloseTcpHole,
                     0,
                     &CloseTcpHole_Alarm, &CloseTcpHole_timerAlarm);

    /* This creates a periodic timer */
    cyg_alarm_initialize(CloseTcpHole_Alarm, cyg_current_time() + interval, 0); //only trigger once after 5 minutes   

}
Ejemplo n.º 7
0
// ------------------------------------------------------------------------
// INITIALIZATION FUNCTION
void
cyg_alarm_timeout_init( void )
{
    // Init the alarm object, attached to the real time clock
    cyg_handle_t h;
    cyg_clock_to_counter(cyg_real_time_clock(), &h);
    cyg_alarm_create(h, do_alarm, 0, &timeout_alarm_handle, &timeout_alarm);
    // Init the flag of waking up
    cyg_flag_init( &alarm_flag );
    // Create alarm background thread to run the callbacks
    cyg_thread_create(
        CYGPKG_NET_FAST_THREAD_PRIORITY, // Priority
        alarm_thread,                   // entry
        0,                              // entry parameter
        "Network alarm support",        // Name
        &alarm_stack[0],                // Stack
        STACK_SIZE,                     // Size
        &alarm_thread_handle,           // Handle
        &alarm_thread_data              // Thread data structure
        );
    cyg_thread_resume(alarm_thread_handle);    // Start it
}
void linklocal_alarm(void){


	/* 10 sec, Follow Link Local IP Stard. If we got ip conflict twice 
	   within 10 seconds, we have to change our link local ip.  
	   											<<<Ron 12/13/04  >>> */    
    int interval = 10; //10 sec
    
    /* Attach the timer to the real-time clock */
    hSysClk = cyg_real_time_clock();

    cyg_clock_to_counter(hSysClk, &hCounter);

//    cyg_alarm_create(hCounter, (cyg_alarm_t *)linklocal_msg_post,
	cyg_alarm_create(hCounter, (cyg_alarm_t *)linklocal_msg_timer,
                     (cyg_addrword_t) &alarmData,
                     &hAlarm, &timerAlarm);

    /* This creates a periodic timer */
    cyg_alarm_initialize(hAlarm, cyg_current_time() + interval, 10);
	
}
Ejemplo n.º 9
0
/*
 * sys_init - System-dependent initialization.
 */
void
sys_init()
{
    if( sockfd == -1 )
    {
        /* Get an internet socket for doing socket ioctl's on. */
        if ((sockfd = socket(AF_INET, SOCK_DGRAM, 0)) < 0) {
            syslog(LOG_ERR, "Couldn't create IP socket: %d",errno);
            die(1);
        }
    }

    ppp_tty.pppd_wakeup = 0;
    ppp_tty.pppd_thread_running = true;
    
    ppp_rtc = cyg_real_time_clock();
    ppp_rtc_resolution = cyg_clock_get_resolution( ppp_rtc );

    cyg_alarm_create( ppp_rtc,
                      wait_input_alarm,
                      (cyg_addrword_t)&ppp_tty,
                      &ppp_tty.alarm,
                      &ppp_tty.alarm_obj);
}
Ejemplo n.º 10
0
cyg_bool_t flash( void )
{
    cyg_counter_create( &counter0, &counter0o );
    cyg_counter_create( &counter1, &counter1o );
    
    cyg_alarm_create( counter0,
                      call_me,
                      (cyg_addrword_t)12,
                      &alarm0,
                      &alarmo[0]);

    res.dividend = 1;
    res.divisor = 2;

    cyg_clock_create( res, &clock0, &clock0o );
    cyg_clock_delete( clock0 );

    cyg_alarm_delete( alarm0 );

    cyg_counter_delete( counter0 );
    cyg_counter_delete( counter1 );

    return true;
}
Ejemplo n.º 11
0
void kclock0_main(void)
{
    CYG_TEST_INIT();

    CHECK(flash());
    CHECK(flash());

    cyg_counter_create( &counter0, &counter0o);

    CHECK( 0 == cyg_counter_current_value( counter0 ) );

    cyg_counter_tick(counter0);

    CHECK( 1 == cyg_counter_current_value(counter0) );

    cyg_counter_tick(counter0);

    CHECK( 2 == cyg_counter_current_value(counter0) );

    cyg_counter_set_value( counter0, 0xffffffff );

    CHECK( 0xffffffff == cyg_counter_current_value(counter0) );

    cyg_counter_tick(counter0); // Overflows 32 bits
    
    CHECK( 0x100000000ULL == cyg_counter_current_value(counter0) );

    cyg_counter_set_value(counter0, 11);
    CHECK( 11 == cyg_counter_current_value(counter0) );
    
    /* the call_me functions cause the "called" bits to toggle
    // checking the value of called checks the parity of # of calls
    // made by each alarm.
    */

    cyg_alarm_create(counter0,
                     call_me,  (cyg_addrword_t)0x1, &alarm0, &alarmo[0]);
    cyg_alarm_create(counter0,
                     call_me,  (cyg_addrword_t)0x2, &alarm1, &alarmo[1]);
    cyg_alarm_create(counter0,
                     call_me2, (cyg_addrword_t)0x4, &alarm2, &alarmo[2]);
    
    CHECK( 0x00 == called );
    cyg_alarm_initialize(alarm0, 12,3);
    cyg_alarm_initialize(alarm2, 21,2);
    CHECK( 0x00 == called );

    cyg_counter_tick(counter0);         /* 12 a0 */
    CHECK( 0x01 == called );

    cyg_alarm_initialize(alarm1, 13,0);
    cyg_counter_tick(counter0);         /* 13 a1 */
    CHECK( 0x03 == called );

    cyg_alarm_initialize(alarm1, 17,0);
    cyg_counter_tick(counter0);         /* 14 */
    CHECK( 0x03 == called );

    cyg_counter_tick(counter0);         /* 15 a0 */
    CHECK( 0x02 == called );

    cyg_counter_tick(counter0);         /* 16 */
    cyg_counter_tick(counter0);         /* 17 a1 */
    CHECK( 0x00 == called );

    cyg_counter_tick(counter0);         /* 18 a0 */
    CHECK( 0x01 == called );

    cyg_counter_tick(counter0);         /* 19 */
    cyg_counter_tick(counter0);         /* 20 */
    cyg_counter_tick(counter0);         /* 21 a0 a2 */
    CHECK( 0x14 == called );

    cyg_counter_tick(counter0);         /* 22 */
    cyg_counter_tick(counter0);         /* 23 a2 */
    CHECK( 0x00 == called );
    
    cyg_alarm_disable(alarm2);  

    cyg_counter_tick(counter0);         /* 24 a0 */
    cyg_counter_tick(counter0);         /* 25 */
    CHECK( 0x01 == called );
    
    cyg_alarm_enable(alarm2);           /* a2 (enabled at 25) */
    CHECK( 0x15 == called );

    cyg_counter_tick(counter0);         /* 26 */
    CHECK( 0x15 == called );
    
    cyg_counter_tick(counter0);         /* 27 a0 a2 */
    cyg_counter_tick(counter0);         /* 28 */
    CHECK( 0x00 == called );
    
    cyg_counter_tick(counter0);         /* 29 a2 */
    cyg_counter_tick(counter0);         /* 30 a0 */
    cyg_counter_tick(counter0);         /* 31 a2 */
    CHECK( 0x01 == called );

    res0.dividend = 100;
    res0.divisor   = 3;

    cyg_clock_create( res0, &clock0, &clock0o );

    res1 = cyg_clock_get_resolution(clock0);
    CHECK( res0.dividend == res1.dividend );
    CHECK( res0.divisor == res1.divisor );

    res1.dividend = 12;
    res1.divisor = 25;

    cyg_clock_set_resolution(clock0, res1);
    res0 = cyg_clock_get_resolution(clock0);
    CHECK( res0.dividend == res1.dividend );
    CHECK( res0.divisor == res1.divisor );

    cyg_clock_to_counter(clock0, &counter1);

    CHECK( 0 == cyg_counter_current_value( counter1 ) );
    CHECK( 0 == cyg_current_time() );

    cyg_counter_tick(counter1);

    CHECK( 1 == cyg_counter_current_value(counter1) );

    res0 = cyg_clock_get_resolution(cyg_real_time_clock());

    /* Current time should be 0 as interrupts will still be disabled */
    CHECK( 0 == cyg_current_time() );

    CYG_TEST_PASS_FINISH("Kernel C API Clock 0 OK");
}
Ejemplo n.º 12
0
Archivo: app.c Proyecto: rbsn/FAU-EZS
void cyg_user_start(void){
	// Initialize framebuffer in graphic mode
	ezs_fb_init();
	// Initialize soundblaster
	ezs_sb16_init(&sb16,
			0x220 /* io address */,
			5 /* interrupt */,
			1 /* 8 bit DMA */,
			5 /* 16 bit DMA */);

	// Initialize HPET counter
	ezs_counter_init();

	// Initialize Tracer
	int res = ezs_trace_init();
	printf("init res: %d\r\n" , res);

	// Create keyboard interrupt, attach to handler table and umask
	cyg_interrupt_create(CYGNUM_HAL_INTERRUPT_KEYBOARD, 1, (cyg_addrword_t) &keyhandle, keyb_isr_handler, keyb_dsr_handler, &handle, &intr) ;
	cyg_interrupt_attach(handle);
	cyg_interrupt_unmask(CYGNUM_HAL_INTERRUPT_KEYBOARD);

	// Create test thread
	cyg_thread_create(17, &thread, 0, "Abtastung1", my_stack, STACKSIZE,
		&threadhndl1, &threaddata);

	// Create keyboard thread
	cyg_thread_create(1, &keythread, 0, "Keyboard", keystack, STACKSIZE,
			&keyhandle, &keydata);
			
	// Create other threads
	cyg_thread_create(1, abtastung1, 0, "thread_abtastung1", my_stack_abt1, STACKSIZE,
				&(threadhndl_abt1), &(threaddata_abt1));
	cyg_thread_create(5, abtastung2, 0, "thread_abtastung2", my_stack_abt2, STACKSIZE,
				&(threadhndl_abt2), &(threaddata_abt2));
	cyg_thread_create(10, analyse, 0, "thread_analyse", my_stack_anal, STACKSIZE,
				&(threadhndl_anal), &(threaddata_anal));
	cyg_thread_create(15, darstellung, 0, "thread_darstellung", my_stack_darst, STACKSIZE,
				&(threadhndl_darst), &(threaddata_darst));
	
	cyg_handle_t counter;
	cyg_clock_to_counter(cyg_real_time_clock(), &counter);

	/*
	cyg_alarm_create(counter, alarm_handler, (cyg_addrword_t) &threadhndl1 , &alarmhnd1, &alarm1);
	cyg_alarm_initialize(alarmhnd1, 0, 10);
	cyg_alarm_enable(alarmhnd1);
	*/
	
	cyg_alarm_create(counter, alarm_handler, (cyg_addrword_t) &threadhndl_abt1 , &alarmhnd_abt1, &alarm_abt1);
	cyg_alarm_initialize(alarmhnd_abt1, cyg_counter_current_value(counter) + 10, 10);
	
	cyg_alarm_create(counter, alarm_handler, (cyg_addrword_t) &threadhndl_abt2 , &alarmhnd_abt2, &alarm_abt2);
	cyg_alarm_initialize(alarmhnd_abt2, cyg_counter_current_value(counter) + 12, 20);
	
	cyg_alarm_create(counter, alarm_handler, (cyg_addrword_t) &threadhndl_anal , &alarmhnd_anal, &alarm_anal);
	cyg_alarm_initialize(alarmhnd_anal, cyg_counter_current_value(counter) + 14, 20);
	
	cyg_alarm_create(counter, alarm_handler, (cyg_addrword_t) &threadhndl_darst , &alarmhnd_darst, &alarm_darst);
	cyg_alarm_initialize(alarmhnd_darst, cyg_counter_current_value(counter) + 22, 100);

}