eren-terzioglu opened a new pull request, #18959:
URL: https://github.com/apache/nuttx/pull/18959
## Summary
The HP core can exchange data with a running ULP LP-Core application in two
ways:
* **Global symbols** — read and write ULP variables exported to shared
memory through ``/dev/ulp``.
* **LP Mailbox** — send and receive messages through the hardware mailbox
using ``/dev/lp_mailbox``.
Global symbols already implemented, this PR implements LP Mailbox.
#### LP Mailbox
The ESP32-P4 LP Mailbox provides inter-core communication between the LP and
HP cores.
It exposes sixteen 32-bit message registers that both cores can read and
write.
LP Mailbox is exposed as ``/dev/lp_mailbox`` and uses ``read()`` and
``write()`` to exchange byte-sized messages or ``ioctl(fd, FIOC_NOTIFY,
handler)``
for interrupt callback when a message arrives to communicate with the LP
core.
<!-- This field should contain a summary of the changes. It will be
pre-filled with the commit's message and descriptions. Adjust it accordingly -->
* Docs/platforms/esp32p4: Add LP Mailbox docs
Add LP Mailbox docs for esp32p4
* boards/risc-v/esp32p4: Add LP Mailbox board support
Add LP Mailbox board support for esp32p4
* arch/risc-v/espressif: Add LP Mailbox support for esp32p4
Add LP Mailbox support for esp32p4
## Impact
<!-- Please fill the following sections with YES/NO and provide a brief
explanation -->
Impact on user: Yes, LP Mailbox supported for esp32p4
<!-- Does it impact user's applications? How? -->
Impact on build: No
<!-- Does it impact on building NuttX? How? (please describe the required
changes on the build system) -->
Impact on hardware: Yes, LP Mailbox support added for esp32p4
<!-- Does it impact a specific hardware supported by NuttX? -->
Impact on documentation: Yes, related docs added
<!-- Does it impact the existing documentation? Please provide additional
documentation to reflect that -->
Impact on security: No
<!-- Does it impact NuttX's security? -->
Impact on compatibility: No
<!-- Does it impact compatibility between previous and current versions? Is
this a breaking change? -->
## Testing
<!-- Please provide all the testing procedure. Consider that upstream
reviewers should be able to reproduce the same testing performed internally -->
`esp32p4-function-ev-board:ulp` config used with these options:
```
CONFIG_ESPRESSIF_LP_MAILBOX=y
```
### Building
<!-- Provide how to build the test for each SoC being tested -->
Command to build:
```
make -j distclean && ./tools/configure.sh esp32p4-function-ev-board:ulp &&
kconfig-tweak -e CONFIG_ESPRESSIF_LP_MAILBOX && make olddefconfig -s -j && make
-j && make flash ESPTOOL_PORT=/dev/ttyUSB0
```
### Running
<!-- Provide how to run the test for each SoC being tested -->
Custom app used to test:
- Tree view:
```
nuttxspace/
├── nuttx/
└── apps/
└── ulp_mailbox/
└── Makefile
└── Kconfig
└── ulp_mailbox.c // HP Application
└── ulp/
└── Makefile // LP Core Makefile
└── ulp_main.c // LP Core Application
```
- Contents in Makefile:
```
include $(APPDIR)/Make.defs
PROGNAME = $(CONFIG_EXAMPLES_ULP_MAILBOX_PROGNAME)
PRIORITY = $(CONFIG_EXAMPLES_ULP_MAILBOX_PRIORITY)
STACKSIZE = $(CONFIG_EXAMPLES_ULP_MAILBOX_STACKSIZE)
MODULE = $(CONFIG_EXAMPLES_ULP_MAILBOX)
MAINSRC = ulp_mailbox.c
include $(APPDIR)/Application.mk
include ulp/Makefile
```
- Contents in Kconfig:
```
config EXAMPLES_ULP_MAILBOX
bool "ULP Mailbox Example"
default n
```
- Contents in ulp_mailbox.c:
```
#include <nuttx/config.h>
#include <errno.h>
#include <fcntl.h>
#include <inttypes.h>
#include <stdio.h>
#include <unistd.h>
#include <nuttx/fs/ioctl.h>
#include <sys/ioctl.h>
#include "ulp/ulp/ulp_main.h"
#include "ulp/ulp/ulp_code.h"
int main(int argc, char *argv[])
{
int fd;
int mailbox;
uint8_t data = 0;
int ret = OK;
int prev_data;
fd = open("/dev/ulp", O_WRONLY);
if (fd < 0)
{
printf("Failed to open ULP: %d\n", errno);
return -1;
}
write(fd, ulp_mailbox_bin, ulp_mailbox_bin_len);
mailbox = open("/dev/lp_mailbox", O_RDWR);
if (mailbox < 0)
{
printf("Failed to open LP Mailbox: %d\n", errno);
return -1;
}
/* Waiting for a while to let ULP start to run */
sleep(3);
for (int i = 0; i < 2; i++)
{
ret = write(mailbox, &data, 1);
if (ret != 1)
{
printf("Failed to send data\n");
return ERROR;
}
prev_data = data;
ret = read(mailbox, &data, 1);
if (ret != 1 || (prev_data + 1 != data))
{
printf("Failed to read data\n");
return ERROR;
}
else
{
printf("Read data: %d\n", data);
}
sleep(1);
}
printf("All done.\n");
return OK;
}
```
- Contents in ulp/Makefile:
```
ULP_APP_NAME = ulp_mailbox
ULP_APP_FOLDER = $(APPDIR)$(DELIM)ulp_mailbox$(DELIM)ulp
ULP_APP_C_SRCS = ulp_main.c
include
$(TOPDIR)$(DELIM)arch$(DELIM)$(CONFIG_ARCH)$(DELIM)src$(DELIM)common$(DELIM)espressif$(DELIM)ulp_makefile.mk
```
- Contents in ulp/ulp_main.c:
```
#include <stdint.h>
#include "nuttx/config.h"
#include <stdbool.h>
#include <stdint.h>
#include "ulp_lp_core_utils.h"
#include "ulp_lp_core_mailbox.h"
#define nop() __asm__ __volatile__ ("nop")
static lp_mailbox_t mailbox;
int main(void)
{
lp_core_mailbox_init(&mailbox, NULL);
lp_message_t message;
esp_err_t ret;
while (1)
{
ret = lp_core_mailbox_receive(mailbox, &message, UINT32_MAX);
if (ret == ESP_OK)
{
message = message + 1;
ret = lp_core_mailbox_send(mailbox, message, UINT32_MAX);
}
for (int i = 0; i < 100; i++)
{
nop();
}
}
return 0;
}
```
### Results
<!-- Provide tests' results and runtime logs -->
Output should look like this:
```
nsh> ls /dev
/dev:
...
lp_mailbox
...
nsh> custom_app
Read data: 1
Read data: 2
All done.
nsh>
```
--
This is an automated message from the Apache Git Service.
To respond to the message, please log on to GitHub and use the
URL above to go to the specific comment.
To unsubscribe, e-mail: [email protected]
For queries about this service, please contact Infrastructure at:
[email protected]