samples: application_development: Fix for userspace

This samples was defining a syscall but the whole machinery to this
work was missing.

Signed-off-by: Flavio Ceolin <flavio.ceolin@intel.com>
This commit is contained in:
Flavio Ceolin 2020-05-18 20:35:04 -07:00 committed by Anas Nashif
commit 636d6cd9cd
5 changed files with 23 additions and 8 deletions

View file

@ -8,11 +8,6 @@ list(APPEND ZEPHYR_EXTRA_MODULES
cmake_minimum_required(VERSION 3.13.1) cmake_minimum_required(VERSION 3.13.1)
# Add an absolute directory path to the CMake variable
# SYSCALL_INCLUDE_DIRS. This ensures that the syscall machinery will
# be able to find the module's syscalls.
list(APPEND SYSCALL_INCLUDE_DIRS ${CMAKE_CURRENT_SOURCE_DIR}/hello_world_module/zephyr)
find_package(Zephyr REQUIRED HINTS $ENV{ZEPHYR_BASE}) find_package(Zephyr REQUIRED HINTS $ENV{ZEPHYR_BASE})
project(out_of_tree_driver) project(out_of_tree_driver)

View file

@ -6,6 +6,7 @@
#include "hello_world_driver.h" #include "hello_world_driver.h"
#include <zephyr/types.h> #include <zephyr/types.h>
#include <syscall_handler.h>
/** /**
* This is a minimal example of an out-of-tree driver * This is a minimal example of an out-of-tree driver
@ -30,6 +31,17 @@ static void print_impl(struct device *dev)
__ASSERT(data.foo == 5, "Device was not initialized!"); __ASSERT(data.foo == 5, "Device was not initialized!");
} }
#ifdef CONFIG_USERSPACE
static inline void z_vrfy_hello_world_print(struct device *dev)
{
Z_OOPS(Z_SYSCALL_DRIVER_HELLO_WORLD(dev, print));
z_impl_hello_world_print(dev);
}
#include <syscalls/hello_world_print_mrsh.c>
#endif /* CONFIG_USERSPACE */
DEVICE_AND_API_INIT(hello_world, "CUSTOM_DRIVER", DEVICE_AND_API_INIT(hello_world, "CUSTOM_DRIVER",
init, &data, NULL, init, &data, NULL,
PRE_KERNEL_1, CONFIG_KERNEL_INIT_PRIORITY_DEVICE, PRE_KERNEL_1, CONFIG_KERNEL_INIT_PRIORITY_DEVICE,

View file

@ -22,8 +22,7 @@ extern "C" {
* The driver exists to demonstrate (and test) custom drivers that are * The driver exists to demonstrate (and test) custom drivers that are
* maintained outside of Zephyr. * maintained outside of Zephyr.
*/ */
__subsystem struct hello_world_driver_api {
struct hello_world_driver_api {
/* This struct has a member called 'print'. 'print' is function /* This struct has a member called 'print'. 'print' is function
* pointer to a function that takes 'struct device *dev' as an * pointer to a function that takes 'struct device *dev' as an
* argument and returns 'void'. * argument and returns 'void'.

View file

@ -1 +1,2 @@
CONFIG_HELLO_WORLD_DRIVER=y CONFIG_HELLO_WORLD_DRIVER=y
CONFIG_APPLICATION_DEFINED_SYSCALL=y

View file

@ -8,6 +8,13 @@
#include <stdio.h> #include <stdio.h>
#include <zephyr.h> #include <zephyr.h>
static void user_entry(void *p1, void *p2, void *p3)
{
struct device *dev = p1;
hello_world_print(dev);
}
void main(void) void main(void)
{ {
printk("Hello World from the app!\n"); printk("Hello World from the app!\n");
@ -18,5 +25,6 @@ void main(void)
printk("device is %p, name is %s\n", dev, dev->name); printk("device is %p, name is %s\n", dev, dev->name);
hello_world_print(dev); k_object_access_grant(dev, k_current_get());
k_thread_user_mode_enter(user_entry, dev, NULL, NULL);
} }