Example #1
0
/**
 * This function will check timer list, if a timeout event happens, the
 * corresponding timeout function will be invoked.
 *
 * @note this function shall be invoked in operating system timer interrupt.
 */
void rt_timer_check(void)
{
    struct rt_timer *t;
    rt_tick_t current_tick;
    register rt_base_t level;

    RT_DEBUG_LOG(RT_DEBUG_TIMER, ("timer check enter\n"));

    current_tick = rt_tick_get();

    /* disable interrupt */
    level = rt_hw_interrupt_disable();

    while (!rt_list_isempty(&rt_timer_list[RT_TIMER_SKIP_LIST_LEVEL-1]))
    {
        t = rt_list_entry(rt_timer_list[RT_TIMER_SKIP_LIST_LEVEL - 1].next,
                          struct rt_timer, row[RT_TIMER_SKIP_LIST_LEVEL - 1]);

        /*
         * It supposes that the new tick shall less than the half duration of
         * tick max.
         */
        if ((current_tick - t->timeout_tick) < RT_TICK_MAX/2)
        {
            RT_OBJECT_HOOK_CALL(rt_timer_timeout_hook, (t));

            /* remove timer from timer list firstly */
            _rt_timer_remove(t);

            /* call timeout function */
            t->timeout_func(t->parameter);

            /* re-get tick */
            current_tick = rt_tick_get();

            RT_DEBUG_LOG(RT_DEBUG_TIMER, ("current tick: %d\n", current_tick));

            if ((t->parent.flag & RT_TIMER_FLAG_PERIODIC) &&
                (t->parent.flag & RT_TIMER_FLAG_ACTIVATED))
            {
                /* start it */
                t->parent.flag &= ~RT_TIMER_FLAG_ACTIVATED;
                rt_timer_start(t);
            }
            else
            {
                /* stop timer */
                t->parent.flag &= ~RT_TIMER_FLAG_ACTIVATED;
            }
        }
        else
            break;
    }

    /* enable interrupt */
    rt_hw_interrupt_enable(level);

    RT_DEBUG_LOG(RT_DEBUG_TIMER, ("timer check leave\n"));
}
Example #2
0
/**
 * This function will check timer list, if a timeout event happens, the
 * corresponding timeout function will be invoked.
 */
void rt_soft_timer_check(void)
{
    rt_tick_t current_tick;
    rt_list_t *n;
    struct rt_timer *t;

    RT_DEBUG_LOG(RT_DEBUG_TIMER, ("software timer check enter\n"));

    current_tick = rt_tick_get();

    for (n = rt_soft_timer_list[RT_TIMER_SKIP_LIST_LEVEL-1].next;
         n != &(rt_soft_timer_list[RT_TIMER_SKIP_LIST_LEVEL-1]);)
    {
        t = rt_list_entry(n, struct rt_timer, row[RT_TIMER_SKIP_LIST_LEVEL-1]);

        /*
         * It supposes that the new tick shall less than the half duration of
         * tick max.
         */
        if ((current_tick - t->timeout_tick) < RT_TICK_MAX / 2)
        {
            RT_OBJECT_HOOK_CALL(rt_timer_timeout_hook, (t));

            /* move node to the next */
            n = n->next;

            /* remove timer from timer list firstly */
            _rt_timer_remove(t);

            /* call timeout function */
            t->timeout_func(t->parameter);

            /* re-get tick */
            current_tick = rt_tick_get();

            RT_DEBUG_LOG(RT_DEBUG_TIMER, ("current tick: %d\n", current_tick));

            if ((t->parent.flag & RT_TIMER_FLAG_PERIODIC) &&
                (t->parent.flag & RT_TIMER_FLAG_ACTIVATED))
            {
                /* start it */
                t->parent.flag &= ~RT_TIMER_FLAG_ACTIVATED;
                rt_timer_start(t);
            }
            else
            {
                /* stop timer */
                t->parent.flag &= ~RT_TIMER_FLAG_ACTIVATED;
            }
        }
        else break; /* not check anymore */
    }

    RT_DEBUG_LOG(RT_DEBUG_TIMER, ("software timer check leave\n"));
}
/**
 * This function will release the previously allocated memory block by
 * rt_malloc. The released memory block is taken back to system heap.
 *
 * @param rmem the address of memory which will be released
 */
