| 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 <stdio.h> |
|---|
| 58 | #include <string.h> |
|---|
| 59 | #include "bapp_task.h" |
|---|
| 60 | #include "bgfx.h" |
|---|
| 61 | #ifndef LINUX |
|---|
| 62 | #define GETTIMEOFDAY(tv) gettimeofday(tv) |
|---|
| 63 | #else |
|---|
| 64 | #include <sys/time.h> |
|---|
| 65 | #define GETTIMEOFDAY(tv) gettimeofday(tv,NULL) |
|---|
| 66 | #endif |
|---|
| 67 | |
|---|
| 68 | #define bapp_util_malloc BKNI_Malloc |
|---|
| 69 | #define bapp_util_free BKNI_Free |
|---|
| 70 | #define bapp_util_memset BKNI_Memset |
|---|
| 71 | #define bapp_util_memcpy BKNI_Memcpy |
|---|
| 72 | #define bapp_util_strlen(x) strlen((const char*)x) |
|---|
| 73 | #define bapp_util_strcpy(dst,src) strcpy((char*)dst,(const char*)src) |
|---|
| 74 | #define bapp_util_strcmp(str1,str2) strcmp((const char*)str1,(const char*)str2) |
|---|
| 75 | #define bapp_util_sleep BKNI_Sleep |
|---|
| 76 | |
|---|
| 77 | #define BAPP_UNUSED(x) ((void)x) |
|---|
| 78 | |
|---|
| 79 | #define BAPP_TICKS_PER_SECOND g_ticks_per_second |
|---|
| 80 | |
|---|
| 81 | typedef struct bin_read_t |
|---|
| 82 | { |
|---|
| 83 | unsigned char *data; |
|---|
| 84 | unsigned int size; |
|---|
| 85 | unsigned int cnt; |
|---|
| 86 | }bin_read_t; |
|---|
| 87 | |
|---|
| 88 | /* |
|---|
| 89 | Summary: |
|---|
| 90 | Utility IO function. |
|---|
| 91 | Description: |
|---|
| 92 | Utility IO function to be used for pseudo IO. |
|---|
| 93 | */ |
|---|
| 94 | |
|---|
| 95 | int bin_read( void *buffer, int size, int count, void *fp ); |
|---|
| 96 | int bin_set(void *fp, int offset, int whence ); |
|---|
| 97 | unsigned int bin_tell(void *fp ); |
|---|
| 98 | |
|---|
| 99 | |
|---|
| 100 | /** |
|---|
| 101 | Summary: |
|---|
| 102 | Get ticks used to establish time deltas in the applicaiton. |
|---|
| 103 | **/ |
|---|
| 104 | |
|---|
| 105 | #define bapp_util_get_ticks bapp_task_getticks |
|---|
| 106 | #define bapp_util_getticks bapp_task_getticks |
|---|
| 107 | |
|---|
| 108 | |
|---|
| 109 | /** |
|---|
| 110 | Summary: |
|---|
| 111 | Convert string to int value |
|---|
| 112 | **/ |
|---|
| 113 | int bapp_util_atoi(unsigned char *str_p, int bytes); |
|---|
| 114 | |
|---|
| 115 | |
|---|
| 116 | int timeval_subtract (struct timeval *result, struct timeval *x, struct timeval *y); |
|---|
| 117 | |
|---|
| 118 | bool get_utc_time(unsigned int *time); |
|---|
| 119 | bool get_local_time(unsigned int *utc_secs); |
|---|
| 120 | bool get_mac_address(unsigned char *hw_address); |
|---|
| 121 | bool get_hw_address(unsigned char *hw_address); |
|---|
| 122 | char *get_unit_address_str(void); |
|---|
| 123 | #define text_box(surf,font,x,y,w,h,msg,len,c,lspace) \ |
|---|
| 124 | bgfx_draw_text_box(surf,x,y,w,h,(const unsigned long*)msg,len,font,c,lspace) |
|---|
| 125 | /* |
|---|
| 126 | Summary: |
|---|
| 127 | Same as text box but with shadow. |
|---|
| 128 | Description: |
|---|
| 129 | Same as text box but with shadow. |
|---|
| 130 | */ |
|---|
| 131 | int text_box_shadow(bgfx_surf_t *p_surf, /* bgfx surface */ |
|---|
| 132 | bgfx_font_t *font, /* bgfx font */ |
|---|
| 133 | uint16_t x, /* x location in pixels */ |
|---|
| 134 | uint16_t y, /* y location in pixels */ |
|---|
| 135 | uint16_t width, /* width in pixels */ |
|---|
| 136 | uint16_t height, /* height in pixels */ |
|---|
| 137 | unsigned int *msg, /* UNI string */ |
|---|
| 138 | unsigned int msg_len, /* Number of characters in the msg */ |
|---|
| 139 | bgfx_pixel c_f, /* palette index for forground text*/ |
|---|
| 140 | bgfx_pixel c_b, /* palette index for background text */ |
|---|
| 141 | int shadow_offset, /* offset from xy to place shaddow (can be negative) */ |
|---|
| 142 | int line_spacing /* number of vertical pixels between lines */ |
|---|
| 143 | ); |
|---|
| 144 | |
|---|
| 145 | /* |
|---|
| 146 | Summary: |
|---|
| 147 | Draw a button. |
|---|
| 148 | Description: |
|---|
| 149 | Draw a button. |
|---|
| 150 | */ |
|---|
| 151 | void draw_button(bgfx_surf_t *p_surf, /* bgfx surface */ |
|---|
| 152 | bgfx_font_t *font, /* bgfx font */ |
|---|
| 153 | uint16_t x, /* x location in pixels */ |
|---|
| 154 | uint16_t y, /* y location in pixels */ |
|---|
| 155 | uint16_t width, /* width in pixels */ |
|---|
| 156 | uint16_t height, /* height in pixels */ |
|---|
| 157 | unsigned int *msg, /* UNI string */ |
|---|
| 158 | unsigned int msg_len, /* Number of characters in the msg */ |
|---|
| 159 | int state, /* button state, 1 - on, 0 - off */ |
|---|
| 160 | int type /* button type, 1 - check box, 0 - menu */ |
|---|
| 161 | ); |
|---|
| 162 | |
|---|
| 163 | /* |
|---|
| 164 | Summary: |
|---|
| 165 | Perform a "hard" chip reset if possible. |
|---|
| 166 | */ |
|---|
| 167 | void chip_reset(void); |
|---|
| 168 | struct utc_tm |
|---|
| 169 | { |
|---|
| 170 | int tm_sec; /* Seconds. [0-60] (1 leap second) */ |
|---|
| 171 | int tm_min; /* Minutes. [0-59] */ |
|---|
| 172 | int tm_hour; /* Hours. [0-23] */ |
|---|
| 173 | int tm_mday; /* Day. [1-31] */ |
|---|
| 174 | int tm_mon; /* Month. [0-11] */ |
|---|
| 175 | int tm_year; /* Year - 1980. */ |
|---|
| 176 | int tm_wday; /* Day of week. [0-6] */ |
|---|
| 177 | int tm_yday; /* Days in year.[0-365] */ |
|---|
| 178 | }; |
|---|
| 179 | |
|---|
| 180 | |
|---|
| 181 | void utctime(unsigned int secs,struct utc_tm *p_tm); |
|---|
| 182 | |
|---|
| 183 | |
|---|
| 184 | #endif /* BAPP_UTIL_H__ */ |
|---|