Ejemplo n.º 1
0
void
kbd_init(void)
{
    // Initialize environment, setup interrupt handler
    cyg_drv_interrupt_create(CYGNUM_HAL_INTERRUPT_KBDINT,
                             99,                     // Priority - what goes here?
                             0,                      //  Data item passed to interrupt handler
                             (cyg_ISR_t *)keyboard_isr,
                             (cyg_DSR_t *)keyboard_dsr,
                             &kbd_interrupt_handle,
                             &kbd_interrupt);
    cyg_drv_interrupt_attach(kbd_interrupt_handle);
    cyg_drv_interrupt_acknowledge(CYGNUM_HAL_INTERRUPT_KBDINT);
    cyg_drv_interrupt_unmask(CYGNUM_HAL_INTERRUPT_KBDINT);
    // Set up the mbox for keyboard data
    cyg_mbox_create(&kbd_events_mbox_handle, &kbd_events_mbox);
    // This semaphore is set when there is a keypress
    cyg_semaphore_init(&kbd_sem, 0);  
    // Create a thread whose job it is to de-bounce the keyboard and
    // actually process the input, turning it into a series of events
    cyg_thread_create(10,                           // Priority - just a number
                      kbd_server,                   // entry
                      0,                            // initial parameter
                      "KBD_server",                 // Name
                      &kbd_server_stack[0],         // Stack
                      STACK_SIZE,                   // Size
                      &kbd_server_thread_handle,    // Handle
                      &kbd_server_thread_data       // Thread data structure
            );
    cyg_thread_resume(kbd_server_thread_handle);  // Start it
}
Ejemplo n.º 2
0
/*
 * Create a new mbox.If no memory is available return NULL 
 */