void rt_free(void *rmem)
{
    struct heap_mem *mem;

    RT_DEBUG_NOT_IN_INTERRUPT;

    if (rmem == RT_NULL)
        return;
    RT_ASSERT((((rt_uint32_t)rmem) & (RT_ALIGN_SIZE-1)) == 0);
    RT_ASSERT((rt_uint8_t *)rmem >= (rt_uint8_t *)heap_ptr &&
              (rt_uint8_t *)rmem < (rt_uint8_t *)heap_end);

    RT_OBJECT_HOOK_CALL(rt_free_hook, (rmem));

    if ((rt_uint8_t *)rmem < (rt_uint8_t *)heap_ptr ||
        (rt_uint8_t *)rmem >= (rt_uint8_t *)heap_end)
    {
        RT_DEBUG_LOG(RT_DEBUG_MEM, ("illegal memory\n"));

        return;
    }

    /* Get the corresponding struct heap_mem ... */
    mem = (struct heap_mem *)((rt_uint8_t *)rmem - SIZEOF_STRUCT_MEM);

    RT_DEBUG_LOG(RT_DEBUG_MEM,
                 ("release memory 0x%x, size: %d\n", 
                  (rt_uint32_t)rmem, 
                  (rt_uint32_t)(mem->next - ((rt_uint8_t *)mem - heap_ptr))));


    /* protect the heap from concurrent access */
    rt_sem_take(&heap_sem, RT_WAITING_FOREVER);

    /* ... which has to be in a used state ... */
    RT_ASSERT(mem->used);
    RT_ASSERT(mem->magic == HEAP_MAGIC);
    /* ... and is now unused. */
    mem->used  = 0;
    mem->magic = 0;

    if (mem < lfree)
    {
        /* the newly freed struct is now the lowest */
        lfree = mem;
    }

#ifdef RT_MEM_STATS
    used_mem -= (mem->next - ((rt_uint8_t*)mem - heap_ptr));
#endif

    /* finally, see if prev or next are free also */
    plug_holes(mem);
    rt_sem_release(&heap_sem);
}
Example #4
0
/**
 * @ingroup SystemInit
 *
 * This function will init system heap
 *
 * @param begin_addr the beginning address of system page
 * @param end_addr the end address of system page
 */
void rt_system_heap_init(void *begin_addr, void *end_addr)
{
    rt_uint32_t limsize, npages;

    RT_DEBUG_NOT_IN_INTERRUPT;

    /* align begin and end addr to page */
    heap_start = RT_ALIGN((rt_uint32_t)begin_addr, RT_MM_PAGE_SIZE);
    heap_end   = RT_ALIGN_DOWN((rt_uint32_t)end_addr, RT_MM_PAGE_SIZE);

    if (heap_start >= heap_end)
    {
        rt_kprintf("rt_system_heap_init, wrong address[0x%x - 0x%x]\n",
                   (rt_uint32_t)begin_addr, (rt_uint32_t)end_addr);

        return;
    }

    limsize = heap_end - heap_start;
    npages  = limsize / RT_MM_PAGE_SIZE;

    /* initialize heap semaphore */
    rt_sem_init(&heap_sem, "heap", 1, RT_IPC_FLAG_FIFO);

    RT_DEBUG_LOG(RT_DEBUG_SLAB, ("heap[0x%x - 0x%x], size 0x%x, 0x%x pages\n",
                                 heap_start, heap_end, limsize, npages));

    /* init pages */
    rt_page_init((void *)heap_start, npages);

    /* calculate zone size */
    zone_size = ZALLOC_MIN_ZONE_SIZE;
    while (zone_size < ZALLOC_MAX_ZONE_SIZE && (zone_size << 1) < (limsize/1024))
        zone_size <<= 1;

    zone_limit = zone_size / 4;
    if (zone_limit > ZALLOC_ZONE_LIMIT)
        zone_limit = ZALLOC_ZONE_LIMIT;

    zone_page_cnt = zone_size / RT_MM_PAGE_SIZE;

    RT_DEBUG_LOG(RT_DEBUG_SLAB, ("zone size 0x%x, zone page count 0x%x\n",
                                 zone_size, zone_page_cnt));

    /* allocate memusage array */
    limsize  = npages * sizeof(struct memusage);
    limsize  = RT_ALIGN(limsize, RT_MM_PAGE_SIZE);
    memusage = rt_page_alloc(limsize/RT_MM_PAGE_SIZE);

    RT_DEBUG_LOG(RT_DEBUG_SLAB, ("memusage 0x%x, size 0x%x\n",
                                 (rt_uint32_t)memusage, limsize));
}
Example #5
0
/**
 * This function will be invoked when usb hub plug out is detected and it would clean 
 * and release all hub class related resources.
 *
 * @param arg the argument.
 * 
 * @return the error code, RT_EOK on successfully.
 */
