-
Notifications
You must be signed in to change notification settings - Fork 0
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
samples: subsys: ipc: basic: Basic cores communication #4
Conversation
Add basic cores communication sample to show how to send messages between two cores using mbox and shared data structure. Signed-off-by: Jakub Zymelka <jakub.zymelka@nordicsemi.no>
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 left a few nitpicking notes. I am also wondering: is it possible that one of the first mbox messages ("No data from host/remote") is missed because the other core enabled mbox after some delay? Or maybe mbox does not send anything until it is enabled by both cores?
Besides that, LGTM.
Overview | ||
******** | ||
|
||
This application demonstrates how to communcate between cores without any backend in |
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.
This application demonstrates how to communcate between cores without any backend in | |
This application demonstrates how to communicate between cores without any backend in |
|
||
*** Booting Zephyr OS build v3.7.0-rc1-427-g7f891a6a40e8 *** | ||
I: No data from remote | ||
I: Sent 14 bytes to host |
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: Sent 14 bytes to host | |
I: Sent 14 bytes to remote |
I guess it should be remote, as it is the host's log.
ordered: false | ||
regex: | ||
- "No data from remote" | ||
- "Sent 14 bytes to host" |
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.
- "Sent 14 bytes to host" | |
- "Sent 14 bytes to remote" |
data_packet_t data_packet; | ||
|
||
/** | ||
* @brief Send data to aother core |
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.
* @brief Send data to aother core | |
* @brief Send data to another core |
int bytes_sent = 0; | ||
|
||
int ret = mbox_init(); |
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.
int bytes_sent = 0; | |
int ret = mbox_init(); | |
int bytes_sent = 0; | |
int ret = mbox_init(); | |
To fix compliance check
|
||
/** | ||
* @brief Verify whether another core has data ready for us to read | ||
* @return -1 if lock is not acquired, otherwise how many items are available for reading |
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 would put it the other way around:
"Number of items available for reading, -1 if lock is not acquired"
* @brief Send data to aother core | ||
* @param buffer | ||
* @param size | ||
* @return -1 if lock is not acquired, otherwise how many items were transfered |
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.
Same as in the host main.c
return -1; | ||
} | ||
|
||
/* Limit size of buffer to be transfered to the size of destine buffer */ |
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 guess it should be "destination buffer" or "destined buffer".
* @brief Get data from another core | ||
* @param buffer | ||
* @param size | ||
* @return -1 if lock is not acquired, otherwise how many items were read |
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.
Same as in the host main.c
Changes moved to nrfconnect/sdk-zephyr#1910 . |
hci_packet_complete(buf, buf_size) should check whether buf_size is enough. For instance, hci_packet_complete can receive buf with buf_size 1, leading to the buffer overflow in cmd->param_len, which is buf[3]. This can happen when rx_thread() receives two frames in 512 bytes and the first frame size is 511. Then, rx_thread() will call hci_packet_complete() with 1. ==5==ERROR: AddressSanitizer: global-buffer-overflow on address 0x000000ad81c2 at pc 0x0000005279b3 bp 0x7fffe74f5b70 sp 0x7fffe74f5b68 READ of size 2 at 0x000000ad81c2 thread T6 #0 0x5279b2 (/root/zephyr.exe+0x5279b2) #1 0x4d697d (/root/zephyr.exe+0x4d697d) #2 0x7ffff60e5daa (/lib/x86_64-linux-gnu/libc.so.6+0x89daa) (BuildId: 2e01923fea4ad9f7fa50fe24e0f3385a45a6cd1c) 0x000000ad81c2 is located 2 bytes to the right of global variable 'rx_thread.frame' defined in 'zephyr/drivers/bluetooth/hci/userchan.c' (0xad7fc0) of size 512 SUMMARY: AddressSanitizer: global-buffer-overflow (/root/zephyr.exe+0x5279b2) Thread T6 created by T2 here: #0 0x48c17c (/root/zephyr.exe+0x48c17c) #1 0x530192 (/root/zephyr.exe+0x530192) #2 0x4dcc22 (/root/zephyr.exe+0x4dcc22) Thread T2 created by T1 here: #0 0x48c17c (/root/zephyr.exe+0x48c17c) #1 0x530192 (/root/zephyr.exe+0x530192) #2 0x4dcc22 (/root/zephyr.exe+0x4dcc22) Thread T1 created by T0 here: #0 0x48c17c (/root/zephyr.exe+0x48c17c) #1 0x52f36c (/root/zephyr.exe+0x52f36c) #2 0x5371dc (/root/zephyr.exe+0x5371dc) #3 0x5312a6 (/root/zephyr.exe+0x5312a6) #4 0x52ed7b (/root/zephyr.exe+0x52ed7b) zephyrproject-rtos#5 0x52eddd (/root/zephyr.exe+0x52eddd) zephyrproject-rtos#6 0x7ffff6083c89 (/lib/x86_64-linux-gnu/libc.so.6+0x27c89) (BuildId: 2e01923fea4ad9f7fa50fe24e0f3385a45a6cd1c) ==5==ABORTING Signed-off-by: Sungwoo Kim <iam@sung-woo.kim>
Add basic cores communication sample to show how to send messages between two cores using mbox and shared data structure.