From 9b492024bd2a29f1be65eece6506eb2939b1681c Mon Sep 17 00:00:00 2001 From: isiora Date: Fri, 19 Jan 2018 14:15:25 +0000 Subject: git-svn-id: svn://svn.code.sf.net/p/chibios/svn/trunk@11351 35acf78f-673a-0410-8e92-d51de3d6d3f4 --- demos/ATSAMA5D2/RT-SAMA5D2-XPLAINED-NSEC/main.c | 22 +++--- .../ATSAMA5D2/RT-SAMA5D2-XPLAINED-NSEC/smcclient.c | 9 +-- .../ATSAMA5D2/RT-SAMA5D2-XPLAINED-NSEC/smcclient.h | 82 ++++++++++++++++++++++ 3 files changed, 101 insertions(+), 12 deletions(-) create mode 100644 demos/ATSAMA5D2/RT-SAMA5D2-XPLAINED-NSEC/smcclient.h (limited to 'demos') diff --git a/demos/ATSAMA5D2/RT-SAMA5D2-XPLAINED-NSEC/main.c b/demos/ATSAMA5D2/RT-SAMA5D2-XPLAINED-NSEC/main.c index c77588deb..0b21f67c1 100755 --- a/demos/ATSAMA5D2/RT-SAMA5D2-XPLAINED-NSEC/main.c +++ b/demos/ATSAMA5D2/RT-SAMA5D2-XPLAINED-NSEC/main.c @@ -19,6 +19,7 @@ #include "rt_test_root.h" #include "oslib_test_root.h" #include "chprintf.h" +#include "smcclient.h" /* * LED blinker thread, times are in milliseconds. */ @@ -50,14 +51,11 @@ static const SerialConfig sdcfg = { UART_MR_PAR_NO }; -msg_t smcInvokeService(msg_t handle, void *data); - /* * Application entry point. */ int main(void) { - - asm("bkpt #0\n\t"); + smc_service_t smcsvc; /* * System initializations. * - HAL initialization, this also initializes the configured device drivers @@ -82,16 +80,24 @@ int main(void) { chThdCreateStatic(waThread1, sizeof(waThread1), NORMALPRIO-1, Thread1, NULL); /* - * Call the null secure service + * Call the dummy secure service */ - chprintf((BaseSequentialStream*)&SD0, "Calling the 'null' secure service\n\r"); - //smcInvokeService(1, (void *)2); + chprintf((BaseSequentialStream*)&SD0, "Calling the 'dummy' secure service\n\r"); + /* Retrieve the service handle by name */ + smcsvc = (smc_service_t) smcInvokeService( + SMC_HND_GET, (smc_params_area_t)"DummyTrustedService", + sizeof "DummyTrustedService"); /* * Normal main() thread activity, in this demo it does nothing except - * sleeping in a loop and check the button state. + * calling periodically the dummy service and check the button state. */ while (true) { + msg_t r; + + /* Invoke the service */ + r = smcInvokeService(smcsvc, (smc_params_area_t)"HELO", sizeof "HELO"); + chprintf((BaseSequentialStream*)&SD0, "Call result: %d\r\n", r); if(!palReadPad(PIOB, PIOB_USER_PB)) { #if 1 test_execute((BaseSequentialStream *)&SD0, &rt_test_suite); diff --git a/demos/ATSAMA5D2/RT-SAMA5D2-XPLAINED-NSEC/smcclient.c b/demos/ATSAMA5D2/RT-SAMA5D2-XPLAINED-NSEC/smcclient.c index ec32af7d6..15f094e2b 100644 --- a/demos/ATSAMA5D2/RT-SAMA5D2-XPLAINED-NSEC/smcclient.c +++ b/demos/ATSAMA5D2/RT-SAMA5D2-XPLAINED-NSEC/smcclient.c @@ -26,6 +26,7 @@ */ #include "ch.h" +#include "smcclient.h" /*===========================================================================*/ /* Module local definitions. */ @@ -50,14 +51,14 @@ /*===========================================================================*/ /* Module exported functions. */ /*===========================================================================*/ - -msg_t smcInvokeService(msg_t handle, void *data) +msg_t smcInvokeService(smc_service_t handle, smc_params_area_t data, + size_t size) { msg_t result; do { - asm volatile("smc #0" : "=r" (result) : "r" (handle), "r" (data)); - } while (result == MSG_RESET); + asm volatile("smc #0" : "=r" (result) : "r" (handle), "r" (data), "r" (size)); + } while (result == MSG_TIMEOUT); return result; } diff --git a/demos/ATSAMA5D2/RT-SAMA5D2-XPLAINED-NSEC/smcclient.h b/demos/ATSAMA5D2/RT-SAMA5D2-XPLAINED-NSEC/smcclient.h new file mode 100644 index 000000000..c537bb0c9 --- /dev/null +++ b/demos/ATSAMA5D2/RT-SAMA5D2-XPLAINED-NSEC/smcclient.h @@ -0,0 +1,82 @@ +/* + ChibiOS - Copyright (C) 2006..2016 Giovanni Di Sirio. + + This file is part of ChibiOS. + + ChibiOS is free software; you can redistribute it and/or modify + it under the terms of the GNU General Public License as published by + the Free Software Foundation; either version 3 of the License, or + (at your option) any later version. + + ChibiOS is distributed in the hope that it will be useful, + but WITHOUT ANY WARRANTY; without even the implied warranty of + MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the + GNU General Public License for more details. + + You should have received a copy of the GNU General Public License + along with this program. If not, see . +*/ + +/** + * @file smcclient.h + * @brief smc Module macros and structures. + * + * @addtogroup SMC + * @{ + */ + +#ifndef SMCCLIENT_H +#define SMCCLIENT_H + +/*===========================================================================*/ +/* Module constants. */ +/*===========================================================================*/ +/* + * Service registry errors + */ +#define SMC_SVC_OK MSG_OK /* No error */ + +/* + * Special service handles + */ +#define SMC_HND_TRAMP ((smc_service_t)0) +#define SMC_HND_GET ((smc_service_t)1) + +/*===========================================================================*/ +/* Module pre-compile time settings. */ +/*===========================================================================*/ + +/*===========================================================================*/ +/* Derived constants and error checks. */ +/*===========================================================================*/ + +/*===========================================================================*/ +/* Module data structures and types. */ +/*===========================================================================*/ +typedef uint8_t * smc_params_area_t; +typedef void * smc_service_t; + +/*===========================================================================*/ +/* Module macros. */ +/*===========================================================================*/ + +/*===========================================================================*/ +/* External declarations. */ +/*===========================================================================*/ + +#ifdef __cplusplus +extern "C" { +#endif +msg_t smcInvokeService(smc_service_t handle, smc_params_area_t data, + size_t size); +#ifdef __cplusplus +} +#endif + +/*===========================================================================*/ +/* Module inline functions. */ +/*===========================================================================*/ + +#endif /* SMCCLIENT_H */ + +/** @} */ -- cgit v1.2.3