static rt_err_t rt_usb_hub_stop(void* arg)
{
    int i;
    uhubinst_t uhub;
    uinst_t uinst;
    uifinst_t ifinst = (uifinst_t)arg;

    /* paremeter check */
    RT_ASSERT(ifinst != RT_NULL);

    RT_DEBUG_LOG(RT_DEBUG_USB, ("rt_usb_hub_stop\n"));

    uinst = ifinst->uinst;
    uhub = (uhubinst_t)ifinst->user_data;

    if(uhub->pipe_in != RT_NULL)
        rt_usb_hcd_free_pipe(uinst->hcd, uhub->pipe_in);

    for(i=0; i<uhub->num_ports; i++)
    {
        if(uhub->child[i] != RT_NULL)
            rt_usb_detach_instance(uhub->child[i]);
    }
    
    if(uhub != RT_NULL) rt_free(uhub);
    if(ifinst != RT_NULL) rt_free(ifinst);

    return RT_EOK;
}
Example #6
0
/**
 * This function is the main entry of usb hub thread, it is in charge of 
 * processing all messages received from the usb message buffer.  
 *
 * @param parameter the parameter of the usb host thread.
 * 
 * @return none.
 */
static void rt_usbh_hub_thread_entry(void* parameter)
{    
    while(1)
    {    
        struct uhost_msg msg;
        
        /* receive message */
        if(rt_mq_recv(usb_mq, &msg, sizeof(struct uhost_msg), RT_WAITING_FOREVER) 
            != RT_EOK ) continue;

        RT_DEBUG_LOG(RT_DEBUG_USB, ("msg type %d\n", msg.type));
        
        switch (msg.type)
        {        
        case USB_MSG_CONNECT_CHANGE:
            rt_usbh_hub_port_change(msg.content.hub);
            break;
        case USB_MSG_CALLBACK:
            /* invoke callback */
            msg.content.cb.function(msg.content.cb.context);
            break;
        default:
            break;
        }            
    }
}
Example #7
0
/**
 * This function will set an address to the usb device.
 *
 * @param uinst the usb device instance.
 *
 * @return the error code, RT_EOK on successfully.
 */
rt_err_t rt_usb_set_address(uinst_t uinst)
{
    struct ureqest setup;
    int timeout = 100;

    RT_ASSERT(uinst != RT_NULL);

    RT_DEBUG_LOG(RT_DEBUG_USB, ("rt_usb_set_address\n"));

    setup.request_type = USB_REQ_TYPE_DIR_OUT | USB_REQ_TYPE_STANDARD |
                         USB_REQ_TYPE_DEVICE;
    setup.request = USB_REQ_SET_ADDRESS;
    setup.index = 0;
    setup.length = 0;
    setup.value = uinst->index;

    if(rt_usb_hcd_control_xfer(uinst->hcd, uinst, &setup, RT_NULL, 0,
                               timeout) != 0) return -RT_EIO;

    rt_thread_delay(50);

    uinst->address = uinst->index;

    return RT_EOK;
}
Example #8
0
/**
 * This function will get an interface descriptor from the configuration descriptor.
 *
 * @param cfg_desc the point of configuration descriptor structure.
 * @param num the number of interface descriptor.
 * @intf_desc the point of interface descriptor point.
 *
 * @return the error code, RT_EOK on successfully.
 */
