本文整理汇总了C++中rt_set_errno函数的典型用法代码示例。如果您正苦于以下问题:C++ rt_set_errno函数的具体用法?C++ rt_set_errno怎么用?C++ rt_set_errno使用的例子?那么恭喜您, 这里精选的函数代码示例或许可以为您提供帮助。
在下文中一共展示了rt_set_errno函数的15个代码示例,这些例子默认根据受欢迎程度排序。您可以为喜欢或者感觉有用的代码点赞,您的评价将有助于系统推荐出更棒的C++代码示例。
示例1: open
/**
* this function is a POSIX compliant version, which will open a file and return
* a file descriptor.
*
* @param file the path name of file.
* @param flags the file open flags.
* @param mode
*
* @return the non-negative integer on successful open, others for failed.
*/
int open(const char *file, int flags, int mode)
{
int fd, result;
struct dfs_fd *d;
/* allocate a fd */
fd = fd_new();
if (fd < 0)
{
rt_set_errno(-DFS_STATUS_ENOMEM);
return -1;
}
d = fd_get(fd);
result = dfs_file_open(d, file, flags);
if (result < 0)
{
/* release the ref-count of fd */
fd_put(d);
fd_put(d);
rt_set_errno(result);
return -1;
}
/* release the ref-count of fd */
fd_put(d);
return fd;
}
示例2: write
/*
+------------------------------------------------------------------------------
| Function : write
+------------------------------------------------------------------------------
| Description :
|
| Parameters :
| Returns :
|
+------------------------------------------------------------------------------
*/
int write(int fd, char *buf, int len)
{
int result;
struct dfs_fd* d;
/* get the fd */
d = fd_get(fd);
if (d == RT_NULL)
{
rt_set_errno(-RT_ERROR);
return -1;
}
result = dfile_raw_write(d, buf, len);
if (result < 0)
{
rt_set_errno(result);
fd_put(d);
return -1;
}
/* release the ref-count of fd */
fd_put(d);
return result;
}
示例3: close
/**
* this function is a POSIX compliant version, which will close the open
* file descriptor.
*
* @param fd the file descriptor.
*
* @return 0 on successful, -1 on failed.
*/
int close(int fd)
{
int result;
struct dfs_fd *d;
d = fd_get(fd);
if (d == RT_NULL)
{
rt_set_errno(-DFS_STATUS_EBADF);
return -1;
}
result = dfs_file_close(d);
fd_put(d);
if (result < 0)
{
rt_set_errno(result);
return -1;
}
fd_put(d);
return 0;
}
示例4: rt_spi_transfer
rt_size_t rt_spi_transfer(struct rt_spi_device *device,
const void *send_buf,
void *recv_buf,
rt_size_t length)
{
rt_err_t result;
struct rt_spi_message message;
RT_ASSERT(device != RT_NULL);
RT_ASSERT(device->bus != RT_NULL);
result = rt_mutex_take(&(device->bus->lock), RT_WAITING_FOREVER);
if (result == RT_EOK)
{
if (device->bus->owner != device)
{
/* not the same owner as current, re-configure SPI bus */
result = device->bus->ops->configure(device, &device->config);
if (result == RT_EOK)
{
/* set SPI bus owner */
device->bus->owner = device;
}
else
{
/* configure SPI bus failed */
rt_set_errno(-RT_EIO);
result = 0;
goto __exit;
}
}
/* initial message */
message.send_buf = send_buf;
message.recv_buf = recv_buf;
message.length = length;
message.cs_take = 1;
message.cs_release = 1;
message.next = RT_NULL;
/* transfer message */
result = device->bus->ops->xfer(device, &message);
if (result == 0)
{
rt_set_errno(-RT_EIO);
goto __exit;
}
}
else
{
rt_set_errno(-RT_EIO);
return 0;
}
__exit:
rt_mutex_release(&(device->bus->lock));
return result;
}
示例5: read
/**
* this function is a POSIX compliant version, which will read specified data buffer
* length for an open file descriptor.
*
* @param fd the file descriptor.
* @param buf the buffer to save the read data.
* @param len the maximal length of data buffer
*
* @return the actual read data buffer length
*/
int read(int fd, void *buf, size_t len)
{
int result;
struct dfs_fd *d;
/* get the fd */
d = fd_get(fd);
if (d == RT_NULL)
{
rt_set_errno(-RT_ERROR);
return -1;
}
result = dfs_file_read(d, buf, len);
if (result < 0)
{
fd_put(d);
rt_set_errno(result);
return -1;
}
/* release the ref-count of fd */
fd_put(d);
return result;
}
示例6: write
/**
* this function is a POSIX compliant version, which will write specified data buffer
* length for an open file descriptor.
*
* @param fd the file descriptor
* @param buf the data buffer to be written.
* @param len the data buffer length.
*
* @return the actual written data buffer length.
*/
int write(int fd, const void *buf, size_t len)
{
int result;
struct dfs_fd *d;
/* get the fd */
d = fd_get(fd);
if (d == RT_NULL)
{
rt_set_errno(-DFS_STATUS_EBADF);
return -1;
}
result = dfs_file_write(d, buf, len);
if (result < 0)
{
fd_put(d);
rt_set_errno(result);
return -1;
}
/* release the ref-count of fd */
fd_put(d);
return result;
}
示例7: lseek
/**
* this function is a POSIX compliant version, which will seek the offset for
* an open file descriptor.
*
* @param fd the file descriptor.
* @param offset the offset to be seeked.
* @param whence the directory of seek.
*
* @return the current file position, or -1 on failed.
*/
off_t lseek(int fd, off_t offset, int whence)
{
int result;
struct dfs_fd *d;
d = fd_get(fd);
if (d == RT_NULL)
{
rt_set_errno(-DFS_STATUS_EBADF);
return -1;
}
switch (whence)
{
case DFS_SEEK_SET:
break;
case DFS_SEEK_CUR:
offset += d->pos;
break;
case DFS_SEEK_END:
offset += d->size;
break;
default:
rt_set_errno(-DFS_STATUS_EINVAL);
return -1;
}
if (offset < 0)
{
rt_set_errno(-DFS_STATUS_EINVAL);
return -1;
}
result = dfs_file_lseek(d, offset);
if (result < 0)
{
fd_put(d);
rt_set_errno(result);
return -1;
}
/* release the ref-count of fd */
fd_put(d);
return offset;
}
示例8: _write
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;
}
示例9: clock_settime
int clock_settime (clockid_t clockid, const struct timespec *tp)
{
int second;
rt_tick_t tick;
rt_device_t device;
if ((clockid != CLOCK_REALTIME) || (tp == RT_NULL)) {
rt_set_errno(EINVAL);
return -1;
}
/* get second */
second = tp->tv_sec;
/* get tick */
tick = rt_tick_get();
/* update timevalue */
_timevalue.tv_usec = MICROSECOND_PER_SECOND - (tick % RT_TICK_PER_SECOND) * MICROSECOND_PER_TICK;
_timevalue.tv_sec = second - tick/RT_TICK_PER_SECOND - 1;
/* update for RTC device */
device = rt_device_find("rtc");
if (device != RT_NULL) {
/* set realtime seconds */
rt_device_control(device, RT_DEVICE_CTRL_RTC_SET_TIME, &second);
} else return -1;
return 0;
}
示例10: _serial_dma_tx
rt_inline int _serial_dma_tx(struct rt_serial_device *serial, const rt_uint8_t *data, int length)
{
rt_base_t level;
rt_err_t result;
struct rt_serial_tx_dma *tx_dma;
tx_dma = (struct rt_serial_tx_dma*)(serial->serial_tx);
result = rt_data_queue_push(&(tx_dma->data_queue), data, length, RT_WAITING_FOREVER);
if (result == RT_EOK)
{
level = rt_hw_interrupt_disable();
if (tx_dma->activated != RT_TRUE)
{
tx_dma->activated = RT_TRUE;
rt_hw_interrupt_enable(level);
/* make a DMA transfer */
serial->ops->dma_transmit(serial, data, length, RT_SERIAL_DMA_TX);
}
else
{
rt_hw_interrupt_enable(level);
}
return length;
}
else
{
rt_set_errno(result);
return 0;
}
}
示例11: rt_spi_take_bus
rt_err_t rt_spi_take_bus(struct rt_spi_device *device)
{
rt_err_t result = RT_EOK;
RT_ASSERT(device != RT_NULL);
RT_ASSERT(device->bus != RT_NULL);
result = rt_mutex_take(&(device->bus->lock), RT_WAITING_FOREVER);
if (result != RT_EOK)
{
rt_set_errno(-RT_EBUSY);
return -RT_EBUSY;
}
/* reset errno */
rt_set_errno(RT_EOK);
/* configure SPI bus */
if (device->bus->owner != device)
{
/* not the same owner as current, re-configure SPI bus */
result = device->bus->ops->configure(device, &device->config);
if (result == RT_EOK)
{
/* set SPI bus owner */
device->bus->owner = device;
}
else
{
/* configure SPI bus failed */
rt_set_errno(-RT_EIO);
/* release lock */
rt_mutex_release(&(device->bus->lock));
return -RT_EIO;
}
}
return result;
}
示例12: rt_serial_read
static rt_size_t rt_serial_read(struct rt_device *dev,
rt_off_t pos,
void *buffer,
rt_size_t size)
{
rt_uint8_t *ptr;
rt_uint32_t read_nbytes;
struct rt_serial_device *serial;
RT_ASSERT(dev != RT_NULL);
if (size == 0)
return 0;
serial = (struct rt_serial_device *)dev;
ptr = (rt_uint8_t *)buffer;
if (dev->flag & RT_DEVICE_FLAG_INT_RX)
{
/* interrupt mode Rx */
while (size)
{
int ch;
ch = serial_ringbuffer_getc(serial->int_rx);
if (ch == -1)
break;
*ptr = ch & 0xff;
ptr ++;
size --;
}
}
else
{
/* polling mode */
while ((rt_uint32_t)ptr - (rt_uint32_t)buffer < size)
{
*ptr = serial->ops->getc(serial);
ptr ++;
}
}
read_nbytes = (rt_uint32_t)ptr - (rt_uint32_t)buffer;
/* set error code */
if (read_nbytes == 0)
{
rt_set_errno(-RT_EEMPTY);
}
return read_nbytes;
}
示例13: clock_getres
int clock_getres (clockid_t clockid, struct timespec *res)
{
if ((clockid != CLOCK_REALTIME) || (res == RT_NULL)) {
rt_set_errno(EINVAL);
return -1;
}
res->tv_sec = 0;
res->tv_nsec = NANOSECOND_PER_SECOND/RT_TICK_PER_SECOND;
return 0;
}
示例14: codec_write
static rt_size_t codec_write(rt_device_t dev, rt_off_t pos,
const void* buffer, rt_size_t size)
{
struct codec_device* device;
struct codec_data_node* node;
rt_uint32_t level;
rt_uint16_t next_index;
device = (struct codec_device*) dev;
RT_ASSERT(device != RT_NULL);
next_index = device->put_index + 1;
if (next_index >= DATA_NODE_MAX)
next_index = 0;
/* check data_list full */
if (next_index == device->read_index)
{
rt_set_errno(-RT_EFULL);
return 0;
}
level = rt_hw_interrupt_disable();
node = &device->data_list[device->put_index];
device->put_index = next_index;
/* set node attribute */
node->data_ptr = (rt_uint16_t*) buffer;
node->data_size = size >> 1; /* size is byte unit, convert to half word unit */
next_index = device->read_index + 1;
if (next_index >= DATA_NODE_MAX)
next_index = 0;
/* check data list whether is empty */
if (next_index == device->put_index)
{
DMA_Configuration((rt_uint32_t) node->data_ptr, node->data_size);
#if CODEC_MASTER_MODE
if ((r06 & MS) == 0)
{
CODEC_I2S_PORT->I2SCFGR |= SPI_I2SCFGR_I2SE;
r06 |= MS;
codec_send(r06);
}
#endif
}
rt_hw_interrupt_enable(level);
return size;
}
示例15: lseek
/*
+------------------------------------------------------------------------------
| Function : lseek
+------------------------------------------------------------------------------
| Description :
|
| Parameters :
| Returns :
|
+------------------------------------------------------------------------------
*/
int lseek(int fd, int offset, int dir)
{
int result;
struct dfs_fd* d;
d = fd_get(fd);
if (d == RT_NULL)
{
rt_set_errno(-RT_ERROR);
return -1;
}
switch (dir)
{
case DFS_SEEK_SET:
break;
case DFS_SEEK_CUR:
offset += d->pos;
break;
case DFS_SEEK_END:
offset += d->size;
break;
}
result = dfile_raw_lseek(d, offset);
if (result < 0)
{
rt_set_errno(result);
fd_put(d);
return -1;
}
/* release the ref-count of fd */
fd_put(d);
return offset;
}