Skip to content

Commit d776866

Browse files
committed
apps/examples/rtc, os/arch/arm/src/armino, os/include/tinyara: Add RTC millisecond test functionality for BK7239N
This commit adds a new "get_ms" command to the RTC example application for testing the aon_rtc_get_ms interface on BK7239N chips. It implements the RTC_GET_MS ioctl command in the RTC driver and provides a test function that can perform multiple readings with configurable delays.
1 parent 42a2777 commit d776866

File tree

5 files changed

+188
-1
lines changed

5 files changed

+188
-1
lines changed

apps/examples/rtc/rtc_main.c

Lines changed: 94 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -65,6 +65,7 @@
6565
#include <sys/types.h>
6666
#include <stdbool.h>
6767
#include <stdlib.h>
68+
#include <unistd.h>
6869
#include <tinyara/rtc.h>
6970

7071
#define TEST_TIME 300 /* 300 secs */
@@ -177,6 +178,12 @@ static void show_usage(void)
177178
printf("\nUsage: rtc\n");
178179
printf("\tor: rtc stop\n");
179180
printf("\t\tStart, or Stop rtc test\n");
181+
#ifdef CONFIG_ARCH_CHIP_BK7239N
182+
printf("\tor: rtc get_ms [count] [delay_ms]\n");
183+
printf("\t\tTest aon_rtc_get_ms interface.\n");
184+
printf("\t\tcount: test count (default: 1, max: 100)\n");
185+
printf("\t\tdelay_ms: delay between tests in milliseconds (default: 100, max: 10000)\n");
186+
#endif
180187
#ifdef CONFIG_RTC_ALARM
181188
printf("\tor rtc alarm [-r seconds] [-a hh:mm:ss] [-c]\n");
182189
printf("\t\tset, or cancel rtc alarm\n");
@@ -410,6 +417,88 @@ int rtc_alarm_main(int argc, char *argv[])
410417
}
411418
#endif
412419

420+
#ifdef CONFIG_ARCH_CHIP_BK7239N
421+
/****************************************************************************
422+
* Name: test_aon_rtc_get_ms
423+
****************************************************************************/
424+
425+
static int test_aon_rtc_get_ms(int argc, char *argv[])
426+
{
427+
uint64_t time_ms = 0;
428+
uint32_t test_count = 1;
429+
uint32_t delay_ms = 100; /* Default delay: 100ms */
430+
uint32_t i;
431+
uint64_t prev_time_ms = 0;
432+
uint64_t time_diff = 0;
433+
int fd;
434+
int ret;
435+
436+
if (argc >= 2) {
437+
test_count = strtoul(argv[1], NULL, 10);
438+
if (test_count == 0 || test_count > 10000) {
439+
test_count = 1;
440+
}
441+
}
442+
443+
if (argc >= 3) {
444+
delay_ms = strtoul(argv[2], NULL, 10);
445+
if (delay_ms == 0 || delay_ms > 10000) {
446+
delay_ms = 100;
447+
}
448+
}
449+
450+
printf("\n=== Testing aon_rtc_get_ms() via ioctl ===\n");
451+
printf("Test count: %u\n", test_count);
452+
printf("Delay between tests: %u ms\n", delay_ms);
453+
printf("----------------------------------------\n");
454+
455+
fd = open(RTC_DEVPATH, O_RDWR);
456+
if (fd < 0) {
457+
printf("ERROR: Fail to open rtc: %d\n", get_errno());
458+
return ERROR;
459+
}
460+
461+
for (i = 0; i < test_count; i++) {
462+
ret = ioctl(fd, RTC_GET_MS, (unsigned long)&time_ms);
463+
if (ret < 0) {
464+
printf("ERROR: Fail to get RTC time in ms via ioctl: %d\n", get_errno());
465+
close(fd);
466+
return ERROR;
467+
}
468+
469+
if (i == 0) {
470+
printf("[%u] aon_rtc_get_ms: %llu ms (0x%08x%08x)\n",
471+
i + 1,
472+
(unsigned long long)time_ms,
473+
(uint32_t)(time_ms >> 32),
474+
(uint32_t)(time_ms & 0xFFFFFFFF));
475+
} else {
476+
time_diff = time_ms - prev_time_ms;
477+
printf("[%u] aon_rtc_get_ms: %llu ms (0x%08x%08x), diff: %llu ms\n",
478+
i + 1,
479+
(unsigned long long)time_ms,
480+
(uint32_t)(time_ms >> 32),
481+
(uint32_t)(time_ms & 0xFFFFFFFF),
482+
(unsigned long long)time_diff);
483+
}
484+
485+
prev_time_ms = time_ms;
486+
487+
if (test_count > 1 && i < test_count - 1) {
488+
usleep(delay_ms * 1000); /* Delay in microseconds */
489+
}
490+
}
491+
492+
close(fd);
493+
494+
printf("----------------------------------------\n");
495+
printf("Test completed. Final time: %llu ms\n", (unsigned long long)time_ms);
496+
printf("========================================\n\n");
497+
498+
return OK;
499+
}
500+
#endif
501+
413502
/****************************************************************************
414503
* rtc_main
415504
****************************************************************************/
@@ -430,6 +519,11 @@ int rtc_main(int argc, char *argv[])
430519
/* stop the rtc test */
431520
rtc_test_stop();
432521
return OK;
522+
#ifdef CONFIG_ARCH_CHIP_BK7239N
523+
} else if (!strncmp(argv[1], "get_ms", strlen("get_ms") + 1)) {
524+
ret = test_aon_rtc_get_ms(argc - 1, ++argv);
525+
return ret;
526+
#endif
433527
#ifdef CONFIG_RTC_ALARM
434528
} else if (!strncmp(argv[1], "alarm", strlen("alarm") + 1)) {
435529
ret = rtc_alarm_main(argc - 1, ++argv);

os/arch/arm/src/armino/armino_rtc.c

Lines changed: 20 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -236,4 +236,24 @@ int up_rtc_initialize(void)
236236
return OK;
237237
}
238238