rt_err_t rt_usb_get_interface_descriptor(ucfg_desc_t cfg_desc, int num,
        uintf_desc_t *intf_desc)
{
    rt_uint32_t ptr, depth = 0;
    udesc_t desc;

    /* check parameter */
    RT_ASSERT(cfg_desc != RT_NULL);

    ptr = (rt_uint32_t)cfg_desc + cfg_desc->bLength;
    while(ptr < (rt_uint32_t)cfg_desc + cfg_desc->wTotalLength)
    {
        if(depth++ > 0x20)
        {
            *intf_desc = RT_NULL;
            return -RT_EIO;
        }
        desc = (udesc_t)ptr;
        if(desc->type == USB_DESC_TYPE_INTERFACE)
        {
            if(((uintf_desc_t)desc)->bInterfaceNumber == num)
            {
                *intf_desc = (uintf_desc_t)desc;

                RT_DEBUG_LOG(RT_DEBUG_USB,
                             ("rt_usb_get_interface_descriptor: %d\n", num));
                return RT_EOK;
            }
        }
        ptr = (rt_uint32_t)desc + desc->bLength;
    }

    rt_kprintf("rt_usb_get_interface_descriptor %d failed\n", num);
    return -RT_EIO;
}
Example #9
0
/**
 * This function will release a semaphore, if there are threads suspended on
 * semaphore, it will be waked up.
 *
 * @param sem the semaphore object
 *
 * @return the error code
 */
rt_err_t rt_sem_release(rt_sem_t sem)
{
	register rt_base_t temp;
	register rt_bool_t need_schedule;

	RT_OBJECT_HOOK_CALL(rt_object_put_hook, (&(sem->parent.parent)));

	need_schedule = RT_FALSE;

	/* disable interrupt */
	temp = rt_hw_interrupt_disable();

	RT_DEBUG_LOG(RT_DEBUG_IPC,
		("thread %s releases sem:%s, which value is: %d\n", rt_thread_self()->name,
		((struct rt_object *)sem)->name, sem->value));


	if (!rt_list_isempty(&sem->parent.suspend_thread))
	{
		/* resume the suspended thread */
		rt_ipc_list_resume(&(sem->parent.suspend_thread));
		need_schedule = RT_TRUE;
	}
	else sem->value ++; /* increase value */

	/* enable interrupt */
	rt_hw_interrupt_enable(temp);

	/* resume a thread, re-schedule */
	if (need_schedule == RT_TRUE) rt_schedule();

	return RT_EOK;
}
Example #10
0
/**
 * This function will detach an usb device instance from its host controller,
 * and release all resource.
 *
 * @param device the usb device instance.
 * 
 * @return the error code, RT_EOK on successfully.
 */
rt_err_t rt_usbh_detach_instance(uinst_t device)
{
    int i = 0;

    if(device == RT_NULL) 
    {
        rt_kprintf("no usb instance to detach\n");
        return -RT_ERROR;
    }
    
    /* free configration descriptor */
    if(device->cfg_desc) rt_free(device->cfg_desc);
    
    for(i=0; i<device->cfg_desc->bNumInterfaces; i++)
    {
        if(device->intf[i] == RT_NULL) continue;
        if(device->intf[i]->drv == RT_NULL) continue;

        RT_ASSERT(device->intf[i]->device == device);

        RT_DEBUG_LOG(RT_DEBUG_USB, ("free interface instance %d\n", i));
        rt_usbh_class_driver_disable(device->intf[i]->drv, (void*)device->intf[i]);
    }
    
    rt_memset(device, 0, sizeof(struct uinstance));
    
    return RT_EOK;
}
Example #11
0
/**
 * @ingroup SystemInit
 * This function will initialize the system scheduler
 */
void rt_system_scheduler_init(void)
{
    register rt_base_t offset;

    rt_scheduler_lock_nest = 0;

    RT_DEBUG_LOG(RT_DEBUG_SCHEDULER, ("start scheduler: max priority 0x%02x\n",
                                      RT_THREAD_PRIORITY_MAX));

    for (offset = 0; offset < RT_THREAD_PRIORITY_MAX; offset ++)
    {
        rt_list_init(&rt_thread_priority_table[offset]);
    }

    rt_current_priority = RT_THREAD_PRIORITY_MAX - 1;
    rt_current_thread = RT_NULL;

    /* initialize ready priority group */
    rt_thread_ready_priority_group = 0;

#if RT_THREAD_PRIORITY_MAX > 32
    /* initialize ready table */
    rt_memset(rt_thread_ready_table, 0, sizeof(rt_thread_ready_table));
#endif

    /* initialize thread defunct */
    rt_list_init(&rt_thread_defunct);
}
Example #12
0
/**
 * This function will start a thread and put it to system ready queue
 *
 * @param thread the thread to be started
 *
 * @return the operation status, RT_EOK on OK, -RT_ERROR on error
 *
 */
