-
Notifications
You must be signed in to change notification settings - Fork 778
Add connectivity peripheral's base class #971
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
Merged
Merged
Changes from all commits
Commits
Show all changes
13 commits
Select commit
Hold shift + click to select a range
ee6eec4
RTC has cheated the MCU
cla7aye15I4nd 3bdec8e
Add BCD util tools
cla7aye15I4nd f009b38
The RTC is harder than I think
cla7aye15I4nd c63335b
Add missing I2c Interrupt
cla7aye15I4nd dfcdf62
Add BCD format utils
cla7aye15I4nd a4522ec
The RTC pass the initlization stage
cla7aye15I4nd 07a08e0
Merge branch 'qilingframework:dev' into dev
cla7aye15I4nd efbb1c0
Thread safe pipe for connectivity periperhal IO
cla7aye15I4nd 6f2670e
Merge branch 'dev' of https://github.com/cla7aye15I4nd/qiling into dev
cla7aye15I4nd f6c4d2f
Add support for device connect
cla7aye15I4nd 203b7e8
Add device support for USART, I2C and SPI
cla7aye15I4nd b02ff65
Adjust the call sequence
cla7aye15I4nd 66d2cc3
Fix the LCD example
cla7aye15I4nd 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 hidden or 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 hidden or 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 hidden or 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,95 @@ | ||
| #!/usr/bin/env python3 | ||
| # | ||
| # Cross Platform and Multi Architecture Advanced Binary Emulation Framework | ||
| # | ||
|
|
||
|
|
||
| import ctypes | ||
| import queue | ||
|
|
||
| from qiling.core import Qiling | ||
| from qiling.hw.peripheral import QlPeripheral | ||
|
|
||
|
|
||
| class QlConnectivityPeripheral(QlPeripheral): | ||
| class Type(ctypes.Structure): | ||
| """ Define the reigister fields of peripheral. | ||
|
|
||
| Example: | ||
| fields_ = [ | ||
| ('SR' , ctypes.c_uint32), | ||
| ('DR' , ctypes.c_uint32), | ||
| ('BRR' , ctypes.c_uint32), | ||
| ('CR1' , ctypes.c_uint32), | ||
| ('CR2' , ctypes.c_uint32), | ||
| ('CR3' , ctypes.c_uint32), | ||
| ('GTPR', ctypes.c_uint32), | ||
| ] | ||
| """ | ||
| _fields_ = [] | ||
|
|
||
| def __init__(self, ql: Qiling, label: str, limit:int = 1): | ||
| super().__init__(ql, label) | ||
|
|
||
| self.rtube = queue.Queue() | ||
| self.wtube = queue.Queue() | ||
|
|
||
| self.limit = limit | ||
| self.device_list = [] | ||
|
|
||
| def has_input(self): | ||
| return not self.rtube.empty() | ||
|
|
||
| def send(self, data: bytes): | ||
| """ Send data into the peripheral. | ||
|
|
||
| Example: | ||
| ql.hw.usart1.send(b'hello') | ||
| """ | ||
|
|
||
| for byte in bytearray(data): | ||
| self.rtube.put(byte) | ||
|
|
||
| def recv(self, numb:int = 4096) -> bytes: | ||
| """ Receive data from peripheral | ||
|
|
||
| Example: | ||
|
Member
There was a problem hiding this comment. Choose a reason for hiding this commentThe reason will be displayed to describe this comment to others. Learn more. typo in comments? this should be recv ? |
||
| data = ql.hw.i2c1.send() | ||
| """ | ||
| data = bytearray() | ||
| while self.can_recv() and numb != 0: | ||
| data.append(self.wtube.get()) | ||
| numb -= 1 | ||
|
|
||
| return bytes(data) | ||
|
|
||
| def can_recv(self): | ||
| return not self.wtube.empty() | ||
|
|
||
| def send_to_user(self, data: int): | ||
| """ send single byte to user | ||
| """ | ||
|
|
||
| self.wtube.put(data) | ||
|
|
||
| def recv_from_user(self) -> bytes: | ||
| """ Read single byte from user input | ||
| """ | ||
|
|
||
| return self.rtube.get() | ||
|
|
||
| def connect(self, device): | ||
| if len(self.device_list) < self.limit: | ||
| self.device_list.append(device) | ||
|
|
||
| @staticmethod | ||
| def device_handler(func): | ||
| def wrapper(self): | ||
| if self.device_list and self.can_recv(): | ||
| data = self.recv(numb=1) | ||
| for device in self.device_list: | ||
| device.send(data) | ||
|
|
||
| func(self) | ||
|
|
||
| return wrapper | ||
This file contains hidden or 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 hidden or 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 hidden or 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 hidden or 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,16 @@ | ||
| #!/usr/bin/env python3 | ||
| # | ||
| # Cross Platform and Multi Architecture Advanced Binary Emulation Framework | ||
| # | ||
|
|
||
|
|
||
| def byte2bcd(value): | ||
| bcdhigh = 0 | ||
| while value >= 10: | ||
| bcdhigh += 1 | ||
| value -= 10 | ||
|
|
||
| return (bcdhigh << 4) | value | ||
|
|
||
| def bcd2byte(value): | ||
| return ((value & 0xF0) >> 0x4) * 10 + (value & 0xf) |
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.
i think we can put this in qiling/hw/protocol or leave it in utils should be ok