[fix] Fix simulator compilation warnings (#6438)

* [fix] Fix simulator compilation warnings

* Update bsp/simulator/rtconfig_project.h

Co-authored-by: Man, Jianting (Meco) <920369182@qq.com>
This commit is contained in:
Tangyuxin 2022-09-20 22:31:11 +08:00 committed by GitHub
parent 746d7a01bd
commit a4829b1c00
No known key found for this signature in database
GPG Key ID: 4AEE18F83AFDEB23
22 changed files with 68 additions and 60 deletions

View File

@ -14,6 +14,7 @@
#ifdef _MSC_VER
/* disable some warning in MSC */
// #pragma warning(disable:4103) /* structure packing changed by including file */
// #pragma warning(disable:4273) /* to ignore: warning C4273: inconsistent dll linkage */
#endif /* _MSC_VER */

View File

@ -157,7 +157,7 @@ int dfs_romfs_read(struct dfs_fd *file, void *buf, size_t count)
int dfs_romfs_lseek(struct dfs_fd *file, off_t offset)
{
if (offset <= file->size)
if (offset >= 0 && (rt_size_t)offset <= file->size)
{
file->pos = offset;
return file->pos;
@ -243,6 +243,7 @@ int dfs_romfs_stat(struct dfs_filesystem *fs, const char *path, struct stat *st)
int dfs_romfs_getdents(struct dfs_fd *file, struct dirent *dirp, uint32_t count)
{
rt_size_t index;
rt_size_t len;
const char *name;
struct dirent *d;
struct romfs_dirent *dirent, *sub_dirent;
@ -261,7 +262,7 @@ int dfs_romfs_getdents(struct dfs_fd *file, struct dirent *dirp, uint32_t count)
return -EINVAL;
index = 0;
for (index = 0; index < count && file->pos < file->size; index ++)
for (index = 0; index < count && (rt_size_t)file->pos < file->size; index ++)
{
d = dirp + index;
@ -274,7 +275,9 @@ int dfs_romfs_getdents(struct dfs_fd *file, struct dirent *dirp, uint32_t count)
else
d->d_type = DT_REG;
d->d_namlen = rt_strlen(name);
len = rt_strlen(name);
RT_ASSERT(len <= RT_UINT8_MAX);
d->d_namlen = (rt_uint8_t)len;
d->d_reclen = (rt_uint16_t)sizeof(struct dirent);
rt_strncpy(d->d_name, name, DFS_PATH_MAX);

View File

@ -231,7 +231,7 @@ static rt_err_t rt_hwtimer_control(struct rt_device *dev, int cmd, void *args)
break;
case HWTIMER_CTRL_FREQ_SET:
{
rt_uint32_t *f;
rt_int32_t *f;
if (args == RT_NULL)
{
@ -239,7 +239,7 @@ static rt_err_t rt_hwtimer_control(struct rt_device *dev, int cmd, void *args)
break;
}
f = (rt_uint32_t*)args;
f = (rt_int32_t*)args;
if ((*f > timer->info->maxfreq) || (*f < timer->info->minfreq))
{
LOG_W("frequency setting out of range! It will maintain at %d Hz", timer->freq);

View File

@ -372,7 +372,8 @@ static rt_size_t i2c_bit_xfer(struct rt_i2c_bus_device *bus,
{
struct rt_i2c_msg *msg;
struct rt_i2c_bit_ops *ops = (struct rt_i2c_bit_ops *)bus->priv;
rt_int32_t i, ret;
rt_int32_t ret;
rt_uint32_t i;
rt_uint16_t ignore_nack;
if (num == 0) return 0;

View File

@ -95,7 +95,7 @@ rt_inline rt_uint16_t rt_ringbuffer_get_size(struct rt_ringbuffer *rb)
}
/** return the size of empty space in rb */
#define rt_ringbuffer_space_len(rb) ((rb)->buffer_size - rt_ringbuffer_data_len(rb))
#define rt_ringbuffer_space_len(rb) ((rb)->buffer_size - (rt_int16_t)rt_ringbuffer_data_len(rb))
#ifdef __cplusplus

View File

@ -497,7 +497,7 @@ static rt_size_t rt_pipe_read(rt_device_t device, rt_off_t pos, void *buffer, rt
while (read_bytes < count)
{
int len = rt_ringbuffer_get(pipe->fifo, &pbuf[read_bytes], count - read_bytes);
int len = rt_ringbuffer_get(pipe->fifo, &pbuf[read_bytes], (rt_uint16_t)(count - read_bytes));
if (len <= 0) break;
read_bytes += len;
@ -539,7 +539,7 @@ static rt_size_t rt_pipe_write(rt_device_t device, rt_off_t pos, const void *buf
while (write_bytes < count)
{
int len = rt_ringbuffer_put(pipe->fifo, &pbuf[write_bytes], count - write_bytes);
int len = rt_ringbuffer_put(pipe->fifo, &pbuf[write_bytes], (rt_uint16_t)(count - write_bytes));
if (len <= 0) break;
write_bytes += len;

View File

@ -192,7 +192,7 @@ rt_size_t rt_ringbuffer_get(struct rt_ringbuffer *rb,
/* less data */
if (size < length)
length = size;
length = (rt_uint16_t)size;
if (rb->buffer_size - rb->read_index > length)
{
@ -248,7 +248,7 @@ rt_size_t rt_ringbuffer_peek(struct rt_ringbuffer *rb, rt_uint8_t **ptr)
if ((rt_size_t)(rb->buffer_size - rb->read_index) > size)
{
rb->read_index += size;
rb->read_index += (rt_uint16_t)size;
return size;
}

View File

@ -162,7 +162,7 @@ rt_err_t rt_mtd_nand_mark_badblock(struct rt_mtd_nand_device *device, rt_uint32_
#include <finsh.h>
#define __is_print(ch) ((unsigned int)((ch) - ' ') < 127u - ' ')
static void mtd_dump_hex(const rt_uint8_t *ptr, rt_size_t buflen)
static void mtd_dump_hex(const rt_uint8_t *ptr, int buflen)
{
unsigned char *buf = (unsigned char *)ptr;
int i, j;

View File

@ -424,7 +424,7 @@ static struct mmcsd_blk_device * rt_mmcsd_create_blkdev(struct rt_mmcsd_card *ca
rt_int32_t rt_mmcsd_blk_probe(struct rt_mmcsd_card *card)
{
rt_int32_t err = 0;
rt_uint8_t status;
rt_err_t status;
rt_uint8_t *sector;
err = mmcsd_set_blksize(card);

View File

@ -196,7 +196,7 @@ static int mmc_parse_ext_csd(struct rt_mmcsd_card *card, rt_uint8_t *ext_csd)
card_capacity = *((rt_uint32_t *)&ext_csd[EXT_CSD_SEC_CNT]);
card_capacity *= card->card_blksize;
card_capacity >>= 10; /* unit:KB */
card->card_capacity = card_capacity;
card->card_capacity = (rt_uint32_t)card_capacity;
LOG_I("emmc card capacity %d KB.", card->card_capacity);
return 0;

View File

@ -284,8 +284,7 @@ rt_err_t mmcsd_send_app_cmd(struct rt_mmcsd_host *host,
int retry)
{
struct rt_mmcsd_req req;
rt_uint32_t i;
int i;
rt_err_t err;
err = -RT_ERROR;
@ -294,7 +293,7 @@ rt_err_t mmcsd_send_app_cmd(struct rt_mmcsd_host *host,
* We have to resend MMC_APP_CMD for each attempt so
* we cannot use the retries field in mmc_command.
*/
for (i = 0;i <= retry;i++)
for (i = 0; i <= retry; i++)
{
rt_memset(&req, 0, sizeof(struct rt_mmcsd_req));

View File

@ -424,7 +424,7 @@ static void rt_dma_recv_update_get_index(struct rt_serial_device *serial, rt_siz
if (rx_fifo->is_full && len != 0) rx_fifo->is_full = RT_FALSE;
rx_fifo->get_index += len;
rx_fifo->get_index += (rt_uint16_t)len;
if (rx_fifo->get_index >= serial->config.bufsz)
{
rx_fifo->get_index %= serial->config.bufsz;
@ -445,7 +445,7 @@ static void rt_dma_recv_update_put_index(struct rt_serial_device *serial, rt_siz
if (rx_fifo->get_index <= rx_fifo->put_index)
{
rx_fifo->put_index += len;
rx_fifo->put_index += (rt_uint16_t)len;
/* beyond the fifo end */
if (rx_fifo->put_index >= serial->config.bufsz)
{
@ -459,7 +459,7 @@ static void rt_dma_recv_update_put_index(struct rt_serial_device *serial, rt_siz
}
else
{
rx_fifo->put_index += len;
rx_fifo->put_index += (rt_uint16_t)len;
if (rx_fifo->put_index >= rx_fifo->get_index)
{
/* beyond the fifo end */

View File

@ -218,7 +218,7 @@ int rt_hw_touch_register(rt_touch_t touch,
rt_uint32_t flag,
void *data)
{
rt_int8_t result;
rt_err_t result;
rt_device_t device;
RT_ASSERT(touch != RT_NULL);

View File

@ -84,9 +84,9 @@ char *ltoa(long value, char *string, int radix)
i = v % radix;
v = v / radix;
if (i < 10)
*tp++ = i+'0';
*tp++ = (char)(i+'0');
else
*tp++ = i + 'a' - 10;
*tp++ = (char)(i + 'a' - 10);
}
sp = string;
@ -129,9 +129,9 @@ char *ultoa(unsigned long value, char *string, int radix)
i = v % radix;
v = v / radix;
if (i < 10)
*tp++ = i+'0';
*tp++ = (char)(i+'0');
else
*tp++ = i + 'a' - 10;
*tp++ = (char)(i + 'a' - 10);
}
sp = string;

View File

@ -171,8 +171,8 @@ static int set_timeval(struct timeval *tv)
struct tm *gmtime_r(const time_t *timep, struct tm *r)
{
time_t i;
time_t work = *timep % (SPD);
int i;
int work = *timep % (SPD);
if(timep == RT_NULL || r == RT_NULL)
{
@ -186,11 +186,11 @@ struct tm *gmtime_r(const time_t *timep, struct tm *r)
work /= 60;
r->tm_min = work % 60;
r->tm_hour = work / 60;
work = *timep / (SPD);
work = (int)(*timep / (SPD));
r->tm_wday = (4 + work) % 7;
for (i = 1970;; ++i)
{
time_t k = __isleap(i) ? 366 : 365;
int k = __isleap(i) ? 366 : 365;
if (work >= k)
work -= k;
else
@ -468,7 +468,7 @@ time_t timegm(struct tm * const t)
/* day is now the number of days since 'Jan 1 1970' */
i = 7;
t->tm_wday = (day + 4) % i; /* Sunday=0, Monday=1, ..., Saturday=6 */
t->tm_wday = (int)((day + 4) % i); /* Sunday=0, Monday=1, ..., Saturday=6 */
i = 24;
day *= i;

View File

@ -100,7 +100,7 @@ int select(int nfds, fd_set *readfds, fd_set *writefds, fd_set *exceptfds, struc
/* Convert the timeout to milliseconds */
if (timeout)
{
msec = timeout->tv_sec * 1000 + timeout->tv_usec / 1000;
msec = (int)timeout->tv_sec * 1000 + (int)timeout->tv_usec / 1000;
}
else
{

View File

@ -475,6 +475,10 @@ static err_t eth_netif_device_init(struct netif *netif)
/* get device object */
device = (rt_device_t) ethif;
if (rt_device_init(device) != RT_EOK)
{
return ERR_IF;
}
if (rt_device_open(device, RT_DEVICE_FLAG_RDWR) != RT_EOK)
{
return ERR_IF;
@ -910,7 +914,7 @@ FINSH_FUNCTION_EXPORT(set_dns, set DNS server address);
void list_if(void)
{
rt_ubase_t index;
rt_uint8_t index;
struct netif * netif;
rt_enter_critical();

View File

@ -18,21 +18,21 @@
#define RT_LINK_AUTO_INIT
#define RT_LINK_FLAG_ACK 0x01
#define RT_LINK_FLAG_CRC 0x02
#define RT_LINK_FLAG_ACK 0x01U
#define RT_LINK_FLAG_CRC 0x02U
#define RT_LINK_FRAME_HEAD 0x15
#define RT_LINK_FRAME_HEAD_MASK 0x1F
#define RT_LINK_FRAME_HEAD 0x15U
#define RT_LINK_FRAME_HEAD_MASK 0x1FU
/* The maximum number of split frames for a long package */
#define RT_LINK_FRAMES_MAX 0x03
#define RT_LINK_FRAMES_MAX 0x03U
/* The length in the rt_link_frame_head structure occupies 11 bits,
so the value range after 4-byte alignment is 0-2044.*/
#define RT_LINK_MAX_FRAME_LENGTH 1024
#define RT_LINK_MAX_FRAME_LENGTH 1024U
#define RT_LINK_ACK_MAX 0x07
#define RT_LINK_CRC_LENGTH 4
#define RT_LINK_HEAD_LENGTH 4
#define RT_LINK_EXTEND_LENGTH 4
#define RT_LINK_ACK_MAX 0x07U
#define RT_LINK_CRC_LENGTH 4U
#define RT_LINK_HEAD_LENGTH 4U
#define RT_LINK_EXTEND_LENGTH 4U
#define RT_LINK_MAX_DATA_LENGTH (RT_LINK_MAX_FRAME_LENGTH - \
RT_LINK_HEAD_LENGTH - \

View File

@ -70,7 +70,7 @@ struct rt_link_session *rt_link_get_scb(void)
return rt_link_scb;
}
static rt_int16_t rt_link_check_seq(rt_uint8_t new, rt_uint8_t used)
static rt_uint8_t rt_link_check_seq(rt_uint8_t new, rt_uint8_t used)
{
rt_int16_t compare_seq = 0;
compare_seq = new - used;
@ -78,7 +78,7 @@ static rt_int16_t rt_link_check_seq(rt_uint8_t new, rt_uint8_t used)
{
compare_seq = compare_seq + 256;
}
return compare_seq;
return (rt_uint8_t)compare_seq;
}
static int rt_link_frame_init(struct rt_link_frame *frame, rt_uint8_t config)
@ -157,7 +157,7 @@ static rt_err_t rt_link_frame_extend_config(struct rt_link_frame *frame, rt_link
return RT_EOK;
}
static int rt_link_command_frame_send(rt_uint8_t serv, rt_uint8_t sequence, rt_link_frame_attr_e attribute, rt_uint16_t parameter)
static int rt_link_command_frame_send(rt_uint16_t serv, rt_uint8_t sequence, rt_link_frame_attr_e attribute, rt_uint16_t parameter)
{
struct rt_link_frame command_frame = {0};
rt_uint8_t data[sizeof(command_frame.head) + sizeof(command_frame.extend)] = {0};
@ -182,7 +182,7 @@ static int rt_link_command_frame_send(rt_uint8_t serv, rt_uint8_t sequence, rt_l
static void rt_link_service_send_finish(rt_link_err_e err)
{
struct rt_link_frame *frame = RT_NULL;
rt_uint8_t service = RT_LINK_SERVICE_MAX;
rt_uint16_t service = RT_LINK_SERVICE_MAX;
void *buffer = RT_NULL;
rt_slist_t *tem_list = rt_slist_first(&rt_link_scb->tx_data_slist);
if (tem_list == RT_NULL)
@ -416,7 +416,7 @@ static rt_err_t rt_link_confirm_handle(struct rt_link_frame *receive_frame)
}
/* serv type rt_link_service_e */
static void rt_link_recv_finish(rt_uint8_t serv, void *data, rt_size_t size)
static void rt_link_recv_finish(rt_uint16_t serv, void *data, rt_size_t size)
{
if (rt_link_scb->service[serv] == RT_NULL)
{
@ -570,7 +570,7 @@ static rt_err_t rt_link_handshake_handle(struct rt_link_frame *receive_frame)
/* sync requester tx seq, responder rx seq = requester tx seq */
rt_link_scb->rx_record.rx_seq = receive_frame->head.sequence;
/* sync requester rx seq, responder tx seq = requester rx seq */
rt_link_scb->tx_seq = receive_frame->extend.parameter;
rt_link_scb->tx_seq = (rt_uint8_t)receive_frame->extend.parameter;
if (rt_link_scb->service[receive_frame->head.service] != RT_NULL)
{
@ -1042,11 +1042,11 @@ rt_size_t rt_link_send(struct rt_link_service *service, const void *data, rt_siz
service->err = RT_LINK_EOK;
if (size % RT_LINK_MAX_DATA_LENGTH == 0)
{
total = size / RT_LINK_MAX_DATA_LENGTH;
total = (rt_uint8_t)(size / RT_LINK_MAX_DATA_LENGTH);
}
else
{
total = size / RT_LINK_MAX_DATA_LENGTH + 1;
total = (rt_uint8_t)(size / RT_LINK_MAX_DATA_LENGTH + 1);
}
if (total > RT_LINK_FRAMES_MAX)
@ -1079,7 +1079,7 @@ rt_size_t rt_link_send(struct rt_link_service *service, const void *data, rt_siz
send_frame->attribute = RT_LINK_LONG_DATA_FRAME;
if (offset + RT_LINK_MAX_DATA_LENGTH > size)
{
send_frame->data_len = size - offset;
send_frame->data_len = (rt_uint16_t)(size - offset);
}
else
{
@ -1087,12 +1087,12 @@ rt_size_t rt_link_send(struct rt_link_service *service, const void *data, rt_siz
offset += RT_LINK_MAX_DATA_LENGTH;
}
rt_link_frame_extend_config(send_frame, RT_LINK_LONG_DATA_FRAME, size);
rt_link_frame_extend_config(send_frame, RT_LINK_LONG_DATA_FRAME, (rt_uint16_t)size);
}
else
{
send_frame->attribute = RT_LINK_SHORT_DATA_FRAME;
send_frame->data_len = size;
send_frame->data_len = (rt_uint16_t)size;
}
/* append the frame on the tail of list */

View File

@ -47,7 +47,7 @@ struct rt_link_receive_buffer *rt_link_hw_buffer_init(void *parameter)
static rt_size_t rt_link_hw_buffer_write(void *data, rt_size_t count)
{
int surplus = 0;
rt_size_t surplus = 0;
if (rx_buffer == RT_NULL)
{
return 0;

View File

@ -522,7 +522,7 @@ static void do_output(rt_uint32_t level, const char *tag, rt_bool_t is_raw, cons
}
else if (ulog.async_rb)
{
rt_ringbuffer_put(ulog.async_rb, (const rt_uint8_t *)log_buf, log_buf_size);
rt_ringbuffer_put(ulog.async_rb, (const rt_uint8_t *)log_buf, (rt_uint16_t)log_buf_size);
/* send a notice */
rt_sem_release(&ulog.async_notice);
}
@ -1405,7 +1405,7 @@ void ulog_async_output(void)
char *log = rt_malloc(log_len + 1);
if (log)
{
rt_size_t len = rt_ringbuffer_get(ulog.async_rb, (rt_uint8_t *)log, log_len);
rt_size_t len = rt_ringbuffer_get(ulog.async_rb, (rt_uint8_t *)log, (rt_uint16_t)log_len);
log[log_len] = '\0';
ulog_output_to_all_backend(LOG_LVL_DBG, "", RT_TRUE, log, len);
rt_free(log);

View File

@ -1797,7 +1797,7 @@ rt_err_t rt_mb_init(rt_mailbox_t mb,
/* initialize mailbox */
mb->msg_pool = (rt_ubase_t *)msgpool;
mb->size = size;
mb->size = (rt_uint16_t)size;
mb->entry = 0;
mb->in_offset = 0;
mb->out_offset = 0;
@ -1899,7 +1899,7 @@ rt_mailbox_t rt_mb_create(const char *name, rt_size_t size, rt_uint8_t flag)
_ipc_object_init(&(mb->parent));
/* initialize mailbox */
mb->size = size;
mb->size = (rt_uint16_t)size;
mb->msg_pool = (rt_ubase_t *)RT_KERNEL_MALLOC(mb->size * sizeof(rt_ubase_t));
if (mb->msg_pool == RT_NULL)
{
@ -2511,7 +2511,7 @@ rt_err_t rt_mq_init(rt_mq_t mq,
/* get correct message size */
mq->msg_size = RT_ALIGN(msg_size, RT_ALIGN_SIZE);
mq->max_msgs = pool_size / (mq->msg_size + sizeof(struct rt_mq_message));
mq->max_msgs = (rt_uint16_t)(pool_size / (mq->msg_size + sizeof(struct rt_mq_message)));
/* initialize message list */
mq->msg_queue_head = RT_NULL;
@ -2636,7 +2636,7 @@ rt_mq_t rt_mq_create(const char *name,
/* get correct message size */
mq->msg_size = RT_ALIGN(msg_size, RT_ALIGN_SIZE);
mq->max_msgs = max_msgs;
mq->max_msgs = (rt_uint16_t)max_msgs;
/* allocate message pool */
mq->msg_pool = RT_KERNEL_MALLOC((mq->msg_size + sizeof(struct rt_mq_message)) * mq->max_msgs);