rt_err_t rt_thread_startup(rt_thread_t thread)
{
	/* thread check */
	RT_ASSERT(thread != RT_NULL);
	RT_ASSERT(thread->stat == RT_THREAD_INIT);

	/* set current priority to init priority */
	thread->current_priority = thread->init_priority;

	/* calculate priority attribute */
#if RT_THREAD_PRIORITY_MAX > 32
	thread->number      = thread->current_priority >> 3; 			/* 5bit */
	thread->number_mask = 1L << thread->number;
	thread->high_mask   = 1L << (thread->current_priority & 0x07); 	/* 3bit */
#else
	thread->number_mask = 1L << thread->current_priority;
#endif

	RT_DEBUG_LOG(RT_DEBUG_THREAD,\
		("startup a thread:%s with priority:%d\n", thread->name, thread->init_priority));
	/* change thread stat */
	thread->stat = RT_THREAD_SUSPEND;
	/* then resume it */
	rt_thread_resume(thread);
	if (rt_thread_self() != RT_NULL)
	{
		/* do a scheduling */
		rt_schedule();
	}

	return RT_EOK;
}
Example #13
0
/**
 * This function will be invoked when usb hub plug out is detected and it would clean 
 * and release all hub class related resources.
 *
 * @param arg the argument.
 * 
 * @return the error code, RT_EOK on successfully.
 */
static rt_err_t rt_usbh_hub_disable(void* arg)
{
    int i;
    uhub_t hub;
    struct uinstance* device;
    struct uintf* intf = (struct uintf*)arg;

    /* paremeter check */
    RT_ASSERT(intf != RT_NULL);

    RT_DEBUG_LOG(RT_DEBUG_USB, ("rt_usbh_hub_stop\n"));

    device = intf->device;
    hub = (uhub_t)intf->user_data;

    if(hub->pipe_in != RT_NULL)
        rt_usb_hcd_free_pipe(device->hcd, hub->pipe_in);

    for(i=0; i<hub->num_ports; i++)
    {
        if(hub->child[i] != RT_NULL)
            rt_usbh_detach_instance(hub->child[i]);
    }
    
    if(hub != RT_NULL) rt_free(hub);
    if(intf != RT_NULL) rt_free(intf);

    return RT_EOK;
}
/**
 * This function will handle cdc bulk out endpoint request.
 *
 * @param func the usb function object.
 * @param size request size.
 *
 * @return RT_EOK.
 */
static rt_err_t _ep_out_handler(ufunction_t func, rt_size_t size)
{
    rt_uint32_t level;
    struct vcom *data;

    RT_ASSERT(func != RT_NULL);

    RT_DEBUG_LOG(RT_DEBUG_USB, ("_ep_out_handler %d\n", size));
    
    data = (struct vcom*)func->user_data;
    /* receive data from USB VCOM */
    level = rt_hw_interrupt_disable();

    rt_ringbuffer_put(&data->rx_ringbuffer, data->ep_out->buffer, size);
    rt_hw_interrupt_enable(level);

    /* notify receive data */
    rt_hw_serial_isr(&data->serial);

    data->ep_out->request.buffer = data->ep_out->buffer;
    data->ep_out->request.size = EP_MAXPACKET(data->ep_out);
    data->ep_out->request.req_type = UIO_REQUEST_READ_MOST;    
    rt_usbd_io_request(func->device, data->ep_out, &data->ep_out->request);

    return RT_EOK;
}
/**
 * This function will handle cdc bulk in endpoint request.
 *
 * @param func the usb function object.
 * @param size request size.
 *
 * @return RT_EOK.
 */
