diff options
| author | Meco Man <[email protected]> | 2021-03-07 08:34:04 +0800 |
|---|---|---|
| committer | Meco Man <[email protected]> | 2021-03-07 08:34:04 +0800 |
| commit | 08af426f01cf0321719c937d29a1d9315a0feab8 (patch) | |
| tree | cb9c4e5ba1db25c5878b732a2651ec3646efc4d1 /examples/test | |
| parent | ce86058201432e865b8d7c4096b3675642a43a42 (diff) | |
[example] 格式化整理
Diffstat (limited to 'examples/test')
| -rw-r--r-- | examples/test/dhry.h | 46 | ||||
| -rw-r--r-- | examples/test/dhry_1.c | 42 | ||||
| -rw-r--r-- | examples/test/dhry_2.c | 12 | ||||
| -rw-r--r-- | examples/test/hwtimer_test.c | 22 | ||||
| -rw-r--r-- | examples/test/net_test.c | 50 | ||||
| -rw-r--r-- | examples/test/rtc_test.c | 38 |
6 files changed, 105 insertions, 105 deletions
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/hwtimer_test.c b/examples/test/hwtimer_test.c index 428373dde0..b488c305b2 100644 --- a/examples/test/hwtimer_test.c +++ b/examples/test/hwtimer_test.c @@ -35,8 +35,8 @@ int hwtimer(void) return -1; } - /* ʱ����� */ - /* ����ʱ������(Ĭ��1Mhz��֧�ֵ���С����Ƶ��) */ + /* 时间测量 */ + /* 计数时钟设置(默认1Mhz或支持的最小计数频率) */ err = rt_device_control(dev, HWTIMER_CTRL_FREQ_SET, &freq); if (err != RT_EOK) { @@ -44,13 +44,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 +62,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 +87,7 @@ int hwtimer(void) goto EXIT; } - /* �ȴ��ص�����ִ�� */ + /* 等待回调函数执行 */ rt_thread_delay((t + 1)*RT_TICK_PER_SECOND); EXIT: diff --git a/examples/test/net_test.c b/examples/test/net_test.c index ec5d50197d..de143147d1 100644 --- a/examples/test/net_test.c +++ b/examples/test/net_test.c @@ -7,7 +7,7 @@ #include <lwip/sockets.h> #include <lwip/init.h> -/* +/* * UDP echo server */ #define UDP_ECHO_PORT 7 @@ -30,12 +30,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 +46,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 +110,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 +148,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 +172,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 +241,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 +285,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 +299,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 +310,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/rtc_test.c b/examples/test/rtc_test.c index 992eb08d3d..48129ca36c 100644 --- a/examples/test/rtc_test.c +++ b/examples/test/rtc_test.c @@ -21,48 +21,48 @@ * 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 +70,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 |
