Modified the signature of tsInvokeService. Added to the api an invoke without yield.

git-svn-id: svn://svn.code.sf.net/p/chibios/svn/trunk@11765 110e8d01-0319-4d1e-a829-52ad28d1bb01
This commit is contained in:
isiora 2018-03-15 12:16:56 +00:00
parent 18f1b739fc
commit 188c45b620
2 changed files with 82 additions and 31 deletions

View File

@ -20,9 +20,6 @@
/** /**
* @file tsclient.c * @file tsclient.c
* @brief TSSI client module code. * @brief TSSI client module code.
*
* @addtogroup TSSI
* @{
*/ */
#include "ch.h" #include "ch.h"
@ -35,6 +32,7 @@
/*===========================================================================*/ /*===========================================================================*/
/* Module exported variables. */ /* Module exported variables. */
/*===========================================================================*/ /*===========================================================================*/
EVENTSOURCE_DECL(stubsEventSource);
/*===========================================================================*/ /*===========================================================================*/
/* Module local types. */ /* Module local types. */
@ -63,7 +61,11 @@ void tsIdle(void) {
} }
/** /**
* @brief Call a service via smc instruction. * @brief Call a service via smc instruction with yield times.
* @details a time slice will be yielded also to the lower prio NSEC threads,
* whenever the service call is interrupted.
* This avoids the starvation of NSEC threads that run to lower prio,
* due to continue polling of the called service status.
* *
* @param[in] handle The handle of the service to invoke. * @param[in] handle The handle of the service to invoke.
* The handle is obtained by an invoke to discovery * The handle is obtained by an invoke to discovery
@ -74,8 +76,9 @@ void tsIdle(void) {
* @param[in] svc_nsec_time The time slice that will be yielded to the lower * @param[in] svc_nsec_time The time slice that will be yielded to the lower
* prio NSEC threads, whenever the service call is * prio NSEC threads, whenever the service call is
* interrupted, in microseconds. * interrupted, in microseconds.
* This avoids the starvation of lower NSEC thread due * This avoids the starvation of NSEC threads that run
* to continue polling of the called service status. * to lower prio, due to continue polling of the
* called service status.
* 0 means no time slice is yielded. * 0 means no time slice is yielded.
* *
* @return The service status. The value depends on the service. * @return The service status. The value depends on the service.
@ -89,17 +92,46 @@ void tsIdle(void) {
* @api * @api
*/ */
msg_t tsInvokeService(ts_service_t handle, ts_params_area_t data, msg_t tsInvokeService(ts_service_t handle, ts_params_area_t data,
size_t size, sysinterval_t svc_nsec_time) size_t size)
{ {
int64_t result; msg_t result;
result = tsInvoke1(handle, data, size, TS_GRANTED_TIMESLICE); result = tsInvoke1(handle, data, size, TS_GRANTED_TIMESLICE);
while ((msg_t)result == SMC_SVC_INTR) { while (result == SMC_SVC_INTR) {
if (svc_nsec_time != 0) chThdSleepMicroseconds(TS_GRANTED_TIMESLICE);
chThdSleepMicroseconds(svc_nsec_time);
result = tsInvoke1(TS_HND_STQRY, handle, 0, TS_GRANTED_TIMESLICE); result = tsInvoke1(TS_HND_STQRY, handle, 0, TS_GRANTED_TIMESLICE);
} }
return (msg_t)result; return result;
} }
/** @} */ /**
* @brief Call a service via smc instruction without yield time to NSEC.
*
* @param[in] handle The handle of the service to invoke.
* The handle is obtained by an invoke to discovery
* service.
* @param[in,out] 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 The service status. The value depends on the service.
*
* @retval SMC_SVC_OK generic success value.
* @retval SMC_SVC_BUSY the service has a pending request.
* @retval SMC_SVC_INVALID bad parameters.
* @retval SMC_SVC_NOENT no such service.
* @retval SMC_SVC_BADH bad handle.
*
* @api
*/
msg_t tsInvokeServiceNoYield(ts_service_t handle, ts_params_area_t data,
size_t size)
{
msg_t result;
result = tsInvoke1(handle, data, size, TS_GRANTED_TIMESLICE);
while (result == SMC_SVC_INTR) {
result = tsInvoke1(TS_HND_STQRY, handle, 0, TS_GRANTED_TIMESLICE);
}
return result;
}

View File

