1 /* 2 * Copyright 2017, NXP 3 * All rights reserved. 4 * 5 * 6 * SPDX-License-Identifier: BSD-3-Clause 7 */ 8 9 #ifndef __SRTM_DISPATCHER_STRUCT_H__ 10 #define __SRTM_DISPATCHER_STRUCT_H__ 11 12 #include "srtm_defs.h" 13 #include "srtm_list.h" 14 #include "srtm_sem.h" 15 #include "srtm_mutex.h" 16 17 /******************************************************************************* 18 * Definitions 19 ******************************************************************************/ 20 /** 21 * @brief SRTM dispatcher message number to hold the received data. 22 * 23 * The received message is freed for reuse once it gets processed by the 24 * dispatcher task. In a busy traffic, 8 received messages might be used 25 * up and latter calling SRTM_Dispatcher_PostRecvData() from channel will 26 * return failed. In this case, user need to augment the number. 27 */ 28 #ifndef SRTM_DISPATCHER_CONFIG_RX_MSG_NUMBER 29 #define SRTM_DISPATCHER_CONFIG_RX_MSG_NUMBER (8U) 30 #endif 31 32 /** 33 * @brief SRTM dispatcher message maximum length in bytes. 34 * 35 * The maximum buffer length for SRTM_Dispatcher_PostRecvData() call. User 36 * need to augment the number when there's long message in application 37 * protocol. 38 */ 39 #ifndef SRTM_DISPATCHER_CONFIG_RX_MSG_MAX_LEN 40 #define SRTM_DISPATCHER_CONFIG_RX_MSG_MAX_LEN (256U) 41 #endif 42 43 /** 44 * @brief SRTM dispatcher struct 45 */ 46 struct _srtm_dispatcher 47 { 48 srtm_list_t cores; /*!< SRTM peer core list head */ 49 srtm_list_t services; /*!< SRTM service list head */ 50 51 srtm_mutex_t mutex; /*!< Mutex for multi-task protection */ 52 #if defined(SRTM_STATIC_API) && SRTM_STATIC_API 53 srtm_mutex_buf_t mutexStatic; 54 #endif 55 56 srtm_list_t freeRxMsgs; /*!< Free Rx messages list to hold the callback Rx data */ 57 srtm_list_t messageQ; /*!< Message queue to hold the messages to process */ 58 srtm_list_t waitingReqs; /*!< Message queue to hold the request waiting for the response */ 59 60 volatile bool stopReq; /*!< SRTM dispatcher stop request flag */ 61 bool started; /*!< SRTM dispatcher started flag */ 62 srtm_sem_t startSig; /*!< SRTM dispatcher start signal */ 63 #if defined(SRTM_STATIC_API) && SRTM_STATIC_API 64 srtm_sem_buf_t startSigStatic; 65 #endif 66 srtm_sem_t stopSig; /*!< SRTM dispatcher stop signal */ 67 #if defined(SRTM_STATIC_API) && SRTM_STATIC_API 68 srtm_sem_buf_t stopSigStatic; 69 #endif 70 srtm_sem_t queueSig; /*!< SRTM dispatcher messageQ signal */ 71 #if defined(SRTM_STATIC_API) && SRTM_STATIC_API 72 srtm_sem_buf_t queueSigStatic; 73 #endif 74 }; 75 76 /******************************************************************************* 77 * API 78 ******************************************************************************/ 79 #ifdef __cplusplus 80 extern "C" { 81 #endif 82 83 /*! 84 * @brief Post received data from channel to dispatcher. 85 * 86 * @param dispatcher SRTM dispatcher handle. 87 * @param channel The channel where Rx data is got from. 88 * @param buf The buffer address of Rx data. 89 * @param len The buffer len of Rx data in bytes. 90 * @return SRTM_Status_Success on success and others on failure. 91 */ 92 srtm_status_t SRTM_Dispatcher_PostRecvData(srtm_dispatcher_t disp, srtm_channel_t channel, void *buf, uint32_t len); 93 94 /*! 95 * @brief The main message processor of dispatcher. 96 * 97 * The function MUST be called in dispatcher running thread context. 98 * 99 * @param dispatcher SRTM dispatcher handle. 100 * @param msg The message to be handled. 101 * @return SRTM_Status_Success on success and others on failure. 102 */ 103 srtm_status_t SRTM_Dispatcher_ProcessMessage(srtm_dispatcher_t disp, srtm_message_t msg); 104 105 /*! 106 * @brief Deliver all messages in the list sequentially and clean up the list. 107 * 108 * This function is used to combine some messages into one delivery to make sure the 109 * messages can be handled in sequence without other messages interleaved. The messages 110 * can be different type, e.g. combining procedure message and response message is allowed. 111 * 112 * @param disp SRTM dispatcher handle. 113 * @param msgs Message list to send to peer core. 114 * @return SRTM_Status_Success on success and others on failure. 115 */ 116 srtm_status_t SRTM_Dispatcher_DeliverMessages(srtm_dispatcher_t disp, srtm_list_t *msgs); 117 118 #ifdef __cplusplus 119 } 120 #endif 121 /*! @} */ 122 123 #endif /* __SRTM_DISPATCHER_STRUCT_H__ */ 124