xiaoxiang781216 commented on code in PR #6897: URL: https://github.com/apache/incubator-nuttx/pull/6897#discussion_r952377494
########## arch/sim/src/sim/win/up_hosttime.c: ########## @@ -0,0 +1,138 @@ +/**************************************************************************** + * arch/sim/src/sim/win/up_hosttime.c + * + * Licensed to the Apache Software Foundation (ASF) under one or more + * contributor license agreements. See the NOTICE file distributed with + * this work for additional information regarding copyright ownership. The + * ASF licenses this file to you under the Apache License, Version 2.0 (the + * "License"); you may not use this file except in compliance with the + * License. You may obtain a copy of the License at + * + * http://www.apache.org/licenses/LICENSE-2.0 + * + * Unless required by applicable law or agreed to in writing, software + * distributed under the License is distributed on an "AS IS" BASIS, WITHOUT + * WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied. See the + * License for the specific language governing permissions and limitations + * under the License. + * + ****************************************************************************/ + +/**************************************************************************** + * Included Files + ****************************************************************************/ + +#include <stdint.h> +#include <stdbool.h> +#include <windows.h> + +/**************************************************************************** + * Pre-processor Definitions + ****************************************************************************/ + +#define POW10_9 (1000000000ull) + +/* Number of 100ns-seconds between the beginning of the Windows epoch + * (Jan. 1, 1601) and the Unix epoch (Jan. 1, 1970) + */ + +#define DELTA_EPOCH_IN_100NS (0x19db1ded53e8000LL) Review Comment: LL->ull ########## arch/sim/src/Makefile: ########## @@ -75,7 +75,12 @@ CSRCS += up_vfork.c endif endif -VPATH = sim +VPATH = :sim +ifeq ($(CONFIG_HOST_WINDOWS),y) Review Comment: CONFIG_WINDOWS_NATIVE ########## arch/sim/src/sim/win/up_hosttime.c: ########## @@ -0,0 +1,138 @@ +/**************************************************************************** + * arch/sim/src/sim/win/up_hosttime.c + * + * Licensed to the Apache Software Foundation (ASF) under one or more + * contributor license agreements. See the NOTICE file distributed with + * this work for additional information regarding copyright ownership. The + * ASF licenses this file to you under the Apache License, Version 2.0 (the + * "License"); you may not use this file except in compliance with the + * License. You may obtain a copy of the License at + * + * http://www.apache.org/licenses/LICENSE-2.0 + * + * Unless required by applicable law or agreed to in writing, software + * distributed under the License is distributed on an "AS IS" BASIS, WITHOUT + * WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied. See the + * License for the specific language governing permissions and limitations + * under the License. + * + ****************************************************************************/ + +/**************************************************************************** + * Included Files + ****************************************************************************/ + +#include <stdint.h> +#include <stdbool.h> +#include <windows.h> + +/**************************************************************************** + * Pre-processor Definitions + ****************************************************************************/ + +#define POW10_9 (1000000000ull) + +/* Number of 100ns-seconds between the beginning of the Windows epoch + * (Jan. 1, 1601) and the Unix epoch (Jan. 1, 1970) + */ + +#define DELTA_EPOCH_IN_100NS (0x19db1ded53e8000LL) + +/**************************************************************************** + * Public Functions + ****************************************************************************/ + +/**************************************************************************** + * Name: host_gettime + ****************************************************************************/ + +uint64_t host_gettime(bool rtc) +{ + static uint64_t start; + LARGE_INTEGER freq, counter; + FILETIME ftime; + + if (rtc) + { + GetSystemTimeAsFileTime(&ftime); + + counter.QuadPart = (((uint64_t)ftime.dwHighDateTime << 32 | + ftime.dwLowDateTime) - + DELTA_EPOCH_IN_100NS) * 100; + } + else + { + QueryPerformanceFrequency(&freq); + QueryPerformanceCounter(&counter); + + counter.QuadPart = counter.QuadPart * POW10_9 / freq.QuadPart; + } + + if (rtc) + { + return counter.QuadPart; + } + + if (start == 0) + { + start = counter.QuadPart; + } + + return counter.QuadPart - start; Review Comment: move after line 68 ########## arch/sim/src/sim/win/up_hosttime.c: ########## @@ -0,0 +1,138 @@ +/**************************************************************************** + * arch/sim/src/sim/win/up_hosttime.c + * + * Licensed to the Apache Software Foundation (ASF) under one or more + * contributor license agreements. See the NOTICE file distributed with + * this work for additional information regarding copyright ownership. The + * ASF licenses this file to you under the Apache License, Version 2.0 (the + * "License"); you may not use this file except in compliance with the + * License. You may obtain a copy of the License at + * + * http://www.apache.org/licenses/LICENSE-2.0 + * + * Unless required by applicable law or agreed to in writing, software + * distributed under the License is distributed on an "AS IS" BASIS, WITHOUT + * WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied. See the + * License for the specific language governing permissions and limitations + * under the License. + * + ****************************************************************************/ + +/**************************************************************************** + * Included Files + ****************************************************************************/ + +#include <stdint.h> +#include <stdbool.h> +#include <windows.h> + +/**************************************************************************** + * Pre-processor Definitions + ****************************************************************************/ + +#define POW10_9 (1000000000ull) + +/* Number of 100ns-seconds between the beginning of the Windows epoch + * (Jan. 1, 1601) and the Unix epoch (Jan. 1, 1970) + */ + +#define DELTA_EPOCH_IN_100NS (0x19db1ded53e8000LL) + +/**************************************************************************** + * Public Functions + ****************************************************************************/ + +/**************************************************************************** + * Name: host_gettime + ****************************************************************************/ + +uint64_t host_gettime(bool rtc) +{ + static uint64_t start; + LARGE_INTEGER freq, counter; + FILETIME ftime; + + if (rtc) + { + GetSystemTimeAsFileTime(&ftime); + + counter.QuadPart = (((uint64_t)ftime.dwHighDateTime << 32 | + ftime.dwLowDateTime) - + DELTA_EPOCH_IN_100NS) * 100; + } + else + { + QueryPerformanceFrequency(&freq); + QueryPerformanceCounter(&counter); + + counter.QuadPart = counter.QuadPart * POW10_9 / freq.QuadPart; + } + + if (rtc) + { + return counter.QuadPart; + } + + if (start == 0) + { + start = counter.QuadPart; + } + + return counter.QuadPart - start; +} + +/**************************************************************************** + * Name: host_sleep + ****************************************************************************/ + +void host_sleep(uint64_t nsec) +{ + LARGE_INTEGER due; + HANDLE timer; + + /* Convert to 100 nanosecond interval, + * negative value indicates relative time + */ + + due.QuadPart = -(10 * ((nsec + 999) / 1000)); Review Comment: ```suggestion due.QuadPart = -((nsec + 99) / 100); ``` ########## arch/sim/src/sim/win/up_hosttime.c: ########## @@ -0,0 +1,138 @@ +/**************************************************************************** + * arch/sim/src/sim/win/up_hosttime.c + * + * Licensed to the Apache Software Foundation (ASF) under one or more + * contributor license agreements. See the NOTICE file distributed with + * this work for additional information regarding copyright ownership. The + * ASF licenses this file to you under the Apache License, Version 2.0 (the + * "License"); you may not use this file except in compliance with the + * License. You may obtain a copy of the License at + * + * http://www.apache.org/licenses/LICENSE-2.0 + * + * Unless required by applicable law or agreed to in writing, software + * distributed under the License is distributed on an "AS IS" BASIS, WITHOUT + * WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied. See the + * License for the specific language governing permissions and limitations + * under the License. + * + ****************************************************************************/ + +/**************************************************************************** + * Included Files + ****************************************************************************/ + +#include <stdint.h> +#include <stdbool.h> +#include <windows.h> + +/**************************************************************************** + * Pre-processor Definitions + ****************************************************************************/ + +#define POW10_9 (1000000000ull) + +/* Number of 100ns-seconds between the beginning of the Windows epoch + * (Jan. 1, 1601) and the Unix epoch (Jan. 1, 1970) + */ + +#define DELTA_EPOCH_IN_100NS (0x19db1ded53e8000LL) + +/**************************************************************************** + * Public Functions + ****************************************************************************/ + +/**************************************************************************** + * Name: host_gettime + ****************************************************************************/ + +uint64_t host_gettime(bool rtc) +{ + static uint64_t start; + LARGE_INTEGER freq, counter; Review Comment: split to two line ########## tools/ci/testlist/sim-02.dat: ########## @@ -12,3 +12,6 @@ # macOS doesn't have X11 -Darwin,sim:touchscreen + +# Do not build Windows configs +-Darwin,sim:windows Review Comment: need disable linux too ########## arch/sim/src/sim/win/up_hosttime.c: ########## @@ -0,0 +1,138 @@ +/**************************************************************************** + * arch/sim/src/sim/win/up_hosttime.c + * + * Licensed to the Apache Software Foundation (ASF) under one or more + * contributor license agreements. See the NOTICE file distributed with + * this work for additional information regarding copyright ownership. The + * ASF licenses this file to you under the Apache License, Version 2.0 (the + * "License"); you may not use this file except in compliance with the + * License. You may obtain a copy of the License at + * + * http://www.apache.org/licenses/LICENSE-2.0 + * + * Unless required by applicable law or agreed to in writing, software + * distributed under the License is distributed on an "AS IS" BASIS, WITHOUT + * WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied. See the + * License for the specific language governing permissions and limitations + * under the License. + * + ****************************************************************************/ + +/**************************************************************************** + * Included Files + ****************************************************************************/ + +#include <stdint.h> +#include <stdbool.h> +#include <windows.h> + +/**************************************************************************** + * Pre-processor Definitions + ****************************************************************************/ + +#define POW10_9 (1000000000ull) + +/* Number of 100ns-seconds between the beginning of the Windows epoch + * (Jan. 1, 1601) and the Unix epoch (Jan. 1, 1970) + */ + +#define DELTA_EPOCH_IN_100NS (0x19db1ded53e8000LL) + +/**************************************************************************** + * Public Functions + ****************************************************************************/ + +/**************************************************************************** + * Name: host_gettime + ****************************************************************************/ + +uint64_t host_gettime(bool rtc) +{ + static uint64_t start; Review Comment: uint64_t to LARGE_INTEGER ########## arch/sim/src/sim/win/up_hosttime.c: ########## @@ -0,0 +1,138 @@ +/**************************************************************************** + * arch/sim/src/sim/win/up_hosttime.c + * + * Licensed to the Apache Software Foundation (ASF) under one or more + * contributor license agreements. See the NOTICE file distributed with + * this work for additional information regarding copyright ownership. The + * ASF licenses this file to you under the Apache License, Version 2.0 (the + * "License"); you may not use this file except in compliance with the + * License. You may obtain a copy of the License at + * + * http://www.apache.org/licenses/LICENSE-2.0 + * + * Unless required by applicable law or agreed to in writing, software + * distributed under the License is distributed on an "AS IS" BASIS, WITHOUT + * WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied. See the + * License for the specific language governing permissions and limitations + * under the License. + * + ****************************************************************************/ + +/**************************************************************************** + * Included Files + ****************************************************************************/ + +#include <stdint.h> +#include <stdbool.h> +#include <windows.h> + +/**************************************************************************** + * Pre-processor Definitions + ****************************************************************************/ + +#define POW10_9 (1000000000ull) + +/* Number of 100ns-seconds between the beginning of the Windows epoch + * (Jan. 1, 1601) and the Unix epoch (Jan. 1, 1970) + */ + +#define DELTA_EPOCH_IN_100NS (0x19db1ded53e8000LL) + +/**************************************************************************** + * Public Functions + ****************************************************************************/ + +/**************************************************************************** + * Name: host_gettime + ****************************************************************************/ + +uint64_t host_gettime(bool rtc) +{ + static uint64_t start; + LARGE_INTEGER freq, counter; + FILETIME ftime; + + if (rtc) + { + GetSystemTimeAsFileTime(&ftime); + + counter.QuadPart = (((uint64_t)ftime.dwHighDateTime << 32 | + ftime.dwLowDateTime) - + DELTA_EPOCH_IN_100NS) * 100; + } + else + { + QueryPerformanceFrequency(&freq); + QueryPerformanceCounter(&counter); + + counter.QuadPart = counter.QuadPart * POW10_9 / freq.QuadPart; + } + + if (rtc) + { + return counter.QuadPart; + } + + if (start == 0) + { + start = counter.QuadPart; + } + + return counter.QuadPart - start; +} + +/**************************************************************************** + * Name: host_sleep + ****************************************************************************/ + +void host_sleep(uint64_t nsec) +{ + LARGE_INTEGER due; + HANDLE timer; + + /* Convert to 100 nanosecond interval, + * negative value indicates relative time + */ + + due.QuadPart = -(10 * ((nsec + 999) / 1000)); + + timer = CreateWaitableTimer(NULL, TRUE, NULL); + if (timer != NULL) + { + SetWaitableTimer(timer, &due, 0, NULL, NULL, 0); + WaitForSingleObject(timer, INFINITE); + CloseHandle(timer); + } +} + +/**************************************************************************** + * Name: host_sleepuntil + ****************************************************************************/ + +void host_sleepuntil(uint64_t nsec) +{ + uint64_t now; + + now = host_gettime(false); + if (nsec > now + 1000) Review Comment: if (nsec > now) ########## arch/sim/src/sim/win/up_hosttime.c: ########## @@ -0,0 +1,138 @@ +/**************************************************************************** + * arch/sim/src/sim/win/up_hosttime.c + * + * Licensed to the Apache Software Foundation (ASF) under one or more + * contributor license agreements. See the NOTICE file distributed with + * this work for additional information regarding copyright ownership. The + * ASF licenses this file to you under the Apache License, Version 2.0 (the + * "License"); you may not use this file except in compliance with the + * License. You may obtain a copy of the License at + * + * http://www.apache.org/licenses/LICENSE-2.0 + * + * Unless required by applicable law or agreed to in writing, software + * distributed under the License is distributed on an "AS IS" BASIS, WITHOUT + * WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied. See the + * License for the specific language governing permissions and limitations + * under the License. + * + ****************************************************************************/ + +/**************************************************************************** + * Included Files + ****************************************************************************/ + +#include <stdint.h> +#include <stdbool.h> +#include <windows.h> + +/**************************************************************************** + * Pre-processor Definitions + ****************************************************************************/ + +#define POW10_9 (1000000000ull) + +/* Number of 100ns-seconds between the beginning of the Windows epoch + * (Jan. 1, 1601) and the Unix epoch (Jan. 1, 1970) + */ + +#define DELTA_EPOCH_IN_100NS (0x19db1ded53e8000LL) + +/**************************************************************************** + * Public Functions + ****************************************************************************/ + +/**************************************************************************** + * Name: host_gettime + ****************************************************************************/ + +uint64_t host_gettime(bool rtc) +{ + static uint64_t start; + LARGE_INTEGER freq, counter; + FILETIME ftime; + + if (rtc) + { + GetSystemTimeAsFileTime(&ftime); + + counter.QuadPart = (((uint64_t)ftime.dwHighDateTime << 32 | + ftime.dwLowDateTime) - + DELTA_EPOCH_IN_100NS) * 100; Review Comment: merge to previous linke ########## arch/sim/src/sim/win/up_hosttime.c: ########## @@ -0,0 +1,138 @@ +/**************************************************************************** + * arch/sim/src/sim/win/up_hosttime.c + * + * Licensed to the Apache Software Foundation (ASF) under one or more + * contributor license agreements. See the NOTICE file distributed with + * this work for additional information regarding copyright ownership. The + * ASF licenses this file to you under the Apache License, Version 2.0 (the + * "License"); you may not use this file except in compliance with the + * License. You may obtain a copy of the License at + * + * http://www.apache.org/licenses/LICENSE-2.0 + * + * Unless required by applicable law or agreed to in writing, software + * distributed under the License is distributed on an "AS IS" BASIS, WITHOUT + * WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied. See the + * License for the specific language governing permissions and limitations + * under the License. + * + ****************************************************************************/ + +/**************************************************************************** + * Included Files + ****************************************************************************/ + +#include <stdint.h> +#include <stdbool.h> +#include <windows.h> + +/**************************************************************************** + * Pre-processor Definitions + ****************************************************************************/ + +#define POW10_9 (1000000000ull) + +/* Number of 100ns-seconds between the beginning of the Windows epoch + * (Jan. 1, 1601) and the Unix epoch (Jan. 1, 1970) + */ + +#define DELTA_EPOCH_IN_100NS (0x19db1ded53e8000LL) + +/**************************************************************************** + * Public Functions + ****************************************************************************/ + +/**************************************************************************** + * Name: host_gettime + ****************************************************************************/ + +uint64_t host_gettime(bool rtc) +{ + static uint64_t start; + LARGE_INTEGER freq, counter; + FILETIME ftime; + + if (rtc) + { + GetSystemTimeAsFileTime(&ftime); + + counter.QuadPart = (((uint64_t)ftime.dwHighDateTime << 32 | + ftime.dwLowDateTime) - + DELTA_EPOCH_IN_100NS) * 100; + } + else + { + QueryPerformanceFrequency(&freq); + QueryPerformanceCounter(&counter); + + counter.QuadPart = counter.QuadPart * POW10_9 / freq.QuadPart; + } + + if (rtc) + { + return counter.QuadPart; Review Comment: move after line 61 -- This is an automated message from the Apache Git Service. To respond to the message, please log on to GitHub and use the URL above to go to the specific comment. To unsubscribe, e-mail: commits-unsubscr...@nuttx.apache.org For queries about this service, please contact Infrastructure at: us...@infra.apache.org