static rt_err_t _ep_in_handler(ufunction_t func, rt_size_t size)
{
    struct vcom *data;

    RT_ASSERT(func != RT_NULL);

    RT_DEBUG_LOG(RT_DEBUG_USB, ("_ep_in_handler %d\n", size));

    data = (struct vcom*)func->user_data;
    if ((size != 0) && (size % CDC_MAX_PACKET_SIZE == 0))
    {
        /* don't have data right now. Send a zero-length-packet to
         * terminate the transaction.
         *
         * FIXME: actually, this might not be the right place to send zlp.
         * Only the rt_device_write could know how much data is sending. */
        data->in_sending = RT_TRUE;

        data->ep_in->request.buffer = RT_NULL;
        data->ep_in->request.size = 0;
        data->ep_in->request.req_type = UIO_REQUEST_WRITE;
        rt_usbd_io_request(func->device, data->ep_in, &data->ep_in->request);

        return RT_EOK;
    }
    
    rt_completion_done(&data->wait);
    
    return RT_EOK;
}
/**
 * This function will be invoked when usb device plug out is detected and it would clean
 * and release all hub class related resources.
 *
 * @param arg the argument.
 *
 * @return the error code, RT_EOK on successfully.
 */
static rt_err_t rt_usb_adk_stop(void* arg)
{
    uadkinst_t adkinst;
    uifinst_t ifinst = (uifinst_t)arg;

    RT_ASSERT(ifinst != RT_NULL);

    RT_DEBUG_LOG(RT_DEBUG_USB, ("rt_usb_adk_stop\n"));

    adkinst = (uadkinst_t)ifinst->user_data;
    if(adkinst == RT_NULL)
    {
        rt_free(ifinst);
        return RT_EOK;
    }

    if(adkinst->pipe_in != RT_NULL)
        rt_usb_hcd_free_pipe(ifinst->uinst->hcd, adkinst->pipe_in);

    if(adkinst->pipe_out != RT_NULL)
        rt_usb_hcd_free_pipe(ifinst->uinst->hcd, adkinst->pipe_out);

    /* unregister adk device */
    rt_device_unregister(&adkinst->device);

    /* free adk instance */
    if(adkinst != RT_NULL) rt_free(adkinst);

    /* free interface instance */
    rt_free(ifinst);

    return RT_EOK;
}
Example #17
0
/**
 * This function will detach an usb device instance from its host controller,
 * and release all resource.
 *
 * @param uinst the usb device instance.
 *
 * @return the error code, RT_EOK on successfully.
 */
rt_err_t rt_usb_detach_instance(uinst_t uinst)
{
    int i = 0;

    if(uinst == RT_NULL)
    {
        rt_kprintf("no usb instance to detach\n");
        return -RT_ERROR;
    }

    /* free configration descriptor */
    if(uinst->cfg_desc) rt_free(uinst->cfg_desc);

    for(i = 0; i < uinst->cfg_desc->bNumInterfaces; i++)
    {
        if(uinst->ifinst[i] == RT_NULL) continue;
        if(uinst->ifinst[i]->drv == RT_NULL) continue;

        RT_ASSERT(uinst->ifinst[i]->uinst == uinst);

        RT_DEBUG_LOG(RT_DEBUG_USB, ("free interface instance %d\n", i));
        rt_usb_class_driver_stop(uinst->ifinst[i]->drv, (void *)uinst->ifinst[i]);
    }

    rt_memset(uinst, 0, sizeof(struct uinstance));

    return RT_EOK;
}
/**
 * This function will stop cdc class, it will be called on handle set configuration request.
 *
 * @param device the usb device object.
 *
 * @return RT_EOK on successful.
 */
static rt_err_t _class_stop(udevice_t device, uclass_t cls)
{
    RT_ASSERT(device != RT_NULL);

    RT_DEBUG_LOG(RT_DEBUG_USB, ("cdc class stop\n"));

    return RT_EOK;
}
static rt_err_t _cdc_set_line_coding_callback(udevice_t device, rt_size_t size)
{
    RT_DEBUG_LOG(RT_DEBUG_USB, ("_cdc_set_line_coding_callback\n"));

    dcd_ep0_send_status(device->dcd);
    
    return RT_EOK;
}
/**
 * This function will handle cdc interrupt in endpoint request.
 *
 * @param device the usb device object.
 * @param size request size.
 *
 * @return RT_EOK.
 */
static rt_err_t _ep_cmd_handler(ufunction_t func, rt_size_t size)
{
    RT_ASSERT(func != RT_NULL);

    RT_DEBUG_LOG(RT_DEBUG_USB, ("_ep_cmd_handler\n"));

    return RT_EOK;
}
/**
 * This function will handle cdc interrupt in endpoint request.
 *
 * @param device the usb device object.
 * @param size request size.
 *
 * @return RT_EOK.
 */
