diff options
author | isiora <none@example.com> | 2018-01-19 08:05:05 +0000 |
---|---|---|
committer | isiora <none@example.com> | 2018-01-19 08:05:05 +0000 |
commit | 37fa634feef054c7ec18aa9ba14e99f5fcc2cfe5 (patch) | |
tree | 4bd898ce9c8faa1c42289cb6aa263c36b23b0a29 /os/common | |
parent | ea577c45b76ce97edebb3863f1aabf9b89024d98 (diff) | |
download | ChibiOS-37fa634feef054c7ec18aa9ba14e99f5fcc2cfe5.tar.gz ChibiOS-37fa634feef054c7ec18aa9ba14e99f5fcc2cfe5.tar.bz2 ChibiOS-37fa634feef054c7ec18aa9ba14e99f5fcc2cfe5.zip |
SMC first release.
git-svn-id: svn://svn.code.sf.net/p/chibios/svn/trunk@11337 35acf78f-673a-0410-8e92-d51de3d6d3f4
Diffstat (limited to 'os/common')
-rw-r--r-- | os/common/ports/ARMCAx-TZ/chsmc.c | 59 | ||||
-rw-r--r-- | os/common/ports/ARMCAx-TZ/chsmc.h | 26 |
2 files changed, 55 insertions, 30 deletions
diff --git a/os/common/ports/ARMCAx-TZ/chsmc.c b/os/common/ports/ARMCAx-TZ/chsmc.c index 2c813f713..9632f8fdc 100644 --- a/os/common/ports/ARMCAx-TZ/chsmc.c +++ b/os/common/ports/ARMCAx-TZ/chsmc.c @@ -24,7 +24,7 @@ * @addtogroup SMC
* @{
*/
-#include <string.h>
+//#include <string.h>
#include "ch.h"
#include "chsmc.h"
@@ -36,6 +36,7 @@ /*===========================================================================*/
/* Module exported variables. */
/*===========================================================================*/
+thread_reference_t _ns_thread;
/*===========================================================================*/
/* Module local types. */
@@ -50,29 +51,41 @@ static memory_pool_t svcs_pool; /* Module local functions. */
/*===========================================================================*/
+static bool isAddrspaceValid(void *addr, uint32_t len)
+{
+ (void) addr;
+ (void) len;
+ return TRUE;
+}
+
/*===========================================================================*/
/* Module exported functions. */
/*===========================================================================*/
/**
* @brief XXX Module initialization.
- * @note This function is implicitly invoked on system initialization,
- * there is no need to explicitly initialize the module.
*
* @notapi
*/
-void _smc_init(void) {
+void smcInit(void) {
chPoolObjectInit(&svcs_pool, sizeof (smc_service_t),
chCoreAllocAlignedI);
}
+registered_object_t *smcFindService(const char *name, uint32_t namelen) {
+ (void) name;
+ (void) namelen;
+ return 0;
+}
+
/**
* @brief The trusted service call entry point.
* @post A request is passed to the thread registered for the service.
- * @post The service thread is resumed, if necessary.
+ * @post The service thread is resumed.
*
* @param[in] svc_handle the handle of the service to be invoked
* @param[in] svc_data service request data, often a reference to a more complex structure
+ * @param[in] svc_datalen size of the svc_data memory area
*
* @return a value defined by the service.
* @retval MSG_OK a success value.
@@ -80,16 +93,23 @@ void _smc_init(void) { *
* @notapi
*/
-msg_t smcEntry(registered_object_t svc_handle, void *svc_data) {
+msg_t smcEntry(smc_service_t *svc_handle, smc_params_area_t svc_data, uint32_t svc_datalen) {
+ registered_object_t *rop;
msg_t r;
asm("bkpt #0\n\t");
- chDbgAssert(_ns_thread == NULL, "main thread consistency");
-
+ if (!isAddrspaceValid(svc_data, svc_datalen))
+ return MSG_RESET;
+ rop = chFactoryFindObjectByPointer(svc_handle);
+ if (rop == NULL)
+ return MSG_RESET;
+ svc_handle->svc_data = svc_data;
+ svc_handle->svc_datalen = svc_datalen;
chSysLock();
+ chThdResumeS(&svc_handle->svct, MSG_OK);
r = chThdSuspendS(&_ns_thread);
- _ns_thread = NULL;
chSysUnlock();
+ chFactoryReleaseObject(rop);
return r;
}
@@ -100,36 +120,33 @@ msg_t smcEntry(registered_object_t svc_handle, void *svc_data) { *
* @param[in] svc_name the name of the service.
*
- * @return A new allocated service object.
+ * @return a registered smc service object.
* @retval NULL if @p svc_name failed to be registered.
*
* @notapi
*/
-smc_service_t *smcRegisterMeAsService(const char *svc_name)
+registered_object_t *smcRegisterMeAsService(const char *svc_name)
{
registered_object_t *rop;
smc_service_t *svcp = chPoolAlloc(&svcs_pool);
- svcp->svct = chThdGetSelfX();
- memset(svcp->params, 0, sizeof svcp->params);
rop = chFactoryRegisterObject(svc_name, svcp);
if (rop == NULL) {
chPoolFree(&svcs_pool, svcp);
return NULL;
}
- return svcp;
+ return rop;
}
/**
* @brief The calling thread is a service and wait the arrival of a request.
- * @post
+ * @post the service object is filled with the parameters of the requestor.
*
- * @param[in] svc_name the name of the service
- * @param[in] svc_number the number of the service
+ * @param[in] svcp the service object reference.
*
- * @return the
- * @retval SMC_SVC_OK a success value.
- * @retval SMC_SVC_MANAGED if the service @p scv_name already exists.
+ * @return the reason of the awakening
+ * @retval MSG_OK a success value.
+ * @retval MSG_TIMEOUT a success value.
*
* @notapi
*/
@@ -139,8 +156,6 @@ msg_t smcServiceWaitRequest(smc_service_t *svcp) chDbgCheck(svcp != NULL);
- if (svcp->svct != chThdGetSelfX())
- return MSG_TIMEOUT;
chSysLock();
r = chThdSuspendTimeoutS(&svcp->svct, TIME_INFINITE);
chSysUnlock();
diff --git a/os/common/ports/ARMCAx-TZ/chsmc.h b/os/common/ports/ARMCAx-TZ/chsmc.h index 8ea42f0f1..bd22b2e94 100644 --- a/os/common/ports/ARMCAx-TZ/chsmc.h +++ b/os/common/ports/ARMCAx-TZ/chsmc.h @@ -29,6 +29,7 @@ #define CHSMC_H
#include "ch.h"
+#include "ccportab.h"
/*===========================================================================*/
/* Module constants. */
@@ -36,12 +37,16 @@ /*
* Service registry errors
*/
-#define SMC_SVC_OK MSG_RESET /* No error */
-#define SMC_SVC_MANAGED 0x01 /* The service is already managed by a thread */
-#define SMC_SVC_THREAD_EXIST 0x02 /* The thread already manages a service */
-#define SMC_SVC_THREAD_NOENT 0x03 /* The thread is not in the registry */
+#define SMC_SVC_OK MSG_RESET /* No error */
+#define SMC_SVC_MANAGED 0x01 /* The service is already managed by a thread */
+#define SMC_SVC_THREAD_EXIST 0x02 /* The thread already manages a service */
+#define SMC_SVC_THREAD_NOENT 0x03 /* The thread is not in the registry */
-#define SMC_SVC_PARAMS_MAX_N 3 /* Max number of parameters for a service */
+/*
+ * Special service handles
+ */
+#define SMC_HND_TRAMP 0
+#define SMC_HND_FIND 1
/*===========================================================================*/
/* Module pre-compile time settings. */
@@ -54,9 +59,12 @@ /*===========================================================================*/
/* Module data structures and types. */
/*===========================================================================*/
+typedef uint8_t * smc_params_area_t;
+
typedef struct ch_smc_service {
thread_reference_t svct;
- msg_t params[SMC_SVC_PARAMS_MAX_N];
+ smc_params_area_t svc_data;
+ uint32_t svc_datalen;
} smc_service_t;
/*===========================================================================*/
@@ -70,9 +78,11 @@ typedef struct ch_smc_service { #ifdef __cplusplus
extern "C" {
#endif
-thread_reference_t _ns_thread;
+extern thread_reference_t _ns_thread;
+CC_NO_RETURN void _ns_trampoline(uint32_t addr);
+void smcInit(void);
msg_t smc_entry(msg_t svc_number, void *svc_data);
-smc_service_t * smcRegisterMeAsService(const char *svc_name);
+registered_object_t * smcRegisterMeAsService(const char *svc_name);
#ifdef __cplusplus
}
#endif
|