yu.dong | c33b307 | 2024-08-21 23:14:49 -0700 | [diff] [blame^] | 1 | /***************************************************************************** |
| 2 | * Copyright Statement: |
| 3 | * -------------------- |
| 4 | * This software is protected by Copyright and the information contained |
| 5 | * herein is confidential. The software may not be copied and the information |
| 6 | * contained herein may not be used or disclosed except with the written |
| 7 | * permission of MediaTek Inc. (C) 2012 |
| 8 | * |
| 9 | * BY OPENING THIS FILE, BUYER HEREBY UNEQUIVOCALLY ACKNOWLEDGES AND AGREES |
| 10 | * THAT THE SOFTWARE/FIRMWARE AND ITS DOCUMENTATIONS ("MEDIATEK SOFTWARE") |
| 11 | * RECEIVED FROM MEDIATEK AND/OR ITS REPRESENTATIVES ARE PROVIDED TO BUYER ON |
| 12 | * AN "AS-IS" BASIS ONLY. MEDIATEK EXPRESSLY DISCLAIMS ANY AND ALL WARRANTIES, |
| 13 | * EXPRESS OR IMPLIED, INCLUDING BUT NOT LIMITED TO THE IMPLIED WARRANTIES OF |
| 14 | * MERCHANTABILITY, FITNESS FOR A PARTICULAR PURPOSE OR NONINFRINGEMENT. |
| 15 | * NEITHER DOES MEDIATEK PROVIDE ANY WARRANTY WHATSOEVER WITH RESPECT TO THE |
| 16 | * SOFTWARE OF ANY THIRD PARTY WHICH MAY BE USED BY, INCORPORATED IN, OR |
| 17 | * SUPPLIED WITH THE MEDIATEK SOFTWARE, AND BUYER AGREES TO LOOK ONLY TO SUCH |
| 18 | * THIRD PARTY FOR ANY WARRANTY CLAIM RELATING THERETO. MEDIATEK SHALL ALSO |
| 19 | * NOT BE RESPONSIBLE FOR ANY MEDIATEK SOFTWARE RELEASES MADE TO BUYER'S |
| 20 | * SPECIFICATION OR TO CONFORM TO A PARTICULAR STANDARD OR OPEN FORUM. |
| 21 | * |
| 22 | * BUYER'S SOLE AND EXCLUSIVE REMEDY AND MEDIATEK'S ENTIRE AND CUMULATIVE |
| 23 | * LIABILITY WITH RESPECT TO THE MEDIATEK SOFTWARE RELEASED HEREUNDER WILL BE, |
| 24 | * AT MEDIATEK'S OPTION, TO REVISE OR REPLACE THE MEDIATEK SOFTWARE AT ISSUE, |
| 25 | * OR REFUND ANY SOFTWARE LICENSE FEES OR SERVICE CHARGE PAID BY BUYER TO |
| 26 | * MEDIATEK FOR SUCH MEDIATEK SOFTWARE AT ISSUE. |
| 27 | * |
| 28 | * THE TRANSACTION CONTEMPLATED HEREUNDER SHALL BE CONSTRUED IN ACCORDANCE |
| 29 | * WITH THE LAWS OF THE STATE OF CALIFORNIA, USA, EXCLUDING ITS CONFLICT OF |
| 30 | * LAWS PRINCIPLES. ANY DISPUTES, CONTROVERSIES OR CLAIMS ARISING THEREOF AND |
| 31 | * RELATED THERETO SHALL BE SETTLED BY ARBITRATION IN SAN FRANCISCO, CA, UNDER |
| 32 | * THE RULES OF THE INTERNATIONAL CHAMBER OF COMMERCE (ICC). |
| 33 | * |
| 34 | *****************************************************************************/ |
| 35 | |
| 36 | /***************************************************************************** |
| 37 | * |
| 38 | * Filename: |
| 39 | * --------- |
| 40 | * mte_if.h |
| 41 | * |
| 42 | * Project: |
| 43 | * -------- |
| 44 | * UMOLYA |
| 45 | * |
| 46 | * Description: |
| 47 | * ------------ |
| 48 | * MT Framework element prototyes |
| 49 | * |
| 50 | * Author: |
| 51 | * ------- |
| 52 | * ------- |
| 53 | * |
| 54 | * |
| 55 | * ========================================================================== |
| 56 | * $Log$ |
| 57 | * |
| 58 | * |
| 59 | ****************************************************************************/ |
| 60 | |
| 61 | |
| 62 | #ifndef _MTE_IF_ |
| 63 | #define _MTE_IF_ |
| 64 | |
| 65 | #include "mt.h" |
| 66 | #include "mt_dispatcher.h" |
| 67 | |
| 68 | |
| 69 | #define MT_METRICS_UNIT_TEST |
| 70 | |
| 71 | /** |
| 72 | * @name mt_set_timer_event |
| 73 | * |
| 74 | * @brief set an timer event from mtf event scheduler |
| 75 | * |
| 76 | * @param [in] callback the callback function when event timeout |
| 77 | * @param [in] callbackparam the user supplied argument for callback function |
| 78 | * @param [in] delaytime how many system ticks elapses before this event timeout |
| 79 | * |
| 80 | * @retval ret Successful: return set eventid. |
| 81 | * Fail: return NULL. |
| 82 | */ |
| 83 | #define mt_set_timer_event(callback, callbackparam, delaytime) \ |
| 84 | evshed_set_event(mtf_event_scheduler, callback, callbackparam, delaytime) |
| 85 | |
| 86 | /** |
| 87 | * @name mt_cancel_timer_event |
| 88 | * |
| 89 | * @brief cancel a timer event freom mtf event scheduler |
| 90 | * |
| 91 | * @param [in] eventID pointer to eventID |
| 92 | * |
| 93 | * @retval ret Successful: remain ticks before this event expires |
| 94 | * Fail: -1 |
| 95 | */ |
| 96 | #define mt_cancel_timer_event(eventID) \ |
| 97 | evshed_cancel_event(mtf_event_scheduler, eventID) |
| 98 | |
| 99 | /** |
| 100 | * @name mt_get_remaining_time |
| 101 | * |
| 102 | * @brief get remain ticks before this event expires |
| 103 | * |
| 104 | * @param [in] eventID pointer to eventID |
| 105 | * |
| 106 | * @retval ret Successful: remain ticks before this event expires |
| 107 | * |
| 108 | */ |
| 109 | #define mt_get_remaining_time(eventID) \ |
| 110 | evshed_get_remaining_time(mtf_event_scheduler, eventID) |
| 111 | |
| 112 | /** |
| 113 | * @name mte_execute_func |
| 114 | * |
| 115 | * @brief Prototype of MTE routine entry function, all MTE should implement this and pass as an argument in register call |
| 116 | * |
| 117 | * @param [in] mte_rule mte_rule_t instance of the matched rule which triggers this element |
| 118 | * @param [in] msg Raw content of source message, use source to determine the format of this msg |
| 119 | * @param [in] msg_size Length of the content in pointed by msg |
| 120 | * |
| 121 | */ |
| 122 | typedef struct _mte_rule_t mte_rule_t; |
| 123 | |
| 124 | typedef void (*mte_execute_func)(const mte_rule_t *mte_rule, void* msg, kal_uint32 msg_size); |
| 125 | |
| 126 | /// Structure of the Metrics Translation Element (MTE) rule descriptor |
| 127 | typedef struct _mte_rule_t |
| 128 | { |
| 129 | char reserved[MT_DISPATCHER_ENTRY_RESERVED_SIZE]; ///< reserved fields |
| 130 | |
| 131 | mt_fmt_id fmt_id; ///< Source of the message to be registered with |
| 132 | kal_uint32 code; ///< Code of the source. When incoming source message matches this code, |
| 133 | /// this MTE_execute_func will be called. See definition of each source for detail format of code |
| 134 | mte_execute_func execute; ///< Pointer to the mte_execute_func which is called when incoming message matches |
| 135 | void* context; ///< Context to be passed when calling mte_entry |
| 136 | } mte_rule_t; |
| 137 | |
| 138 | /** |
| 139 | * @name mt_register_mte_rule |
| 140 | * |
| 141 | * @brief Register a metrics translation element (MTE) to framework. This function should be only called in mte_init() |
| 142 | * The framework will dispatch message to the registered MTE based on the given source/code |
| 143 | * |
| 144 | * @param [in] mte_rule Pointer to the descriptor of the MTE rule to be registered |
| 145 | * Caller should allocate the memory pointed by this pointer and let callee to keep this memory |
| 146 | */ |
| 147 | void mt_register_mte_rule(mte_rule_t *mte_rule); |
| 148 | /** |
| 149 | * @name mt_register_mte_rule_with_mask |
| 150 | * |
| 151 | * @brief Register a metrics translation element (MTE) to framework. This function should be only called in mte_init() |
| 152 | * The framework will dispatch message to the registered MTE based on the given source/code and mask |
| 153 | * |
| 154 | * @param [in] mte_rule Pointer to the descriptor of the MTE rule to be registered |
| 155 | * Caller should allocate the memory pointed by this pointer and let callee to keep this memory |
| 156 | * @param [in] rule_code_mask mask on will dispatch message when code match, mask off will dispatch all message. |
| 157 | * also can only on of special flag, |
| 158 | * i.e RULE_CODE_MASK_ICD_TYPE_FLAG_ON, RULE_CODE_MASK_ICD_CODE_FLAG_ON |
| 159 | * RULE_CODE_MASK_ICD_PROTOCOL_FLAG_ON |
| 160 | */ |
| 161 | void mt_register_mte_rule_with_mask(mte_rule_t *mte_rule, kal_uint32 rule_code_mask); |
| 162 | |
| 163 | |
| 164 | #define GEN_MSG_ID(destID, metricID) MSG_ID_##destID##_##metricID##_IND |
| 165 | |
| 166 | extern int |
| 167 | mt_ext_ut_submit_metrics(msg_type msg_id, void* payload, kal_uint32 payload_size); |
| 168 | |
| 169 | /** |
| 170 | * @name mt_submit_metric |
| 171 | * |
| 172 | * @brief Submit metric value to the dedicated destination module |
| 173 | * |
| 174 | * @param [in] dest_id Destination module name |
| 175 | * @param [in] metric_id Destination specified metric ID |
| 176 | * @param [in] payload Pointer to the payload content |
| 177 | * @param [in] payload Size of payload content pointed by payload |
| 178 | * |
| 179 | * @retval ret Return value specified by the destination module |
| 180 | * |
| 181 | * @code |
| 182 | * auto r = mt_submit_metric(MT_DEST_CIQ, 10, struct_for_metric_10); |
| 183 | */ |
| 184 | //#ifdef __MTK_TARGET__ |
| 185 | #define mt_submit_metric(_dest_id, _metric_id, _payload, _payload_size) mt_ext_ut_submit_metrics(GEN_MSG_ID(_dest_id, _metric_id), (_payload), (_payload_size)) |
| 186 | |
| 187 | //#endif |
| 188 | /** |
| 189 | * @name mt_format_return |
| 190 | * |
| 191 | * @brief Translate destination specified return code to standard result code |
| 192 | * |
| 193 | * @param [in] dest_id Destination module ID |
| 194 | * @param [in] ret Return code given by the destination module |
| 195 | * |
| 196 | * @retval 0 Success |
| 197 | * @retval EINVAL Invalid argument |
| 198 | * @retval ENOMEM Out of memory |
| 199 | * @retval EINVAL Invalid argument |
| 200 | * @retval EAGAIN Try again |
| 201 | * @retval EIO I/O error (channeel error) |
| 202 | * @retval EPERM Operation not permitted (all other errors) |
| 203 | * |
| 204 | * @code |
| 205 | * int ret = mt_format_return(MT_DEST_CIQ, mt_submit_metric(MT_DEST_CIQ, 10, struct_for_metric_10)); |
| 206 | */ |
| 207 | #ifdef MT_METRICS_UNIT_TEST |
| 208 | #define mt_format_return(_dest_id, _ret) (_ret) |
| 209 | #else |
| 210 | #define mt_format_return(_dest_id, _ret) \ |
| 211 | _dest_id ## _format_return(_ret) |
| 212 | #endif |
| 213 | |
| 214 | void mt_elements_reset(); |
| 215 | |
| 216 | void mt_elements_init(); |
| 217 | |
| 218 | void mt_elements_init_proc(); |
| 219 | void mt_nvram_write_cnf_hdlr(ilm_struct *ilm_ptr); |
| 220 | |
| 221 | |
| 222 | #endif // _MTE_IF_ |