| 1 | /****************************************************************************** |
|---|
| 2 | * (c)2008-2009 Broadcom Corporation |
|---|
| 3 | * |
|---|
| 4 | * This program is the proprietary software of Broadcom Corporation and/or its licensors, |
|---|
| 5 | * and may only be used, duplicated, modified or distributed pursuant to the terms and |
|---|
| 6 | * conditions of a separate, written license agreement executed between you and Broadcom |
|---|
| 7 | * (an "Authorized License"). Except as set forth in an Authorized License, Broadcom grants |
|---|
| 8 | * no license (express or implied), right to use, or waiver of any kind with respect to the |
|---|
| 9 | * Software, and Broadcom expressly reserves all rights in and to the Software and all |
|---|
| 10 | * intellectual property rights therein. IF YOU HAVE NO AUTHORIZED LICENSE, THEN YOU |
|---|
| 11 | * HAVE NO RIGHT TO USE THIS SOFTWARE IN ANY WAY, AND SHOULD IMMEDIATELY |
|---|
| 12 | * NOTIFY BROADCOM AND DISCONTINUE ALL USE OF THE SOFTWARE. |
|---|
| 13 | * |
|---|
| 14 | * Except as expressly set forth in the Authorized License, |
|---|
| 15 | * |
|---|
| 16 | * 1. This program, including its structure, sequence and organization, constitutes the valuable trade |
|---|
| 17 | * secrets of Broadcom, and you shall use all reasonable efforts to protect the confidentiality thereof, |
|---|
| 18 | * and to use this information only in connection with your use of Broadcom integrated circuit products. |
|---|
| 19 | * |
|---|
| 20 | * 2. TO THE MAXIMUM EXTENT PERMITTED BY LAW, THE SOFTWARE IS PROVIDED "AS IS" |
|---|
| 21 | * AND WITH ALL FAULTS AND BROADCOM MAKES NO PROMISES, REPRESENTATIONS OR |
|---|
| 22 | * WARRANTIES, EITHER EXPRESS, IMPLIED, STATUTORY, OR OTHERWISE, WITH RESPECT TO |
|---|
| 23 | * THE SOFTWARE. BROADCOM SPECIFICALLY DISCLAIMS ANY AND ALL IMPLIED WARRANTIES |
|---|
| 24 | * OF TITLE, MERCHANTABILITY, NONINFRINGEMENT, FITNESS FOR A PARTICULAR PURPOSE, |
|---|
| 25 | * LACK OF VIRUSES, ACCURACY OR COMPLETENESS, QUIET ENJOYMENT, QUIET POSSESSION |
|---|
| 26 | * OR CORRESPONDENCE TO DESCRIPTION. YOU ASSUME THE ENTIRE RISK ARISING OUT OF |
|---|
| 27 | * USE OR PERFORMANCE OF THE SOFTWARE. |
|---|
| 28 | * |
|---|
| 29 | * 3. TO THE MAXIMUM EXTENT PERMITTED BY LAW, IN NO EVENT SHALL BROADCOM OR ITS |
|---|
| 30 | * LICENSORS BE LIABLE FOR (i) CONSEQUENTIAL, INCIDENTAL, SPECIAL, INDIRECT, OR |
|---|
| 31 | * EXEMPLARY DAMAGES WHATSOEVER ARISING OUT OF OR IN ANY WAY RELATING TO YOUR |
|---|
| 32 | * USE OF OR INABILITY TO USE THE SOFTWARE EVEN IF BROADCOM HAS BEEN ADVISED OF |
|---|
| 33 | * THE POSSIBILITY OF SUCH DAMAGES; OR (ii) ANY AMOUNT IN EXCESS OF THE AMOUNT |
|---|
| 34 | * ACTUALLY PAID FOR THE SOFTWARE ITSELF OR U.S. $1, WHICHEVER IS GREATER. THESE |
|---|
| 35 | * LIMITATIONS SHALL APPLY NOTWITHSTANDING ANY FAILURE OF ESSENTIAL PURPOSE OF |
|---|
| 36 | * ANY LIMITED REMEDY. |
|---|
| 37 | * |
|---|
| 38 | * $brcm_Workfile: $ |
|---|
| 39 | * $brcm_Revision: $ |
|---|
| 40 | * $brcm_Date: $ |
|---|
| 41 | * |
|---|
| 42 | * Module Description: |
|---|
| 43 | * |
|---|
| 44 | * Revision History: |
|---|
| 45 | * |
|---|
| 46 | * Created: 09/28/2009 by Jeff Fisher |
|---|
| 47 | * |
|---|
| 48 | * $brcm_Log: $ |
|---|
| 49 | * |
|---|
| 50 | * |
|---|
| 51 | *****************************************************************************/ |
|---|
| 52 | #ifndef BAPP_UTIL_H__ |
|---|
| 53 | #define BAPP_UTIL_H__ |
|---|
| 54 | #include "bstd.h" |
|---|
| 55 | #include "bkni.h" |
|---|
| 56 | |
|---|
| 57 | #include "bgfx.h" |
|---|
| 58 | #include "bos.h" |
|---|
| 59 | #include "ministd.h" |
|---|
| 60 | #ifdef BCM_DEBUG |
|---|
| 61 | #define BAPP_ASSERT(expr) { \ |
|---|
| 62 | if (!expr) \ |
|---|
| 63 | printf("%s failed at %s:%d\n",#expr, __FILE__, __LINE__); \ |
|---|
| 64 | } |
|---|
| 65 | #else |
|---|
| 66 | #define BAPP_ASSERT(expr) if (!(expr)) ; |
|---|
| 67 | #endif |
|---|
| 68 | |
|---|
| 69 | #define bapp_util_malloc BKNI_Malloc |
|---|
| 70 | #define bapp_util_free BKNI_Free |
|---|
| 71 | #define bapp_util_memset BKNI_Memset |
|---|
| 72 | #define bapp_util_memcpy BKNI_Memcpy |
|---|
| 73 | #define bapp_util_strlen(x) strlen((const char*)x) |
|---|
| 74 | #define bapp_util_strcpy(dst,src) strcpy((char*)dst,(const char*)src) |
|---|
| 75 | #define bapp_util_strcmp(str1,str2) strcmp((const char*)str1,(const char*)str2) |
|---|
| 76 | #define bapp_util_sleep BKNI_Sleep |
|---|
| 77 | |
|---|
| 78 | #define BAPP_UNUSED(x) ((void)x) |
|---|
| 79 | |
|---|
| 80 | #define BAPP_TICKS_PER_SECOND g_ticks_per_second |
|---|
| 81 | |
|---|
| 82 | |
|---|
| 83 | typedef void (*get_str_t)(void *p_app, |
|---|
| 84 | void *p_screen, |
|---|
| 85 | int text_id, /* Text id */ |
|---|
| 86 | unsigned int *p_uni_str, /* Buffer to put UNI string into */ |
|---|
| 87 | unsigned int *str_len, /* On input the max length in words on output the actual size in characters. */ |
|---|
| 88 | void *data /* User data */ |
|---|
| 89 | ); |
|---|
| 90 | |
|---|
| 91 | |
|---|
| 92 | /** |
|---|
| 93 | Summary: |
|---|
| 94 | Get ticks used to establish time deltas in the applicaiton. |
|---|
| 95 | **/ |
|---|
| 96 | |
|---|
| 97 | #define bapp_util_get_ticks bapp_task_getticks |
|---|
| 98 | #define bapp_util_getticks bapp_task_getticks |
|---|
| 99 | |
|---|
| 100 | |
|---|
| 101 | /** |
|---|
| 102 | Summary: |
|---|
| 103 | Convert string to int value |
|---|
| 104 | **/ |
|---|
| 105 | int bapp_util_atoi(unsigned char *str_p, int bytes); |
|---|
| 106 | |
|---|
| 107 | |
|---|
| 108 | int timeval_subtract (b_timeval *result, b_timeval *x, b_timeval *y); |
|---|
| 109 | |
|---|
| 110 | bool get_utc_time(unsigned int *time); |
|---|
| 111 | bool get_local_time(unsigned int *utc_secs); |
|---|
| 112 | bool get_mac_address(unsigned char *hw_address); |
|---|
| 113 | bool get_hw_address(unsigned char *hw_address); |
|---|
| 114 | char *get_unit_address_str(void); |
|---|
| 115 | #define text_box(surf,font,x,y,w,h,msg,len,c,lspace) \ |
|---|
| 116 | bgfx_draw_text_box(surf,x,y,w,h,(const unsigned long*)msg,len,font,c,lspace) |
|---|
| 117 | /* |
|---|
| 118 | Summary: |
|---|
| 119 | Same as text box but with shadow. |
|---|
| 120 | Description: |
|---|
| 121 | Same as text box but with shadow. |
|---|
| 122 | */ |
|---|
| 123 | int text_box_shadow(bgfx_surf_t *p_surf, /* bgfx surface */ |
|---|
| 124 | bgfx_font_t *font, /* bgfx font */ |
|---|
| 125 | uint16_t x, /* x location in pixels */ |
|---|
| 126 | uint16_t y, /* y location in pixels */ |
|---|
| 127 | uint16_t width, /* width in pixels */ |
|---|
| 128 | uint16_t height, /* height in pixels */ |
|---|
| 129 | unsigned int *msg, /* UNI string */ |
|---|
| 130 | unsigned int msg_len, /* Number of characters in the msg */ |
|---|
| 131 | bgfx_pixel c_f, /* palette index for forground text*/ |
|---|
| 132 | bgfx_pixel c_b, /* palette index for background text */ |
|---|
| 133 | int shadow_offset, /* offset from xy to place shaddow (can be negative) */ |
|---|
| 134 | int line_spacing /* number of vertical pixels between lines */ |
|---|
| 135 | ); |
|---|
| 136 | |
|---|
| 137 | /* |
|---|
| 138 | Summary: |
|---|
| 139 | Draw a button. |
|---|
| 140 | Description: |
|---|
| 141 | Draw a button. |
|---|
| 142 | */ |
|---|
| 143 | void draw_button(bgfx_surf_t *p_surf, /* bgfx surface */ |
|---|
| 144 | bgfx_font_t *font, /* bgfx font */ |
|---|
| 145 | uint16_t x, /* x location in pixels */ |
|---|
| 146 | uint16_t y, /* y location in pixels */ |
|---|
| 147 | uint16_t width, /* width in pixels */ |
|---|
| 148 | uint16_t height, /* height in pixels */ |
|---|
| 149 | unsigned int *msg, /* UNI string */ |
|---|
| 150 | unsigned int msg_len, /* Number of characters in the msg */ |
|---|
| 151 | int state, /* button state, 1 - on, 0 - off */ |
|---|
| 152 | int type /* button type, 1 - check box, 0 - menu */ |
|---|
| 153 | ); |
|---|
| 154 | |
|---|
| 155 | /* |
|---|
| 156 | Summary: |
|---|
| 157 | Perform a "hard" chip reset if possible. |
|---|
| 158 | */ |
|---|
| 159 | void chip_reset(void); |
|---|
| 160 | |
|---|
| 161 | |
|---|
| 162 | /** |
|---|
| 163 | Summary: |
|---|
| 164 | parse the mso string looking for a delimiter and return true if successful |
|---|
| 165 | */ |
|---|
| 166 | void parse_mso_str(char *pMSO, /* MSO string from EMM phone # field */ |
|---|
| 167 | char *pServiceInterrupted, /* allocated buffer to return service interrupted string in */ |
|---|
| 168 | char *pActivationSupport, /* allocated buffer to return activation support string in */ |
|---|
| 169 | int max_len /* size of each buffer */ |
|---|
| 170 | ); |
|---|
| 171 | |
|---|
| 172 | |
|---|
| 173 | typedef struct timing_profile_t { |
|---|
| 174 | uint32_t min; /* minimal */ |
|---|
| 175 | uint32_t ave; /* average */ |
|---|
| 176 | uint32_t max; /* maximum */ |
|---|
| 177 | uint32_t diff; /* last time */ |
|---|
| 178 | uint32_t total; /* total */ |
|---|
| 179 | uint32_t cnt; /* cnt */ |
|---|
| 180 | bool in_use; /* in use flag */ |
|---|
| 181 | char name[8]; /* name */ |
|---|
| 182 | uint32_t cur_ticks; /* current ticks */ |
|---|
| 183 | } timing_profile_t, *p_timing_profile_t; |
|---|
| 184 | |
|---|
| 185 | /** |
|---|
| 186 | Summary: |
|---|
| 187 | initialize timing structure to use |
|---|
| 188 | |
|---|
| 189 | true if OK |
|---|
| 190 | false otherwise |
|---|
| 191 | */ |
|---|
| 192 | bool timing_profile_init(void); |
|---|
| 193 | |
|---|
| 194 | /** |
|---|
| 195 | Summary: |
|---|
| 196 | uninitialize timing structure used |
|---|
| 197 | |
|---|
| 198 | true if OK |
|---|
| 199 | false otherwise |
|---|
| 200 | */ |
|---|
| 201 | bool timing_profile_uninit(void); |
|---|
| 202 | |
|---|
| 203 | /** |
|---|
| 204 | Summary: |
|---|
| 205 | get timing profile object |
|---|
| 206 | |
|---|
| 207 | return NULL if all timing profile resources are used |
|---|
| 208 | pointer to a timing profile resource to use |
|---|
| 209 | */ |
|---|
| 210 | p_timing_profile_t timing_profile_get(char *name); |
|---|
| 211 | |
|---|
| 212 | /** |
|---|
| 213 | Summary: |
|---|
| 214 | reset timing profile object |
|---|
| 215 | |
|---|
| 216 | true if OK |
|---|
| 217 | false otherwise |
|---|
| 218 | */ |
|---|
| 219 | bool timing_profile_reset(p_timing_profile_t ptp); |
|---|
| 220 | |
|---|
| 221 | /** |
|---|
| 222 | Summary: |
|---|
| 223 | start timing profile |
|---|
| 224 | |
|---|
| 225 | true if OK |
|---|
| 226 | false otherwise |
|---|
| 227 | */ |
|---|
| 228 | bool timing_profile_start(p_timing_profile_t ptp); |
|---|
| 229 | |
|---|
| 230 | /** |
|---|
| 231 | Summary: |
|---|
| 232 | stop timing profiling |
|---|
| 233 | |
|---|
| 234 | true if OK |
|---|
| 235 | false otherwise |
|---|
| 236 | */ |
|---|
| 237 | bool timing_profile_stop(p_timing_profile_t ptp); |
|---|
| 238 | |
|---|
| 239 | /** |
|---|
| 240 | Summary: |
|---|
| 241 | print timing profile information |
|---|
| 242 | |
|---|
| 243 | true if OK |
|---|
| 244 | false otherwise |
|---|
| 245 | */ |
|---|
| 246 | bool timing_profile_print(p_timing_profile_t ptp); |
|---|
| 247 | |
|---|
| 248 | /* |
|---|
| 249 | Summary: |
|---|
| 250 | Profiling utility start profiling. |
|---|
| 251 | */ |
|---|
| 252 | void bapp_util_start_profiling(void); |
|---|
| 253 | /* |
|---|
| 254 | Summary: |
|---|
| 255 | Profiling utility stop profiling. |
|---|
| 256 | */ |
|---|
| 257 | void bapp_util_stop_profiling(void); |
|---|
| 258 | |
|---|
| 259 | #endif /* BAPP_UTIL_H__ */ |
|---|