static rt_err_t _ep_cmd_handler(udevice_t device, uclass_t cls, rt_size_t size)
{
    RT_ASSERT(device != RT_NULL);

    RT_DEBUG_LOG(RT_DEBUG_USB, ("_ep_cmd_handler\n"));

    return RT_EOK;
}
Example #22
0
/**
 * This function will be invoked by BSP, when leave interrupt service routine
 *
 * @note please don't invoke this routine in application
 *
 * @see rt_interrupt_enter
 */
void rt_interrupt_leave()
{
    rt_base_t level;

    RT_DEBUG_LOG(RT_DEBUG_IRQ,("irq leave, irq nest:%d\n", rt_interrupt_nest));

    level = rt_hw_interrupt_disable();
    rt_interrupt_nest --;
    rt_hw_interrupt_enable(level);
}
Example #23
0
void warn_power_drop(void)
{	
	if(power_status() == WARN_POWER_OFF)
	{
		#if ( WARN_EN > 0 )	
			RT_DEBUG_LOG(DEBUG_WARN, ("power drop warn.\n"));
			warn_judge_set(RT_NULL, WARN_POWER_DROP_SET, WHICH_WARN_POWER_DROP);
		#endif	
	}
}
Example #24
0
/**
 * This function will be invoked by BSP, when enter interrupt service routine
 *
 * @note please don't invoke this routine in application
 *
 * @see rt_interrupt_leave
 */
void rt_interrupt_enter()
{
    rt_base_t level;

    RT_DEBUG_LOG(RT_DEBUG_IRQ,("irq comming..., irq nest:%d\n", rt_interrupt_nest));

    level = rt_hw_interrupt_disable();
    rt_interrupt_nest ++;
    rt_hw_interrupt_enable(level);
}
Example #25
0
/**
 * This function will run cdc class, it will be called on handle set configuration request.
 *
 * @param device the usb device object.
 *
 * @return RT_EOK on successful.
 */
static rt_err_t _class_run(udevice_t device)
{
    RT_ASSERT(device != RT_NULL);

    RT_DEBUG_LOG(RT_DEBUG_USB, ("cdc class run\n"));

    dcd_ep_read(device->dcd, ep_out, ep_out->buffer,
                ep_out->ep_desc->wMaxPacketSize);

    return RT_EOK;
}
Example #26
0
/*
 * This function will remove a thread from system ready queue.
 *
 * @param thread the thread to be removed
 *
 * @note Please do not invoke this function in user application.
 */
void rt_schedule_remove_thread(struct rt_thread *thread)
{
    register rt_base_t temp;

    RT_ASSERT(thread != RT_NULL);

    /* disable interrupt */
    temp = rt_hw_interrupt_disable();

#if RT_THREAD_PRIORITY_MAX <= 32
    RT_DEBUG_LOG(RT_DEBUG_SCHEDULER, ("remove thread[%.*s], the priority: %d\n",
                                      RT_NAME_MAX, thread->name,
                                      thread->current_priority));
#else
    RT_DEBUG_LOG(RT_DEBUG_SCHEDULER,
                 ("remove thread[%.*s], the priority: %d 0x%x %d\n",
                  RT_NAME_MAX,
                  thread->name,
                  thread->number,
                  thread->number_mask,
                  thread->high_mask));
#endif

    /* remove thread from ready list */
    rt_list_remove(&(thread->tlist));
    if (rt_list_isempty(&(rt_thread_priority_table[thread->current_priority])))
    {
#if RT_THREAD_PRIORITY_MAX > 32
        rt_thread_ready_table[thread->number] &= ~thread->high_mask;
        if (rt_thread_ready_table[thread->number] == 0)
        {
            rt_thread_ready_priority_group &= ~thread->number_mask;
        }
#else
        rt_thread_ready_priority_group &= ~thread->number_mask;
#endif
    }

    /* enable interrupt */
    rt_hw_interrupt_enable(temp);
}
/**
 * This function will handle cdc_set_line_coding request.
 *
 * @param device the usb device object.
 * @param setup the setup request.
 *
 * @return RT_EOK on successful.
 */
