-
Notifications
You must be signed in to change notification settings - Fork 3k
Commit
This commit does not belong to any branch on this repository, and may belong to a fork outside of the repository.
System time read/write callbacks (#2637)
- Add new API for setting system time read and write callbacks. - Update ws_pae to use the new time service.
- Loading branch information
Arto Kinnunen
committed
Jun 9, 2021
1 parent
9c6fe22
commit b822013
Showing
6 changed files
with
147 additions
and
24 deletions.
There are no files selected for viewing
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
55 changes: 55 additions & 0 deletions
55
features/nanostack/sal-stack-nanostack/source/Service_Libs/utils/ns_time.c
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,55 @@ | ||
/* | ||
* Copyright (c) 2021, Pelion and affiliates. | ||
* SPDX-License-Identifier: Apache-2.0 | ||
* | ||
* Licensed 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. | ||
*/ | ||
|
||
#include <string.h> | ||
#include <stdio.h> | ||
#include "ns_types.h" | ||
#include "ns_time_api.h" //ns_time_api_system_time_callback | ||
|
||
static ns_time_api_system_time_callback *system_time_read_callback = NULL; | ||
static ns_time_api_system_time_write_callback *system_time_write_callback = NULL; | ||
|
||
void ns_time_api_system_time_callback_set(ns_time_api_system_time_callback callback_rd) | ||
{ | ||
system_time_read_callback = callback_rd; | ||
} | ||
|
||
void ns_time_api_system_time_write_callback_set(ns_time_api_system_time_write_callback callback_wr) | ||
{ | ||
system_time_write_callback = callback_wr; | ||
} | ||
|
||
int ns_time_system_time_write(uint64_t time_write) | ||
{ | ||
if (system_time_write_callback) { | ||
system_time_write_callback(time_write); | ||
return 0; | ||
} | ||
|
||
return -1; | ||
} | ||
|
||
int ns_time_system_time_read(uint64_t *time_read) | ||
{ | ||
if (system_time_read_callback && time_read) { | ||
uint64_t new_time = system_time_read_callback(); | ||
*time_read = new_time; | ||
return 0; | ||
} | ||
|
||
return -1; | ||
} |
56 changes: 56 additions & 0 deletions
56
features/nanostack/sal-stack-nanostack/source/Service_Libs/utils/ns_time.h
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,56 @@ | ||
/* | ||
* Copyright (c) 2021, Pelion and affiliates. | ||
* SPDX-License-Identifier: Apache-2.0 | ||
* | ||
* Licensed 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. | ||
*/ | ||
|
||
#ifndef _NS_TIME_H_ | ||
#define _NS_TIME_H_ | ||
|
||
/** | ||
* \file ns_time.h | ||
* \brief Nanostack internal time handling API. | ||
*/ | ||
|
||
/** | ||
* Write new time as a platform time | ||
* | ||
* Write a new time to platform provided time system. | ||
* Platform time callbacks must be set by using method ns_time_api_system_time_callbacks_set. | ||
* | ||
* \param time_write time to be written as a new system time. | ||
* | ||
* \return 0 in success. | ||
* \return <0 in case of errors. | ||
* | ||
*/ | ||
int ns_time_system_time_write(uint64_t time_write); | ||
|
||
/** | ||
* Read platform time from a time callback | ||
* | ||
* Read a new time from time system provided by the platform. | ||
* Platform time callbacks must be set by using the method ns_time_api_system_time_callbacks_set. | ||
* | ||
* \param time_read Address to variable where new time will be written. | ||
* | ||
* \return 0 in success. | ||
* \return <0 in case of errors. | ||
* | ||
*/ | ||
int ns_time_system_time_read(uint64_t *time_read); | ||
|
||
|
||
|
||
#endif /* _NS_TIME_H_ */ |
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters