static rt_size_t _write(rt_device_t dev, rt_off_t pos, const void *buffer, rt_size_t size)
{
    rt_err_t err;
    struct rt_vbus_dev *vdev = dev->user_data;

    RT_ASSERT(vdev->chnr != 0);

    if (rt_interrupt_get_nest() == 0)
    {
        /* Thread context. */
        err = rt_vbus_post(vdev->chnr, vdev->req.prio,
                           buffer, size, RT_WAITING_FOREVER);
    }
    else
    {
        /* Interrupt context. */
        err = rt_vbus_post(vdev->chnr, vdev->req.prio,
                           buffer, size, 0);
    }

    if (err)
    {
        rt_set_errno(err);
        return 0;
    }

    return size;
}
Ejemplo n.º 2
0
/**
 * This function returns errno.
 *
 * @return the errno in the system
 */
int *_rt_errno(void)
{
	rt_thread_t tid;
	
	if (rt_interrupt_get_nest() != 0) return (int *)&_errno;

	tid = rt_thread_self();
	if (tid != RT_NULL) return (int *)&(tid->error);
	return (int *)&_errno;
}
Ejemplo n.º 3
0
/*
 * This function will get errno
 *
 * @return errno
 */
rt_err_t rt_get_errno(void)
{
	rt_thread_t tid;

	if (rt_interrupt_get_nest() != 0) {
		/* it's in interrupt context */
		return _errno;
	}

	tid = rt_thread_self();
	if (tid == RT_NULL) return _errno;

	return tid->error;
}
Ejemplo n.º 4
0
/*
 * This function will set errno
 *
 * @param error the errno shall be set
 */
void rt_set_errno(rt_err_t error)
{
	rt_thread_t tid;

	if (rt_interrupt_get_nest() != 0)
	{
		/* it's in interrupt context */
		_errno = error;
		return;
	}

	tid = rt_thread_self();
	if (tid == RT_NULL) { _errno = error; return; }

	tid->error = error;
}
static rt_size_t _read(rt_device_t dev, rt_off_t pos, void *buffer, rt_size_t size)
{
    rt_size_t outsz = 0;
    struct rt_vbus_dev *vdev = dev->user_data;

    RT_ASSERT(vdev->chnr != 0);

    if (vdev->act == RT_NULL)
    {
        vdev->act = rt_vbus_data_pop(vdev->chnr);
        vdev->pos = 0;
    }

    while (1)
    {
        rt_err_t err;

        while (vdev->act)
        {
            rt_size_t cpysz;

            if (size - outsz > vdev->act->size - vdev->pos)
                cpysz = vdev->act->size - vdev->pos;
            else
                cpysz = size - outsz;

            rt_memcpy((char*)buffer + outsz, ((char*)(vdev->act+1)) + vdev->pos, cpysz);
            vdev->pos += cpysz;

            outsz += cpysz;
            if (outsz == size)
            {
                return outsz;
            }
            else if (outsz > size)
                RT_ASSERT(0);

            /* free old and get new */
            rt_free(vdev->act);
            vdev->act = rt_vbus_data_pop(vdev->chnr);
            vdev->pos = 0;
        }

        /* TODO: We don't want to touch the rx_indicate here. But this lead to
         * some duplication. Maybe we should find a better way to handle this.
         */
        if (rt_interrupt_get_nest() == 0)
        {
            err = rt_vbus_listen_on(vdev->chnr, RT_WAITING_FOREVER);
        }
        else
        {
            err = rt_vbus_listen_on(vdev->chnr, 0);
        }
        if (err != RT_EOK)
        {
            rt_set_errno(err);
            return outsz;
        }
        vdev->act = rt_vbus_data_pop(vdev->chnr);
        vdev->pos = 0;
    }
}