zephyr/samples/drivers/ipm/ipm_esp32/src/main.c
Keith Packard 0b90fd5adf samples, tests, boards: Switch main return type from void to int
As both C and C++ standards require applications running under an OS to
return 'int', adapt that for Zephyr to align with those standard. This also
eliminates errors when building with clang when not using -ffreestanding,
and reduces the need for compiler flags to silence warnings for both clang
and gcc.

Most of these changes were automated using coccinelle with the following
script:

@@
@@
- void
+ int
main(...) {
	...
-	return;
+	return 0;
	...
}

Approximately 40 files had to be edited by hand as coccinelle was unable to
fix them.

Signed-off-by: Keith Packard <keithp@keithp.com>
2023-04-14 07:49:41 +09:00

53 lines
1.2 KiB
C

/*
* Copyright (c) 2022 Espressif Systems (Shanghai) Co., Ltd.
*
* SPDX-License-Identifier: Apache-2.0
*/
#include <zephyr/kernel.h>
#include <zephyr/sys/printk.h>
#include <zephyr/drivers/ipm.h>
#include <zephyr/device.h>
#include <string.h>
static const char fake_request[] = {"PRO_CPU: Fake request to APP_CPU"};
static const struct device *ipm_dev;
static char received_string[64];
static struct k_sem sync;
static void ipm_receive_callback(const struct device *ipmdev, void *user_data,
uint32_t id, volatile void *data)
{
ARG_UNUSED(ipmdev);
ARG_UNUSED(user_data);
strcpy(received_string, (const char *)data);
k_sem_give(&sync);
}
int main(void)
{
k_sem_init(&sync, 0, 1);
ipm_dev = DEVICE_DT_GET(DT_NODELABEL(ipm0));
if (!ipm_dev) {
printk("Failed to get IPM device.\n\r");
return 0;
}
ipm_register_callback(ipm_dev, ipm_receive_callback, NULL);
while (1) {
printk("PRO_CPU is sending a fake request, waiting remote response...\n\r");
ipm_send(ipm_dev, -1, sizeof(fake_request), &fake_request, sizeof(fake_request));
k_sem_take(&sync, K_FOREVER);
printk("PRO_CPU received a message from APP_CPU : %s\n\r", received_string);
k_sleep(K_MSEC(200));
}
return 0;
}