sys_mbox_t sys_mbox_new(void)
{
	cyg_mbox * mbox;
	cyg_handle_t m;
	mbox = (cyg_mbox *)cyg_mempool_var_try_alloc(var_mempool_h, sizeof(cyg_mbox));
	
	/* out of memory? */
	if(!mbox) 
		return SYS_MBOX_NULL;
	
	cyg_mbox_create(&m, mbox);
	return m;
}
Ejemplo n.º 3
0
void DNS_init(void) 
{
	int val=0;

	CFG_get(CFG_DNS_EN, &val);
	if(val)
	{
		cyg_mbox_create( &dns_mbox_id, &dns_mbox_obj );	
		cyg_thread_create(DNS_PRIORITY, &DNS_daemon, 0, "DNS_daemon",
                     &dns_stack, DNS_STACKSIZE,
                     &dns_handle, &dns_thread);
		cyg_thread_resume(dns_handle);	
	}
   	
}
Ejemplo n.º 4
0
void 
create_cleanup_thread(void)
{
    unsigned int err;

    cyg_mbox_create(&cleanup.mbox_handle, &cleanup_mbox);
    cyg_semaphore_init(&cleanup.cleanup_sem, 0);
    
    if((err = shell_create_thread(NULL,
				 5,
				 cleanup_thread,
				 0,
				 "Cleanup Thread",
				 NULL,
				 0,
				 NULL) != SHELL_OK)) {
	SHELL_ERROR("Failed to create Cleanup thread\n");
	HAL_PLATFORM_RESET();
    }
    
    SHELL_DEBUG_PRINT("Created Cleanup thread\n");
}
Ejemplo n.º 5
0
static void
lcd_panel_init(void)
{
    // Enable touch panel
    *(volatile cyg_uint8 *)PEDR   |= 0x04;  

    // Idle state (so interrupt works)
    *(volatile cyg_uint8 *)TOUCH_CTL = 0x70;  

    // Enable ADC machinery
    *(volatile cyg_uint32 *)SYSCON1 |= SYSCON1_ADC_CLOCK_128kHZ;

    cyg_drv_interrupt_create(CYGNUM_HAL_INTERRUPT_EINT2,
                             99,                     // Priority - what goes here?
                             0,                      //  Data item passed to interrupt handler
                             lcd_panel_isr,
                             lcd_panel_dsr,
                             &lcd_panel_interrupt_handle,
                             &lcd_panel_interrupt);
    cyg_drv_interrupt_attach(lcd_panel_interrupt_handle);
    cyg_drv_interrupt_acknowledge(CYGNUM_HAL_INTERRUPT_EINT2);
    cyg_drv_interrupt_unmask(CYGNUM_HAL_INTERRUPT_EINT2);
    // Set up the mbox for panel data
    cyg_mbox_create(&lcd_panel_events_mbox_handle, &lcd_panel_events_mbox);
    // This semaphore is set when there is a touch
    cyg_semaphore_init(&lcd_panel_sem, 0);  
    // Create a thread whose job it is to de-bounce the keyboard and
    // actually process the input, turning it into a series of events
    cyg_thread_create(10,                           // Priority - just a number
                      lcd_panel_server,             // entry
                      0,                            // initial parameter
                      "LCD_PANEL_server",           // Name
                      &lcd_panel_server_stack[0],   // Stack
                      STACK_SIZE,                   // Size
                      &lcd_panel_server_thread_handle,    // Handle
                      &lcd_panel_server_thread_data       // Thread data structure
            );
    cyg_thread_resume(lcd_panel_server_thread_handle);  // Start it
}
Ejemplo n.º 6
0
/**
creates the particle array, resources and communication threads

@param number_of_particles: number of particles
@param particle_block_size: size of a particle block
*/
void create_particle_filter (unsigned int number_of_particles, unsigned int particle_block_size){

   int i;

   // set variables
   N = number_of_particles;
   block_size = particle_block_size;
 
   // particles
   volatile int * mem_p = malloc((N * sizeof(particle)) + 8 + 256); // 8 bytes extra
   volatile int * src_p = (volatile int*)(((int)mem_p / 8 + 1) * 8);

   // indexes
   volatile int * mem_i = malloc((N * sizeof(particle)) + 8 + 256); // 8 bytes extra
   volatile int * src_i = (volatile int*)(((int)mem_i / 8 + 1) * 8);

   // observations
   volatile int * mem_o = malloc((N * sizeof(observation)) + 8 + 256 ); // 8 bytes extra
   volatile int * src_o = (volatile int*)(((int)mem_o / 8 + 1) * 8);

   // reference data
   volatile int * mem_r = malloc(sizeof(observation) + 8 + 256 ); // 8 bytes extra
   volatile int * src_r = (volatile int*)(((int)mem_r / 8 + 1) * 8);


   // Resampling function U
   volatile int * mem_U; 
   volatile int * src_U;

   number_of_blocks = N / block_size;

   if (N % block_size > 0) number_of_blocks++;

   mem_U = (int*) malloc((number_of_blocks *(sizeof(int))) + 8 + 256 ); // 8 bytes extra
   src_U =  (volatile int*)(((int)mem_U / 8 + 1) * 8);
   
   particles    = (particle *   ) src_p;
   indexes      = (index_type * ) src_i;
   ref_data     = (observation *) src_r;
   observations = (observation *) src_o;
   U            = (int *        ) src_U;
   

   /*
   particles    = (particle *   ) 0x80000000;
   observations = (observation *) 0x80002000;
   indexes      = (index_type * ) 0x8000D000;
   ref_data     = (reference_data_type *) 0x8000E000;
   U            = (int *        ) 0x8000F000;
   

   number_of_blocks = N / block_size;
   if (N % block_size > 0) number_of_blocks++;
   */
   
   #ifndef ONLYPC
   // create message box variables
   mb_sampling        = (cyg_mbox *) malloc (sizeof(cyg_mbox));
   mb_importance   = (cyg_mbox *) malloc (sizeof(cyg_mbox));
   mb_resampling      = (cyg_mbox *) malloc (sizeof(cyg_mbox));
   mb_sampling_done   = (cyg_mbox *) malloc (sizeof(cyg_mbox));
   mb_importance_done = (cyg_mbox *) malloc (sizeof(cyg_mbox));
   mb_resampling_done = (cyg_mbox *) malloc (sizeof(cyg_mbox));

   // create message box handles
   mb_sampling_handle      = (cyg_handle_t *) malloc (sizeof(cyg_handle_t));
   mb_importance_handle = (cyg_handle_t *) malloc (sizeof(cyg_handle_t));;
   mb_resampling_handle    = (cyg_handle_t *) malloc (sizeof(cyg_handle_t));
   mb_sampling_done_handle   = (cyg_handle_t *) malloc (sizeof(cyg_handle_t));
   mb_importance_done_handle = (cyg_handle_t *) malloc (sizeof(cyg_handle_t));
   mb_resampling_done_handle = (cyg_handle_t *) malloc (sizeof(cyg_handle_t));

   // create message boxes
   cyg_mbox_create( mb_sampling_handle,        mb_sampling);
   cyg_mbox_create( mb_importance_handle,      mb_importance );
   cyg_mbox_create( mb_resampling_handle,      mb_resampling );
   cyg_mbox_create( mb_sampling_done_handle,   mb_sampling_done );
   cyg_mbox_create( mb_importance_done_handle, mb_importance_done );
   cyg_mbox_create( mb_resampling_done_handle, mb_resampling_done ); 

   // create message box variable for time measurement
   hw_mb_sampling_measurement      = (cyg_mbox *) malloc (sizeof(cyg_mbox));
   hw_mb_observation_measurement   = (cyg_mbox *) malloc (sizeof(cyg_mbox));
   hw_mb_importance_measurement    = (cyg_mbox *) malloc (sizeof(cyg_mbox));
   hw_mb_resampling_measurement    = (cyg_mbox *) malloc (sizeof(cyg_mbox));

   // create message box handles for time measurements 
   hw_mb_sampling_measurement_handle      = (cyg_handle_t *) malloc (sizeof(cyg_handle_t));
   hw_mb_observation_measurement_handle   = (cyg_handle_t *) malloc (sizeof(cyg_handle_t));
   hw_mb_importance_measurement_handle    = (cyg_handle_t *) malloc (sizeof(cyg_handle_t));
   hw_mb_resampling_measurement_handle    = (cyg_handle_t *) malloc (sizeof(cyg_handle_t));

   // create message boxes for time measurements
   cyg_mbox_create( hw_mb_sampling_measurement_handle,    hw_mb_sampling_measurement);
   cyg_mbox_create( hw_mb_observation_measurement_handle, hw_mb_observation_measurement);
   cyg_mbox_create( hw_mb_importance_measurement_handle,  hw_mb_importance_measurement);
   cyg_mbox_create( hw_mb_resampling_measurement_handle,  hw_mb_resampling_measurement);

   // create pre threads
   create_preSampling_thread();
   create_preResampling_thread();
   #endif

   // set inital indexes
   for (i=0; i<N; i++)
   {

       indexes[i].index = i;
       indexes[i].replication = 1;   
   }
}
Ejemplo n.º 7
0
int main( int argc, char *argv[] )
{

    unsigned int i, start_count = 0, done_count = 0, j;
    timing_t t_start = 0, t_stop = 0, t_gen = 0, t_sort = 0, t_merge =
                                       0, t_check = 0, t_tmp;

    printf( "-------------------------------------------------------\n"
            "ReconOS hardware multithreading case study (sort)\n"
            "(c) Computer Engineering Group, University of Paderborn\n\n"
            "eCos, single-threaded hardware version (" __FILE__ ")\n"
            "Compiled on " __DATE__ ", " __TIME__ ".\n"
            "-------------------------------------------------------\n\n" );

#ifdef USE_CACHE
    printf( "enabling data cache for external ram\n" );
    XCache_EnableDCache( 0x80000000 );
#else
    printf( "data cache disabled\n" );
    XCache_DisableDCache(  );
#endif

    data = buf_a;

    //----------------------------------
    //-- GENERATE DATA
    //----------------------------------
    printf( "Generating data..." );
    t_start = gettime(  );
    generate_data( data, SIZE );
    t_stop = gettime(  );
    t_gen = calc_timediff_ms( t_start, t_stop );
    printf( "done\n" );

#ifdef USE_CACHE
    // flush cache contents - the hardware can only read from main memory
    // TODO: storing could be more efficient
    printf( "Flushing cache..." );
    XCache_EnableDCache( 0x80000000 );
    printf( "done\n" );
#endif

    //----------------------------------
    //-- SORT DATA
    //----------------------------------
    // create mail boxes for 'start' and 'complete' messages
    cyg_mbox_create( &mb_start_handle, &mb_start );
    cyg_mbox_create( &mb_done_handle, &mb_done );
    // create sorting thread
    reconos_hwthread_create( 16,                                               // priority
                             0,                                                // entry data (not needed)
                             "MT_HW_SORT",                                     // thread name
                             hwthread_sorter_stack,                            // stack
                             STACK_SIZE,                                       // stack size
                             &hwthread_sorter_handle,                          // thread handle
                             &hwthread_sorter,                                 // thread object
                             (void*)UPBHWR_OSIF_0_BASEADDR,
                             XPAR_OPB_INTC_0_OSIF_0_INTERRUPT_INTR+1,
                             //                         ( void * ) XPAR_PLB_RECONOS_SLOT_0_BASEADDR,      // base address
                             //                         XPAR_OPB_INTC_0_PLB_RECONOS_SLOT_0_INTERRUPT_INTR + 1,     // interrupt
                             hwthread_sorter_resources,                        // resource array
                             2,                                                 // number of resources
                             0xFFFFFFFF, 0xFFFFFFFF
                           );
    cyg_thread_resume( hwthread_sorter_handle );

    printf( "Sorting data..." );
    i = 0;
    while ( done_count < SIZE / N ) {
        t_start = gettime(  );
        // if we have something to distribute,
        // put as many as possile into the start mailbox
        while ( start_count < SIZE / N ) {
            if ( cyg_mbox_tryput( mb_start_handle, ( void * ) &data[i] ) ==
                    true ) {
                start_count++;
                i += N;
            } else {                                                           // mailbox full
                break;
            }
        }
        t_stop = gettime(  );
        t_sort += calc_timediff_ms( t_start, t_stop );
        // see whether anybody's done
        t_start = gettime(  );
        if ( ( t_tmp = ( timing_t ) cyg_mbox_get( mb_done_handle ) ) != 0 ) {
            done_count++;
        } else {
            printf( "cyg_mbox_get returned NULL!\n" );
        }
        t_stop = gettime(  );
        t_sort += calc_timediff_ms( t_start, t_stop );
    }
    printf( "done\n" );


#ifdef USE_CACHE
    // flush cache contents
    // TODO: invalidating would suffice
    printf( "Flushing cache..." );
    XCache_EnableDCache( 0x80000000 );
    printf( "done\n" );
#endif


    //----------------------------------
    //-- MERGE DATA
    //----------------------------------
    printf( "Merging data..." );
    t_start = gettime(  );
    data = recursive_merge( data, buf_b, SIZE, N, simple_merge );
    t_stop = gettime(  );
    t_merge = calc_timediff_ms( t_start, t_stop );
    printf( "done\n" );

    //----------------------------------
    //-- CHECK DATA
    //----------------------------------
    printf( "Checking sorted data..." );
    t_start = gettime(  );
    if ( check_data( data, SIZE ) != 0 )
        printf( "CHECK FAILED!\n" );
    else
        printf( "check successful.\n" );
    t_stop = gettime(  );
    t_check = calc_timediff_ms( t_start, t_stop );

    printf( "\nRunning times (size: %d words):\n"
            "\tGenerate data: %d ms\n"
            "\tSort data    : %d ms\n"
            "\tMerge data   : %d ms\n"
            "\tCheck data   : %d ms\n"
            "\nTotal computation time (sort & merge): %d ms\n",
            SIZE, t_gen, t_sort, t_merge, t_check, t_sort + t_merge );


    return 0;

}