@ -20,9 +20,6 @@
/** /**
* @file tsclient.h * @file tsclient.h
* @brief TSSI client module macros and structures. * @brief TSSI client module macros and structures.
*
* @addtogroup TSSI
* @{
*/ */
#ifndef TSCLIENT_H #ifndef TSCLIENT_H
@ -53,9 +50,13 @@
#define TS_GRANTED_TIMESLICE 1000 /* Microseconds.*/ #define TS_GRANTED_TIMESLICE 1000 /* Microseconds.*/
#if !defined(TS_CHECK_EVENT_HOOK)
#define TS_CHECK_EVENT_HOOK(f) { \ #define TS_CHECK_EVENT_HOOK(f) { \
(void)f; \ extern event_source_t stubsEventSource; \
if (f) \
chEvtBroadcastFlags(&stubsEventSource, f); \
} }
#endif
/*===========================================================================*/ /*===========================================================================*/
/* Derived constants and error checks. */ /* Derived constants and error checks. */
@ -78,7 +79,27 @@ typedef void * ts_service_t;
/** /**
* @brief Call a service via smc instruction. * @brief Call a service via smc instruction.
* @note see tsInvoke1() * @details call a given service via smc.
*
* @param[in] handle The handle of the service to invoke.
* The handle is obtained by an invoke to discovery
* service.
* @param[in,out] svc_data Service request data, often a reference to a more
* complex structure.
* @param[in] svc_datalen Size of the svc_data memory area.
* @param[in] yieldtime The time yield to SEC service to run, in microsec.
*
* @return A 64bit value. It is composed by the 32bit service
* status in the lo-word with the 32bit event mask in
* the hi-word.
* The retval values are returned in the lower word
* as 32bit int.
* @retval SMC_SVC_OK generic success value.
* @retval SMC_SVC_INTR call interrupted.
* @retval SMC_SVC_BUSY the service has a pending request.
* @retval SMC_SVC_INVALID bad parameters.
* @retval SMC_SVC_NOENT no such service.
* @retval SMC_SVC_BADH bad handle.
* *
* @notapi * @notapi
*/ */
@ -110,11 +131,8 @@ static inline int64_t tsInvoke0(ts_service_t handle, ts_params_area_t data,
* @param[in] svc_datalen Size of the svc_data memory area. * @param[in] svc_datalen Size of the svc_data memory area.
* @param[in] yieldtime The time yield to SEC service to run, in microsec. * @param[in] yieldtime The time yield to SEC service to run, in microsec.
* *
* @return A 64bit value. It is composed by the 32bit service * @return The service status. The value depends on the service.
* status in the lo-word with the 32bit event mask in *
* the hi-word.
* The retval values are returned in the lower word
* as 32bit int.
* @retval SMC_SVC_OK generic success value. * @retval SMC_SVC_OK generic success value.
* @retval SMC_SVC_INTR call interrupted. * @retval SMC_SVC_INTR call interrupted.
* @retval SMC_SVC_BUSY the service has a pending request. * @retval SMC_SVC_BUSY the service has a pending request.
@ -124,15 +142,15 @@ static inline int64_t tsInvoke0(ts_service_t handle, ts_params_area_t data,
* *
* @api * @api
*/ */
static inline int64_t tsInvoke1(ts_service_t handle, ts_params_area_t data, static inline msg_t tsInvoke1(ts_service_t handle, ts_params_area_t data,
size_t size, sysinterval_t timeslice) { size_t size, sysinterval_t yieldtime) {
int64_t result; int64_t result;
eventflags_t f; eventflags_t f;
result = tsInvoke0(handle, data, size, timeslice); result = tsInvoke0(handle, data, size, yieldtime);
f = (eventflags_t)(result >> 32); f = (eventflags_t)(result >> 32);
TS_CHECK_EVENT_HOOK(f); TS_CHECK_EVENT_HOOK(f);
return result; return (msg_t)result;
} }
/*===========================================================================*/ /*===========================================================================*/
@ -142,8 +160,11 @@ static inline int64_t tsInvoke1(ts_service_t handle, ts_params_area_t data,
#ifdef __cplusplus #ifdef __cplusplus
extern "C" { extern "C" {
#endif #endif
msg_t tsInvokeService(ts_service_t handle, ts_params_area_t data, msg_t tsInvokeService(ts_service_t handle, ts_params_area_t data,
size_t size, sysinterval_t svc_nsec_time); size_t size);
msg_t tsInvokeServiceNoYield(ts_service_t handle, ts_params_area_t data,
size_t size);
extern event_source_t stubsEventSource;
#ifdef __cplusplus #ifdef __cplusplus
} }
#endif #endif
@ -153,5 +174,3 @@ msg_t tsInvokeService(ts_service_t handle, ts_params_area_t data,
/*===========================================================================*/ /*===========================================================================*/
#endif /* TSCLIENT_H */ #endif /* TSCLIENT_H */
/** @} */