Exemplo n.º 1
0
void kmutex1_main( void )
{
    CYG_TEST_INIT();

    cyg_thread_create(4, entry0 , (cyg_addrword_t)0, "kmutex1-0",
        (void *)stack[0], STACKSIZE, &thread[0], &thread_obj[0]);
    cyg_thread_resume(thread[0]);

    cyg_thread_create(4, entry1 , (cyg_addrword_t)1, "kmutex1-1",
        (void *)stack[1], STACKSIZE, &thread[1], &thread_obj[1]);
    cyg_thread_resume(thread[1]);

    cyg_thread_create(4, entry2 , (cyg_addrword_t)2, "kmutex1-2",
        (void *)stack[2], STACKSIZE, &thread[2], &thread_obj[2]);
    cyg_thread_resume(thread[2]);

    cyg_mutex_init( &m0 );
    cyg_mutex_init( &m1 );

    cyg_cond_init( &cvar0, &m0 );
    cyg_cond_init( &cvar1, &m0 );
    cyg_cond_init( &cvar2, &m1 );

    cyg_scheduler_start();

    CYG_TEST_FAIL_FINISH("Not reached");
}
Exemplo n.º 2
0
usbTerm::usbTerm(cyg_uint32 b_size, const char * const prompt_str) : cTerm(b_size, prompt_str)
{
	mBannerFlag = false;

	cyg_thread_create(USB_PRIORITY,
			usbTerm::rx_thread_func,
			(cyg_addrword_t)this,
			(char *)"usbTerm",
			mRXStack,
			USB_STACK_SIZE,
			&mRXThreadHandle,
			&mRXThread);

	cyg_thread_resume(mRXThreadHandle);


	mUSBRXlen = 0;
	mCMDidx = 0;
	mUSBstatus = unknown;

	cyg_mutex_init(&mUSBmutex);
	cyg_cond_init(&mUSBrxCond, &mUSBmutex);



	USBD_Init(&USB_OTG_dev,
			USB_OTG_FS_CORE_ID,
			&USR_desc,
			&USBD_CDC_cb,
			&USR_cb);

}
Exemplo n.º 3
0
static int 
e_cond_new(lua_State *L) 
{
    cyg_mutex_t *mx;
    cyg_cond_t  *cond;
    mx   = (cyg_mutex_t *) check_user_data(L, 1, E_MUTEX);
    cond = (cyg_cond_t *) lua_newuserdata(L, sizeof(cyg_cond_t));  
    cyg_cond_init(cond, mx);
    set_user_data_type(L, E_COND);
    return 1;
}
Exemplo n.º 4
0
// init
void reconos_hwsched_init() {
    reconos_hwthread_list = NULL;
    num_global_yield_requests = 0;

    cyg_mutex_init(&reconos_hwsched_mutex);
    cyg_cond_init(&reconos_hwsched_condvar, &reconos_hwsched_mutex);

    cyg_thread_create( 0, 
                       reconos_hw_scheduler, 
                       (cyg_addrword_t)NULL, 
                       "RECONOS_HW_SCHEDULER", 
                       reconos_hwsched_stack,
                       RECONOS_HWSCHED_STACK_SIZE,
                       &reconos_hwsched_thread_handle,
                       &reconos_hwsched_thread
                    );

    cyg_thread_resume( reconos_hwsched_thread_handle );
};
Exemplo n.º 5
0
void
cyg_start(void)
{
    CYG_TEST_INIT();
    
    cyg_mutex_init(&can_lock);
    cyg_cond_init(&can_wait, &can_lock);
    
    //
    // create the main thread
    //
    cyg_thread_create(4, can_thread, 
                        (cyg_addrword_t) 0,
                        "can_thread", 
                        (void *) can_thread_data.stack, 
                        1024 * sizeof(long),
                        &can_thread_data.hdl, 
                        &can_thread_data.obj);
                        
    cyg_thread_resume(can_thread_data.hdl);
    
    cyg_scheduler_start();
}
Exemplo n.º 6
0
void controller( cyg_addrword_t id )
{
    cyg_priority_t pri;
    int i;

    cyg_mutex_init( &worker_mutex );
    cyg_cond_init( &worker_cv, &worker_mutex );
    
// 1 thread, it is running, it calls BREAKME();
//  +++ Thread status returned:
//  +++ 1 thread, running, is the current one
    
    breakme();

// Create N more threads; they are all suspended after creation.  Adjust
// the priorities of all the threads to lower than the controlling thread.
// Make them all be distinct priorities as far as possible.  BREAKME();
//  +++ 1 thread, running, + N suspended ones of different prios.

    for( i = 1; i < THREADS; i++ )
    {
        pri = CONTROLLER_PRI_HI + 1 + i % WORKER_PRI_RANGE;

        cyg_thread_create(pri, worker, (cyg_addrword_t)i, "worker",
                          (void *)(&thread_stack[i]), STACKSIZE,
                          &thread_handle[i], &thread[i]);

    }

    breakme();

// Adjust the priorities of all the threads to lower than the controlling
// thread.  Make them all be THE SAME priority.  BREAKME();
//  +++ 1 thread, running, + N suspended ones of same prio.

    for( i = 1; i < THREADS; i++ )
    {
        cyg_thread_set_priority( thread_handle[i], WORKER_PRI );
    }

    breakme();
    
// Release all the N threads, BREAKME();
//  +++ 1 thread, running, + N ready ones of same prio.

    for( i = 1; i < THREADS; i++ )
    {
        cyg_thread_resume( thread_handle[i] );
    }

    breakme();

// Adjust the priorities of all the threads, lower than the controlling
// thread.  Make them all be distinct priorities as far as possible.
// BREAKME();
//  +++ 1 thread, running, + N ready ones of different prios.

    for( i = 1; i < THREADS; i++ )
    {
        pri = CONTROLLER_PRI_HI + 1 + i % WORKER_PRI_RANGE;
        
        cyg_thread_set_priority( thread_handle[i], pri );
    }

    breakme();
    
// Command all the N threads to sleep; switch my own priority to lower
// than theirs so that they all run and sleep, then I get back in and
// BREAKME();
// +++ 1 thread, running, + N sleeping ones of different prios.

    worker_state = WORKER_STATE_WAIT;

    cyg_thread_set_priority( thread_handle[0], CONTROLLER_PRI_LO );

    breakme();
    
// Make them all be THE SAME priority; BREAKME();
//  +++ 1 thread, running, + N sleeping ones of same prio.

    for( i = 1; i < THREADS; i++ )
    {
        cyg_thread_set_priority( thread_handle[i], WORKER_PRI );
    }

    breakme();

// Wake them all up, they'll loop once and sleep again; I get in and
// BREAKME();
//  +++ 1 thread, running, + N sleeping ones of same prio.

    cyg_cond_broadcast( &worker_cv );

    breakme();

// Adjust the priorities of all the threads, higher than the controlling
// thread.  Make them all be distinct priorities as far as possible.
// BREAKME();
//  +++ 1 thread, running, + N sleeping ones of different prios.

    for( i = 1; i < THREADS; i++ )
    {
        pri = CONTROLLER_PRI_HI + 1 + i % WORKER_PRI_RANGE;
        
        cyg_thread_set_priority( thread_handle[i], pri );
    }

    breakme();

// Wake them all up, they'll loop once and sleep again; I get in and
// BREAKME();
//  +++ 1 thread, running, + N sleeping ones of different prios.

    cyg_cond_broadcast( &worker_cv );

    breakme();

// Set them all the same prio, set me to the same prio, BREAKME();
//  +++ 1 running, + N sleeping, *all* the same prio.

    for( i = 0; i < THREADS; i++ )
    {
        cyg_thread_set_priority( thread_handle[i], WORKER_PRI );
    }

    breakme();

// Wake them all up, they'll loop once and sleep again; I get in and
// BREAKME(); repeatedly until they have all slept again.
//  +++ 1 running, + some sleeping, some ready, *all* the same prio.

    cyg_cond_broadcast( &worker_cv );

//    cyg_thread_yield();
    
    do
    {
        breakme();
        
    } while( workers_asleep != THREADS-1 ); 

    breakme();
    
// Suspend some of the threads, BREAKME();
//  +++ 1 running, + some sleeping, some suspended, *all* the same prio.

    for( i = 1; i < THREADS; i++ )
    {
        // suspend every 3rd thread
        if( 0 == (i % 3) ) cyg_thread_suspend( thread_handle[i] );
    }

    breakme();


// Change the prios all different, change my prio to highest , BREAKME();
//  +++ 1 running, + some sleeping, some suspended, different prios.

    cyg_thread_set_priority( thread_handle[0], CONTROLLER_PRI_HI );
        
    for( i = 1; i < THREADS; i++ )
    {
        pri = CONTROLLER_PRI_HI + 1 + i % WORKER_PRI_RANGE;
        
        cyg_thread_set_priority( thread_handle[i], pri );
    }

    breakme();
    
// Wake up all the threads, BREAKME();
//  +++ 1 running, + some ready, some suspended/ready, different prios.

    cyg_cond_broadcast( &worker_cv );

    breakme();


// Change my prio to lowest, let all the threads run, BREAKME().
//  +++ 1 running + some sleeping, some suspended/ready, different prios.

    cyg_thread_set_priority( thread_handle[0], CONTROLLER_PRI_LO );
    
    breakme();
    
// Resume all the threads, BREAKME();
//  +++ 1 running, + N ready, different prios.

    for( i = 1; i < THREADS; i++ )
    {
        cyg_thread_resume( thread_handle[i] );
    }
    
    breakme();
    
// Command some of the N threads to call BREAKME(); themselves (then sleep
// again).  Change my prio to low, so that they all get to run and hit the
// breakpoint.
//  +++ A different one running every time, others in a mixture of
//      ready and sleeping states.
    
    worker_state = WORKER_STATE_BREAK;

    cyg_cond_broadcast( &worker_cv );
    
    cyg_thread_set_priority( thread_handle[0], CONTROLLER_PRI_LO );
    
    breakme();
    
// Command all the threads to exit; switch my own priority to lower
// than theirs so that they all run and exit, then I get back in and
// BREAKME();
//  +++ 1 thread, running, + N dormant ones.

    worker_state = WORKER_STATE_EXIT;

    cyg_cond_broadcast( &worker_cv );
    
    breakme();

#if 0

// Cannot do this yet...
    
// Destroy some of the N threads to invalidate their IDs.  Re-create them
// with new IDs, so that we get IDs 1,2,4,6,8,11,12,13,14,15 in use instead
// of 1,2,3,4,5,6,7,8,9, if you see what I mean.  Do all the above again.
// Loop forever, or whatever...

#endif

    breakme();
    
    CYG_TEST_PASS_FINISH("GDB Thread test OK");
    
}
Exemplo n.º 7
0
void resinit(void)
{
    cyg_mutex_init(&res_lock);
    cyg_cond_init(&res_wait, &res_lock);
}
Exemplo n.º 8
0
//static 
wlan_private *
wlan_add_card(void *card)
{
    //struct net_device *dev = NULL;
    wlan_private *priv = NULL;
	//struct eth_drv_sc *dev;

    ENTER();

    /* probe the card */
    if (sbi_probe_card(card) < 0) {
        diag_printf("NO card found!\n");
        return NULL;
    }
#if 0
    /* Allocate an Ethernet device and register it */
    if (!(dev = alloc_etherdev(sizeof(wlan_private)))) {
        diag_printf("Init ethernet device failed!\n");
        return NULL;
    }
#endif

    priv = (wlan_private *)((cyg_uint32)&w99702_priv_data0 | NON_CACHE_FLAG);

    /* allocate buffer for wlan_adapter */
    MALLOC(priv->adapter, wlan_adapter *, sizeof(wlan_adapter), 0, M_NOWAIT);
    if(!priv->adapter)
    {
        diag_printf("Allocate buffer for wlan_adapter failed!\n");
        goto err_kmalloc;
    }
	priv->adapter = (wlan_adapter *)((unsigned int)priv->adapter | NON_CACHE_FLAG);
    /* init wlan_adapter */
    memset(priv->adapter, 0, sizeof(wlan_adapter));

    priv->wlan_dev.netdev = &w99702_netdev;
    priv->wlan_dev.card = card;
   // wlanpriv = priv;

   // SET_MODULE_OWNER(dev);

 #if 0
    /* Setup the OS Interface to our functions */
    dev->open = wlan_open;
    dev->hard_start_xmit = wlan_hard_start_xmit;
    dev->stop = wlan_close;
    dev->do_ioctl = wlan_do_ioctl;
    dev->set_mac_address = wlan_set_mac_address;

#define	WLAN_WATCHDOG_TIMEOUT	(2 * HZ)

    dev->tx_timeout = wlan_tx_timeout;
    dev->get_stats = wlan_get_stats;
    dev->watchdog_timeo = WLAN_WATCHDOG_TIMEOUT;

#ifdef	WIRELESS_EXT
    dev->get_wireless_stats = wlan_get_wireless_stats;
    dev->wireless_handlers = (struct iw_handler_def *) &wlan_handler_def;
#endif
#define NETIF_F_DYNALLOC 16
    dev->features |= NETIF_F_DYNALLOC;
    dev->flags |= IFF_BROADCAST | IFF_MULTICAST;
    dev->set_multicast_list = wlan_set_multicast_list;

#endif//clyu



#ifdef MFG_CMD_SUPPORT
    /* Required for the mfg command */
    //init_waitqueue_head(&priv->adapter->mfg_cmd_q);
    cyg_cond_init(&priv->adapter->mfg_cond_q, &priv->adapter->mfg_mutex);
#endif

    //init_waitqueue_head(&priv->adapter->ds_awake_q);
    cyg_cond_init(&priv->adapter->ds_cond_q, &priv->adapter->ds_mutex);

#ifdef ENABLE_PM
    if (!(wlan_pm_dev = pm_register(PM_UNKNOWN_DEV, 0, wlan_pm_callback)))
        diag_printf("Failed to register PM callback\n");
#endif

    INIT_LIST_HEAD(&priv->adapter->CmdFreeQ);
    INIT_LIST_HEAD(&priv->adapter->CmdPendingQ);

    diag_printf("Starting kthread...\n");
    priv->MainThread.priv = priv;
	
	cyg_thread_create(WIRELESS_THREAD_PRIORITY,          // Priority
                      wlan_service_main_thread,                   // entry
                      (cyg_addrword_t)&w99702_sc,                    // entry parameter
                      "pxa270m card support",                // Name
                      &thread_stack[0],         // Stack
                      sizeof(thread_stack),                            // Size
                      &thread_handle,    // Handle
                      &thread_data       // Thread data structure
            );
    priv->MainThread.task = thread_handle;
    cyg_thread_resume(thread_handle);    // Start it
	
//    ConfigureThreadPriority();

#ifdef REASSOCIATION
    priv->ReassocThread.priv = priv;
   /*
    wlan_create_thread(wlan_reassociation_thread,
                       &priv->ReassocThread, "wlan_reassoc_service");*/
	
	cyg_thread_create(WIRELESS_THREAD_PRIORITY,          // Priority
                      wlan_reassociation_thread,                   // entry
                      (cyg_addrword_t)&w99702_sc,                    // entry parameter
                      "wlan_reassoc_service",                // Name
                      &reassoc_stack[0],         // Stack
                      sizeof(reassoc_stack),                            // Size
                      &reassoc_handle,    // Handle
                      &reassoc_data       // Thread data structure
            );
	priv->ReassocThread.task = reassoc_handle;
    cyg_thread_resume(reassoc_handle);    // Start it
	
#endif /* REASSOCIATION */

    /*
     * Register the device. Fillup the private data structure with
     * relevant information from the card and request for the required
     * IRQ. 
     */

    if (sbi_register_dev(priv) < 0) {
        diag_printf("Failed to register wlan device!\n");
        goto err_registerdev;
    }
#if 0
    diag_printf("%s: Marvell Wlan 802.11 Adapter "
           "revision 0x%02X at IRQ %i\n", dev->name,
           priv->adapter->chip_rev, dev->irq);
#endif
    //wlan_proc_entry(priv, dev);
#ifdef PROC_DEBUG
    wlan_debug_entry(priv, dev);
#endif

#if 0
    /* Get the CIS Table */
    sbi_get_cis_info(priv);
#endif

    /* init FW and HW */
    if (wlan_init_fw(priv)) {
        diag_printf("Firmware Init Failed\n");
        goto err_init_fw;
    }
#if 0
    if (register_netdev(dev)) {
        printk(KERN_ERR "Cannot register network device!\n");
        goto err_init_fw;
    }
#endif

    LEAVE();
    return priv;

  err_init_fw:
    sbi_unregister_dev(priv);

  err_registerdev:
    /* Stop the thread servicing the interrupts */
    //wake_up_interruptible(&priv->MainThread.waitQ);

    cyg_flag_setbits( &priv->MainThread.waitQ_flag_q, 1 ); 
    wlan_terminate_thread(&priv->MainThread);

#ifdef REASSOCIATION
    //wake_up_interruptible(&priv->ReassocThread.waitQ);

    cyg_flag_setbits( &priv->ReassocThread.waitQ_flag_q, 1 ); 
    wlan_terminate_thread(&priv->ReassocThread);
#endif /* REASSOCIATION */
  err_kmalloc:
   // unregister_netdev(dev);
    FREE(priv->adapter, 0);
    //wlanpriv = NULL;

    LEAVE();
    return NULL;
}