-
Notifications
You must be signed in to change notification settings - Fork 2.1k
New issue
Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.
By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.
Already on GitHub? Sign in to your account
Adapt System layer to Zephyr OS #1594
Merged
andy31415
merged 3 commits into
project-chip:master
from
Damian-Nordic:feature/systemwakeevent
Jul 17, 2020
Merged
Changes from all commits
Commits
File filter
Filter by extension
Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
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
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
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,127 @@ | ||
/* | ||
* | ||
* Copyright (c) 2020 Project CHIP Authors | ||
* | ||
* 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. | ||
*/ | ||
|
||
/** | ||
* @file | ||
* This file declares the abstraction of one-directional, anonymous | ||
* data stream built on top of two file descriptors. | ||
*/ | ||
|
||
#include <system/SystemWakeEvent.h> | ||
|
||
#if CHIP_SYSTEM_CONFIG_USE_SOCKETS | ||
|
||
// Include additional CHIP headers | ||
#include <support/CodeUtils.h> | ||
|
||
// Include system and language headers | ||
#include <errno.h> | ||
#include <fcntl.h> | ||
#include <unistd.h> | ||
|
||
#if !CHIP_SYSTEM_CONFIG_USE_POSIX_PIPE | ||
#include <sys/eventfd.h> | ||
#endif | ||
|
||
namespace chip { | ||
namespace System { | ||
|
||
#if CHIP_SYSTEM_CONFIG_USE_POSIX_PIPE | ||
|
||
namespace { | ||
inline int SetNonBlockingMode(int fd) | ||
{ | ||
int flags = ::fcntl(fd, F_GETFL, 0); | ||
return ::fcntl(fd, F_SETFL, flags | O_NONBLOCK); | ||
} | ||
} // anonymous namespace | ||
|
||
Error SystemWakeEvent::Open() | ||
{ | ||
mFDs[FD_READ] = mFDs[FD_WRITE] = -1; | ||
|
||
if (::pipe(mFDs) < 0) | ||
return chip::System::MapErrorPOSIX(errno); | ||
|
||
if (SetNonBlockingMode(mFDs[FD_READ]) < 0) | ||
return chip::System::MapErrorPOSIX(errno); | ||
|
||
if (SetNonBlockingMode(mFDs[FD_WRITE]) < 0) | ||
return chip::System::MapErrorPOSIX(errno); | ||
|
||
return CHIP_SYSTEM_NO_ERROR; | ||
} | ||
|
||
void SystemWakeEvent::Close() | ||
{ | ||
::close(mFDs[FD_WRITE]); | ||
::close(mFDs[FD_READ]); | ||
mFDs[FD_READ] = mFDs[FD_WRITE] = -1; | ||
} | ||
|
||
void SystemWakeEvent::Confirm() | ||
{ | ||
uint8_t buffer[128]; | ||
|
||
while (::read(mFDs[FD_READ], buffer, sizeof(buffer)) == sizeof(buffer)) | ||
continue; | ||
} | ||
|
||
void SystemWakeEvent::Notify() | ||
{ | ||
char byte = 1; | ||
::write(mFDs[FD_WRITE], &byte, 1); | ||
} | ||
|
||
#else // CHIP_SYSTEM_CONFIG_USE_POSIX_PIPE | ||
|
||
Error SystemWakeEvent::Open() | ||
{ | ||
mFD = eventfd(0, EFD_NONBLOCK); | ||
|
||
if (mFD == -1) | ||
{ | ||
return chip::System::MapErrorPOSIX(errno); | ||
} | ||
|
||
return CHIP_SYSTEM_NO_ERROR; | ||
} | ||
|
||
void SystemWakeEvent::Close() | ||
{ | ||
::close(mFD); | ||
mFD = -1; | ||
} | ||
|
||
void SystemWakeEvent::Confirm() | ||
{ | ||
uint64_t value; | ||
::read(mFD, &value, sizeof(value)); | ||
} | ||
|
||
void SystemWakeEvent::Notify() | ||
{ | ||
uint64_t value = 1; | ||
::write(mFD, &value, sizeof(value)); | ||
} | ||
|
||
#endif // CHIP_SYSTEM_CONFIG_USE_POSIX_PIPE | ||
|
||
} // namespace System | ||
} // namespace chip | ||
|
||
#endif // CHIP_SYSTEM_CONFIG_USE_SOCKETS |
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,69 @@ | ||
/* | ||
* | ||
* Copyright (c) 2020 Project CHIP Authors | ||
* | ||
* 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. | ||
*/ | ||
|
||
/** | ||
* @file | ||
* This file declares the abstraction of system wake event used for | ||
* resuming task from select system call. | ||
*/ | ||
|
||
#ifndef SYSTEMWAKEEVENT_H | ||
#define SYSTEMWAKEEVENT_H | ||
|
||
// Include configuration headers | ||
#include <system/SystemConfig.h> | ||
|
||
#include <system/SystemError.h> | ||
|
||
namespace chip { | ||
namespace System { | ||
|
||
using ::chip::System::Error; | ||
|
||
class SystemWakeEvent | ||
{ | ||
public: | ||
Error Open(); /**< Initialize the pipeline */ | ||
void Close(); /**< Close both ends of the pipeline. */ | ||
|
||
#if CHIP_SYSTEM_CONFIG_USE_POSIX_PIPE | ||
int GetNotifFD() const { return mFDs[FD_READ]; } | ||
#else | ||
int GetNotifFD() const { return mFD; } | ||
#endif | ||
|
||
void Notify(); /**< Set the event. */ | ||
void Confirm(); /**< Clear the event. */ | ||
|
||
private: | ||
#if CHIP_SYSTEM_CONFIG_USE_POSIX_PIPE | ||
enum | ||
{ | ||
FD_READ = 0, | ||
FD_WRITE = 1 | ||
}; | ||
|
||
int mFDs[2]; | ||
#else | ||
int mFD; | ||
#endif | ||
}; | ||
|
||
} // namespace System | ||
} // namespace chip | ||
|
||
#endif // SYSTEMWAKEEVENT_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
Oops, something went wrong.
Add this suggestion to a batch that can be applied as a single commit.
This suggestion is invalid because no changes were made to the code.
Suggestions cannot be applied while the pull request is closed.
Suggestions cannot be applied while viewing a subset of changes.
Only one suggestion per line can be applied in a batch.
Add this suggestion to a batch that can be applied as a single commit.
Applying suggestions on deleted lines is not supported.
You must change the existing code in this line in order to create a valid suggestion.
Outdated suggestions cannot be applied.
This suggestion has been applied or marked resolved.
Suggestions cannot be applied from pending reviews.
Suggestions cannot be applied on multi-line comments.
Suggestions cannot be applied while the pull request is queued to merge.
Suggestion cannot be applied right now. Please check back later.
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
Have you verified this change on Zephyr?