diff options
Diffstat (limited to 'examples')
79 files changed, 1619 insertions, 1130 deletions
diff --git a/examples/file/listdir.c b/examples/file/listdir.c index d8ea7af82a..98fbc5ea2c 100644 --- a/examples/file/listdir.c +++ b/examples/file/listdir.c @@ -1,5 +1,5 @@ /* - * Copyright (c) 2006-2020, RT-Thread Development Team + * Copyright (c) 2006-2021, RT-Thread Development Team * * SPDX-License-Identifier: Apache-2.0 * diff --git a/examples/file/readspeed.c b/examples/file/readspeed.c index e5073856b4..ffc19635cf 100644 --- a/examples/file/readspeed.c +++ b/examples/file/readspeed.c @@ -1,5 +1,5 @@ /* - * Copyright (c) 2006-2020, RT-Thread Development Team + * Copyright (c) 2006-2021, RT-Thread Development Team * * SPDX-License-Identifier: Apache-2.0 * @@ -46,9 +46,9 @@ void readspeed(const char* filename, int block_size) } tick = rt_tick_get() - tick; - /* close file and release memory */ + /* close file and release memory */ close(fd); - rt_free(buff_ptr); + rt_free(buff_ptr); /* calculate read speed */ rt_kprintf("File read speed: %d byte/s\n", total_length /tick * RT_TICK_PER_SECOND); diff --git a/examples/file/readwrite.c b/examples/file/readwrite.c index 5738323805..56f3b7e16c 100644 --- a/examples/file/readwrite.c +++ b/examples/file/readwrite.c @@ -1,5 +1,5 @@ /* - * Copyright (c) 2006-2020, RT-Thread Development Team + * Copyright (c) 2006-2021, RT-Thread Development Team * * SPDX-License-Identifier: Apache-2.0 * @@ -17,21 +17,21 @@ /* file read write test */ void readwrite(const char* filename) { - int fd; - int index, length; - char* test_data; - char* buffer; - int block_size = TEST_DATA_LEN; + int fd; + int index, length; + char* test_data; + char* buffer; + int block_size = TEST_DATA_LEN; - /* open with write only & create */ - fd = open(filename, O_WRONLY | O_CREAT | O_TRUNC, 0); - if (fd < 0) - { - rt_kprintf("open file for write failed\n"); - return; - } + /* open with write only & create */ + fd = open(filename, O_WRONLY | O_CREAT | O_TRUNC, 0); + if (fd < 0) + { + rt_kprintf("open file for write failed\n"); + return; + } - test_data = rt_malloc(block_size); + test_data = rt_malloc(block_size); if (test_data == RT_NULL) { rt_kprintf("no memory\n"); @@ -48,94 +48,94 @@ void readwrite(const char* filename) return; } - /* prepare some data */ - for (index = 0; index < block_size; index ++) - { - test_data[index] = index + 27; - } + /* prepare some data */ + for (index = 0; index < block_size; index ++) + { + test_data[index] = index + 27; + } - /* write to file */ - length = write(fd, test_data, block_size); - if (length != block_size) - { - rt_kprintf("write data failed\n"); - close(fd); - goto __exit; - } + /* write to file */ + length = write(fd, test_data, block_size); + if (length != block_size) + { + rt_kprintf("write data failed\n"); + close(fd); + goto __exit; + } - /* close file */ - close(fd); + /* close file */ + close(fd); - /* reopen the file with append to the end */ - fd = open(filename, O_WRONLY | O_CREAT | O_APPEND, 0); - if (fd < 0) - { - rt_kprintf("open file for append write failed\n"); - goto __exit;; - } + /* reopen the file with append to the end */ + fd = open(filename, O_WRONLY | O_CREAT | O_APPEND, 0); + if (fd < 0) + { + rt_kprintf("open file for append write failed\n"); + goto __exit;; + } - length = write(fd, test_data, block_size); - if (length != block_size) - { - rt_kprintf("append write data failed\n"); - close(fd); - goto __exit; - } - /* close the file */ - close(fd); + length = write(fd, test_data, block_size); + if (length != block_size) + { + rt_kprintf("append write data failed\n"); + close(fd); + goto __exit; + } + /* close the file */ + close(fd); - /* open the file for data validation. */ - fd = open(filename, O_RDONLY, 0); - if (fd < 0) - { - rt_kprintf("check: open file for read failed\n"); - goto __exit; - } + /* open the file for data validation. */ + fd = open(filename, O_RDONLY, 0); + if (fd < 0) + { + rt_kprintf("check: open file for read failed\n"); + goto __exit; + } - /* read the data (should be the data written by the first time ) */ - length = read(fd, buffer, block_size); - if (length != block_size) - { - rt_kprintf("check: read file failed\n"); - close(fd); - goto __exit; - } + /* read the data (should be the data written by the first time ) */ + length = read(fd, buffer, block_size); + if (length != block_size) + { + rt_kprintf("check: read file failed\n"); + close(fd); + goto __exit; + } - /* validate */ - for (index = 0; index < block_size; index ++) - { - if (test_data[index] != buffer[index]) - { - rt_kprintf("check: check data failed at %d\n", index); - close(fd); - goto __exit; - } - } + /* validate */ + for (index = 0; index < block_size; index ++) + { + if (test_data[index] != buffer[index]) + { + rt_kprintf("check: check data failed at %d\n", index); + close(fd); + goto __exit; + } + } - /* read the data (should be the second time data) */ - length = read(fd, buffer, block_size); - if (length != block_size) - { - rt_kprintf("check: read file failed\n"); - close(fd); - goto __exit; - } + /* read the data (should be the second time data) */ + length = read(fd, buffer, block_size); + if (length != block_size) + { + rt_kprintf("check: read file failed\n"); + close(fd); + goto __exit; + } - /* validate */ - for (index = 0; index < block_size; index ++) - { - if (test_data[index] != buffer[index]) - { - rt_kprintf("check: check data failed at %d\n", index); - close(fd); - goto __exit; - } - } + /* validate */ + for (index = 0; index < block_size; index ++) + { + if (test_data[index] != buffer[index]) + { + rt_kprintf("check: check data failed at %d\n", index); + close(fd); + goto __exit; + } + } - /* close the file */ - close(fd); - /* print result */ - rt_kprintf("read/write test successful!\n"); + /* close the file */ + close(fd); + /* print result */ + rt_kprintf("read/write test successful!\n"); __exit: rt_free(test_data); diff --git a/examples/file/seekdir.c b/examples/file/seekdir.c index d6a33426b4..efadd3a1c8 100644 --- a/examples/file/seekdir.c +++ b/examples/file/seekdir.c @@ -1,5 +1,5 @@ /* - * Copyright (c) 2006-2020, RT-Thread Development Team + * Copyright (c) 2006-2021, RT-Thread Development Team * * SPDX-License-Identifier: Apache-2.0 * @@ -12,35 +12,35 @@ void seekdir_test(void) { - DIR * dirp; - long save3 = 0; - int i = 0; - struct dirent *dp; + DIR * dirp; + long save3 = 0; + int i = 0; + struct dirent *dp; - dirp = opendir ("/"); - save3 = telldir(dirp); - for (dp = readdir(dirp); dp != RT_NULL; dp = readdir(dirp)) - { - rt_kprintf("direntry: %s\n", dp->d_name); + dirp = opendir ("/"); + save3 = telldir(dirp); + for (dp = readdir(dirp); dp != RT_NULL; dp = readdir(dirp)) + { + rt_kprintf("direntry: %s\n", dp->d_name); - /* save the pointer of the third directory */ - if (i++ == 3) - { - save3 = telldir(dirp); - } - } + /* save the pointer of the third directory */ + if (i++ == 3) + { + save3 = telldir(dirp); + } + } - /* get back to the third directory */ - seekdir (dirp, save3); - rt_kprintf("seek dientry to: %d\n", save3); - for (dp = readdir(dirp); dp != RT_NULL; dp = readdir(dirp)) - { - rt_kprintf("direntry: %s\n", dp->d_name); - } + /* get back to the third directory */ + seekdir (dirp, save3); + rt_kprintf("seek dientry to: %d\n", save3); + for (dp = readdir(dirp); dp != RT_NULL; dp = readdir(dirp)) + { + rt_kprintf("direntry: %s\n", dp->d_name); + } - /* close the directory */ - closedir (dirp); -} + /* close the directory */ + closedir (dirp); +} #ifdef RT_USING_FINSH #include <finsh.h> diff --git a/examples/file/writespeed.c b/examples/file/writespeed.c index 60dd900a68..680761583c 100644 --- a/examples/file/writespeed.c +++ b/examples/file/writespeed.c @@ -1,5 +1,5 @@ /* - * Copyright (c) 2006-2020, RT-Thread Development Team + * Copyright (c) 2006-2021, RT-Thread Development Team * * SPDX-License-Identifier: Apache-2.0 * diff --git a/examples/kernel/cpuusage.c b/examples/kernel/cpuusage.c index 490061ddb7..5f9d480139 100644 --- a/examples/kernel/cpuusage.c +++ b/examples/kernel/cpuusage.c @@ -1,3 +1,11 @@ +/* + * Copyright (c) 2006-2021, RT-Thread Development Team + * + * SPDX-License-Identifier: Apache-2.0 + * + * Change Logs: + * + */ #include <rtthread.h> #include <rthw.h> diff --git a/examples/kernel/event_simple.c b/examples/kernel/event_simple.c index e377e721bb..d2a2948fc7 100644 --- a/examples/kernel/event_simple.c +++ b/examples/kernel/event_simple.c @@ -1,4 +1,12 @@ /* + * Copyright (c) 2006-2021, RT-Thread Development Team + * + * SPDX-License-Identifier: Apache-2.0 + * + * Change Logs: + * + */ +/* * 程序清单:事件例程 * * 这个程序会创建3个动态线程及初始化一个静态事件对象 diff --git a/examples/kernel/heap_malloc.c b/examples/kernel/heap_malloc.c index 271202ad8f..e2fa4511e7 100644 --- a/examples/kernel/heap_malloc.c +++ b/examples/kernel/heap_malloc.c @@ -1,3 +1,12 @@ +/* + * Copyright (c) 2006-2021, RT-Thread Development Team + * + * SPDX-License-Identifier: Apache-2.0 + * + * Change Logs: + * + */ + #include <rtthread.h> #include "tc_comm.h" diff --git a/examples/kernel/heap_realloc.c b/examples/kernel/heap_realloc.c index bc7b56a999..ab603c5d8d 100644 --- a/examples/kernel/heap_realloc.c +++ b/examples/kernel/heap_realloc.c @@ -1,3 +1,12 @@ +/* + * Copyright (c) 2006-2021, RT-Thread Development Team + * + * SPDX-License-Identifier: Apache-2.0 + * + * Change Logs: + * + */ + #include <rtthread.h> #include "tc_comm.h" diff --git a/examples/kernel/mbox_send_wait.c b/examples/kernel/mbox_send_wait.c index 86513fcb13..67f358ecea 100644 --- a/examples/kernel/mbox_send_wait.c +++ b/examples/kernel/mbox_send_wait.c @@ -1,4 +1,13 @@ /* + * Copyright (c) 2006-2021, RT-Thread Development Team + * + * SPDX-License-Identifier: Apache-2.0 + * + * Change Logs: + * + */ + +/* * 程序清单:邮箱例程_发送阻塞 * * 这个程序用来测试邮箱发送时候的阻塞情况。 diff --git a/examples/kernel/mbox_simple.c b/examples/kernel/mbox_simple.c index 5d588decb3..3f39bc0016 100644 --- a/examples/kernel/mbox_simple.c +++ b/examples/kernel/mbox_simple.c @@ -1,4 +1,13 @@ /* + * Copyright (c) 2006-2021, RT-Thread Development Team + * + * SPDX-License-Identifier: Apache-2.0 + * + * Change Logs: + * + */ + +/* * 程序清单:邮箱例程 * * 这个程序会创建2个动态线程,一个静态的邮箱对象,其中一个线程往邮箱中发送邮件, diff --git a/examples/kernel/memp_simple.c b/examples/kernel/memp_simple.c index ab8f3b94ed..055db41912 100644 --- a/examples/kernel/memp_simple.c +++ b/examples/kernel/memp_simple.c @@ -1,4 +1,13 @@ /* + * Copyright (c) 2006-2021, RT-Thread Development Team + * + * SPDX-License-Identifier: Apache-2.0 + * + * Change Logs: + * + */ + +/* * 程序清单:内存池例程 * * 这个程序会创建一个静态的内存池对象,2个动态线程。两个线程会试图分别从内存池中获得 diff --git a/examples/kernel/messageq_simple.c b/examples/kernel/messageq_simple.c index 51b371f59c..62504bebb7 100644 --- a/examples/kernel/messageq_simple.c +++ b/examples/kernel/messageq_simple.c @@ -1,4 +1,13 @@ /* + * Copyright (c) 2006-2021, RT-Thread Development Team + * + * SPDX-License-Identifier: Apache-2.0 + * + * Change Logs: + * + */ + +/* * 程序清单:消息队列例程 * * 这个程序会创建3个动态线程,一个线程会从消息队列中收取消息;一个线程会定时给消 diff --git a/examples/kernel/mutex_priority.c b/examples/kernel/mutex_priority.c index f647fc4039..c1db934157 100755 --- a/examples/kernel/mutex_priority.c +++ b/examples/kernel/mutex_priority.c @@ -1,4 +1,13 @@ /* + * Copyright (c) 2006-2021, RT-Thread Development Team + * + * SPDX-License-Identifier: Apache-2.0 + * + * Change Logs: + * + */ + +/* * 创建7个进程,tid20、tid21、tid22、tid23、tid24、tid25、tid26、tid27、tid28、tid29 * 各任务优先级分别为20、21、22、23、24、25、26、27、28、29, * 其中tid26最先获得锁,tid22不需要使用到互斥锁,其他所有进程均需要使用互斥锁, diff --git a/examples/kernel/mutex_simple.c b/examples/kernel/mutex_simple.c index afbab3a3e1..4f6c5d7d28 100644 --- a/examples/kernel/mutex_simple.c +++ b/examples/kernel/mutex_simple.c @@ -1,5 +1,10 @@ /* - * 程序清单: + * Copyright (c) 2006-2021, RT-Thread Development Team + * + * SPDX-License-Identifier: Apache-2.0 + * + * Change Logs: + * */ #include <rtthread.h> #include "tc_comm.h" diff --git a/examples/kernel/semaphore_buffer_worker.c b/examples/kernel/semaphore_buffer_worker.c index db3285c74b..5e4723b417 100644 --- a/examples/kernel/semaphore_buffer_worker.c +++ b/examples/kernel/semaphore_buffer_worker.c @@ -1,4 +1,13 @@ /* + * Copyright (c) 2006-2021, RT-Thread Development Team + * + * SPDX-License-Identifier: Apache-2.0 + * + * Change Logs: + * + */ + +/* * 程序清单:信号量实现生产者消费者间的互斥 * * 在这个程序中,会创建两个线程,一个是生成者线程worker一个是消费者线程thread diff --git a/examples/kernel/semaphore_dynamic.c b/examples/kernel/semaphore_dynamic.c index dc088e6e44..564d73c496 100644 --- a/examples/kernel/semaphore_dynamic.c +++ b/examples/kernel/semaphore_dynamic.c @@ -1,4 +1,13 @@ /* + * Copyright (c) 2006-2021, RT-Thread Development Team + * + * SPDX-License-Identifier: Apache-2.0 + * + * Change Logs: + * + */ + +/* * 程序清单:动态信号量 * * 这个例子中将创建一个动态信号量(初始值为0 )及一个动态线程,在这个动态线程中 diff --git a/examples/kernel/semaphore_priority.c b/examples/kernel/semaphore_priority.c index d6e3ce3914..7e37a826cb 100644 --- a/examples/kernel/semaphore_priority.c +++ b/examples/kernel/semaphore_priority.c @@ -1,3 +1,12 @@ +/* + * Copyright (c) 2006-2021, RT-Thread Development Team + * + * SPDX-License-Identifier: Apache-2.0 + * + * Change Logs: + * + */ + #include <rtthread.h> #include "tc_comm.h" diff --git a/examples/kernel/semaphore_producer_consumer.c b/examples/kernel/semaphore_producer_consumer.c index a240cfa8b2..b6f996ff57 100644 --- a/examples/kernel/semaphore_producer_consumer.c +++ b/examples/kernel/semaphore_producer_consumer.c @@ -1,4 +1,13 @@ /* + * Copyright (c) 2006-2021, RT-Thread Development Team + * + * SPDX-License-Identifier: Apache-2.0 + * + * Change Logs: + * + */ + +/* * 程序清单:生产者消费者例子 * * 这个例子中将创建两个线程用于实现生产者消费者问题 diff --git a/examples/kernel/semaphore_static.c b/examples/kernel/semaphore_static.c index cb199886a4..641b0bc7c9 100644 --- a/examples/kernel/semaphore_static.c +++ b/examples/kernel/semaphore_static.c @@ -1,4 +1,13 @@ /* + * Copyright (c) 2006-2021, RT-Thread Development Team + * + * SPDX-License-Identifier: Apache-2.0 + * + * Change Logs: + * + */ + +/* * 程序清单:静态信号量 * * 这个例子中将创建一个静态信号量(初始值为0 )及一个静态线程,在这个静态线程中 diff --git a/examples/kernel/tc_comm.c b/examples/kernel/tc_comm.c index f6493389a6..7153412aa0 100644 --- a/examples/kernel/tc_comm.c +++ b/examples/kernel/tc_comm.c @@ -1,3 +1,12 @@ +/* + * Copyright (c) 2006-2021, RT-Thread Development Team + * + * SPDX-License-Identifier: Apache-2.0 + * + * Change Logs: + * + */ + #include "tc_comm.h" #ifdef RT_USING_FINSH #include <finsh.h> diff --git a/examples/kernel/tc_comm.h b/examples/kernel/tc_comm.h index aee1fec2d2..17dd8eb924 100644 --- a/examples/kernel/tc_comm.h +++ b/examples/kernel/tc_comm.h @@ -1,7 +1,16 @@ + +/* + * Copyright (c) 2006-2021, RT-Thread Development Team + * + * SPDX-License-Identifier: Apache-2.0 + * + * Change Logs: + * + */ #ifndef __TC_COMM_H__ #define __TC_COMM_H__ -/* +/* * RT-Thread TestCase * */ diff --git a/examples/kernel/tc_sample.c b/examples/kernel/tc_sample.c index 212875b716..272edc0e39 100644 --- a/examples/kernel/tc_sample.c +++ b/examples/kernel/tc_sample.c @@ -1,3 +1,12 @@ +/* + * Copyright (c) 2006-2021, RT-Thread Development Team + * + * SPDX-License-Identifier: Apache-2.0 + * + * Change Logs: + * + */ + #include <rtthread.h> #include "tc_comm.h" diff --git a/examples/kernel/thread_delay.c b/examples/kernel/thread_delay.c index f9404d704c..50740e2c8f 100644 --- a/examples/kernel/thread_delay.c +++ b/examples/kernel/thread_delay.c @@ -1,3 +1,12 @@ +/* + * Copyright (c) 2006-2021, RT-Thread Development Team + * + * SPDX-License-Identifier: Apache-2.0 + * + * Change Logs: + * + */ + #include <rtthread.h> #include "tc_comm.h" diff --git a/examples/kernel/thread_delete.c b/examples/kernel/thread_delete.c index 72eb4ec008..924a823f35 100644 --- a/examples/kernel/thread_delete.c +++ b/examples/kernel/thread_delete.c @@ -1,4 +1,13 @@ /* + * Copyright (c) 2006-2021, RT-Thread Development Team + * + * SPDX-License-Identifier: Apache-2.0 + * + * Change Logs: + * + */ + +/* * 程序清单:删除线程 * * 这个例子会创建两个线程,在一个线程中删除另外一个线程。 diff --git a/examples/kernel/thread_detach.c b/examples/kernel/thread_detach.c index 9370f212e1..d0d72d017b 100644 --- a/examples/kernel/thread_detach.c +++ b/examples/kernel/thread_detach.c @@ -1,4 +1,13 @@ /* + * Copyright (c) 2006-2021, RT-Thread Development Team + * + * SPDX-License-Identifier: Apache-2.0 + * + * Change Logs: + * + */ + +/* * 程序清单:线程脱离 * * 这个例子会创建两个线程,在其中一个线程中执行对另一个线程的脱离。 diff --git a/examples/kernel/thread_dynamic.c b/examples/kernel/thread_dynamic.c index 0afb7f8f84..35c67c02fc 100644 --- a/examples/kernel/thread_dynamic.c +++ b/examples/kernel/thread_dynamic.c @@ -1,3 +1,12 @@ +/* + * Copyright (c) 2006-2021, RT-Thread Development Team + * + * SPDX-License-Identifier: Apache-2.0 + * + * Change Logs: + * + */ + #include <rtthread.h> #include "tc_comm.h" diff --git a/examples/kernel/thread_dynamic_simple.c b/examples/kernel/thread_dynamic_simple.c index 28944b1f34..dc378a6696 100644 --- a/examples/kernel/thread_dynamic_simple.c +++ b/examples/kernel/thread_dynamic_simple.c @@ -1,4 +1,13 @@ /* + * Copyright (c) 2006-2021, RT-Thread Development Team + * + * SPDX-License-Identifier: Apache-2.0 + * + * Change Logs: + * + */ + +/* * 程序清单:动态线程 * * 这个程序会初始化2个动态线程,它们拥有共同的入口函数,但参数不相同 diff --git a/examples/kernel/thread_priority.c b/examples/kernel/thread_priority.c index 0045b0e578..abf45bbe07 100644 --- a/examples/kernel/thread_priority.c +++ b/examples/kernel/thread_priority.c @@ -1,3 +1,12 @@ +/* + * Copyright (c) 2006-2021, RT-Thread Development Team + * + * SPDX-License-Identifier: Apache-2.0 + * + * Change Logs: + * + */ + #include <rtthread.h> #include "tc_comm.h" diff --git a/examples/kernel/thread_resume.c b/examples/kernel/thread_resume.c index cea814616f..e776466326 100644 --- a/examples/kernel/thread_resume.c +++ b/examples/kernel/thread_resume.c @@ -1,4 +1,13 @@ /* + * Copyright (c) 2006-2021, RT-Thread Development Team + * + * SPDX-License-Identifier: Apache-2.0 + * + * Change Logs: + * + */ + +/* * 程序清单:唤醒线程 * * 这个例子中将创建两个动态线程,低优先级线程将挂起自身,然后 diff --git a/examples/kernel/thread_same_priority.c b/examples/kernel/thread_same_priority.c index c7da2087a0..a238e24932 100644 --- a/examples/kernel/thread_same_priority.c +++ b/examples/kernel/thread_same_priority.c @@ -1,3 +1,12 @@ +/* + * Copyright (c) 2006-2021, RT-Thread Development Team + * + * SPDX-License-Identifier: Apache-2.0 + * + * Change Logs: + * + */ + #include <rtthread.h> #include "tc_comm.h" diff --git a/examples/kernel/thread_static.c b/examples/kernel/thread_static.c index 3033f2cda1..9234255679 100644 --- a/examples/kernel/thread_static.c +++ b/examples/kernel/thread_static.c @@ -1,3 +1,12 @@ +/* + * Copyright (c) 2006-2021, RT-Thread Development Team + * + * SPDX-License-Identifier: Apache-2.0 + * + * Change Logs: + * + */ + #include <rtthread.h> #include "tc_comm.h" diff --git a/examples/kernel/thread_static_simple.c b/examples/kernel/thread_static_simple.c index d9e3ff6f61..e0021d2c5f 100644 --- a/examples/kernel/thread_static_simple.c +++ b/examples/kernel/thread_static_simple.c @@ -1,4 +1,13 @@ /* + * Copyright (c) 2006-2021, RT-Thread Development Team + * + * SPDX-License-Identifier: Apache-2.0 + * + * Change Logs: + * + */ + +/* * 程序清单:静态线程 * * 这个程序会初始化2个静态线程,它们拥有共同的入口函数,但参数不相同 diff --git a/examples/kernel/thread_suspend.c b/examples/kernel/thread_suspend.c index 947cc3cbf6..2219c7b8d6 100644 --- a/examples/kernel/thread_suspend.c +++ b/examples/kernel/thread_suspend.c @@ -1,4 +1,13 @@ /* + * Copyright (c) 2006-2021, RT-Thread Development Team + * + * SPDX-License-Identifier: Apache-2.0 + * + * Change Logs: + * + */ + +/* * 程序清单:挂起线程 * * 这个例子中将创建两个动态线程,高优先级线程将在一定时刻后挂起低优先级线程。 diff --git a/examples/kernel/thread_yield.c b/examples/kernel/thread_yield.c index 4ed6b90e2a..97e57ba841 100644 --- a/examples/kernel/thread_yield.c +++ b/examples/kernel/thread_yield.c @@ -1,6 +1,12 @@ /* - * 程序清单: + * Copyright (c) 2006-2021, RT-Thread Development Team + * + * SPDX-License-Identifier: Apache-2.0 + * + * Change Logs: + * */ + #include <rtthread.h> #include "tc_comm.h" diff --git a/examples/kernel/timer_control.c b/examples/kernel/timer_control.c index 9fcb0d4c4d..c92d558d5c 100644 --- a/examples/kernel/timer_control.c +++ b/examples/kernel/timer_control.c @@ -1,4 +1,13 @@ /* + * Copyright (c) 2006-2021, RT-Thread Development Team + * + * SPDX-License-Identifier: Apache-2.0 + * + * Change Logs: + * + */ + +/* * 程序清单:动态定时器例程 * * 这个例程会创建1个动态周期型定时器对象,然后控制它进行定时时间长度的更改。 @@ -14,7 +23,7 @@ static rt_uint8_t count; static void timeout1(void* parameter) { rt_tick_t timeout = 50; - + rt_kprintf("periodic timer is timeout\n"); count ++; diff --git a/examples/kernel/timer_dynamic.c b/examples/kernel/timer_dynamic.c index 1260d50c09..35d7b845dd 100644 --- a/examples/kernel/timer_dynamic.c +++ b/examples/kernel/timer_dynamic.c @@ -1,4 +1,13 @@ /* + * Copyright (c) 2006-2021, RT-Thread Development Team + * + * SPDX-License-Identifier: Apache-2.0 + * + * Change Logs: + * + */ + +/* * 程序清单:动态定时器例程 * * 这个例程会创建两个动态定时器对象,一个是单次定时,一个是周期性的定时 diff --git a/examples/kernel/timer_static.c b/examples/kernel/timer_static.c index 884927bbc3..1523869b9a 100644 --- a/examples/kernel/timer_static.c +++ b/examples/kernel/timer_static.c @@ -1,4 +1,13 @@ /* + * Copyright (c) 2006-2021, RT-Thread Development Team + * + * SPDX-License-Identifier: Apache-2.0 + * + * Change Logs: + * + */ + +/* * 程序清单:定时器例程 * * 这个程序会初始化2个静态定时器,一个是单次定时,一个是周期性的定时 diff --git a/examples/kernel/timer_stop_self.c b/examples/kernel/timer_stop_self.c index 38ec9c441b..584bc4128e 100644 --- a/examples/kernel/timer_stop_self.c +++ b/examples/kernel/timer_stop_self.c @@ -1,4 +1,13 @@ /* + * Copyright (c) 2006-2021, RT-Thread Development Team + * + * SPDX-License-Identifier: Apache-2.0 + * + * Change Logs: + * + */ + +/* * 程序清单:动态定时器例程 * * 这个例程会创建1个动态周期型定时器对象 diff --git a/examples/kernel/timer_timeout.c b/examples/kernel/timer_timeout.c index d1a7099e2e..40bbbf2831 100644 --- a/examples/kernel/timer_timeout.c +++ b/examples/kernel/timer_timeout.c @@ -1,21 +1,30 @@ /* - * �����嵥����Ϣ�������� + * Copyright (c) 2006-2021, RT-Thread Development Team * - * �������ᴴ��3����̬�̣߳�һ���̻߳����Ϣ��������ȡ��Ϣ��һ���̻߳ᶨʱ���� - * Ϣ���з�����Ϣ��һ���̻߳ᶨʱ����Ϣ���з��ͽ�����Ϣ�� + * SPDX-License-Identifier: Apache-2.0 + * + * Change Logs: + * + */ + +/* + * 程序清单:消息队列例程 + * + * 这个程序会创建3个动态线程,一个线程会从消息队列中收取消息;一个线程会定时给消 + * 息队列发送消息;一个线程会定时给消息队列发送紧急消息。 */ #include <rtthread.h> #include "tc_comm.h" -/* ָ���߳̿��ƿ��ָ�� */ +/* 指向线程控制块的指针 */ static rt_thread_t tid = RT_NULL; -/* ��Ϣ���п��ƿ� */ +/* 消息队列控制块 */ static struct rt_messagequeue mq; -/* ��Ϣ�������õ��ķ�����Ϣ���ڴ�� */ +/* 消息队列中用到的放置消息的内存池 */ static char msg_pool[2048]; -/* ��ʱ���Ŀ��ƿ� */ +/* 定时器的控制块 */ static struct rt_timer timer; static rt_uint16_t no = 0; static void timer_timeout(void* parameter) @@ -27,24 +36,24 @@ static void timer_timeout(void* parameter) rt_mq_send(&mq, &buf[0], length); } -/* �߳���ں��� */ +/* 线程入口函数 */ static void thread_entry(void* parameter) { char buf[64]; rt_err_t result; - /* ��ʼ����ʱ�� */ - rt_timer_init(&timer, "timer", /* ��ʱ�������� timer1 */ - timer_timeout, /* ��ʱʱ�ص��Ĵ������� */ - RT_NULL, /* ��ʱ��������ڲ��� */ - 1, /* ��ʱ���ȣ���OS TickΪ��λ����1��OS Tick */ - RT_TIMER_FLAG_PERIODIC); /* �����Զ�ʱ�� */ + /* 初始化定时器 */ + rt_timer_init(&timer, "timer", /* 定时器名字是 timer1 */ + timer_timeout, /* 超时时回调的处理函数 */ + RT_NULL, /* 超时函数的入口参数 */ + 1, /* 定时长度,以OS Tick为单位,即1个OS Tick */ + RT_TIMER_FLAG_PERIODIC); /* 周期性定时器 */ while (1) { rt_memset(&buf[0], 0, sizeof(buf)); - /* ����Ϣ�����н�����Ϣ */ + /* 从消息队列中接收消息 */ result = rt_mq_recv(&mq, &buf[0], sizeof(buf), 1); if (result == RT_EOK) { @@ -59,16 +68,16 @@ static void thread_entry(void* parameter) int timer_timeout_init() { - /* ��ʼ����Ϣ���� */ - rt_mq_init(&mq, "mqt", - &msg_pool[0], /* �ڴ��ָ��msg_pool */ - 128 - sizeof(void*), /* ÿ����Ϣ�Ĵ�С�� 128 - void* */ - sizeof(msg_pool), /* �ڴ�صĴ�С��msg_pool�Ĵ�С */ - RT_IPC_FLAG_FIFO); /* ����ж���̵߳ȴ������������ȵõ��ķ���������Ϣ */ + /* 初始化消息队列 */ + rt_mq_init(&mq, "mqt", + &msg_pool[0], /* 内存池指向msg_pool */ + 128 - sizeof(void*), /* 每个消息的大小是 128 - void* */ + sizeof(msg_pool), /* 内存池的大小是msg_pool的大小 */ + RT_IPC_FLAG_FIFO); /* 如果有多个线程等待,按照先来先得到的方法分配消息 */ - /* �����߳� */ + /* 创建线程 */ tid = rt_thread_create("t", - thread_entry, RT_NULL, /* �߳������thread_entry, ��ڲ�����RT_NULL */ + thread_entry, RT_NULL, /* 线程入口是thread_entry, 入口参数是RT_NULL */ THREAD_STACK_SIZE, THREAD_PRIORITY, THREAD_TIMESLICE); if (tid != RT_NULL) rt_thread_startup(tid); @@ -81,38 +90,38 @@ int timer_timeout_init() #ifdef RT_USING_TC static void _tc_cleanup() { - /* �����������������������л��������̣߳�����Ӧ�ж� */ + /* 调度器上锁,上锁后,将不再切换到其他线程,仅响应中断 */ rt_enter_critical(); - /* ɾ���߳� */ + /* 删除线程 */ if (tid != RT_NULL && tid->stat != RT_THREAD_CLOSE) rt_thread_delete(tid); - /* ִ����Ϣ���ж������� */ + /* 执行消息队列对象脱离 */ rt_mq_detach(&mq); - /* ִ�ж�ʱ������ */ + /* 执行定时器脱离 */ rt_timer_detach(&timer); - /* ���������� */ + /* 调度器解锁 */ rt_exit_critical(); - /* ����TestCase״̬ */ + /* 设置TestCase状态 */ tc_done(TC_STAT_PASSED); } int _tc_timer_timeout() { - /* ����TestCase�����ص����� */ + /* 设置TestCase清理回调函数 */ tc_cleanup(_tc_cleanup); timer_timeout_init(); - /* ����TestCase���е��ʱ�� */ + /* 返回TestCase运行的最长时间 */ return 100; } -/* ����������finsh shell�� */ +/* 输出函数命令到finsh shell中 */ FINSH_FUNCTION_EXPORT(_tc_timer_timeout, a thread timer testcase); #else -/* �û�Ӧ����� */ +/* 用户应用入口 */ int rt_application_init() { timer_timeout_init(); diff --git a/examples/libc/dirent.c b/examples/libc/dirent.c index 75604f6067..03fa94151d 100644 --- a/examples/libc/dirent.c +++ b/examples/libc/dirent.c @@ -1,8 +1,11 @@ /* - * dirent.c + * Copyright (c) 2006-2021, RT-Thread Development Team * - * Created on: 2010-11-17 - * Author: bernard + * SPDX-License-Identifier: Apache-2.0 + * + * Change Logs: + * Date Author Notes + * 2010-11-17 Bernard first version */ #include <stdio.h> #include <stdlib.h> @@ -11,46 +14,46 @@ #include <dirent.h> int libc_dirent() { - DIR * dirp; - long int save3 = 0; - long int cur; - int i = 0; - int result = 0; - struct dirent *dp; + DIR * dirp; + long int save3 = 0; + long int cur; + int i = 0; + int result = 0; + struct dirent *dp; - dirp = opendir("/"); - for (dp = readdir(dirp); dp != NULL; dp = readdir(dirp)) - { - /* save position 3 (after fourth entry) */ - if (i++ == 3) - save3 = telldir(dirp); + dirp = opendir("/"); + for (dp = readdir(dirp); dp != NULL; dp = readdir(dirp)) + { + /* save position 3 (after fourth entry) */ + if (i++ == 3) + save3 = telldir(dirp); - printf("%s\n", dp->d_name); + printf("%s\n", dp->d_name); - /* stop at 400 (just to make sure dirp->__offset and dirp->__size are - scrambled */ - if (i == 400) - break; - } + /* stop at 400 (just to make sure dirp->__offset and dirp->__size are + scrambled */ + if (i == 400) + break; + } - printf("going back past 4-th entry...\n"); + printf("going back past 4-th entry...\n"); - /* go back to saved entry */ - seekdir(dirp, save3); + /* go back to saved entry */ + seekdir(dirp, save3); - /* Check whether telldir equals to save3 now. */ - cur = telldir(dirp); - if (cur != save3) - { - printf("seekdir (d, %ld); telldir (d) == %ld\n", save3, cur); - result = 1; - } + /* Check whether telldir equals to save3 now. */ + cur = telldir(dirp); + if (cur != save3) + { + printf("seekdir (d, %ld); telldir (d) == %ld\n", save3, cur); + result = 1; + } - /* print remaining files (3-last) */ - for (dp = readdir(dirp); dp != NULL; dp = readdir(dirp)) - printf("%s\n", dp->d_name); + /* print remaining files (3-last) */ + for (dp = readdir(dirp); dp != NULL; dp = readdir(dirp)) + printf("%s\n", dp->d_name); - closedir(dirp); - return result; + closedir(dirp); + return result; } FINSH_FUNCTION_EXPORT(libc_dirent, dirent test for libc); diff --git a/examples/libc/env.c b/examples/libc/env.c index ca67ac2e2a..05005c2d1f 100644 --- a/examples/libc/env.c +++ b/examples/libc/env.c @@ -1,18 +1,22 @@ /* - * env.c + * Copyright (c) 2006-2021, RT-Thread Development Team * - * Created on: 2010-11-17 - * Author: bernard + * SPDX-License-Identifier: Apache-2.0 + * + * Change Logs: + * Date Author Notes + * 2010-11-17 Bernard first version */ + #include <stdio.h> #include <stdlib.h> #include <finsh.h> int libc_env() { - printf("PATH=%s\n", getenv("PATH")); - putenv("foo=bar"); - printf("foo=%s\n", getenv("foo")); - return 0; + printf("PATH=%s\n", getenv("PATH")); + putenv("foo=bar"); + printf("foo=%s\n", getenv("foo")); + return 0; } FINSH_FUNCTION_EXPORT(libc_env, get/set_env test); diff --git a/examples/libc/ex1.c b/examples/libc/ex1.c index 2acbfc3a39..8f0ccfff1c 100644 --- a/examples/libc/ex1.c +++ b/examples/libc/ex1.c @@ -1,3 +1,11 @@ +/* + * Copyright (c) 2006-2021, RT-Thread Development Team + * + * SPDX-License-Identifier: Apache-2.0 + * + * Change Logs: + * Date Author Notes + */ /* Creates two threads, one printing 10000 "a"s, the other printing 10000 "b"s. Illustrates: thread creation, thread joining. */ @@ -9,29 +17,29 @@ static void *process(void * arg) { - int i; - printf("Starting process %s\n", (char *)arg); - for (i = 0; i < 10000; i++) - write(1, (char *) arg, 1); - return NULL; + int i; + printf("Starting process %s\n", (char *)arg); + for (i = 0; i < 10000; i++) + write(1, (char *) arg, 1); + return NULL; } #define sucfail(r) (r != 0 ? "failed" : "succeeded") int libc_ex1(void) { - int pret, ret = 0; - pthread_t th_a, th_b; - void *retval; + int pret, ret = 0; + pthread_t th_a, th_b; + void *retval; - ret += (pret = pthread_create(&th_a, NULL, process, (void *)"a")); - printf("create a %s %d\n", sucfail(pret), pret); - ret += (pret = pthread_create(&th_b, NULL, process, (void *)"b")); - printf("create b %s %d\n", sucfail(pret), pret); - ret += (pret = pthread_join(th_a, &retval)); - printf("join a %s %d\n", sucfail(pret), pret); - ret += (pret = pthread_join(th_b, &retval)); - printf("join b %s %d\n", sucfail(pret), pret); - return ret; + ret += (pret = pthread_create(&th_a, NULL, process, (void *)"a")); + printf("create a %s %d\n", sucfail(pret), pret); + ret += (pret = pthread_create(&th_b, NULL, process, (void *)"b")); + printf("create b %s %d\n", sucfail(pret), pret); + ret += (pret = pthread_join(th_a, &retval)); + printf("join a %s %d\n", sucfail(pret), pret); + ret += (pret = pthread_join(th_b, &retval)); + printf("join b %s %d\n", sucfail(pret), pret); + return ret; } #include <finsh.h> FINSH_FUNCTION_EXPORT(libc_ex1, example 1 for libc); diff --git a/examples/libc/ex2.c b/examples/libc/ex2.c index 925f4e1f23..df8f9a26a3 100644 --- a/examples/libc/ex2.c +++ b/examples/libc/ex2.c @@ -1,3 +1,11 @@ +/* + * Copyright (c) 2006-2021, RT-Thread Development Team + * + * SPDX-License-Identifier: Apache-2.0 + * + * Change Logs: + * Date Author Notes + */ /* The classic producer-consumer example. Illustrates mutexes and conditions. All integers between 0 and 9999 should be printed exactly twice, diff --git a/examples/libc/ex3.c b/examples/libc/ex3.c index e4e3405d20..1697e7145b 100644 --- a/examples/libc/ex3.c +++ b/examples/libc/ex3.c @@ -1,3 +1,11 @@ +/* + * Copyright (c) 2006-2021, RT-Thread Development Team + * + * SPDX-License-Identifier: Apache-2.0 + * + * Change Logs: + * Date Author Notes + */ /* Multi-thread searching. Illustrates: thread cancellation, cleanup handlers. */ diff --git a/examples/libc/ex4.c b/examples/libc/ex4.c index eb79840372..ec1c533a98 100644 --- a/examples/libc/ex4.c +++ b/examples/libc/ex4.c @@ -1,3 +1,11 @@ +/* + * Copyright (c) 2006-2021, RT-Thread Development Team + * + * SPDX-License-Identifier: Apache-2.0 + * + * Change Logs: + * Date Author Notes + */ /* Making a library function that uses static variables thread-safe. Illustrates: thread-specific data, pthread_once(). */ diff --git a/examples/libc/ex5.c b/examples/libc/ex5.c index aa94c34063..cce5306894 100644 --- a/examples/libc/ex5.c +++ b/examples/libc/ex5.c @@ -1,3 +1,11 @@ +/* + * Copyright (c) 2006-2021, RT-Thread Development Team + * + * SPDX-License-Identifier: Apache-2.0 + * + * Change Logs: + * Date Author Notes + */ /* The classic producer-consumer example, implemented with semaphores. All integers between 0 and 9999 should be printed exactly twice, once to the right of the arrow and once to the left. */ diff --git a/examples/libc/ex6.c b/examples/libc/ex6.c index dea6ead8cb..ac6319d74c 100644 --- a/examples/libc/ex6.c +++ b/examples/libc/ex6.c @@ -1,3 +1,11 @@ +/* + * Copyright (c) 2006-2021, RT-Thread Development Team + * + * SPDX-License-Identifier: Apache-2.0 + * + * Change Logs: + * Date Author Notes + */ #include <errno.h> #include <stdio.h> #include <string.h> @@ -7,31 +15,31 @@ #define usleep rt_thread_sleep static void *test_thread(void *v_param) { - return NULL; + return NULL; } int libc_ex6(void) { - unsigned long count; + unsigned long count; - setvbuf(stdout, NULL, _IONBF, 0); + setvbuf(stdout, NULL, _IONBF, 0); - for (count = 0; count < 2000; ++count) { - pthread_t thread; - int status; + for (count = 0; count < 2000; ++count) { + pthread_t thread; + int status; - status = pthread_create(&thread, NULL, test_thread, NULL); - if (status != 0) { - printf("status = %d, count = %lu: %s\n", status, count, strerror( - errno)); - return 1; - } else { - printf("count = %lu\n", count); - } - /* pthread_detach (thread); */ - pthread_join(thread, NULL); - usleep(10); - } - return 0; + status = pthread_create(&thread, NULL, test_thread, NULL); + if (status != 0) { + printf("status = %d, count = %lu: %s\n", status, count, strerror( + errno)); + return 1; + } else { + printf("count = %lu\n", count); + } + /* pthread_detach (thread); */ + pthread_join(thread, NULL); + usleep(10); + } + return 0; } #include <finsh.h> FINSH_FUNCTION_EXPORT(libc_ex6, example 6 for libc); diff --git a/examples/libc/ex7.c b/examples/libc/ex7.c index 859d18e7bd..e885f79c57 100644 --- a/examples/libc/ex7.c +++ b/examples/libc/ex7.c @@ -1,3 +1,11 @@ +/* + * Copyright (c) 2006-2021, RT-Thread Development Team + * + * SPDX-License-Identifier: Apache-2.0 + * + * Change Logs: + * Date Author Notes + */ /* ex7 * * Test case that illustrates a timed wait on a condition variable. @@ -14,88 +22,88 @@ /* Our event variable using a condition variable contruct. */ typedef struct { - pthread_mutex_t mutex; - pthread_cond_t cond; - int flag; + pthread_mutex_t mutex; + pthread_cond_t cond; + int flag; } event_t; /* Global event to signal main thread the timeout of the child thread. */ event_t main_event; static void *test_thread(void *ms_param) { - int status = 0; - event_t foo; - struct timespec time; - struct timeval now; - long ms = (long) ms_param; + int status = 0; + event_t foo; + struct timespec time; + struct timeval now; + long ms = (long) ms_param; - /* initialize cond var */ - pthread_cond_init(&foo.cond, NULL); - pthread_mutex_init(&foo.mutex, NULL); - foo.flag = 0; + /* initialize cond var */ + pthread_cond_init(&foo.cond, NULL); + pthread_mutex_init(&foo.mutex, NULL); + foo.flag = 0; - /* set the time out value */ - printf("waiting %ld ms ...\n", ms); - gettimeofday(&now, NULL); - time.tv_sec = now.tv_sec + ms / 1000 + (now.tv_usec + (ms % 1000) * 1000) - / 1000000; - time.tv_nsec = ((now.tv_usec + (ms % 1000) * 1000) % 1000000) * 1000; + /* set the time out value */ + printf("waiting %ld ms ...\n", ms); + gettimeofday(&now, NULL); + time.tv_sec = now.tv_sec + ms / 1000 + (now.tv_usec + (ms % 1000) * 1000) + / 1000000; + time.tv_nsec = ((now.tv_usec + (ms % 1000) * 1000) % 1000000) * 1000; - /* Just use this to test the time out. The cond var is never signaled. */ - pthread_mutex_lock(&foo.mutex); - while (foo.flag == 0 && status != ETIMEDOUT) { - status = pthread_cond_timedwait(&foo.cond, &foo.mutex, &time); - } - pthread_mutex_unlock(&foo.mutex); + /* Just use this to test the time out. The cond var is never signaled. */ + pthread_mutex_lock(&foo.mutex); + while (foo.flag == 0 && status != ETIMEDOUT) { + status = pthread_cond_timedwait(&foo.cond, &foo.mutex, &time); + } + pthread_mutex_unlock(&foo.mutex); - /* post the main event */ - pthread_mutex_lock(&main_event.mutex); - main_event.flag = 1; - pthread_cond_signal(&main_event.cond); - pthread_mutex_unlock(&main_event.mutex); + /* post the main event */ + pthread_mutex_lock(&main_event.mutex); + main_event.flag = 1; + pthread_cond_signal(&main_event.cond); + pthread_mutex_unlock(&main_event.mutex); - /* that's it, bye */ - return (void*) status; + /* that's it, bye */ + return (void*) status; } int libc_ex7(void) { - unsigned long count; + unsigned long count; - setvbuf(stdout, NULL, _IONBF, 0); + setvbuf(stdout, NULL, _IONBF, 0); - /* initialize main event cond var */ - pthread_cond_init(&main_event.cond, NULL); - pthread_mutex_init(&main_event.mutex, NULL); - main_event.flag = 0; + /* initialize main event cond var */ + pthread_cond_init(&main_event.cond, NULL); + pthread_mutex_init(&main_event.mutex, NULL); + main_event.flag = 0; - for (count = 0; count < 20; ++count) { - pthread_t thread; - int status; + for (count = 0; count < 20; ++count) { + pthread_t thread; + int status; - /* pass down the milli-second timeout in the void* param */ - status = pthread_create(&thread, NULL, test_thread, (void*) (count - * 100)); - if (status != 0) { - printf("status = %d, count = %lu: %s\n", status, count, strerror( - errno)); - return 1; - } else { + /* pass down the milli-second timeout in the void* param */ + status = pthread_create(&thread, NULL, test_thread, (void*) (count + * 100)); + if (status != 0) { + printf("status = %d, count = %lu: %s\n", status, count, strerror( + errno)); + return 1; + } else { - /* wait for the event posted by the child thread */ - pthread_mutex_lock(&main_event.mutex); - while (main_event.flag == 0) { - pthread_cond_wait(&main_event.cond, &main_event.mutex); - } - main_event.flag = 0; - pthread_mutex_unlock(&main_event.mutex); + /* wait for the event posted by the child thread */ + pthread_mutex_lock(&main_event.mutex); + while (main_event.flag == 0) { + pthread_cond_wait(&main_event.cond, &main_event.mutex); + } + main_event.flag = 0; + pthread_mutex_unlock(&main_event.mutex); - printf("count = %lu\n", count); - } + printf("count = %lu\n", count); + } - usleep(10); - } + usleep(10); + } - return 0; + return 0; } #include <finsh.h> FINSH_FUNCTION_EXPORT(libc_ex7, example 7 for libc); diff --git a/examples/libc/file.c b/examples/libc/file.c index f366e04702..79cdce3092 100644 --- a/examples/libc/file.c +++ b/examples/libc/file.c @@ -1,9 +1,13 @@ /* - * fstat.c + * Copyright (c) 2006-2021, RT-Thread Development Team * - * Created on: 2010-11-17 - * Author: bernard + * SPDX-License-Identifier: Apache-2.0 + * + * Change Logs: + * Date Author Notes + * 2010-11-17 Bernard first version */ + #include <stdio.h> #include <stdlib.h> #include <finsh.h> @@ -14,503 +18,503 @@ const char* text = "this is a test string\n"; void libc_fstat() { - int fd; - struct stat s; + int fd; + struct stat s; - fd = open("/tmp/tt.txt", O_WRONLY | O_CREAT, 0); - if (fd < 0) - { - printf("open failed\n"); - return; - } + fd = open("/tmp/tt.txt", O_WRONLY | O_CREAT, 0); + if (fd < 0) + { + printf("open failed\n"); + return; + } - write(fd, text, strlen(text) + 1); - printf("begin: %d\n", lseek(fd, 0, SEEK_SET)); - printf("end: %d\n", lseek(fd, 0, SEEK_END)); + write(fd, text, strlen(text) + 1); + printf("begin: %d\n", lseek(fd, 0, SEEK_SET)); + printf("end: %d\n", lseek(fd, 0, SEEK_END)); - printf("fstat result: %d\n", fstat(fd, &s)); - close(fd); + printf("fstat result: %d\n", fstat(fd, &s)); + close(fd); } FINSH_FUNCTION_EXPORT(libc_fstat, fstat test for libc); void libc_lseek() { - int fd; + int fd; - fd = open("/tmp/tt.txt", O_WRONLY | O_CREAT, 0); - if (fd < 0) - { - printf("open failed\n"); - return; - } + fd = open("/tmp/tt.txt", O_WRONLY | O_CREAT, 0); + if (fd < 0) + { + printf("open failed\n"); + return; + } - write(fd, text, strlen(text) + 1); - printf("begin: %d\n", lseek(fd, 0, SEEK_SET)); - printf("end: %d\n", lseek(fd, 0, SEEK_END)); - close(fd); + write(fd, text, strlen(text) + 1); + printf("begin: %d\n", lseek(fd, 0, SEEK_SET)); + printf("end: %d\n", lseek(fd, 0, SEEK_END)); + close(fd); } FINSH_FUNCTION_EXPORT(libc_lseek, lseek test for libc); void sleep(int tick) { - rt_thread_sleep(tick); + rt_thread_sleep(tick); } int libc_fseek(void) { - const char *tmpdir; - char *fname; - int fd; - FILE *fp; - const char outstr[] = "hello world!\n"; - char strbuf[sizeof outstr]; - char buf[200]; - struct stat st1; - struct stat st2; - int result = 0; + const char *tmpdir; + char *fname; + int fd; + FILE *fp; + const char outstr[] = "hello world!\n"; + char strbuf[sizeof outstr]; + char buf[200]; + struct stat st1; + struct stat st2; + int result = 0; - tmpdir = getenv("TMPDIR"); - if (tmpdir == NULL || tmpdir[0] == '\0') - tmpdir = "/tmp"; + tmpdir = getenv("TMPDIR"); + if (tmpdir == NULL || tmpdir[0] == '\0') + tmpdir = "/tmp"; - asprintf(&fname, "%s/tst-fseek.XXXXXX", tmpdir); - if (fname == NULL) - { - fprintf(stderr, "cannot generate name for temporary file: %s\n", - strerror(errno)); - return 1; - } + asprintf(&fname, "%s/tst-fseek.XXXXXX", tmpdir); + if (fname == NULL) + { + fprintf(stderr, "cannot generate name for temporary file: %s\n", + strerror(errno)); + return 1; + } - /* Create a temporary file. */ - fd = mkstemp(fname); - if (fd == -1) - { - fprintf(stderr, "cannot open temporary file: %s\n", strerror(errno)); - return 1; - } + /* Create a temporary file. */ + fd = mkstemp(fname); + if (fd == -1) + { + fprintf(stderr, "cannot open temporary file: %s\n", strerror(errno)); + return 1; + } - fp = fdopen(fd, "w+"); - if (fp == NULL) - { - fprintf(stderr, "cannot get FILE for temporary file: %s\n", strerror( - errno)); - return 1; - } - setbuffer(fp, strbuf, sizeof(outstr) - 1); + fp = fdopen(fd, "w+"); + if (fp == NULL) + { + fprintf(stderr, "cannot get FILE for temporary file: %s\n", strerror( + errno)); + return 1; + } + setbuffer(fp, strbuf, sizeof(outstr) - 1); - if (fwrite(outstr, sizeof(outstr) - 1, 1, fp) != 1) - { - printf("%d: write error\n", __LINE__); - result = 1; - goto out; - } + if (fwrite(outstr, sizeof(outstr) - 1, 1, fp) != 1) + { + printf("%d: write error\n", __LINE__); + result = 1; + goto out; + } - /* The EOF flag must be reset. */ - if (fgetc(fp) != EOF) - { - printf("%d: managed to read at end of file\n", __LINE__); - result = 1; - } - else if (!feof(fp)) - { - printf("%d: EOF flag not set\n", __LINE__); - result = 1; - } - if (fseek(fp, 0, SEEK_CUR) != 0) - { - printf("%d: fseek(fp, 0, SEEK_CUR) failed\n", __LINE__); - result = 1; - } - else if (feof(fp)) - { - printf("%d: fseek() didn't reset EOF flag\n", __LINE__); - result = 1; - } + /* The EOF flag must be reset. */ + if (fgetc(fp) != EOF) + { + printf("%d: managed to read at end of file\n", __LINE__); + result = 1; + } + else if (!feof(fp)) + { + printf("%d: EOF flag not set\n", __LINE__); + result = 1; + } + if (fseek(fp, 0, SEEK_CUR) != 0) + { + printf("%d: fseek(fp, 0, SEEK_CUR) failed\n", __LINE__); + result = 1; + } + else if (feof(fp)) + { + printf("%d: fseek() didn't reset EOF flag\n", __LINE__); + result = 1; + } - /* Do the same for fseeko(). */ - if (fgetc(fp) != EOF) - { - printf("%d: managed to read at end of file\n", __LINE__); - result = 1; - } - else if (!feof(fp)) - { - printf("%d: EOF flag not set\n", __LINE__); - result = 1; - } - if (fseeko(fp, 0, SEEK_CUR) != 0) - { - printf("%d: fseek(fp, 0, SEEK_CUR) failed\n", __LINE__); - result = 1; - } - else if (feof(fp)) - { - printf("%d: fseek() didn't reset EOF flag\n", __LINE__); - result = 1; - } + /* Do the same for fseeko(). */ + if (fgetc(fp) != EOF) + { + printf("%d: managed to read at end of file\n", __LINE__); + result = 1; + } + else if (!feof(fp)) + { + printf("%d: EOF flag not set\n", __LINE__); + result = 1; + } + if (fseeko(fp, 0, SEEK_CUR) != 0) + { + printf("%d: fseek(fp, 0, SEEK_CUR) failed\n", __LINE__); + result = 1; + } + else if (feof(fp)) + { + printf("%d: fseek() didn't reset EOF flag\n", __LINE__); + result = 1; + } - /* Go back to the beginning of the file: absolute. */ - if (fseek(fp, 0, SEEK_SET) != 0) - { - printf("%d: fseek(fp, 0, SEEK_SET) failed\n", __LINE__); - result = 1; - } - else if (fflush(fp) != 0) - { - printf("%d: fflush() failed\n", __LINE__); - result = 1; - } - else if (lseek(fd, 0, SEEK_CUR) != 0) - { - int pos = lseek(fd, 0, SEEK_CUR); - printf("%d: lseek() returned different position, pos %d\n", __LINE__, - pos); - result = 1; - } - else if (fread(buf, sizeof(outstr) - 1, 1, fp) != 1) - { - printf("%d: fread() failed\n", __LINE__); - result = 1; - } - else if (memcmp(buf, outstr, sizeof(outstr) - 1) != 0) - { - printf("%d: content after fseek(,,SEEK_SET) wrong\n", __LINE__); - result = 1; - } + /* Go back to the beginning of the file: absolute. */ + if (fseek(fp, 0, SEEK_SET) != 0) + { + printf("%d: fseek(fp, 0, SEEK_SET) failed\n", __LINE__); + result = 1; + } + else if (fflush(fp) != 0) + { + printf("%d: fflush() failed\n", __LINE__); + result = 1; + } + else if (lseek(fd, 0, SEEK_CUR) != 0) + { + int pos = lseek(fd, 0, SEEK_CUR); + printf("%d: lseek() returned different position, pos %d\n", __LINE__, + pos); + result = 1; + } + else if (fread(buf, sizeof(outstr) - 1, 1, fp) != 1) + { + printf("%d: fread() failed\n", __LINE__); + result = 1; + } + else if (memcmp(buf, outstr, sizeof(outstr) - 1) != 0) + { + printf("%d: content after fseek(,,SEEK_SET) wrong\n", __LINE__); + result = 1; + } - /* Now with fseeko. */ - if (fseeko(fp, 0, SEEK_SET) != 0) - { - printf("%d: fseeko(fp, 0, SEEK_SET) failed\n", __LINE__); - result = 1; - } - else if (fflush(fp) != 0) - { - printf("%d: fflush() failed\n", __LINE__); - result = 1; - } - else if (lseek(fd, 0, SEEK_CUR) != 0) - { - printf("%d: lseek() returned different position\n", __LINE__); - result = 1; - } - else if (fread(buf, sizeof(outstr) - 1, 1, fp) != 1) - { - printf("%d: fread() failed\n", __LINE__); - result = 1; - } - else if (memcmp(buf, outstr, sizeof(outstr) - 1) != 0) - { - printf("%d: content after fseeko(,,SEEK_SET) wrong\n", __LINE__); - result = 1; - } + /* Now with fseeko. */ + if (fseeko(fp, 0, SEEK_SET) != 0) + { + printf("%d: fseeko(fp, 0, SEEK_SET) failed\n", __LINE__); + result = 1; + } + else if (fflush(fp) != 0) + { + printf("%d: fflush() failed\n", __LINE__); + result = 1; + } + else if (lseek(fd, 0, SEEK_CUR) != 0) + { + printf("%d: lseek() returned different position\n", __LINE__); + result = 1; + } + else if (fread(buf, sizeof(outstr) - 1, 1, fp) != 1) + { + printf("%d: fread() failed\n", __LINE__); + result = 1; + } + else if (memcmp(buf, outstr, sizeof(outstr) - 1) != 0) + { + printf("%d: content after fseeko(,,SEEK_SET) wrong\n", __LINE__); + result = 1; + } - /* Go back to the beginning of the file: relative. */ - if (fseek(fp, -((int) sizeof(outstr) - 1), SEEK_CUR) != 0) - { - printf("%d: fseek(fp, 0, SEEK_SET) failed\n", __LINE__); - result = 1; - } - else if (fflush(fp) != 0) - { - printf("%d: fflush() failed\n", __LINE__); - result = 1; - } - else if (lseek(fd, 0, SEEK_CUR) != 0) - { - printf("%d: lseek() returned different position\n", __LINE__); - result = 1; - } - else if (fread(buf, sizeof(outstr) - 1, 1, fp) != 1) - { - printf("%d: fread() failed\n", __LINE__); - result = 1; - } - else if (memcmp(buf, outstr, sizeof(outstr) - 1) != 0) - { - printf("%d: content after fseek(,,SEEK_SET) wrong\n", __LINE__); - result = 1; - } + /* Go back to the beginning of the file: relative. */ + if (fseek(fp, -((int) sizeof(outstr) - 1), SEEK_CUR) != 0) + { + printf("%d: fseek(fp, 0, SEEK_SET) failed\n", __LINE__); + result = 1; + } + else if (fflush(fp) != 0) + { + printf("%d: fflush() failed\n", __LINE__); + result = 1; + } + else if (lseek(fd, 0, SEEK_CUR) != 0) + { + printf("%d: lseek() returned different position\n", __LINE__); + result = 1; + } + else if (fread(buf, sizeof(outstr) - 1, 1, fp) != 1) + { + printf("%d: fread() failed\n", __LINE__); + result = 1; + } + else if (memcmp(buf, outstr, sizeof(outstr) - 1) != 0) + { + printf("%d: content after fseek(,,SEEK_SET) wrong\n", __LINE__); + result = 1; + } - /* Now with fseeko. */ - if (fseeko(fp, -((int) sizeof(outstr) - 1), SEEK_CUR) != 0) - { - printf("%d: fseeko(fp, 0, SEEK_SET) failed\n", __LINE__); - result = 1; - } - else if (fflush(fp) != 0) - { - printf("%d: fflush() failed\n", __LINE__); - result = 1; - } - else if (lseek(fd, 0, SEEK_CUR) != 0) - { - printf("%d: lseek() returned different position\n", __LINE__); - result = 1; - } - else if (fread(buf, sizeof(outstr) - 1, 1, fp) != 1) - { - printf("%d: fread() failed\n", __LINE__); - result = 1; - } - else if (memcmp(buf, outstr, sizeof(outstr) - 1) != 0) - { - printf("%d: content after fseeko(,,SEEK_SET) wrong\n", __LINE__); - result = 1; - } + /* Now with fseeko. */ + if (fseeko(fp, -((int) sizeof(outstr) - 1), SEEK_CUR) != 0) + { + printf("%d: fseeko(fp, 0, SEEK_SET) failed\n", __LINE__); + result = 1; + } + else if (fflush(fp) != 0) + { + printf("%d: fflush() failed\n", __LINE__); + result = 1; + } + else if (lseek(fd, 0, SEEK_CUR) != 0) + { + printf("%d: lseek() returned different position\n", __LINE__); + result = 1; + } + else if (fread(buf, sizeof(outstr) - 1, 1, fp) != 1) + { + printf("%d: fread() failed\n", __LINE__); + result = 1; + } + else if (memcmp(buf, outstr, sizeof(outstr) - 1) != 0) + { + printf("%d: content after fseeko(,,SEEK_SET) wrong\n", __LINE__); + result = 1; + } - /* Go back to the beginning of the file: from the end. */ - if (fseek(fp, -((int) sizeof(outstr) - 1), SEEK_END) != 0) - { - printf("%d: fseek(fp, 0, SEEK_SET) failed\n", __LINE__); - result = 1; - } - else if (fflush(fp) != 0) - { - printf("%d: fflush() failed\n", __LINE__); - result = 1; - } - else if (lseek(fd, 0, SEEK_CUR) != 0) - { - printf("%d: lseek() returned different position\n", __LINE__); - result = 1; - } - else if (fread(buf, sizeof(outstr) - 1, 1, fp) != 1) - { - printf("%d: fread() failed\n", __LINE__); - result = 1; - } - else if (memcmp(buf, outstr, sizeof(outstr) - 1) != 0) - { - printf("%d: content after fseek(,,SEEK_SET) wrong\n", __LINE__); - result = 1; - } + /* Go back to the beginning of the file: from the end. */ + if (fseek(fp, -((int) sizeof(outstr) - 1), SEEK_END) != 0) + { + printf("%d: fseek(fp, 0, SEEK_SET) failed\n", __LINE__); + result = 1; + } + else if (fflush(fp) != 0) + { + printf("%d: fflush() failed\n", __LINE__); + result = 1; + } + else if (lseek(fd, 0, SEEK_CUR) != 0) + { + printf("%d: lseek() returned different position\n", __LINE__); + result = 1; + } + else if (fread(buf, sizeof(outstr) - 1, 1, fp) != 1) + { + printf("%d: fread() failed\n", __LINE__); + result = 1; + } + else if (memcmp(buf, outstr, sizeof(outstr) - 1) != 0) + { + printf("%d: content after fseek(,,SEEK_SET) wrong\n", __LINE__); + result = 1; + } - /* Now with fseeko. */ - if (fseeko(fp, -((int) sizeof(outstr) - 1), SEEK_END) != 0) - { - printf("%d: fseeko(fp, 0, SEEK_SET) failed\n", __LINE__); - result = 1; - } - else if (fflush(fp) != 0) - { - printf("%d: fflush() failed\n", __LINE__); - result = 1; - } - else if (lseek(fd, 0, SEEK_CUR) != 0) - { - printf("%d: lseek() returned different position\n", __LINE__); - result = 1; - } - else if (fread(buf, sizeof(outstr) - 1, 1, fp) != 1) - { - printf("%d: fread() failed\n", __LINE__); - result = 1; - } - else if (memcmp(buf, outstr, sizeof(outstr) - 1) != 0) - { - printf("%d: content after fseeko(,,SEEK_SET) wrong\n", __LINE__); - result = 1; - } + /* Now with fseeko. */ + if (fseeko(fp, -((int) sizeof(outstr) - 1), SEEK_END) != 0) + { + printf("%d: fseeko(fp, 0, SEEK_SET) failed\n", __LINE__); + result = 1; + } + else if (fflush(fp) != 0) + { + printf("%d: fflush() failed\n", __LINE__); + result = 1; + } + else if (lseek(fd, 0, SEEK_CUR) != 0) + { + printf("%d: lseek() returned different position\n", __LINE__); + result = 1; + } + else if (fread(buf, sizeof(outstr) - 1, 1, fp) != 1) + { + printf("%d: fread() failed\n", __LINE__); + result = 1; + } + else if (memcmp(buf, outstr, sizeof(outstr) - 1) != 0) + { + printf("%d: content after fseeko(,,SEEK_SET) wrong\n", __LINE__); + result = 1; + } - if (fwrite(outstr, sizeof(outstr) - 1, 1, fp) != 1) - { - printf("%d: write error 2\n", __LINE__); - result = 1; - goto out; - } + if (fwrite(outstr, sizeof(outstr) - 1, 1, fp) != 1) + { + printf("%d: write error 2\n", __LINE__); + result = 1; + goto out; + } - if (fwrite(outstr, sizeof(outstr) - 1, 1, fp) != 1) - { - printf("%d: write error 3\n", __LINE__); - result = 1; - goto out; - } + if (fwrite(outstr, sizeof(outstr) - 1, 1, fp) != 1) + { + printf("%d: write error 3\n", __LINE__); + result = 1; + goto out; + } - if (fwrite(outstr, sizeof(outstr) - 1, 1, fp) != 1) - { - printf("%d: write error 4\n", __LINE__); - result = 1; - goto out; - } + if (fwrite(outstr, sizeof(outstr) - 1, 1, fp) != 1) + { + printf("%d: write error 4\n", __LINE__); + result = 1; + goto out; + } - if (fwrite(outstr, sizeof(outstr) - 1, 1, fp) != 1) - { - printf("%d: write error 5\n", __LINE__); - result = 1; - goto out; - } + if (fwrite(outstr, sizeof(outstr) - 1, 1, fp) != 1) + { + printf("%d: write error 5\n", __LINE__); + result = 1; + goto out; + } - if (fputc('1', fp) == EOF || fputc('2', fp) == EOF) - { - printf("%d: cannot add characters at the end\n", __LINE__); - result = 1; - goto out; - } + if (fputc('1', fp) == EOF || fputc('2', fp) == EOF) + { + printf("%d: cannot add characters at the end\n", __LINE__); + result = 1; + goto out; + } - /* Check the access time. */ - if (fstat(fd, &st1) < 0) - { - printf("%d: fstat64() before fseeko() failed\n\n", __LINE__); - result = 1; - } - else - { - sleep(1); + /* Check the access time. */ + if (fstat(fd, &st1) < 0) + { + printf("%d: fstat64() before fseeko() failed\n\n", __LINE__); + result = 1; + } + else + { + sleep(1); - if (fseek(fp, -(2 + 2 * (sizeof(outstr) - 1)), SEEK_CUR) != 0) - { - printf("%d: fseek() after write characters failed\n", __LINE__); - result = 1; - goto out; - } - else - { + if (fseek(fp, -(2 + 2 * (sizeof(outstr) - 1)), SEEK_CUR) != 0) + { + printf("%d: fseek() after write characters failed\n", __LINE__); + result = 1; + goto out; + } + else + { - time_t t; - /* Make sure the timestamp actually can be different. */ - sleep(1); - t = time(NULL); + time_t t; + /* Make sure the timestamp actually can be different. */ + sleep(1); + t = time(NULL); - if (fstat(fd, &st2) < 0) - { - printf("%d: fstat64() after fseeko() failed\n\n", __LINE__); - result = 1; - } - if (st1.st_ctime >= t) - { - printf("%d: st_ctime not updated\n", __LINE__); - result = 1; - } - if (st1.st_mtime >= t) - { - printf("%d: st_mtime not updated\n", __LINE__); - result = 1; - } - if (st1.st_ctime >= st2.st_ctime) - { - printf("%d: st_ctime not changed\n", __LINE__); - result = 1; - } - if (st1.st_mtime >= st2.st_mtime) - { - printf("%d: st_mtime not changed\n", __LINE__); - result = 1; - } - } - } + if (fstat(fd, &st2) < 0) + { + printf("%d: fstat64() after fseeko() failed\n\n", __LINE__); + result = 1; + } + if (st1.st_ctime >= t) + { + printf("%d: st_ctime not updated\n", __LINE__); + result = 1; + } + if (st1.st_mtime >= t) + { + printf("%d: st_mtime not updated\n", __LINE__); + result = 1; + } + if (st1.st_ctime >= st2.st_ctime) + { + printf("%d: st_ctime not changed\n", __LINE__); + result = 1; + } + if (st1.st_mtime >= st2.st_mtime) + { + printf("%d: st_mtime not changed\n", __LINE__); + result = 1; + } + } + } - if (fread(buf, 1, 2 + 2 * (sizeof(outstr) - 1), fp) != 2 + 2 - * (sizeof(outstr) - 1)) - { - printf("%d: reading 2 records plus bits failed\n", __LINE__); - result = 1; - } - else if (memcmp(buf, outstr, sizeof(outstr) - 1) != 0 || memcmp( - &buf[sizeof(outstr) - 1], outstr, sizeof(outstr) - 1) != 0 || buf[2 - * (sizeof(outstr) - 1)] != '1' || buf[2 * (sizeof(outstr) - 1) + 1] - != '2') - { - printf("%d: reading records failed\n", __LINE__); - result = 1; - } - else if (ungetc('9', fp) == EOF) - { - printf("%d: ungetc() failed\n", __LINE__); - result = 1; - } - else if (fseek(fp, -(2 + 2 * (sizeof(outstr) - 1)), SEEK_END) != 0) - { - printf("%d: fseek after ungetc failed\n", __LINE__); - result = 1; - } - else if (fread(buf, 1, 2 + 2 * (sizeof(outstr) - 1), fp) != 2 + 2 - * (sizeof(outstr) - 1)) - { - printf("%d: reading 2 records plus bits failed\n", __LINE__); - result = 1; - } - else if (memcmp(buf, outstr, sizeof(outstr) - 1) != 0 || memcmp( - &buf[sizeof(outstr) - 1], outstr, sizeof(outstr) - 1) != 0 || buf[2 - * (sizeof(outstr) - 1)] != '1') - { - printf("%d: reading records for the second time failed\n", __LINE__); - result = 1; - } - else if (buf[2 * (sizeof(outstr) - 1) + 1] == '9') - { - printf("%d: unget character not ignored\n", __LINE__); - result = 1; - } - else if (buf[2 * (sizeof(outstr) - 1) + 1] != '2') - { - printf("%d: unget somehow changed character\n", __LINE__); - result = 1; - } + if (fread(buf, 1, 2 + 2 * (sizeof(outstr) - 1), fp) != 2 + 2 + * (sizeof(outstr) - 1)) + { + printf("%d: reading 2 records plus bits failed\n", __LINE__); + result = 1; + } + else if (memcmp(buf, outstr, sizeof(outstr) - 1) != 0 || memcmp( + &buf[sizeof(outstr) - 1], outstr, sizeof(outstr) - 1) != 0 || buf[2 + * (sizeof(outstr) - 1)] != '1' || buf[2 * (sizeof(outstr) - 1) + 1] + != '2') + { + printf("%d: reading records failed\n", __LINE__); + result = 1; + } + else if (ungetc('9', fp) == EOF) + { + printf("%d: ungetc() failed\n", __LINE__); + result = 1; + } + else if (fseek(fp, -(2 + 2 * (sizeof(outstr) - 1)), SEEK_END) != 0) + { + printf("%d: fseek after ungetc failed\n", __LINE__); + result = 1; + } + else if (fread(buf, 1, 2 + 2 * (sizeof(outstr) - 1), fp) != 2 + 2 + * (sizeof(outstr) - 1)) + { + printf("%d: reading 2 records plus bits failed\n", __LINE__); + result = 1; + } + else if (memcmp(buf, outstr, sizeof(outstr) - 1) != 0 || memcmp( + &buf[sizeof(outstr) - 1], outstr, sizeof(outstr) - 1) != 0 || buf[2 + * (sizeof(outstr) - 1)] != '1') + { + printf("%d: reading records for the second time failed\n", __LINE__); + result = 1; + } + else if (buf[2 * (sizeof(outstr) - 1) + 1] == '9') + { + printf("%d: unget character not ignored\n", __LINE__); + result = 1; + } + else if (buf[2 * (sizeof(outstr) - 1) + 1] != '2') + { + printf("%d: unget somehow changed character\n", __LINE__); + result = 1; + } - fclose(fp); + fclose(fp); - fp = fopen(fname, "r"); - if (fp == NULL) - { - printf("%d: fopen() failed\n\n", __LINE__); - result = 1; - } - else if (fstat(fileno(fp), &st1) < 0) - { - printf("%d: fstat64() before fseeko() failed\n\n", __LINE__); - result = 1; - } - else if (fseeko(fp, 0, SEEK_END) != 0) - { - printf("%d: fseeko(fp, 0, SEEK_END) failed\n", __LINE__); - result = 1; - } - else if (ftello(fp) != st1.st_size) - { - printf("%d: fstat64 st_size %zd ftello %zd\n", __LINE__, - (size_t) st1.st_size, (size_t) ftello(fp)); - result = 1; - } - else - printf("%d: SEEK_END works\n", __LINE__); - if (fp != NULL) - fclose(fp); + fp = fopen(fname, "r"); + if (fp == NULL) + { + printf("%d: fopen() failed\n\n", __LINE__); + result = 1; + } + else if (fstat(fileno(fp), &st1) < 0) + { + printf("%d: fstat64() before fseeko() failed\n\n", __LINE__); + result = 1; + } + else if (fseeko(fp, 0, SEEK_END) != 0) + { + printf("%d: fseeko(fp, 0, SEEK_END) failed\n", __LINE__); + result = 1; + } + else if (ftello(fp) != st1.st_size) + { + printf("%d: fstat64 st_size %zd ftello %zd\n", __LINE__, + (size_t) st1.st_size, (size_t) ftello(fp)); + result = 1; + } + else + printf("%d: SEEK_END works\n", __LINE__); + if (fp != NULL) + fclose(fp); - fp = fopen(fname, "r"); - if (fp == NULL) - { - printf("%d: fopen() failed\n\n", __LINE__); - result = 1; - } - else if (fstat(fileno(fp), &st1) < 0) - { - printf("%d: fstat64() before fgetc() failed\n\n", __LINE__); - result = 1; - } - else if (fgetc(fp) == EOF) - { - printf("%d: fgetc() before fseeko() failed\n\n", __LINE__); - result = 1; - } - else if (fseeko(fp, 0, SEEK_END) != 0) - { - printf("%d: fseeko(fp, 0, SEEK_END) failed\n", __LINE__); - result = 1; - } - else if (ftello(fp) != st1.st_size) - { - printf("%d: fstat64 st_size %zd ftello %zd\n", __LINE__, - (size_t) st1.st_size, (size_t) ftello(fp)); - result = 1; - } - else - printf("%d: SEEK_END works\n", __LINE__); - if (fp != NULL) - fclose(fp); + fp = fopen(fname, "r"); + if (fp == NULL) + { + printf("%d: fopen() failed\n\n", __LINE__); + result = 1; + } + else if (fstat(fileno(fp), &st1) < 0) + { + printf("%d: fstat64() before fgetc() failed\n\n", __LINE__); + result = 1; + } + else if (fgetc(fp) == EOF) + { + printf("%d: fgetc() before fseeko() failed\n\n", __LINE__); + result = 1; + } + else if (fseeko(fp, 0, SEEK_END) != 0) + { + printf("%d: fseeko(fp, 0, SEEK_END) failed\n", __LINE__); + result = 1; + } + else if (ftello(fp) != st1.st_size) + { + printf("%d: fstat64 st_size %zd ftello %zd\n", __LINE__, + (size_t) st1.st_size, (size_t) ftello(fp)); + result = 1; + } + else + printf("%d: SEEK_END works\n", __LINE__); + if (fp != NULL) + fclose(fp); - out: unlink(fname); + out: unlink(fname); - return result; + return result; } FINSH_FUNCTION_EXPORT(libc_fseek, lseek test for libc); diff --git a/examples/libc/memory.c b/examples/libc/memory.c index ee524fa43d..063d90cfdc 100644 --- a/examples/libc/memory.c +++ b/examples/libc/memory.c @@ -1,9 +1,13 @@ /* - * memory.c + * Copyright (c) 2006-2021, RT-Thread Development Team * - * Created on: 2010-11-17 - * Author: bernard + * SPDX-License-Identifier: Apache-2.0 + * + * Change Logs: + * Date Author Notes + * 2010-11-17 Bernard first version */ + #include <stdio.h> #include <stdlib.h> #include <finsh.h> @@ -12,45 +16,45 @@ static int errors = 0; static void merror(const char *msg) { - ++errors; - printf("Error: %s\n", msg); + ++errors; + printf("Error: %s\n", msg); } int libc_mem(void) { - void *p; - int save; + void *p; + int save; - errno = 0; + errno = 0; - p = malloc(-1); - save = errno; + p = malloc(-1); + save = errno; - if (p != NULL) - merror("malloc (-1) succeeded."); + if (p != NULL) + merror("malloc (-1) succeeded."); - if (p == NULL && save != ENOMEM) - merror("errno is not set correctly"); + if (p == NULL && save != ENOMEM) + merror("errno is not set correctly"); - p = malloc(10); - if (p == NULL) - merror("malloc (10) failed."); + p = malloc(10); + if (p == NULL) + merror("malloc (10) failed."); - /* realloc (p, 0) == free (p). */ - p = realloc(p, 0); - if (p != NULL) - merror("realloc (p, 0) failed."); + /* realloc (p, 0) == free (p). */ + p = realloc(p, 0); + if (p != NULL) + merror("realloc (p, 0) failed."); - p = malloc(0); - if (p == NULL) - { - printf("malloc(0) returns NULL\n"); - } + p = malloc(0); + if (p == NULL) + { + printf("malloc(0) returns NULL\n"); + } - p = realloc(p, 0); - if (p != NULL) - merror("realloc (p, 0) failed."); + p = realloc(p, 0); + if (p != NULL) + merror("realloc (p, 0) failed."); - return errors != 0; + return errors != 0; } FINSH_FUNCTION_EXPORT(libc_mem, memory test for libc); diff --git a/examples/libc/mq.c b/examples/libc/mq.c index 3163e27975..a7f3f924dc 100644 --- a/examples/libc/mq.c +++ b/examples/libc/mq.c @@ -1,3 +1,13 @@ +/* + * Copyright (c) 2006-2021, RT-Thread Development Team + * + * SPDX-License-Identifier: Apache-2.0 + * + * Change Logs: + * Date Author Notes + * 2010-11-17 Bernard first version + */ + #include <stdio.h> #include <fcntl.h> #include <stdlib.h> @@ -7,113 +17,113 @@ #define MQ_NAME_1 "testmsg1" #define MQ_NAME_2 "testmsg2" -#define MSG_SIZE 128 -#define MAX_MSG 3 +#define MSG_SIZE 128 +#define MAX_MSG 3 const char *s_msg_ptr[] = {"msg test 1", "msg test 2", "msg test 3"}; char r_msg_ptr_1[MAX_MSG][MSG_SIZE]; char r_msg_ptr_2[MAX_MSG][MSG_SIZE]; pthread_t send1, send2, rev1, rev2; -int * send_1(void * mq) +int * send_1(void * mq) { - int i; - mqd_t mq1 = *(mqd_t *)mq; + int i; + mqd_t mq1 = *(mqd_t *)mq; - printf("Enter into send_1 \n"); - for (i = 0; i < MAX_MSG; i++ ) { - if ( -1 == mq_send(mq1, s_msg_ptr[i], MSG_SIZE, i)) { - perror("mq_send doesn't return success \n"); - pthread_exit((void *)1); - } - printf("[%d] send '%s' in thread send_1. \n", i+1, s_msg_ptr[i]); - } - pthread_exit((void *)0); + printf("Enter into send_1 \n"); + for (i = 0; i < MAX_MSG; i++ ) { + if ( -1 == mq_send(mq1, s_msg_ptr[i], MSG_SIZE, i)) { + perror("mq_send doesn't return success \n"); + pthread_exit((void *)1); + } + printf("[%d] send '%s' in thread send_1. \n", i+1, s_msg_ptr[i]); + } + pthread_exit((void *)0); } -int * send_2(void * mq) +int * send_2(void * mq) { - int i; - mqd_t mq2 = *(mqd_t *)mq; + int i; + mqd_t mq2 = *(mqd_t *)mq; - printf("Enter into send_2 \n"); - for (i = 0; i < MAX_MSG; i++ ) { - if ( -1 == mq_send(mq2, s_msg_ptr[i], MSG_SIZE, i)) { - perror("mq_send doesn't return success \n"); - pthread_exit((void *)1); - } - printf("[%d] send '%s' in thread send_2. \n", i+1, s_msg_ptr[i]); - } - pthread_exit((void *)0); + printf("Enter into send_2 \n"); + for (i = 0; i < MAX_MSG; i++ ) { + if ( -1 == mq_send(mq2, s_msg_ptr[i], MSG_SIZE, i)) { + perror("mq_send doesn't return success \n"); + pthread_exit((void *)1); + } + printf("[%d] send '%s' in thread send_2. \n", i+1, s_msg_ptr[i]); + } + pthread_exit((void *)0); } -int * receive_1(void * mq) +int * receive_1(void * mq) { - int i; - mqd_t mq1 = *(mqd_t *)mq; + int i; + mqd_t mq1 = *(mqd_t *)mq; - printf("Enter into receive_1 \n"); - for (i = 0; i< MAX_MSG; i++) { - if ( -1 == mq_receive(mq1, r_msg_ptr_1[i], MSG_SIZE, NULL) ) { - perror("mq_receive doesn't return success \n"); - pthread_exit((void *)1); - } - printf("[%d] receive '%s' in thread receive_1. \n", i+1, r_msg_ptr_1[i]); - } - pthread_exit((void *)0); + printf("Enter into receive_1 \n"); + for (i = 0; i< MAX_MSG; i++) { + if ( -1 == mq_receive(mq1, r_msg_ptr_1[i], MSG_SIZE, NULL) ) { + perror("mq_receive doesn't return success \n"); + pthread_exit((void *)1); + } + printf("[%d] receive '%s' in thread receive_1. \n", i+1, r_msg_ptr_1[i]); + } + pthread_exit((void *)0); } -int * receive_2(void * mq) +int * receive_2(void * mq) { - int i; - mqd_t mq2 = *(mqd_t *)mq; + int i; + mqd_t mq2 = *(mqd_t *)mq; - printf("Enter into receive_2 \n"); - for (i = 0; i< MAX_MSG; i++) { - if ( -1 == mq_receive(mq2, r_msg_ptr_2[i], MSG_SIZE, NULL) ) { - perror("mq_receive doesn't return success \n"); - pthread_exit((void *)1); - } - printf("[%d] receive '%s' in thread receive_2. \n", i+1, r_msg_ptr_2[i]); - } - pthread_exit((void *)0); + printf("Enter into receive_2 \n"); + for (i = 0; i< MAX_MSG; i++) { + if ( -1 == mq_receive(mq2, r_msg_ptr_2[i], MSG_SIZE, NULL) ) { + perror("mq_receive doesn't return success \n"); + pthread_exit((void *)1); + } + printf("[%d] receive '%s' in thread receive_2. \n", i+1, r_msg_ptr_2[i]); + } + pthread_exit((void *)0); } int libc_mq() { - mqd_t mq1 = 0, mq2 = 0; - struct mq_attr mqstat; - int oflag = O_CREAT|O_RDWR; + mqd_t mq1 = 0, mq2 = 0; + struct mq_attr mqstat; + int oflag = O_CREAT|O_RDWR; + + memset(&mqstat, 0, sizeof(mqstat)); + mqstat.mq_maxmsg = MAX_MSG; + mqstat.mq_msgsize = MSG_SIZE; + mqstat.mq_flags = 0; + + if( ((mqd_t) -1) == (mq1 = mq_open(MQ_NAME_1,oflag,0777, &mqstat)) ) { + printf("mq_open doesn't return success \n"); + return -1; + } + if( ((mqd_t) -1) == (mq2 = mq_open(MQ_NAME_2,oflag,0777, &mqstat)) ) { + printf("mq_open doesn't return success \n"); + return -1; + } + pthread_create(&send1, NULL, (void *)send_1, (void *)&mq1); + pthread_create(&send2, NULL, (void *)send_2, (void *)&mq2); + pthread_create(&rev1, NULL, (void *)receive_1, (void *)&mq1); + pthread_create(&rev2, NULL, (void *)receive_2, (void *)&mq2); + pthread_join(send1, NULL); + pthread_join(send2, NULL); + pthread_join(rev1, NULL); + pthread_join(rev2, NULL); - memset(&mqstat, 0, sizeof(mqstat)); - mqstat.mq_maxmsg = MAX_MSG; - mqstat.mq_msgsize = MSG_SIZE; - mqstat.mq_flags = 0; - - if( ((mqd_t) -1) == (mq1 = mq_open(MQ_NAME_1,oflag,0777, &mqstat)) ) { - printf("mq_open doesn't return success \n"); - return -1; - } - if( ((mqd_t) -1) == (mq2 = mq_open(MQ_NAME_2,oflag,0777, &mqstat)) ) { - printf("mq_open doesn't return success \n"); - return -1; - } - pthread_create(&send1, NULL, (void *)send_1, (void *)&mq1); - pthread_create(&send2, NULL, (void *)send_2, (void *)&mq2); - pthread_create(&rev1, NULL, (void *)receive_1, (void *)&mq1); - pthread_create(&rev2, NULL, (void *)receive_2, (void *)&mq2); - pthread_join(send1, NULL); - pthread_join(send2, NULL); - pthread_join(rev1, NULL); - pthread_join(rev2, NULL); - - mq_close(mq1); - mq_close(mq2); - mq_unlink(MQ_NAME_1); - mq_unlink(MQ_NAME_2); + mq_close(mq1); + mq_close(mq2); + mq_unlink(MQ_NAME_1); + mq_unlink(MQ_NAME_2); - printf("PASSED\n"); - return 0; + printf("PASSED\n"); + return 0; } #include <finsh.h> FINSH_FUNCTION_EXPORT(libc_mq, posix mqueue test); diff --git a/examples/libc/printf.c b/examples/libc/printf.c index 2d2d8a7763..c7968b9a0b 100644 --- a/examples/libc/printf.c +++ b/examples/libc/printf.c @@ -1,3 +1,13 @@ +/* + * Copyright (c) 2006-2021, RT-Thread Development Team + * + * SPDX-License-Identifier: Apache-2.0 + * + * Change Logs: + * Date Author Notes + * 2010-11-17 Bernard first version + */ + #include <stdio.h> #include <stdlib.h> #include <sys/fcntl.h> @@ -142,59 +152,59 @@ int printf_test() int i; printf ("snprintf (\"%%30s\", \"foo\") == %d, \"%.*s\"\n", - snprintf (buf, sizeof (buf), "%30s", "foo"), (int) sizeof (buf), - buf); + snprintf (buf, sizeof (buf), "%30s", "foo"), (int) sizeof (buf), + buf); memset(buf2,0,sizeof(buf)); i=snprintf(buf2, 256, "%.9999u", 10); printf("%i %i\n",i,strlen(buf2)); printf ("snprintf (\"%%.999999u\", 10) == %d\n", - snprintf(buf2, sizeof(buf2), "%.999999u", 10)); + snprintf(buf2, sizeof(buf2), "%.999999u", 10)); } return 0; } void libc_printf() { - printf("stdout test!!\n"); - fprintf(stdout, "fprintf test!!\n"); - fprintf(stderr, "fprintf test!!\n"); - puts("puts test!!\n"); + printf("stdout test!!\n"); + fprintf(stdout, "fprintf test!!\n"); + fprintf(stderr, "fprintf test!!\n"); + puts("puts test!!\n"); - putc('1', stderr); - putc('2', stderr); - putc('\n', stderr); + putc('1', stderr); + putc('2', stderr); + putc('\n', stderr); - printf_test(); + printf_test(); } FINSH_FUNCTION_EXPORT(libc_printf, printf test in libc); void libc_dprintf() { - int fd; + int fd; - fd = open("/dev/console", O_WRONLY, 0); - if (fd >0) - { - dprintf(fd, "fd:%d printf test!!\n", fd); - close(fd); - } + fd = open("/dev/console", O_WRONLY, 0); + if (fd >0) + { + dprintf(fd, "fd:%d printf test!!\n", fd); + close(fd); + } } FINSH_FUNCTION_EXPORT(libc_dprintf, dprintf test); void libc_fdopen() { - int fd; - FILE* fp; + int fd; + FILE* fp; - fd = open("/dev/console", O_WRONLY, 0); - if (fd >0) - { - fp = fdopen(fd, "w"); - fprintf(fp, "fdopen test, fd %d!!\n", fileno(fp)); - fclose(fp); - } + fd = open("/dev/console", O_WRONLY, 0); + if (fd >0) + { + fp = fdopen(fd, "w"); + fprintf(fp, "fdopen test, fd %d!!\n", fileno(fp)); + fclose(fp); + } } FINSH_FUNCTION_EXPORT(libc_fdopen, fdopen test); diff --git a/examples/libc/rand.c b/examples/libc/rand.c index 8f52ad28bb..96f5628bb8 100644 --- a/examples/libc/rand.c +++ b/examples/libc/rand.c @@ -1,43 +1,47 @@ /* - * rand.c + * Copyright (c) 2006-2021, RT-Thread Development Team * - * Created on: 2010-11-17 - * Author: bernard + * SPDX-License-Identifier: Apache-2.0 + * + * Change Logs: + * Date Author Notes + * 2010-11-17 Bernard first version */ + #include <stdio.h> #include <stdlib.h> #include <finsh.h> int libc_rand(void) { - int i1, i2; - int j1, j2; + int i1, i2; + int j1, j2; - /* The C standard says that "If rand is called before any calls to - srand have been made, the same sequence shall be generated as - when srand is first called with a seed value of 1." */ - i1 = rand(); - i2 = rand(); - srand(1); - j1 = rand(); - j2 = rand(); - if (i1 < 0 || i2 < 0 || j1 < 0 || j2 < 0) - { - puts("Test FAILED!"); - } - if (j1 == i1 && j2 == i2) - { - puts("Test succeeded."); - return 0; - } - else - { - if (j1 != i1) - printf("%d != %d\n", j1, i1); - if (j2 != i2) - printf("%d != %d\n", j2, i2); - puts("Test FAILED!"); - return 1; - } + /* The C standard says that "If rand is called before any calls to + srand have been made, the same sequence shall be generated as + when srand is first called with a seed value of 1." */ + i1 = rand(); + i2 = rand(); + srand(1); + j1 = rand(); + j2 = rand(); + if (i1 < 0 || i2 < 0 || j1 < 0 || j2 < 0) + { + puts("Test FAILED!"); + } + if (j1 == i1 && j2 == i2) + { + puts("Test succeeded."); + return 0; + } + else + { + if (j1 != i1) + printf("%d != %d\n", j1, i1); + if (j2 != i2) + printf("%d != %d\n", j2, i2); + puts("Test FAILED!"); + return 1; + } } FINSH_FUNCTION_EXPORT(libc_rand, rand test for libc); diff --git a/examples/libc/sem.c b/examples/libc/sem.c index d081d246e9..55b85114b8 100644 --- a/examples/libc/sem.c +++ b/examples/libc/sem.c @@ -1,3 +1,12 @@ +/* + * Copyright (c) 2006-2021, RT-Thread Development Team + * + * SPDX-License-Identifier: Apache-2.0 + * + * Change Logs: + * Date Author Notes + */ + #include <pthread.h> #include <semaphore.h> #include <stdio.h> @@ -5,61 +14,61 @@ static sem_t sema; static void* other_thread() { - printf("other_thread here!\n"); + printf("other_thread here!\n"); + + sleep(1); - sleep(1); + while (1) + { + printf("other_thread: sem_post...\n"); + if(sem_post(&sema) == -1) + printf("sem_post failed\n"); + sleep(1); + } - while (1) - { - printf("other_thread: sem_post...\n"); - if(sem_post(&sema) == -1) - printf("sem_post failed\n"); - sleep(1); - } - - printf("other_thread dies!\n"); - pthread_exit(0); + printf("other_thread dies!\n"); + pthread_exit(0); } static void test_thread(void* parameter) { - pthread_t tid; + pthread_t tid; + + printf("main thread here!\n"); + printf("sleep 5 seconds..."); + sleep(5); + printf("done\n"); - printf("main thread here!\n"); - printf("sleep 5 seconds..."); - sleep(5); - printf("done\n"); + sem_init(&sema, 0, 0); - sem_init(&sema, 0, 0); - - /* create the "other" thread */ - if(pthread_create(&tid, 0, &other_thread, 0)!=0) - /* error */ - printf("pthread_create OtherThread failed.\n"); - else - printf("created OtherThread=%x\n", tid); + /* create the "other" thread */ + if(pthread_create(&tid, 0, &other_thread, 0)!=0) + /* error */ + printf("pthread_create OtherThread failed.\n"); + else + printf("created OtherThread=%x\n", tid); - /* let the other thread run */ - while (1) - { - printf("Main: sem_wait...\n"); - if(sem_wait(&sema) == -1) - printf("sem_wait failed\n"); - printf("Main back.\n\n"); - } + /* let the other thread run */ + while (1) + { + printf("Main: sem_wait...\n"); + if(sem_wait(&sema) == -1) + printf("sem_wait failed\n"); + printf("Main back.\n\n"); + } - pthread_exit(0); + pthread_exit(0); } #include <finsh.h> void libc_sem() { - rt_thread_t tid; + rt_thread_t tid; - tid = rt_thread_create("semtest", test_thread, RT_NULL, - 2048, 20, 5); - if (tid != RT_NULL) - { - rt_thread_startup(tid); - } + tid = rt_thread_create("semtest", test_thread, RT_NULL, + 2048, 20, 5); + if (tid != RT_NULL) + { + rt_thread_startup(tid); + } } FINSH_FUNCTION_EXPORT(libc_sem, posix semaphore test); diff --git a/examples/libc/termios_test.c b/examples/libc/termios_test.c index 192021b9ab..f65bff1a9f 100644 --- a/examples/libc/termios_test.c +++ b/examples/libc/termios_test.c @@ -1,8 +1,11 @@ /* - * termios_test.c + * Copyright (c) 2006-2021, RT-Thread Development Team * - * Created on: 2017-12-06 - * Author: JasonJia + * SPDX-License-Identifier: Apache-2.0 + * + * Change Logs: + * Date Author Notes + * 2017-12-06 JasonJia first version */ #include <rtthread.h> diff --git a/examples/libc/time.c b/examples/libc/time.c index fa6dee74c8..5e91c1df80 100644 --- a/examples/libc/time.c +++ b/examples/libc/time.c @@ -1,8 +1,11 @@ /* - * time.c + * Copyright (c) 2006-2021, RT-Thread Development Team * - * Created on: 2010-11-17 - * Author: bernard + * SPDX-License-Identifier: Apache-2.0 + * + * Change Logs: + * Date Author Notes + * 2010-11-17 Bernard first version */ #include <stdio.h> @@ -11,14 +14,14 @@ int speed() { - int i; - time_t t; + int i; + time_t t; - printf("%d\n", time(0)); - for (i = 0; i < 10000000; ++i) - t = time(0); + printf("%d\n", time(0)); + for (i = 0; i < 10000000; ++i) + t = time(0); - printf("%d\n", time(0)); - return 0; + printf("%d\n", time(0)); + return 0; } FINSH_FUNCTION_EXPORT(speed, speed test); diff --git a/examples/network/chargen.c b/examples/network/chargen.c index 218449b845..3b4feaca9e 100644 --- a/examples/network/chargen.c +++ b/examples/network/chargen.c @@ -1,3 +1,12 @@ +/* + * Copyright (c) 2006-2021, RT-Thread Development Team + * + * SPDX-License-Identifier: Apache-2.0 + * + * Change Logs: + * Date Author Notes + */ + #include <rtthread.h> #include <sys/socket.h> diff --git a/examples/network/tcpclient.c b/examples/network/tcpclient.c index cc67645868..8f88985b10 100644 --- a/examples/network/tcpclient.c +++ b/examples/network/tcpclient.c @@ -1,3 +1,12 @@ +/* + * Copyright (c) 2006-2021, RT-Thread Development Team + * + * SPDX-License-Identifier: Apache-2.0 + * + * Change Logs: + * Date Author Notes + */ + #include <rtthread.h> #include <string.h> diff --git a/examples/network/tcpsendpacket.c b/examples/network/tcpsendpacket.c index 47bb562506..da8bc4f524 100644 --- a/examples/network/tcpsendpacket.c +++ b/examples/network/tcpsendpacket.c @@ -1,3 +1,12 @@ +/* + * Copyright (c) 2006-2021, RT-Thread Development Team + * + * SPDX-License-Identifier: Apache-2.0 + * + * Change Logs: + * Date Author Notes + */ + #include <rtthread.h> #include <netdb.h> /* 为了解析主机名,需要包含netdb.h头文件 */ @@ -26,9 +35,9 @@ void tcp_senddata(const char *url, int port, int length) { /* 申请内存失败 */ rt_kprintf("No memory\n"); - return; + return; } - + /* 构造发送数据 */ for (index = 0; index < length; index ++) buffer_ptr[index] = index & 0xff; diff --git a/examples/network/tcpserver.c b/examples/network/tcpserver.c index 8c7382dcbb..e7438eb6f3 100644 --- a/examples/network/tcpserver.c +++ b/examples/network/tcpserver.c @@ -1,3 +1,12 @@ +/* + * Copyright (c) 2006-2021, RT-Thread Development Team + * + * SPDX-License-Identifier: Apache-2.0 + * + * Change Logs: + * Date Author Notes + */ + #include <rtthread.h> #include <string.h> diff --git a/examples/network/udpclient.c b/examples/network/udpclient.c index f8c42f3a12..1a3f0268af 100644 --- a/examples/network/udpclient.c +++ b/examples/network/udpclient.c @@ -1,3 +1,12 @@ +/* + * Copyright (c) 2006-2021, RT-Thread Development Team + * + * SPDX-License-Identifier: Apache-2.0 + * + * Change Logs: + * Date Author Notes + */ + #include <rtthread.h> #include <sys/socket.h> /* 使用BSD socket,需要包含sockets.h头文件 */ diff --git a/examples/network/udpserver.c b/examples/network/udpserver.c index a249475e04..a33a27da10 100644 --- a/examples/network/udpserver.c +++ b/examples/network/udpserver.c @@ -1,3 +1,12 @@ +/* + * Copyright (c) 2006-2021, RT-Thread Development Team + * + * SPDX-License-Identifier: Apache-2.0 + * + * Change Logs: + * Date Author Notes + */ + #include <rtthread.h> #include <string.h> diff --git a/examples/pm/timer_app.c b/examples/pm/timer_app.c index b7ff675b39..5797693149 100644 --- a/examples/pm/timer_app.c +++ b/examples/pm/timer_app.c @@ -1,5 +1,5 @@ /* - * Copyright (c) 2006-2018, RT-Thread Development Team + * Copyright (c) 2006-2021, RT-Thread Development Team * * SPDX-License-Identifier: Apache-2.0 * diff --git a/examples/pm/wakeup_app.c b/examples/pm/wakeup_app.c index 0d4c42a997..d287bf74ec 100644 --- a/examples/pm/wakeup_app.c +++ b/examples/pm/wakeup_app.c @@ -1,5 +1,5 @@ /* - * Copyright (c) 2006-2018, RT-Thread Development Team + * Copyright (c) 2006-2021, RT-Thread Development Team * * SPDX-License-Identifier: Apache-2.0 * diff --git a/examples/test/device_test.c b/examples/test/device_test.c index d62c2168ff..f9a7591478 100644 --- a/examples/test/device_test.c +++ b/examples/test/device_test.c @@ -1,11 +1,7 @@ /* - * File : device_test.c - * This file is part of RT-Thread RTOS - * COPYRIGHT (C) 2011, RT-Thread Development Team + * Copyright (c) 2006-2021, RT-Thread Development Team * - * The license and distribution terms for this file may be - * found in the file LICENSE in this distribution or at - * http://openlab.rt-thread.com/license/LICENSE. + * SPDX-License-Identifier: Apache-2.0 * * Change Logs: * Date Author Notes diff --git a/examples/test/dhry.h b/examples/test/dhry.h index 8f47233802..dc42492417 100644 --- a/examples/test/dhry.h +++ b/examples/test/dhry.h @@ -3,9 +3,9 @@ * * "DHRYSTONE" Benchmark Program * ----------------------------- - * + * * Version: C, Version 2.1 - * + * * File: dhry.h (part 1 of 3) * * Date: May 25, 1988 @@ -33,12 +33,12 @@ * * Collection of Results: * Reinhold Weicker (address see above) and - * + * * Rick Richardson * PC Research. Inc. * 94 Apple Orchard Drive * Tinton Falls, NJ 07724 - * Phone: (201) 389-8963 (9-17 EST) + * Phone: (201) 389-8963 (9-17 EST) * Usenet: ...!uunet!pcrat!rick * * Please send results to Rick Richardson and/or Reinhold Weicker. @@ -91,7 +91,7 @@ * version previously distributed by Reinhold Weicker. * * At several places in the benchmark, code has been added, - * but within the measurement loop only in branches that + * but within the measurement loop only in branches that * are not executed. The intention is that optimizing compilers * should be prevented from moving code out of the measurement * loop, or from removing code altogether. Since the statements @@ -101,7 +101,7 @@ * still hold. Except for sophisticated optimizing compilers, * execution times for this version should be the same as * for previous versions. - * + * * Since it has proven difficult to subtract the time for the * measurement loop overhead in a correct way, the loop check * has been made a part of the benchmark. This does have @@ -151,7 +151,7 @@ * -DTIME * The "times" function of UNIX (returning process times) * or the "time" function (returning wallclock time) - * is used for measurement. + * is used for measurement. * For single user machines, "time ()" is adequate. For * multi-user machines where you cannot get single-user * access, use the "times ()" function. If you have @@ -198,23 +198,23 @@ * different from the Ada version.] * * The following program contains statements of a high level programming - * language (here: C) in a distribution considered representative: + * language (here: C) in a distribution considered representative: * * assignments 52 (51.0 %) * control statements 33 (32.4 %) * procedure, function calls 17 (16.7 %) * * 103 statements are dynamically executed. The program is balanced with - * respect to the three aspects: + * respect to the three aspects: * * - statement type * - operand type * - operand locality - * operand global, local, parameter, or constant. + * operand global, local, parameter, or constant. * - * The combination of these three aspects is balanced only approximately. + * The combination of these three aspects is balanced only approximately. * - * 1. Statement Type: + * 1. Statement Type: * ----------------- number * * V1 = V2 9 @@ -258,9 +258,9 @@ * library procedure 1 * X = F (...) * function call 6 - * user function 5 - * library function 1 - * -- + * user function 5 + * library function 1 + * -- * 17 17 * --- * 103 @@ -274,10 +274,10 @@ * number approximate * percentage * - * Arithmetic 32 50.8 + * Arithmetic 32 50.8 * - * + 21 33.3 - * - 7 11.1 + * + 21 33.3 + * - 7 11.1 * * 3 4.8 * / (int div) 1 1.6 * @@ -295,7 +295,7 @@ * && (AND-THEN) 1 1.6 * | (OR) 1 1.6 * ! (NOT) 2 3.2 - * + * * -- ----- * 63 100.1 * @@ -315,10 +315,10 @@ * 242 100.0 % * * When there is an access path leading to the final operand (e.g. a record - * component), only the final data type on the access path is counted. + * component), only the final data type on the access path is counted. * * - * 4. Operand Locality: + * 4. Operand Locality: * ------------------- * number approximate * percentage @@ -375,7 +375,7 @@ /* for strcpy, strcmp */ #include <rtthread.h> -#define Null 0 +#define Null 0 /* Value of a Null pointer */ #define true 1 #define false 0 @@ -388,7 +388,7 @@ typedef char Str_30 [31]; typedef int Arr_1_Dim [50]; typedef int Arr_2_Dim [50] [50]; -typedef struct record +typedef struct record { struct record *Ptr_Comp; Enumeration Discr; diff --git a/examples/test/dhry_1.c b/examples/test/dhry_1.c index b45b9ddafa..44283649f6 100644 --- a/examples/test/dhry_1.c +++ b/examples/test/dhry_1.c @@ -3,9 +3,9 @@ * * "DHRYSTONE" Benchmark Program * ----------------------------- - * + * * Version: C, Version 2.1 - * + * * File: dhry_1.c (part 2 of 3) * * Date: May 25, 1988 @@ -14,8 +14,8 @@ * **************************************************************************** */ - -#define NUMBER_OF_RUNS 1000000 + +#define NUMBER_OF_RUNS 1000000 #include "dhry.h" #define printf rt_kprintf @@ -34,7 +34,7 @@ int Arr_2_Glob [50] [50]; Enumeration Func_1 (); /* forward declaration necessary since Enumeration may not simply be int */ - + #ifndef REG Boolean Reg = false; #define REG @@ -71,7 +71,7 @@ void dhry_test(void) REG int Number_Of_Runs; /* Initializations */ - + Next_Ptr_Glob = (Rec_Pointer) rt_malloc (sizeof (Rec_Type)); Ptr_Glob = (Rec_Pointer) rt_malloc (sizeof (Rec_Type)); @@ -79,7 +79,7 @@ void dhry_test(void) Ptr_Glob->Discr = Ident_1; Ptr_Glob->variant.var_1.Enum_Comp = Ident_3; Ptr_Glob->variant.var_1.Int_Comp = 40; - rt_strncpy (Ptr_Glob->variant.var_1.Str_Comp, + rt_strncpy (Ptr_Glob->variant.var_1.Str_Comp, "DHRYSTONE PROGRAM, SOME STRING", sizeof(Ptr_Glob->variant.var_1.Str_Comp)); rt_strncpy (Str_1_Loc, "DHRYSTONE PROGRAM, 1'ST STRING", sizeof(Str_1_Loc)); @@ -114,9 +114,9 @@ void dhry_test(void) /***************/ /* Start timer */ /***************/ - + // Add your timer initializing code here - + Begin_Time = rt_tick_get(); /* get start tick */ for (Run_Index = 1; Run_Index <= Number_Of_Runs; ++Run_Index) @@ -169,8 +169,8 @@ void dhry_test(void) /* Stop timer */ /**************/ - End_Time = rt_tick_get(); // Get end tick - + End_Time = rt_tick_get(); // Get end tick + printf ("Execution ends\n"); printf ("\n"); printf ("Final values of the variables used in the benchmark:\n"); @@ -226,7 +226,7 @@ void dhry_test(void) User_Time = (End_Time - Begin_Time) / RT_TICK_PER_SECOND; - Microseconds = (float) User_Time * Mic_secs_Per_Second + Microseconds = (float) User_Time * Mic_secs_Per_Second / (float) Number_Of_Runs; Dhrystones_Per_Second = (float) Number_Of_Runs / (float) User_Time; @@ -237,7 +237,7 @@ void dhry_test(void) printf ("Dhrystones MIPS: "); printf ("%6d \n", (int)(Dhrystones_Per_Second / 1757.0)); printf ("\n"); - + } Proc_1 (Ptr_Val_Par) @@ -246,27 +246,27 @@ Proc_1 (Ptr_Val_Par) REG Rec_Pointer Ptr_Val_Par; /* executed once */ { - REG Rec_Pointer Next_Record = Ptr_Val_Par->Ptr_Comp; + REG Rec_Pointer Next_Record = Ptr_Val_Par->Ptr_Comp; /* == Ptr_Glob_Next */ /* Local variable, initialized with Ptr_Val_Par->Ptr_Comp, */ /* corresponds to "rename" in Ada, "with" in Pascal */ - - structassign (*Ptr_Val_Par->Ptr_Comp, *Ptr_Glob); + + structassign (*Ptr_Val_Par->Ptr_Comp, *Ptr_Glob); Ptr_Val_Par->variant.var_1.Int_Comp = 5; - Next_Record->variant.var_1.Int_Comp + Next_Record->variant.var_1.Int_Comp = Ptr_Val_Par->variant.var_1.Int_Comp; Next_Record->Ptr_Comp = Ptr_Val_Par->Ptr_Comp; Proc_3 (&Next_Record->Ptr_Comp); - /* Ptr_Val_Par->Ptr_Comp->Ptr_Comp + /* Ptr_Val_Par->Ptr_Comp->Ptr_Comp == Ptr_Glob->Ptr_Comp */ if (Next_Record->Discr == Ident_1) /* then, executed */ { Next_Record->variant.var_1.Int_Comp = 6; - Proc_6 (Ptr_Val_Par->variant.var_1.Enum_Comp, + Proc_6 (Ptr_Val_Par->variant.var_1.Enum_Comp, &Next_Record->variant.var_1.Enum_Comp); Next_Record->Ptr_Comp = Ptr_Glob->Ptr_Comp; - Proc_7 (Next_Record->variant.var_1.Int_Comp, 10, + Proc_7 (Next_Record->variant.var_1.Int_Comp, 10, &Next_Record->variant.var_1.Int_Comp); } else /* not executed */ @@ -281,7 +281,7 @@ Proc_2 (Int_Par_Ref) One_Fifty *Int_Par_Ref; { - One_Fifty Int_Loc; + One_Fifty Int_Loc; Enumeration Enum_Loc; Int_Loc = *Int_Par_Ref + 10; diff --git a/examples/test/dhry_2.c b/examples/test/dhry_2.c index 63a3d3ea03..ac5be3baf4 100644 --- a/examples/test/dhry_2.c +++ b/examples/test/dhry_2.c @@ -3,9 +3,9 @@ * * "DHRYSTONE" Benchmark Program * ----------------------------- - * + * * Version: C, Version 2.1 - * + * * File: dhry_2.c (part 3 of 3) * * Date: May 25, 1988 @@ -41,10 +41,10 @@ Enumeration *Enum_Ref_Par; *Enum_Ref_Par = Ident_4; switch (Enum_Val_Par) { - case Ident_1: + case Ident_1: *Enum_Ref_Par = Ident_1; break; - case Ident_2: + case Ident_2: if (Int_Glob > 100) /* then */ *Enum_Ref_Par = Ident_1; @@ -54,7 +54,7 @@ Enumeration *Enum_Ref_Par; *Enum_Ref_Par = Ident_2; break; case Ident_4: break; - case Ident_5: + case Ident_5: *Enum_Ref_Par = Ident_3; break; } /* switch */ @@ -63,7 +63,7 @@ Enumeration *Enum_Ref_Par; Proc_7 (Int_1_Par_Val, Int_2_Par_Val, Int_Par_Ref) /**********************************************/ - /* executed three times */ + /* executed three times */ /* first call: Int_1_Par_Val == 2, Int_2_Par_Val == 3, */ /* Int_Par_Ref becomes 7 */ /* second call: Int_1_Par_Val == 10, Int_2_Par_Val == 5, */ diff --git a/examples/test/fs_test.c b/examples/test/fs_test.c index 2404b82e59..a86bbd6ac2 100644 --- a/examples/test/fs_test.c +++ b/examples/test/fs_test.c @@ -1,11 +1,7 @@ /* - * File : fs_test.c - * This file is part of RT-Thread RTOS - * COPYRIGHT (C) 2011, RT-Thread Development Team + * Copyright (c) 2006-2021, RT-Thread Development Team * - * The license and distribution terms for this file may be - * found in the file LICENSE in this distribution or at - * http://openlab.rt-thread.com/license/LICENSE. + * SPDX-License-Identifier: Apache-2.0 * * Change Logs: * Date Author Notes diff --git a/examples/test/hwtimer_test.c b/examples/test/hwtimer_test.c index 428373dde0..15d7aa830f 100644 --- a/examples/test/hwtimer_test.c +++ b/examples/test/hwtimer_test.c @@ -1,3 +1,12 @@ +/* + * Copyright (c) 2006-2021, RT-Thread Development Team + * + * SPDX-License-Identifier: Apache-2.0 + * + * Change Logs: + * Date Author Notes + */ + #include <rtthread.h> #include <rtdevice.h> #include <finsh.h> @@ -35,8 +44,8 @@ int hwtimer(void) return -1; } - /* ʱ����� */ - /* ����ʱ������(Ĭ��1Mhz��֧�ֵ���С����Ƶ��) */ + /* 时间测量 */ + /* 计数时钟设置(默认1Mhz或支持的最小计数频率) */ err = rt_device_control(dev, HWTIMER_CTRL_FREQ_SET, &freq); if (err != RT_EOK) { @@ -44,13 +53,13 @@ int hwtimer(void) goto EXIT; } - /* ����ģʽ */ + /* 周期模式 */ mode = HWTIMER_MODE_PERIOD; err = rt_device_control(dev, HWTIMER_CTRL_MODE_SET, &mode); tick = rt_tick_get(); rt_kprintf("Start Timer> Tick: %d\n", tick); - /* ���ö�ʱ����ʱֵ��������ʱ�� */ + /* 设置定时器超时值并启动定时器 */ val.sec = t; val.usec = 0; rt_kprintf("SetTime: Sec %d, Usec %d\n", val.sec, val.usec); @@ -62,22 +71,22 @@ int hwtimer(void) rt_kprintf("Sleep %d sec\n", t); rt_thread_delay(t*RT_TICK_PER_SECOND); - /* ֹͣ��ʱ�� */ + /* 停止定时器 */ err = rt_device_control(dev, HWTIMER_CTRL_STOP, RT_NULL); rt_kprintf("Timer Stoped\n"); - /* ��ȡ���� */ + /* 读取计数 */ rt_device_read(dev, 0, &val, sizeof(val)); rt_kprintf("Read: Sec = %d, Usec = %d\n", val.sec, val.usec); - /* ��ʱִ�лص����� -- ����ģʽ */ - /* ���ó�ʱ�ص����� */ + /* 定时执行回调函数 -- 单次模式 */ + /* 设置超时回调函数 */ rt_device_set_rx_indicate(dev, timer_timeout_cb); - /* ����ģʽ */ + /* 单次模式 */ mode = HWTIMER_MODE_PERIOD; err = rt_device_control(dev, HWTIMER_CTRL_MODE_SET, &mode); - /* ���ö�ʱ����ʱֵ��������ʱ�� */ + /* 设置定时器超时值并启动定时器 */ val.sec = t; val.usec = 0; rt_kprintf("SetTime: Sec %d, Usec %d\n", val.sec, val.usec); @@ -87,7 +96,7 @@ int hwtimer(void) goto EXIT; } - /* �ȴ��ص�����ִ�� */ + /* 等待回调函数执行 */ rt_thread_delay((t + 1)*RT_TICK_PER_SECOND); EXIT: diff --git a/examples/test/mem_test.c b/examples/test/mem_test.c index 549be80ab4..cd7d1b3552 100644 --- a/examples/test/mem_test.c +++ b/examples/test/mem_test.c @@ -1,3 +1,12 @@ +/* + * Copyright (c) 2006-2021, RT-Thread Development Team + * + * SPDX-License-Identifier: Apache-2.0 + * + * Change Logs: + * Date Author Notes + */ + #include <stdint.h> #include <rthw.h> diff --git a/examples/test/net_test.c b/examples/test/net_test.c index ec5d50197d..656686f091 100644 --- a/examples/test/net_test.c +++ b/examples/test/net_test.c @@ -1,4 +1,13 @@ /* + * Copyright (c) 2006-2021, RT-Thread Development Team + * + * SPDX-License-Identifier: Apache-2.0 + * + * Change Logs: + * Date Author Notes + */ + +/* * Net Test Utilities for RT-Thread */ #include <rtthread.h> @@ -7,7 +16,7 @@ #include <lwip/sockets.h> #include <lwip/init.h> -/* +/* * UDP echo server */ #define UDP_ECHO_PORT 7 @@ -30,12 +39,12 @@ void udpecho_entry(void *parameter) while(1) { /* received data to buffer */ -#if LWIP_VERSION_MINOR==3U +#if LWIP_VERSION_MINOR==3U buf = netconn_recv(conn); #else netconn_recv(conn, &buf); #endif - if(buf == NULL) + if(buf == NULL) { break; } @@ -46,25 +55,25 @@ void udpecho_entry(void *parameter) netconn_connect(conn, addr, port); /* reset address, and send to client */ -#if LWIP_VERSION_MINOR==3U +#if LWIP_VERSION_MINOR==3U buf->addr = RT_NULL; #else buf->addr = *IP_ADDR_ANY; #endif - + netconn_send(conn, buf); - + /* release buffer */ netbuf_delete(buf); } - + netconn_delete(conn); } /* * UDP socket echo server */ -#define UDP_SOCKET_ECHO_PORT 700 -#define UDP_SOCKET_BUFFER_SIZE 4096 +#define UDP_SOCKET_ECHO_PORT 700 +#define UDP_SOCKET_BUFFER_SIZE 4096 rt_thread_t udpecho_socket_tid = RT_NULL; void udpecho_socket_entry(void *parameter) { @@ -110,7 +119,7 @@ void udpecho_socket_entry(void *parameter) /* try to receive from UDP socket */ bytes_read = recvfrom(sock, recv_data, UDP_SOCKET_BUFFER_SIZE, 0, (struct sockaddr *)&client_addr, &addr_len); - + /* send back */ sendto(sock, recv_data, bytes_read, 0, (struct sockaddr *)&client_addr, addr_len); @@ -148,7 +157,7 @@ void tcpecho_entry(void *parameter) while(1) { /* Grab new connection. */ -#if LWIP_VERSION_MINOR==3U +#if LWIP_VERSION_MINOR==3U newconn = netconn_accept(conn); if(newconn != NULL) #else @@ -172,25 +181,25 @@ void tcpecho_entry(void *parameter) err = netconn_write(newconn, data, len, NETCONN_COPY); if(err != ERR_OK) { - break; + break; } }while(netbuf_next(buf) >= 0); - + netbuf_delete(buf); } /* Close connection and discard connection identifier. */ netconn_delete(newconn); } } - + netconn_delete(conn); } /* * TCP socket echo server */ -#define TCP_SOCKET_ECHO_PORT 700 -#define TCP_SOCKET_BUFFER_SIZE 4096 +#define TCP_SOCKET_ECHO_PORT 700 +#define TCP_SOCKET_BUFFER_SIZE 4096 rt_thread_t tcpecho_socket_tid = RT_NULL; void tcpecho_socket_entry(void *parameter) { @@ -241,7 +250,7 @@ void tcpecho_socket_entry(void *parameter) if (connected > 0) { int timeout; - + /* set timeout option */ timeout = 5000; /* 5second */ setsockopt(connected, SOL_SOCKET, SO_RCVTIMEO, &timeout, sizeof(timeout)); @@ -285,8 +294,8 @@ void net_test(void) { udpecho_tid = rt_thread_create("uecho", udpecho_entry, - RT_NULL, - 512, + RT_NULL, + 512, RT_THREAD_PRIORITY_MAX/2, 5); if (udpecho_tid != RT_NULL) { @@ -299,7 +308,7 @@ void net_test(void) udpecho_socket_tid = rt_thread_create("uecho_s", udpecho_socket_entry, RT_NULL, - 512, + 512, RT_THREAD_PRIORITY_MAX/2 + 1, 5); if (udpecho_socket_tid != RT_NULL) { @@ -310,22 +319,22 @@ void net_test(void) if (tcpecho_tid == RT_NULL) { tcpecho_tid = rt_thread_create("techo", - tcpecho_entry, + tcpecho_entry, RT_NULL, - 512, + 512, RT_THREAD_PRIORITY_MAX/2 + 2, 5); if (tcpecho_tid != RT_NULL) { rt_thread_startup(tcpecho_tid); } } - + if (tcpecho_socket_tid == RT_NULL) { tcpecho_socket_tid = rt_thread_create("techo_s", - tcpecho_socket_entry, + tcpecho_socket_entry, RT_NULL, - 512, + 512, RT_THREAD_PRIORITY_MAX/2 + 3, 5); if (tcpecho_socket_tid != RT_NULL) { diff --git a/examples/test/rbb_test.c b/examples/test/rbb_test.c index f276c993da..c4236bca44 100644 --- a/examples/test/rbb_test.c +++ b/examples/test/rbb_test.c @@ -1,21 +1,7 @@ /* - * File : rbb_test.c - * This file is part of RT-Thread RTOS - * COPYRIGHT (C) 2006 - 2018, RT-Thread Development Team + * Copyright (c) 2006-2021, RT-Thread Development Team * - * This program is free software; you can redistribute it and/or modify - * it under the terms of the GNU General Public License as published by - * the Free Software Foundation; either version 2 of the License, or - * (at your option) any later version. - * - * This program is distributed in the hope that it will be useful, - * but WITHOUT ANY WARRANTY; without even the implied warranty of - * MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the - * GNU General Public License for more details. - * - * You should have received a copy of the GNU General Public License along - * with this program; if not, write to the Free Software Foundation, Inc., - * 51 Franklin Street, Fifth Floor, Boston, MA 02110-1301 USA. + * SPDX-License-Identifier: Apache-2.0 * * Change Logs: * Date Author Notes diff --git a/examples/test/rtc_test.c b/examples/test/rtc_test.c index 992eb08d3d..4ed1349de4 100644 --- a/examples/test/rtc_test.c +++ b/examples/test/rtc_test.c @@ -1,68 +1,55 @@ /* - * File : rtc_test.c - * This file is part of RT-Thread RTOS - * COPYRIGHT (C) 2017, RT-Thread Development Team + * Copyright (c) 2006-2021, RT-Thread Development Team * - * This program is free software; you can redistribute it and/or modify - * it under the terms of the GNU General Public License as published by - * the Free Software Foundation; either version 2 of the License, or - * (at your option) any later version. - * - * This program is distributed in the hope that it will be useful, - * but WITHOUT ANY WARRANTY; without even the implied warranty of - * MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the - * GNU General Public License for more details. - * - * You should have received a copy of the GNU General Public License along - * with this program; if not, write to the Free Software Foundation, Inc., - * 51 Franklin Street, Fifth Floor, Boston, MA 02110-1301 USA. + * SPDX-License-Identifier: Apache-2.0 * * Change Logs: * Date Author Notes * 2018-01-15 Liu2guang the first version. */ -#include <rtthread.h> -#include <rtdevice.h> + +#include <rtthread.h> +#include <rtdevice.h> int rtc_test(void) -{ +{ uint8_t i; time_t now; - rt_err_t ret = RT_EOK; - + rt_err_t ret = RT_EOK; + rt_kprintf("[RTC Test]RTC Test Start...\n"); rt_thread_delay(RT_TICK_PER_SECOND); - rt_kprintf("[RTC Test]Set RTC 2017-04-01 12:30:46\n\n"); + rt_kprintf("[RTC Test]Set RTC 2017-04-01 12:30:46\n\n"); rt_thread_delay(RT_TICK_PER_SECOND); - - ret = set_date(2017, 4, 1); + + ret = set_date(2017, 4, 1); if(ret != RT_EOK) { - rt_kprintf("[RTC Test]Set RTC Date failed\n"); + rt_kprintf("[RTC Test]Set RTC Date failed\n"); return RT_ERROR; } - + rt_thread_delay(RT_TICK_PER_SECOND); - - ret = set_time(12, 30, 46); + + ret = set_time(12, 30, 46); if(ret != RT_EOK) { - rt_kprintf("[RTC Test]Set RTC Time failed\n"); + rt_kprintf("[RTC Test]Set RTC Time failed\n"); return RT_ERROR; } - + rt_thread_delay(RT_TICK_PER_SECOND); - + for(i = 0; i < 10; i++) { - rt_kprintf("[RTC Test]Read RTC Date and Time: "); + rt_kprintf("[RTC Test]Read RTC Date and Time: "); now = time(RT_NULL); rt_kprintf("%s", ctime(&now)); - + rt_thread_delay(RT_TICK_PER_SECOND); } - + rt_kprintf("\n"); return RT_EOK; @@ -70,5 +57,5 @@ int rtc_test(void) #ifdef RT_USING_FINSH #include <finsh.h> FINSH_FUNCTION_EXPORT(rtc_test, rtc drive test. e.g: rtc_test()); -MSH_CMD_EXPORT(rtc_test, rtc drive test. e.g: rtc_test()); +MSH_CMD_EXPORT(rtc_test, rtc drive test. e.g: rtc_test()); #endif diff --git a/examples/ulog/ulog_example.c b/examples/ulog/ulog_example.c index 88572f5152..f7ee068799 100644 --- a/examples/ulog/ulog_example.c +++ b/examples/ulog/ulog_example.c @@ -1,5 +1,5 @@ /* - * Copyright (c) 2006-2018, RT-Thread Development Team + * Copyright (c) 2006-2021, RT-Thread Development Team * * SPDX-License-Identifier: Apache-2.0 * diff --git a/examples/ymodem/echo.c b/examples/ymodem/echo.c index 5cb807f519..fdd7e5228b 100644 --- a/examples/ymodem/echo.c +++ b/examples/ymodem/echo.c @@ -1,3 +1,12 @@ +/* + * Copyright (c) 2006-2021, RT-Thread Development Team + * + * SPDX-License-Identifier: Apache-2.0 + * + * Change Logs: + * Date Author Notes + */ + #include <ymodem.h> static rt_device_t _odev; diff --git a/examples/ymodem/null.c b/examples/ymodem/null.c index c72ea064f8..640b8ba11b 100644 --- a/examples/ymodem/null.c +++ b/examples/ymodem/null.c @@ -1,3 +1,12 @@ +/* + * Copyright (c) 2006-2021, RT-Thread Development Team + * + * SPDX-License-Identifier: Apache-2.0 + * + * Change Logs: + * Date Author Notes + */ + #include <ymodem.h> static enum rym_code _rym_dummy_write( diff --git a/examples/ymodem/tofile.c b/examples/ymodem/tofile.c index 4a3705ede7..35dca2f2c1 100644 --- a/examples/ymodem/tofile.c +++ b/examples/ymodem/tofile.c @@ -1,3 +1,12 @@ +/* + * Copyright (c) 2006-2021, RT-Thread Development Team + * + * SPDX-License-Identifier: Apache-2.0 + * + * Change Logs: + * Date Author Notes + */ + #include <rtthread.h> #include <ymodem.h> #include <dfs_posix.h> |