239+
/************************************************************************************
240+
* Name: aon_rtc_get_ms
241+
*
242+
* Description:
243+
* Get the current RTC time in milliseconds (64-bit). This is an adapter
244+
* function that wraps the bk_aon_rtc_get_ms() function.
245+
*
246+
* Input Parameters:
247+
* None
248+
*
249+
* Returned Value:
250+
* The current time in milliseconds (64-bit)
251+
*
252+
************************************************************************************/
253+
254+
uint64_t aon_rtc_get_ms(void)
255+
{
256+
return bk_aon_rtc_get_ms();
257+
}
258+
239259
#endif /* CONFIG_RTC */

os/arch/arm/src/armino/armino_rtc.h

Lines changed: 16 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -101,6 +101,22 @@ struct rtc_lowerhalf_s;
101101
FAR struct rtc_lowerhalf_s *armino_rtc_lowerhalf(void);
102102
#endif
103103

104+
/****************************************************************************
105+
* Name: aon_rtc_get_ms
106+
*
107+
* Description:
108+
* Get the current RTC time in milliseconds (64-bit).
109+
*
110+
* Input Parameters:
111+
* None
112+
*
113+
* Returned Value:
114+
* The current time in milliseconds (64-bit)
115+
*
116+
****************************************************************************/
117+
118+
uint64_t aon_rtc_get_ms(void);
119+
104120
#undef EXTERN
105121
#if defined(__cplusplus)
106122
}

os/arch/arm/src/armino/armino_rtc_lowerhalf.c

Lines changed: 50 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -116,6 +116,10 @@ static int armino_cancelalarm(FAR struct rtc_lowerhalf_s *lower, int alarmid);
116116
static void armino_alarm_callback(aon_rtc_id_t id, uint8_t *name_p, void *param);
117117
#endif
118118

119+
#ifdef CONFIG_RTC_IOCTL
120+
static int armino_ioctl(FAR struct rtc_lowerhalf_s *lower, int cmd, unsigned long arg);
121+
#endif
122+
119123
/****************************************************************************
120124
* Private Data
121125
****************************************************************************/
@@ -130,7 +134,7 @@ static const struct rtc_ops_s g_rtc_ops = {
130134
.cancelalarm = armino_cancelalarm,
131135
#endif
132136
#ifdef CONFIG_RTC_IOCTL
133-
.ioctl = NULL,
137+
.ioctl = armino_ioctl,
134138
#endif
135139
#ifndef CONFIG_DISABLE_PSEUDOFS_OPERATIONS
136140
.destroy = NULL,
@@ -431,6 +435,51 @@ static int armino_cancelalarm(FAR struct rtc_lowerhalf_s *lower, int alarmid)
431435
}
432436
#endif
433437

438+
#ifdef CONFIG_RTC_IOCTL
439+
/****************************************************************************
440+
* Name: armino_ioctl
441+
*
442+
* Description:
443+
* The standard ioctl method. This is where all of the RTC ioctl commands
444+
* are handled.
445+
*
446+
* Input Parameters:
447+
* lower - A reference to RTC lower half driver state structure
448+
* cmd - The ioctl command
449+
* arg - The argument of the ioctl cmd
450+
*
451+
* Returned Value:
452+
* Zero (OK) is returned on success; a negated errno value is returned
453+
* on any failure.
454+
*
455+
****************************************************************************/
456+
457+
static int armino_ioctl(FAR struct rtc_lowerhalf_s *lower, int cmd, unsigned long arg)
458+
{
459+
int ret = -ENOTTY;
460+
461+
switch (cmd) {
462+
case RTC_GET_MS: {
463+
FAR uint64_t *time_ms = (FAR uint64_t *)((uintptr_t)arg);
464+
465+
if (time_ms == NULL) {
466+
return -EINVAL;
467+
}
468+
469+
*time_ms = aon_rtc_get_ms();
470+
ret = OK;
471+
}
472+
break;
473+
474+
default:
475+
ret = -ENOTTY;
476+
break;
477+
}
478+
479+
return ret;
480+
}
481+
#endif
482+
434483
/****************************************************************************
435484
* Public Functions
436485
****************************************************************************/

os/include/tinyara/rtc.h

Lines changed: 8 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -195,6 +195,14 @@
195195

196196
#define RTC_USER_IOCBASE 0x0006
197197

198+
/* RTC_GET_MS returns the current RTC time in milliseconds (64-bit).
199+
*
200+
* Argument: A writeable reference to a uint64_t to receive the RTC's
201+
* time in milliseconds.
202+
*/
203+
204+
#define RTC_GET_MS _RTCIOC(RTC_USER_IOCBASE)
205+
198206
/****************************************************************************
199207
* Public Types
200208
****************************************************************************/

0 commit comments

Comments
 (0)