Skip to content
GitLab
Explore
Sign in
Primary navigation
Search or go to…
Project
NuttX RTOS
Manage
Activity
Members
Labels
Plan
Issues
Issue boards
Milestones
Wiki
Code
Repository
Branches
Commits
Tags
Repository graph
Compare revisions
Deploy
Releases
Container registry
Model registry
Monitor
Incidents
Analyze
Value stream analytics
Contributor analytics
Repository analytics
Model experiments
Help
Help
Support
GitLab documentation
Compare GitLab plans
Community forum
Contribute to GitLab
Provide feedback
Keyboard shortcuts
?
Snippets
Groups
Projects
Show more breadcrumbs
f4grx
NuttX RTOS
Commits
a2e1ece8
Commit
a2e1ece8
authored
9 years ago
by
Gregory Nutt
Browse files
Options
Downloads
Patches
Plain Diff
RTC: Handle RTC failures. If mktime is called with garbage, it may crash
parent
a696b807
Branches
Branches containing commit
Tags
Tags containing commit
No related merge requests found
Changes
2
Hide whitespace changes
Inline
Side-by-side
Showing
2 changed files
drivers/timers/pcf85263.c
+2
-2
2 additions, 2 deletions
drivers/timers/pcf85263.c
sched/clock/clock_initialize.c
+17
-10
17 additions, 10 deletions
sched/clock/clock_initialize.c
with
19 additions
and
12 deletions
drivers/timers/pcf85263.c
+
2
−
2
View file @
a2e1ece8
...
...
@@ -241,8 +241,8 @@ int pcf85263_rtc_initialize(FAR struct i2c_dev_s *i2c)
{
/* Remember the i2c device and claim that the RTC is enabled */
g_pcf85263
.
i2c
=
i2c
;
g_rtc_enabled
=
true
;
g_pcf85263
.
i2c
=
i2c
;
g_rtc_enabled
=
true
;
return
OK
;
}
...
...
This diff is collapsed.
Click to expand it.
sched/clock/clock_initialize.c
+
17
−
10
View file @
a2e1ece8
...
...
@@ -110,47 +110,53 @@ struct timespec g_basetime;
#if defined(CONFIG_RTC_DATETIME)
/* Initialize the system time using a broken out date/time structure */
static
inline
void
clock_basetime
(
FAR
struct
timespec
*
tp
)
static
inline
int
clock_basetime
(
FAR
struct
timespec
*
tp
)
{
struct
tm
rtctime
;
int
ret
;
/* Get the broken-out time from the date/time RTC. */
(
void
)
up_rtc_getdatetime
(
&
rtctime
);
ret
=
up_rtc_getdatetime
(
&
rtctime
);
if
(
ret
>=
0
)
{
/* And use the broken-out time to initialize the system time */
/* And use the broken-out time to initialize the system time */
tp
->
tv_sec
=
mktime
(
&
rtctime
);
tp
->
tv_nsec
=
0
;
}
tp
->
tv_sec
=
mktime
(
&
rtctime
);
tp
->
tv_nsec
=
0
;
return
ret
;
}
#elif defined(CONFIG_RTC_HIRES)
/* Initialize the system time using a high-resolution structure */
static
inline
void
clock_basetime
(
FAR
struct
timespec
*
tp
)
static
inline
int
clock_basetime
(
FAR
struct
timespec
*
tp
)
{
/* Get the complete time from the hi-res RTC. */
(
void
)
up_rtc_gettime
(
tp
);
return
up_rtc_gettime
(
tp
);
}
#else
/* Initialize the system time using seconds only */
static
inline
void
clock_basetime
(
FAR
struct
timespec
*
tp
)
static
inline
int
clock_basetime
(
FAR
struct
timespec
*
tp
)
{
/* Get the seconds (only) from the lo-resolution RTC */
tp
->
tv_sec
=
up_rtc_time
();
tp
->
tv_nsec
=
0
;
return
OK
;
}
#endif
/* CONFIG_RTC_HIRES */
#else
/* CONFIG_RTC */
static
inline
void
clock_basetime
(
FAR
struct
timespec
*
tp
)
static
inline
int
clock_basetime
(
FAR
struct
timespec
*
tp
)
{
time_t
jdn
=
0
;
...
...
@@ -165,6 +171,7 @@ static inline void clock_basetime(FAR struct timespec *tp)
tp
->
tv_sec
=
jdn
*
SEC_PER_DAY
;
tp
->
tv_nsec
=
0
;
return
OK
;
}
#endif
/* CONFIG_RTC */
...
...
@@ -181,7 +188,7 @@ static void clock_inittime(void)
{
/* (Re-)initialize the time value to match the RTC */
clock_basetime
(
&
g_basetime
);
(
void
)
clock_basetime
(
&
g_basetime
);
#ifndef CONFIG_SCHED_TICKLESS
g_system_timer
=
0
;
#endif
...
...
This diff is collapsed.
Click to expand it.
Preview
0%
Loading
Try again
or
attach a new file
.
Cancel
You are about to add
0
people
to the discussion. Proceed with caution.
Finish editing this message first!
Save comment
Cancel
Please
register
or
sign in
to comment