static rt_err_t _cdc_set_line_coding(udevice_t device, ureq_t setup)
{
    RT_ASSERT(device != RT_NULL);
    RT_ASSERT(setup != RT_NULL);

    RT_DEBUG_LOG(RT_DEBUG_USB, ("_cdc_set_line_coding\n"));

    rt_usbd_ep0_read(device, (void*)&line_coding, sizeof(struct ucdc_line_coding),
        _cdc_set_line_coding_callback);

    return RT_EOK;
}
Example #28
0
/*
 * This function will insert a thread to system ready queue. The state of
 * thread will be set as READY and remove from suspend queue.
 *
 * @param thread the thread to be inserted
 * @note Please do not invoke this function in user application.
 */
void rt_schedule_insert_thread(struct rt_thread *thread)
{
    register rt_base_t temp;

    RT_ASSERT(thread != RT_NULL);

    /* disable interrupt */
    temp = rt_hw_interrupt_disable();

    /* change stat */
    thread->stat = RT_THREAD_READY;

    /* insert thread to ready list */
    rt_list_insert_before(&(rt_thread_priority_table[thread->current_priority]),
                          &(thread->tlist));

    /* set priority mask */
#if RT_THREAD_PRIORITY_MAX <= 32
    RT_DEBUG_LOG(RT_DEBUG_SCHEDULER, ("insert thread[%.*s], the priority: %d\n",
                                      RT_NAME_MAX, thread->name, thread->current_priority));
#else
    RT_DEBUG_LOG(RT_DEBUG_SCHEDULER,
                 ("insert thread[%.*s], the priority: %d 0x%x %d\n",
                  RT_NAME_MAX,
                  thread->name,
                  thread->number,
                  thread->number_mask,
                  thread->high_mask));
#endif

#if RT_THREAD_PRIORITY_MAX > 32
    rt_thread_ready_table[thread->number] |= thread->high_mask;
#endif
    rt_thread_ready_priority_group |= thread->number_mask;

    /* enable interrupt */
    rt_hw_interrupt_enable(temp);
}
Example #29
0
/**
 * This function will resume the first thread in the list of a IPC object:
 * - remove the thread from suspend queue of IPC object
 * - put the thread into system ready queue
 *
 * @param list the thread list
 *
 * @return the operation status, RT_EOK on successful
 */
rt_inline rt_err_t rt_ipc_list_resume(rt_list_t *list)
{
	struct rt_thread *thread;

	/* get thread entry */
	thread = rt_list_entry(list->next, struct rt_thread, tlist);

	RT_DEBUG_LOG(RT_DEBUG_IPC, ("resume thread:%s\n", thread->name));

	/* resume it */
	rt_thread_resume(thread);

	return RT_EOK;
}
Example #30
0
/**
 * This function will handle get_string_descriptor request.
 *
 * @param device the usb device object.
 * @param setup the setup request.
 *
 * @return RT_EOK on successful, -RT_ERROR on invalid request.
 */
static rt_err_t _get_string_descriptor(struct udevice* device, ureq_t setup)
{
    struct ustring_descriptor str_desc;
    rt_uint8_t index, i;
    rt_uint32_t len;

    /* parameter check */
    RT_ASSERT(device != RT_NULL);
    RT_ASSERT(setup != RT_NULL);

    RT_DEBUG_LOG(RT_DEBUG_USB, ("_get_string_descriptor\n"));

    str_desc.type = USB_DESC_TYPE_STRING;
    index = setup->value & 0xFF;

    if (index > USB_STRING_INTERFACE_INDEX)
    {
        rt_kprintf("unknown string index\n");
        dcd_ep_stall(device->dcd, 0);
        return -RT_ERROR;
    }
    if (index == 0)
    {
        str_desc.bLength = 4;
        str_desc.String[0] = 0x09;
        str_desc.String[1] = 0x04;
    }
    else
    {
        len = rt_strlen(device->str[index]);
        str_desc.bLength = len*2 + 2;

        for (i=0; i<len; i++)
        {
            str_desc.String[i*2] = device->str[index][i];
            str_desc.String[i*2 + 1] = 0;
        }
    }

    if (setup->length > str_desc.bLength)
        len = str_desc.bLength;
    else
        len = setup->length;

    /* send string descriptor to endpoint 0 */
    dcd_ep_write(device->dcd, 0, (rt_uint8_t*)&str_desc, len);

    return RT_EOK;
}