| 1 | /****************************************************************************** |
|---|
| 2 | * (c)2008-2010 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 | * $brcm_Log: $ |
|---|
| 47 | * |
|---|
| 48 | *****************************************************************************/ |
|---|
| 49 | #include "nexus_msg.h" |
|---|
| 50 | #include "nexus_platform.h" |
|---|
| 51 | #include "nexus_pid_channel.h" |
|---|
| 52 | #include "nexus_parser_band.h" |
|---|
| 53 | #include "nexus_message.h" |
|---|
| 54 | #include "ministd.h" |
|---|
| 55 | |
|---|
| 56 | #include "bstd.h" |
|---|
| 57 | #include "bkni.h" |
|---|
| 58 | BDBG_MODULE(nexus_msg); |
|---|
| 59 | #define NEXUS_MSG_STK_SIZE 1024 |
|---|
| 60 | typedef struct nexus_p_msg_t |
|---|
| 61 | { |
|---|
| 62 | b_task_t task_h; |
|---|
| 63 | unsigned short pid; |
|---|
| 64 | unsigned char name[64]; |
|---|
| 65 | unsigned int stack[NEXUS_MSG_STK_SIZE]; |
|---|
| 66 | }nexus_p_msg_t; |
|---|
| 67 | |
|---|
| 68 | void message_callback(void *context, int param) |
|---|
| 69 | { |
|---|
| 70 | BSTD_UNUSED(param); |
|---|
| 71 | BKNI_SetEvent((BKNI_EventHandle)context); |
|---|
| 72 | } |
|---|
| 73 | #if 1 |
|---|
| 74 | void msg_main(void *data) |
|---|
| 75 | { |
|---|
| 76 | NEXUS_PidChannelHandle pidChannel; |
|---|
| 77 | NEXUS_MessageHandle msg; |
|---|
| 78 | NEXUS_MessageSettings settings; |
|---|
| 79 | NEXUS_MessageStartSettings startSettings; |
|---|
| 80 | NEXUS_ParserBandSettings parserBandSettings; |
|---|
| 81 | NEXUS_PidChannelSettings pidChannelSettings; |
|---|
| 82 | BKNI_EventHandle event; |
|---|
| 83 | NEXUS_Error rc; |
|---|
| 84 | nexus_p_msg_t *p_msg = (nexus_p_msg_t*)data; |
|---|
| 85 | BDBG_ERR(("Start filter for PID[0x%04x]\n",p_msg->pid)); |
|---|
| 86 | |
|---|
| 87 | NEXUS_PidChannel_GetDefaultSettings(&pidChannelSettings); |
|---|
| 88 | pidChannel = NEXUS_PidChannel_Open(NEXUS_ParserBand_e0, p_msg->pid, &pidChannelSettings); |
|---|
| 89 | |
|---|
| 90 | BKNI_CreateEvent(&event); |
|---|
| 91 | |
|---|
| 92 | NEXUS_Message_GetDefaultSettings(&settings); |
|---|
| 93 | settings.dataReady.callback = message_callback; |
|---|
| 94 | settings.dataReady.context = event; |
|---|
| 95 | //settings.maxContiguousMessageSize = 4096; |
|---|
| 96 | msg = NEXUS_Message_Open(&settings); |
|---|
| 97 | BDBG_ASSERT(msg); |
|---|
| 98 | |
|---|
| 99 | NEXUS_Message_GetDefaultStartSettings(msg, &startSettings); |
|---|
| 100 | startSettings.pidChannel = pidChannel; |
|---|
| 101 | /* use the default filter for any data */ |
|---|
| 102 | |
|---|
| 103 | |
|---|
| 104 | /* Read the PAT a few times */ |
|---|
| 105 | while (1) |
|---|
| 106 | { |
|---|
| 107 | const uint8_t *buffer; |
|---|
| 108 | size_t size; |
|---|
| 109 | int message_length; |
|---|
| 110 | rc = NEXUS_Message_Start(msg, &startSettings); |
|---|
| 111 | BDBG_ASSERT(!rc); |
|---|
| 112 | |
|---|
| 113 | rc = NEXUS_Message_GetBuffer(msg, (const void **)&buffer, &size); |
|---|
| 114 | BDBG_ASSERT(!rc); |
|---|
| 115 | if (!size) |
|---|
| 116 | { |
|---|
| 117 | BERR_Code rc = BKNI_WaitForEvent(event, 5 * 1000); /* wait 5 seconds */ |
|---|
| 118 | if (rc) |
|---|
| 119 | { |
|---|
| 120 | BDBG_ERR(("Timeout waiting for section[0x%04x]\n",p_msg->pid)); |
|---|
| 121 | } |
|---|
| 122 | NEXUS_Message_Stop(msg); |
|---|
| 123 | continue; |
|---|
| 124 | } |
|---|
| 125 | |
|---|
| 126 | #define TS_READ_16( BUF ) ((uint16_t)((BUF)[0]<<8|(BUF)[1])) |
|---|
| 127 | #define TS_PSI_GET_SECTION_LENGTH( BUF ) (uint16_t)(TS_READ_16( &(BUF)[1] ) & 0x0FFF) |
|---|
| 128 | |
|---|
| 129 | /* We should always get whole PAT's because maxContiguousMessageSize is 4K */ |
|---|
| 130 | message_length = TS_PSI_GET_SECTION_LENGTH(buffer) + 3; |
|---|
| 131 | |
|---|
| 132 | /* XPT HW is configured to pad all messages to 4 bytes. If we are calling NEXUS_Message_ReadComplete |
|---|
| 133 | based on message length and not the size returned by NEXUS_Message_GetBuffer, then we must add that pad. |
|---|
| 134 | If we are wrong, NEXUS_Message_ReadComplete will fail. */ |
|---|
| 135 | if (message_length % 4) |
|---|
| 136 | { |
|---|
| 137 | message_length += 4 - (message_length % 4); |
|---|
| 138 | } |
|---|
| 139 | if (size < (size_t)message_length) |
|---|
| 140 | { |
|---|
| 141 | BDBG_ERR(("Invalid Section Length[0x%04x](size %d < msg_length %d)\n",p_msg->pid,size,(size_t)message_length)); |
|---|
| 142 | } |
|---|
| 143 | |
|---|
| 144 | // printf("Found Section[0x%04x]: id=%d size=%d\n", p_msg->pid, buffer[0], message_length); |
|---|
| 145 | |
|---|
| 146 | /* only complete one PAT */ |
|---|
| 147 | rc = NEXUS_Message_ReadComplete(msg, size); |
|---|
| 148 | BDBG_ASSERT(!rc); |
|---|
| 149 | NEXUS_Message_Stop(msg); |
|---|
| 150 | // bos_sleep(10); |
|---|
| 151 | } |
|---|
| 152 | |
|---|
| 153 | NEXUS_Message_Stop(msg); |
|---|
| 154 | NEXUS_Message_Close(msg); |
|---|
| 155 | NEXUS_PidChannel_Close(pidChannel); |
|---|
| 156 | |
|---|
| 157 | NEXUS_Platform_Uninit(); |
|---|
| 158 | return; |
|---|
| 159 | } |
|---|
| 160 | |
|---|
| 161 | #else |
|---|
| 162 | void msg_main(void *data) |
|---|
| 163 | { |
|---|
| 164 | NEXUS_PidChannelHandle pidChannel; |
|---|
| 165 | NEXUS_MessageHandle msg; |
|---|
| 166 | NEXUS_MessageSettings settings; |
|---|
| 167 | NEXUS_MessageStartSettings startSettings; |
|---|
| 168 | NEXUS_ParserBandSettings parserBandSettings; |
|---|
| 169 | NEXUS_PidChannelSettings pidChannelSettings; |
|---|
| 170 | BKNI_EventHandle event; |
|---|
| 171 | NEXUS_Error rc; |
|---|
| 172 | nexus_p_msg_t *p_msg = (nexus_p_msg_t*)data; |
|---|
| 173 | BDBG_ERR(("Start filter for PID[0x%04x]\n",p_msg->pid)); |
|---|
| 174 | |
|---|
| 175 | NEXUS_PidChannel_GetDefaultSettings(&pidChannelSettings); |
|---|
| 176 | pidChannel = NEXUS_PidChannel_Open(NEXUS_ParserBand_e0, p_msg->pid, &pidChannelSettings); |
|---|
| 177 | |
|---|
| 178 | BKNI_CreateEvent(&event); |
|---|
| 179 | |
|---|
| 180 | NEXUS_Message_GetDefaultSettings(&settings); |
|---|
| 181 | settings.dataReady.callback = message_callback; |
|---|
| 182 | settings.dataReady.context = event; |
|---|
| 183 | settings.maxContiguousMessageSize = 4096; |
|---|
| 184 | msg = NEXUS_Message_Open(&settings); |
|---|
| 185 | BDBG_ASSERT(msg); |
|---|
| 186 | |
|---|
| 187 | NEXUS_Message_GetDefaultStartSettings(msg, &startSettings); |
|---|
| 188 | startSettings.pidChannel = pidChannel; |
|---|
| 189 | /* use the default filter for any data */ |
|---|
| 190 | |
|---|
| 191 | rc = NEXUS_Message_Start(msg, &startSettings); |
|---|
| 192 | BDBG_ASSERT(!rc); |
|---|
| 193 | |
|---|
| 194 | /* Read the PAT a few times */ |
|---|
| 195 | while (1) |
|---|
| 196 | { |
|---|
| 197 | const uint8_t *buffer; |
|---|
| 198 | size_t size; |
|---|
| 199 | int message_length; |
|---|
| 200 | |
|---|
| 201 | rc = NEXUS_Message_GetBuffer(msg, (const void **)&buffer, &size); |
|---|
| 202 | BDBG_ASSERT(!rc); |
|---|
| 203 | if (!size) |
|---|
| 204 | { |
|---|
| 205 | BERR_Code rc = BKNI_WaitForEvent(event, 5 * 1000); /* wait 5 seconds */ |
|---|
| 206 | if (rc) |
|---|
| 207 | { |
|---|
| 208 | BDBG_ERR(("Timeout waiting for section[0x%04x]\n",p_msg->pid)); |
|---|
| 209 | } |
|---|
| 210 | continue; |
|---|
| 211 | } |
|---|
| 212 | |
|---|
| 213 | #define TS_READ_16( BUF ) ((uint16_t)((BUF)[0]<<8|(BUF)[1])) |
|---|
| 214 | #define TS_PSI_GET_SECTION_LENGTH( BUF ) (uint16_t)(TS_READ_16( &(BUF)[1] ) & 0x0FFF) |
|---|
| 215 | |
|---|
| 216 | /* We should always get whole PAT's because maxContiguousMessageSize is 4K */ |
|---|
| 217 | message_length = TS_PSI_GET_SECTION_LENGTH(buffer) + 3; |
|---|
| 218 | |
|---|
| 219 | /* XPT HW is configured to pad all messages to 4 bytes. If we are calling NEXUS_Message_ReadComplete |
|---|
| 220 | based on message length and not the size returned by NEXUS_Message_GetBuffer, then we must add that pad. |
|---|
| 221 | If we are wrong, NEXUS_Message_ReadComplete will fail. */ |
|---|
| 222 | if (message_length % 4) |
|---|
| 223 | { |
|---|
| 224 | message_length += 4 - (message_length % 4); |
|---|
| 225 | } |
|---|
| 226 | if (size < (size_t)message_length) |
|---|
| 227 | { |
|---|
| 228 | BDBG_ERR(("Invalid Section Length[0x%04x](size %d < msg_length %d)\n",p_msg->pid,size,(size_t)message_length)); |
|---|
| 229 | } |
|---|
| 230 | |
|---|
| 231 | // printf("Found Section[0x%04x]: id=%d size=%d\n", p_msg->pid, buffer[0], message_length); |
|---|
| 232 | |
|---|
| 233 | /* only complete one PAT */ |
|---|
| 234 | rc = NEXUS_Message_ReadComplete(msg, size); |
|---|
| 235 | BDBG_ASSERT(!rc); |
|---|
| 236 | // bos_sleep(10); |
|---|
| 237 | } |
|---|
| 238 | |
|---|
| 239 | NEXUS_Message_Stop(msg); |
|---|
| 240 | NEXUS_Message_Close(msg); |
|---|
| 241 | NEXUS_PidChannel_Close(pidChannel); |
|---|
| 242 | |
|---|
| 243 | NEXUS_Platform_Uninit(); |
|---|
| 244 | return; |
|---|
| 245 | } |
|---|
| 246 | #endif |
|---|
| 247 | static int s_msg_thread_cnt = 0; |
|---|
| 248 | int nexus_msg_start(unsigned short pid) |
|---|
| 249 | { |
|---|
| 250 | b_task_params task_params; |
|---|
| 251 | |
|---|
| 252 | nexus_p_msg_t *p_msg = (nexus_p_msg_t*)malloc(sizeof(nexus_p_msg_t)); |
|---|
| 253 | |
|---|
| 254 | BDBG_ASSERT(p_msg); |
|---|
| 255 | p_msg->pid = pid; |
|---|
| 256 | snprintf(p_msg->name,64,"nexus_msg_%d",pid); |
|---|
| 257 | task_params.name=p_msg->name; |
|---|
| 258 | task_params.priority = 60 + s_msg_thread_cnt++; |
|---|
| 259 | task_params.stack_size = NEXUS_MSG_STK_SIZE; |
|---|
| 260 | task_params.stack = p_msg->stack; |
|---|
| 261 | |
|---|
| 262 | bos_start_task(&(p_msg->task_h), &task_params, msg_main,p_msg); |
|---|
| 263 | } |
|---|
| 264 | |
|---|