source: svn/trunk/newcon3bcm2_21bu/magnum/basemodules/hab/3461/bhab_3461_priv.c

Last change on this file was 2, checked in by phkim, 11 years ago

1.phkim

  1. revision copy newcon3sk r27
  • Property svn:executable set to *
File size: 43.2 KB
Line 
1/***************************************************************************
2 *     Copyright (c) 2005-2011, Broadcom Corporation
3 *     All Rights Reserved
4 *     Confidential Property of Broadcom Corporation
5 *
6 *  THIS SOFTWARE MAY ONLY BE USED SUBJECT TO AN EXECUTED SOFTWARE LICENSE
7 *  AGREEMENT  BETWEEN THE USER AND BROADCOM.  YOU HAVE NO RIGHT TO USE OR
8 *  EXPLOIT THIS MATERIAL EXCEPT SUBJECT TO THE TERMS OF SUCH AN AGREEMENT.
9 *
10 * $brcm_Workfile: bhab_3461_priv.c $
11 * $brcm_Revision: Hydra_Software_Devel/9 $
12 * $brcm_Date: 6/5/11 8:41p $
13 *
14 * [File Description:]
15 *
16 * Revision History:
17 *
18 * $brcm_Log: /magnum/basemodules/hab/3461/bhab_3461_priv.c $
19 *
20 * Hydra_Software_Devel/9   6/5/11 8:41p vishk
21 * SW3461-3: Add PI Support for BCM3461
22 *
23 * Hydra_Software_Devel/8   6/5/11 8:37p vishk
24 * SW3461-3: Add PI Support for BCM3461
25 *
26 * Hydra_Software_Devel/7   6/5/11 8:21p vishk
27 * SW3461-3: Add PI Support for BCM3461
28 *
29 * Hydra_Software_Devel/6   6/1/11 3:44p atanugul
30 * SW3461-5: Add THD support to 3461
31 *
32 * Hydra_Software_Devel/5   5/27/11 4:28p atanugul
33 * SW3461-3: Added BHAB_GetConfigSettings() and BHAB_SetConfigSettings()
34 *
35 * Hydra_Software_Devel/4   4/19/11 12:33p atanugul
36 * SW3461-3: Implement BTNR_SetSettings(), Powermode for 3461 TNR and
37 * update BHAB_3461_P_DecodeInterrupt()
38 *
39 * Hydra_Software_Devel/3   3/31/11 11:25a atanugul
40 * SW3461-3: Update GetStatus, DecodeInterrupt and code cleanup
41 *
42 * Hydra_Software_Devel/2   3/17/11 1:16p vishk
43 * SW7231-32: Implement the Nexus code to support the 3461 frontend chip
44 *
45 * Hydra_Software_Devel/1   3/16/11 3:33p atanugul
46 * SW3461-3: Add support for BCM3461
47 *
48 *
49 ***************************************************************************/
50#include "bhab_3461_priv.h"
51#include "bhab_3461_bbsi.h"
52#include "bchp_leap_ctrl.h"
53#include "bchp_leap_hab_mem.h"
54
55
56BDBG_MODULE(bhab_3461_priv);
57
58/******************************************************************************
59 BHAB_3461_Open()
60******************************************************************************/
61BERR_Code BHAB_3461_Open(
62    BHAB_Handle *handle,     /* [out] BHAB handle */
63    void        *pReg,       /* [in] pointer ot i2c or spi handle */
64    const BHAB_Settings *pDefSettings /* [in] Default Settings */
65)
66{
67    BERR_Code retCode = BERR_SUCCESS;
68    BHAB_Handle hDev;
69    BHAB_3461_P_Handle *h3461Dev;
70    unsigned i;
71
72    BDBG_ASSERT(pDefSettings->interruptEnableFunc);
73
74    hDev = (BHAB_Handle)BKNI_Malloc(sizeof(BHAB_P_Handle));
75    BDBG_ASSERT(hDev);
76    h3461Dev = (BHAB_3461_P_Handle *)BKNI_Malloc(sizeof(BHAB_3461_P_Handle));
77    BDBG_ASSERT(h3461Dev);
78    BKNI_Memset( h3461Dev, 0x00, sizeof(BHAB_3461_P_Handle));
79    hDev->pImpl = (void*)h3461Dev;
80   
81    h3461Dev->hRegister = (BREG_I2C_Handle)pReg;
82    BKNI_Memcpy((void*)(&(hDev->settings)), (void*)pDefSettings, sizeof(BHAB_Settings));
83   
84    /* create events */
85    BHAB_CHK_RETCODE(BKNI_CreateEvent(&(h3461Dev->hInterruptEvent)));
86    BHAB_CHK_RETCODE(BKNI_CreateEvent(&(h3461Dev->hApiEvent)));
87    BHAB_CHK_RETCODE(BKNI_CreateEvent(&(h3461Dev->hInitDoneEvent)));
88    BHAB_CHK_RETCODE(BKNI_CreateEvent(&(h3461Dev->hHabDoneEvent)));
89    BHAB_CHK_RETCODE(BKNI_CreateMutex(&(h3461Dev->hMutex)));
90
91    for(i=0; i<BHAB_DevId_eMax; i++){
92        h3461Dev->InterruptCallbackInfo[i].func = NULL;
93        h3461Dev->InterruptCallbackInfo[i].pParm1 = NULL;
94        h3461Dev->InterruptCallbackInfo[i].parm2 = (int)NULL;
95    }
96
97    BKNI_Memset( &h3461Dev->nmiSettings, 0x00, sizeof(BHAB_NmiSettings));
98    BKNI_Memset( &h3461Dev->wdtSettings, 0x00, sizeof(BHAB_WatchDogTimerSettings));
99
100    retCode = BHAB_3461_P_DisableInterrupts(hDev);
101
102done:
103    *handle = hDev;
104
105    return retCode;
106}
107
108
109/******************************************************************************
110 BHAB_3461_Close()
111******************************************************************************/
112BERR_Code BHAB_3461_Close(BHAB_Handle handle)
113{
114    BERR_Code retCode = BERR_SUCCESS;
115    BHAB_3461_P_Handle *p3461 = (BHAB_3461_P_Handle *)(handle->pImpl);
116    uint32_t sb, buf;
117   
118    BDBG_ASSERT(handle);
119
120    /* If we didn't load the AP when starting, don't reset it when closing */
121    if (p3461->loadAP)
122    {   
123        /* reset the AP */
124        sb = 0x01;
125        BHAB_CHK_RETCODE(BHAB_3461_WriteRegister(handle, BCHP_LEAP_CTRL_CTRL, &sb));
126       
127        /* reset all interrupt status */
128        buf = 0;
129        BHAB_CHK_RETCODE(BHAB_3461_WriteRegister(handle, BCHP_LEAP_CTRL_HOST_IRQ, &buf));
130        BHAB_CHK_RETCODE(BHAB_3461_WriteRegister(handle, BCHP_LEAP_CTRL_SPARE, &buf));
131    }
132
133    retCode = BHAB_3461_P_DisableInterrupts(handle);
134done:
135    if (p3461->hInterruptEvent) {BKNI_DestroyEvent(p3461->hInterruptEvent);}
136    if (p3461->hApiEvent){BKNI_DestroyEvent(p3461->hApiEvent);}
137    if (p3461->hInitDoneEvent){BKNI_DestroyEvent(p3461->hInitDoneEvent);}
138    if (p3461->hHabDoneEvent){BKNI_DestroyEvent(p3461->hHabDoneEvent);}
139    if (p3461->hMutex){BKNI_DestroyMutex(p3461->hMutex);}
140
141    BKNI_Free((void*)p3461);
142    BKNI_Free((void*)handle);
143
144    return retCode;
145}
146
147
148/******************************************************************************
149 BHAB_3461_P_InitAp()
150******************************************************************************/
151BERR_Code BHAB_3461_InitAp(
152    BHAB_Handle handle,       /* [in] BHAB handle */
153    const uint8_t *pHexImage  /* [in] pointer to BCM3461 microcode image */
154)
155{
156    BERR_Code retCode = BERR_SUCCESS;
157    BHAB_3461_P_Handle *p3461 = (BHAB_3461_P_Handle *)(handle->pImpl);
158    uint32_t n, instlen, datalen, instaddr, dataaddr;
159    const uint8_t *pImage;
160    uint8_t retries, count=0;
161
162    /* We are loading AP code, it is appropriate to reset the AP when closing */
163    p3461->loadAP = true;
164
165    /* Disable host interrupt */   
166    BHAB_CHK_RETCODE(BHAB_3461_P_EnableHostInterrupt(handle, false));
167
168    /* reset the AP before downloading the microcode */
169    BHAB_CHK_RETCODE(BHAB_3461_P_ResetAp(handle));
170
171    if (pHexImage)
172    {
173        /* download to RAM */
174        pImage = pHexImage;
175
176        instlen = (pImage[10] << 16) | (pImage[11] << 8) | pImage[12];
177        datalen = (pImage[16] << 16) | (pImage[17] << 8) | pImage[18];
178        n = instlen + datalen;
179        if (n != 0)
180        {
181            instaddr = (pImage[7] << 16) | (pImage[8] << 8) | pImage[9];
182            dataaddr = (pImage[13] << 16) | (pImage[14] << 8) | pImage[15];
183           
184            for (retries = 0; retries < 3; retries++)
185            {
186                BHAB_CHK_RETCODE(BHAB_3461_WriteMemory(handle, instaddr, &pImage[19], instlen));           
187                /*BHAB_CHK_RETCODE(BHAB_3461_WriteMemory(handle, dataaddr, &pImage[19 + instlen] , datalen)); */               
188                break;           
189            }
190
191            if (retries == 3)
192                return(BERR_OS_ERROR);
193        }
194
195    }
196    /* enable init done interrupt */
197    BHAB_CHK_RETCODE(BHAB_3461_P_EnableInitDoneInterrupt(handle));
198
199    /* start running the AP */
200    if ((retCode = BHAB_3461_P_RunAp(handle)) != BERR_SUCCESS)
201        return retCode;   
202 
203        for (count = 0; count < BHAB_INIT_RETRIES; count++) {
204        /* wait for init done interrupt */
205                if (BHAB_3461_P_WaitForEvent(handle, p3461->hInitDoneEvent, 150) == BERR_SUCCESS)
206                        break;
207        /* Disable host interrupt */ 
208        BHAB_CHK_RETCODE(BHAB_3461_P_EnableHostInterrupt(handle, false));
209        }
210        if (count < BHAB_INIT_RETRIES)
211                retCode = BERR_SUCCESS;
212        else
213    {
214        /* Disable host interrupt */   
215        BHAB_CHK_RETCODE(BHAB_3461_P_EnableHostInterrupt(handle, false));
216   
217        /* reset the AP before running */
218        BHAB_CHK_RETCODE(BHAB_3461_P_ResetAp(handle));
219        BKNI_Sleep(20);
220        BDBG_WRN(("AP initialization timeout. Starting over %d times", count));
221        BERR_TRACE(retCode = BHAB_ERR_AP_NOT_INIT);           
222    }
223
224done:
225    return retCode;
226}
227
228
229/******************************************************************************
230 BHAB_3461_GetApStatus()
231******************************************************************************/
232BERR_Code BHAB_3461_GetApStatus(
233   BHAB_Handle handle,      /* [in] HAB device handle */
234   BHAB_ApStatus *pStatus   /* [out] AP status */
235)
236{
237    BERR_Code retCode = BERR_SUCCESS;
238    uint32_t sb;
239
240    *pStatus = 0;
241    BHAB_CHK_RETCODE(BHAB_3461_ReadRegister(handle, BCHP_LEAP_CTRL_SPARE, &sb));
242    *pStatus = sb;
243   
244done:
245    return retCode;
246}
247
248
249/******************************************************************************
250 BHAB_3461_GetApVersion()
251******************************************************************************/
252BERR_Code BHAB_3461_GetApVersion(
253    BHAB_Handle handle,     /* [in] BHAB handle */
254    uint16_t    *pChipId,   /* [out] BHAB chip ID */
255    uint16_t    *pChipVer,  /* [out] chip revision number */
256    uint8_t     *pApVer,    /* [out] AP microcode version */
257    uint8_t     *pScrVer,   /* [out] acquisition script version */
258    uint8_t     *pCfgVer    /* [out] host configuration version */
259)
260{
261    BERR_Code retCode = BERR_SUCCESS;
262    uint8_t buf[8];
263
264    buf[0] = ((BHAB_GETVERSION >> 2) & 0xFF);
265    buf[1] = (((BHAB_GETVERSION & 0x3) << 6) | ((PAYLOAD_LEN >> 4) & 0x3F));
266    buf[2] = ((PAYLOAD_LEN & 0xF) << 4);
267    buf[3] = CORE_ID;
268    buf[4] = 0;    /* CRC */
269
270    BHAB_CHK_RETCODE(BHAB_3461_SendHabCommand(handle, buf, 5, buf, 8, false, true, 8));
271    *pChipId = ((buf[4] << 8) | buf[5]);
272    *pChipVer = ((buf[6] << 8) | buf[7]);
273    *pApVer = buf[5];
274    *pScrVer = 0; /* Not supported */
275    *pCfgVer = 0; /* Not supported */
276
277done:
278    return retCode;
279}
280
281
282/******************************************************************************
283 BHAB_3461_ReadMemory()
284******************************************************************************/
285BERR_Code BHAB_3461_ReadMemory(BHAB_Handle handle, uint32_t addr, uint8_t *buf, uint32_t n)
286{   
287    BERR_Code retCode = BERR_SUCCESS;
288    BHAB_3461_P_Handle *p3461 = (BHAB_3461_P_Handle *)(handle->pImpl);
289    uint8_t sb, data, offset;
290    uint32_t sb1;
291
292    if (((uint32_t)addr + (uint32_t)n) > (BCHP_LEAP_HAB_MEM_WORDi_ARRAY_BASE + 128))
293        return BERR_TRACE(BERR_INVALID_PARAMETER); 
294       
295    sb1 = ((addr & 0x000000FF) << 24 |
296           (addr & 0x0000FF00) << 8 |
297           (addr & 0x00FF0000) >> 8 |
298           (addr & 0xFF000000) >> 24 );
299 
300    /* enable read mode and speculative read*/
301    data = CSR_CONFIG_READ_RBUS_READ | (CSR_CONFIG_SPECULATIVE_READ_EN_BITS << CSR_CONFIG_SPECULATIVE_READ_EN_SHIFT);
302    BHAB_CHK_RETCODE(BREG_I2C_Write(p3461->hRegister, handle->settings.chipAddr, CSR_CONFIG, &data, 1)); 
303
304    /* set CSR pointer to point to ADDR0 and set RBUS address to read */
305    BHAB_CHK_RETCODE(BREG_I2C_Write(p3461->hRegister, handle->settings.chipAddr, CSR_RBUS_ADDR0, (uint8_t *)&sb1, 4));   
306   
307    /* poll the busy bit to make sure the transaction is completed */
308    sb=0;
309    while(1)
310    {
311        BHAB_CHK_RETCODE(BREG_I2C_P_Read3461(p3461->hRegister, handle->settings.chipAddr, CSR_STATUS, &sb, 1));
312        if (sb == BHAB_CPU_RUNNIG) 
313            break;
314    }
315
316    for (offset = 0; offset < n; offset+=4) {
317        BHAB_CHK_RETCODE(BREG_I2C_P_Read3461(p3461->hRegister, handle->settings.chipAddr, CSR_RBUS_DATA0, buf+offset, 4)); 
318        while(1)
319        {
320            BHAB_CHK_RETCODE(BREG_I2C_P_Read3461(p3461->hRegister, handle->settings.chipAddr, CSR_STATUS, &sb, 1));
321            if(sb == BHAB_CPU_RUNNIG)
322                break;
323        }
324    }
325   
326    data =0;   
327    BHAB_CHK_RETCODE(BREG_I2C_Write(p3461->hRegister, handle->settings.chipAddr, CSR_CONFIG, &data, 1));     
328   
329done:
330    return retCode;
331}
332
333
334/******************************************************************************
335 BHAB_3461_WriteMemory()
336******************************************************************************/
337BERR_Code BHAB_3461_WriteMemory(BHAB_Handle handle, uint32_t addr, const uint8_t *buf, uint32_t n)
338{   
339    BERR_Code retCode = BERR_SUCCESS;
340    BHAB_3461_P_Handle *p3461 = (BHAB_3461_P_Handle *)(handle->pImpl);
341    uint8_t pad, i, sb;
342    uint16_t bytes_left;
343    uint32_t data, sb1, curr_addr;
344
345    if ((addr + n) >= (BCHP_LEAP_HAB_MEM_WORDi_ARRAY_BASE +128))
346        return BERR_TRACE(BERR_INVALID_PARAMETER);
347
348    sb1 = ((addr & 0x000000FF) << 24 |
349           (addr & 0x0000FF00) << 8 |
350           (addr & 0x00FF0000) >> 8 |
351           (addr & 0xFF000000) >> 24 );
352    data = 0;
353   
354    BHAB_CHK_RETCODE(BREG_I2C_Write(p3461->hRegister, handle->settings.chipAddr, CSR_CONFIG, (uint8_t *)&data, 1)); 
355     
356    /* set CSR pointer to point to ADDR0 and set RBUS address to zero */
357    BHAB_CHK_RETCODE(BREG_I2C_Write(p3461->hRegister, handle->settings.chipAddr, CSR_RBUS_ADDR0, (uint8_t *)&sb1, 4));               
358               
359    /* set CSR pointer to point to DATA0 and provide the data to be downloaded */
360    BHAB_CHK_RETCODE(BREG_I2C_Write(p3461->hRegister, handle->settings.chipAddr, CSR_RBUS_DATA0, buf, n));
361
362    /* check for host transfer error */
363    for(i=0; i < 5; i++){
364        BKNI_Sleep(10);   
365        BHAB_CHK_RETCODE(BREG_I2C_P_Read3461(p3461->hRegister, handle->settings.chipAddr, CSR_STATUS, &sb, 1));           
366        if ((sb & CSR_STATUS_ERROR_BITS) == 0)
367            break;
368    } 
369    if(i==5)   
370        BDBG_WRN(("Write transaction not finished"));   
371   
372    bytes_left = n%4;
373
374    /* pad with zeros at the end, so that an RBUS write can be triggered for the last word */
375    if(bytes_left)
376    {   
377        pad = 0;       
378        /*curr_addr = CSR_RBUS_DATA0 + bytes_left;*/
379        curr_addr = CSR_RBUS_ADDR0 + 4 - bytes_left;
380       
381        for(i=1; i<=bytes_left; i++)
382        {
383            BHAB_CHK_RETCODE(BREG_I2C_Write(p3461->hRegister, handle->settings.chipAddr, curr_addr++, &pad, 1));
384        }         
385    }
386   
387    /* check for host transfer error */
388    BHAB_CHK_RETCODE(BREG_I2C_P_Read3461(p3461->hRegister, handle->settings.chipAddr, CSR_STATUS, &sb, 1));           
389    if ((sb & CSR_STATUS_ERROR_BITS) != 0)
390           BDBG_WRN(("before bytes_left CSR_STATUS bytes_left is 0x%x 0x%x\n", sb, bytes_left));                 
391
392done:
393    return retCode;
394}
395
396
397/******************************************************************************
398 BHAB_3461_ReadMbox()
399******************************************************************************/
400BERR_Code BHAB_3461_ReadMbox(
401    BHAB_Handle handle,    /* [in] BHAB PI Handle */
402    uint32_t    reg,  /* [in] RBUS register address */
403    uint32_t    *val  /* [out] value read from register */
404)
405{
406    BERR_Code retCode = BERR_SUCCESS;
407    BSTD_UNUSED(handle);
408    BSTD_UNUSED(reg);
409    BSTD_UNUSED(val);
410
411    return retCode;
412}
413
414
415/******************************************************************************
416 BHAB_3461_WriteMbox()
417******************************************************************************/
418BERR_Code BHAB_3461_WriteMbox(
419    BHAB_Handle handle,    /* [in] BHAB PI Handle */
420    uint32_t    reg,  /* [in] RBUS register address */
421    uint32_t    *val  /* [in] value to write */
422)
423{
424    BERR_Code retCode = BERR_SUCCESS;
425    BSTD_UNUSED(handle);
426    BSTD_UNUSED(reg);
427    BSTD_UNUSED(val);
428
429    return retCode;
430}
431
432
433/******************************************************************************
434 BHAB_3461_ReadRegister()
435******************************************************************************/
436BERR_Code BHAB_3461_ReadRegister(
437    BHAB_Handle handle,    /* [in] BHAB PI Handle */
438    uint32_t    reg,  /* [in] RBUS register address */
439    uint32_t    *val  /* [out] value read from register */
440)
441{   
442    BERR_Code retCode = BERR_SUCCESS;
443    BHAB_3461_P_Handle *p3461 = (BHAB_3461_P_Handle *)(handle->pImpl);
444    uint8_t data, sb, buf[4], i=0;
445    uint32_t sb1;
446
447    data=0;
448    BHAB_CHK_RETCODE(BREG_I2C_Write(p3461->hRegister, handle->settings.chipAddr, CSR_CONFIG, (uint8_t *)&data, 1)); 
449
450    /* read CSR_CONFIG value*/
451    BHAB_CHK_RETCODE(BREG_I2C_P_Read3461(p3461->hRegister, handle->settings.chipAddr, CSR_CONFIG, &data, 1)); 
452    data &= ~CSR_CONFIG_READ_RBUS_MASK;
453    data |= ((CSR_CONFIG_READ_RBUS_READ << CSR_CONFIG_READ_RBUS_SHIFT) | (1 << CSR_CONFIG_NO_RBUS_ADDR_INC_SHIFT));
454
455    /* set READ_RBUS to the reset value for read mode */
456    BHAB_CHK_RETCODE(BREG_I2C_Write(p3461->hRegister, handle->settings.chipAddr, CSR_CONFIG, &data, 1)); 
457
458    /* set CSR pointer to point to ADDR0 and set RBUS address to read */
459    sb1 = ((reg & 0x000000FF) << 24 |
460           (reg & 0x0000FF00) << 8 |
461           (reg & 0x00FF0000) >> 8 |
462           (reg & 0xFF000000) >> 24 );
463           
464    BHAB_CHK_RETCODE(BREG_I2C_Write(p3461->hRegister, handle->settings.chipAddr, CSR_RBUS_ADDR0, (uint8_t *)&sb1, 4));
465
466    /* poll the busy bit to make sure the transaction is completed */
467    for(i=0; i < 5; i++){
468        BKNI_Sleep(10);
469        retCode = BREG_I2C_P_Read3461(p3461->hRegister, handle->settings.chipAddr, CSR_STATUS, &sb, 1);
470        if ((sb & (1 << CSR_STATUS_BUSY_SHIFT)) == 0)
471            break;
472    }
473    if(i==5)
474        BDBG_WRN(("Read transaction not finished\n"));   
475    /* read the data */
476    BHAB_CHK_RETCODE(BREG_I2C_P_Read3461(p3461->hRegister, handle->settings.chipAddr, CSR_RBUS_DATA0, buf, 4));
477    *val = (buf[0] << 24) | (buf[1] << 16) | (buf[2] << 8) | buf[3];
478           
479    /* set READ_RBUS to the reset value for write mode */
480    data = CSR_CONFIG_READ_RBUS_WRITE;
481    BHAB_CHK_RETCODE(BREG_I2C_Write(p3461->hRegister, handle->settings.chipAddr, CSR_CONFIG, &data, 1));       
482
483done:
484    return retCode;
485}
486
487
488/******************************************************************************
489 BHAB_3461_WriteRegister()
490******************************************************************************/
491BERR_Code BHAB_3461_WriteRegister(
492    BHAB_Handle handle,    /* [in] BHAB PI Handle */
493    uint32_t    reg,  /* [in] RBUS register address */
494    uint32_t    *val  /* [in] value to write */
495)
496{   
497    BERR_Code retCode = BERR_SUCCESS;
498    BHAB_3461_P_Handle *p3461 = (BHAB_3461_P_Handle *)(handle->pImpl);
499    uint8_t data, sb, buf[4], i=0;
500    uint32_t sb1;
501    BSTD_UNUSED(reg);
502 
503    /* read CSR_CONFIG value*/
504    BHAB_CHK_RETCODE(BREG_I2C_P_Read3461(p3461->hRegister, handle->settings.chipAddr, CSR_CONFIG, &data, 1)); 
505     
506    data &= ~CSR_CONFIG_READ_RBUS_MASK; 
507    data |= (CSR_CONFIG_READ_RBUS_WRITE << CSR_CONFIG_READ_RBUS_SHIFT);
508   
509    /* set READ_RBUS to the reset value for write mode */
510    BHAB_CHK_RETCODE(BREG_I2C_Write(p3461->hRegister, handle->settings.chipAddr, CSR_CONFIG, &data, 1)); 
511
512        sb1 = ((reg & 0x000000FF) << 24 |
513               (reg & 0x0000FF00) << 8 |
514               (reg & 0x00FF0000) >> 8 |
515               (reg & 0xFF000000) >> 24 );
516           
517    /* set CSR pointer to point to ADDR0 and set RBUS address to write */
518    BHAB_CHK_RETCODE(BREG_I2C_Write(p3461->hRegister, handle->settings.chipAddr, CSR_RBUS_ADDR0, (uint8_t *)&sb1, 4));
519               
520        sb1 = ((*((uint8_t *)val+0)) << 24 |
521               (*((uint8_t *)val+1)) << 16 |
522               (*((uint8_t *)val+2)) << 8 |
523               (*((uint8_t *)val+3)));                 
524           
525    /* write to RBUS*/
526    BHAB_CHK_RETCODE(BREG_I2C_Write(p3461->hRegister, handle->settings.chipAddr, CSR_RBUS_DATA0, (uint8_t *)&sb1, 4));
527   
528    BHAB_CHK_RETCODE(BREG_I2C_P_Read3461(p3461->hRegister, handle->settings.chipAddr, CSR_RBUS_DATA0, buf, 4));
529   
530    /* poll the busy bit to make sure the transaction is completed */
531    for(i=0; i < 5; i++){
532        BKNI_Sleep(10);
533        retCode = BREG_I2C_P_Read3461(p3461->hRegister, handle->settings.chipAddr, CSR_STATUS, &sb, 1);
534        if ((sb & (1 << CSR_STATUS_BUSY_SHIFT)) == 0)
535            break;
536    }
537    if(i==5)
538        BDBG_WRN(("Write transaction not finished\n"));
539   
540done:
541    return retCode;
542}
543
544
545/******************************************************************************
546 BHAB_3461_HandleInterrupt_isr()
547******************************************************************************/
548BERR_Code BHAB_3461_HandleInterrupt_isr(
549    BHAB_Handle handle /* [in] BHAB handle */
550)
551{
552    BHAB_3461_P_Handle *p3461 = (BHAB_3461_P_Handle *)(handle->pImpl);
553    BKNI_ASSERT_ISR_CONTEXT();
554
555    BDBG_ASSERT(handle);
556    handle->settings.interruptEnableFunc(false, handle->settings.interruptEnableFuncParam);
557           
558    BKNI_SetEvent(p3461->hApiEvent);   
559    BKNI_SetEvent(p3461->hInterruptEvent);
560    return BERR_SUCCESS;
561}
562
563
564/******************************************************************************
565 BHAB_3461_ProcessInterruptEvent()
566******************************************************************************/
567BERR_Code BHAB_3461_ProcessInterruptEvent(
568    BHAB_Handle handle  /* [in] BHAB handle */
569)
570{
571    BERR_Code retCode = BERR_SUCCESS;
572    BDBG_ASSERT(handle);
573
574    BHAB_3461_P_EnableHostInterrupt(handle, false);
575    BHAB_CHK_RETCODE(BHAB_3461_P_DecodeInterrupt(handle));
576    BHAB_3461_P_EnableHostInterrupt(handle, true);
577
578done:
579    return retCode;
580}
581
582
583/******************************************************************************
584 BHAB_3461_EnableLockInterrupt()
585******************************************************************************/ 
586BERR_Code BHAB_3461_EnableLockInterrupt(
587    BHAB_Handle handle,  /* [in] BHAB handle */
588    BHAB_DevId eDevId,    /* [in] Device ID */
589    bool bEnable   /* [in] true = enable Lock  interrupt */
590)
591{
592    BERR_Code retCode = BERR_SUCCESS;
593    BSTD_UNUSED(handle);
594    BSTD_UNUSED(eDevId);
595    BSTD_UNUSED(bEnable);
596   
597    return retCode;   
598}
599   
600
601/******************************************************************************
602 BHAB_3461_InstallInterruptCallback()
603******************************************************************************/ 
604BERR_Code BHAB_3461_InstallInterruptCallback(
605    BHAB_Handle handle,  /* [in] BHAB handle */
606    BHAB_DevId eDevId,    /* [in] Device ID */
607    BHAB_IntCallbackFunc fCallBack,
608    void * pParm1, 
609    int parm2
610)
611{
612    BHAB_P_CallbackInfo *callback;
613    BHAB_3461_P_Handle *p3461 = (BHAB_3461_P_Handle *)(handle->pImpl);
614
615    BDBG_ASSERT(handle);
616   
617    /*TODO : setup bitmask to enable/disable interrupt callabcks*/
618
619    if (eDevId >= BHAB_DevId_eMax) {
620        return BERR_TRACE(BERR_INVALID_PARAMETER);
621    }
622
623    callback = &p3461->InterruptCallbackInfo[eDevId];
624
625    callback->func = fCallBack;
626    callback->pParm1 = pParm1;
627    callback->parm2 = parm2;
628
629    return BERR_TRACE(BERR_SUCCESS);
630}
631
632
633/******************************************************************************
634 BHAB_3461_UnInstallInterruptCallback()
635******************************************************************************/ 
636BERR_Code BHAB_3461_UnInstallInterruptCallback(
637    BHAB_Handle handle,  /* [in] BHAB handle */
638    BHAB_DevId eDevId    /* [in] Device ID */
639)
640{
641    BHAB_P_CallbackInfo *callback;
642    BHAB_3461_P_Handle *p3461 = (BHAB_3461_P_Handle *)(handle->pImpl);
643
644    BDBG_ASSERT(handle);
645   
646    if (eDevId >= BHAB_DevId_eMax) {
647        return BERR_TRACE(BERR_INVALID_PARAMETER);
648    }
649
650    callback = &p3461->InterruptCallbackInfo[eDevId];
651
652    callback->func = NULL;
653    callback->pParm1 = NULL;
654    callback->parm2 = (int)NULL;
655
656    return BERR_TRACE(BERR_SUCCESS);
657}   
658   
659
660/******************************************************************************
661 BHAB_3461_SendHabCommand()
662******************************************************************************/
663BERR_Code BHAB_3461_SendHabCommand(
664    BHAB_Handle handle, /* [in] BHAB PI Handle */
665    uint8_t *write_buf, /* [in] specifies the HAB command to send */
666    uint8_t write_len,  /* [in] number of bytes in the HAB command */ 
667    uint8_t *read_buf,  /* [out] holds the data read from the HAB */ 
668    uint8_t read_len,   /* [in] number of bytes to read from the HAB */
669    bool bCheckForAck,  /* [in] true = determine if the AP has serviced the command */
670    bool bInsertTermination, /* [in] true = insert termination byte 0x00 in write buffer at read_len position */
671    uint8_t command_len
672)
673{
674    BERR_Code retCode = BERR_SUCCESS;
675    uint8_t term_buf;
676
677    BHAB_P_ACQUIRE_MUTEX(handle);
678   
679    if ((write_len > 127) || (read_len > 127) || (write_len == 0))
680        return (BERR_TRACE(BERR_INVALID_PARAMETER));
681
682    BHAB_CHK_RETCODE(BHAB_3461_P_CheckHab(handle));
683 
684    /* write the command to the HAB */
685    BHAB_CHK_RETCODE(BHAB_3461_P_WriteHab(handle, 0, write_buf, write_len));
686
687    if(bInsertTermination){
688        term_buf = 0x00;
689        BHAB_CHK_RETCODE(BHAB_3461_P_WriteHab(handle, command_len, &term_buf, 1));
690    }
691    /* wait for the AP to service the HAB, and then read any return data */
692    BHAB_CHK_RETCODE(BHAB_3461_P_ServiceHab(handle, read_buf, read_len, bCheckForAck, write_buf[0] | 0x80));
693
694done:
695    BHAB_P_RELEASE_MUTEX(handle);
696
697    return retCode;
698}
699
700/******************************************************************************
701 BHAB_3461_GetInterruptEventHandle()
702******************************************************************************/
703BERR_Code BHAB_3461_GetInterruptEventHandle(
704    BHAB_Handle handle,            /* [in] BHAB handle */
705    BKNI_EventHandle *hEvent       /* [out] interrupt event handle */
706)
707{
708    *hEvent = ((BHAB_3461_P_Handle *)(handle->pImpl))->hInterruptEvent;
709    return BERR_SUCCESS;
710}
711
712
713/****************************Private Functions*********************************/
714
715
716/******************************************************************************
717 BREG_I2C_P_Read3461()
718******************************************************************************/
719BERR_Code BREG_I2C_P_Read3461(
720    BREG_I2C_Handle i2cHandle,    /* [in] BREG_I2C Handle */
721    uint16_t chipAddr, 
722    uint8_t subAddr, 
723    uint8_t *pData, 
724    size_t length
725)
726{
727    BERR_Code retCode = BERR_SUCCESS;
728   
729    BREG_I2C_WriteNoAddr(i2cHandle, chipAddr, (uint8_t *)&subAddr, 1);
730    BREG_I2C_ReadNoAddr(i2cHandle, chipAddr, pData, length);
731 
732    return retCode;
733}
734
735
736/******************************************************************************
737 BHAB_3461_P_EnableHostInterrupt()
738******************************************************************************/
739BERR_Code BHAB_3461_P_EnableHostInterrupt(
740    BHAB_Handle handle, /* [in] HAB handle */
741    bool bEnable        /* [in] true=enables the L1 interrupt on the host processor */
742)
743{
744    BKNI_EnterCriticalSection();
745    handle->settings.interruptEnableFunc(bEnable, handle->settings.interruptEnableFuncParam);
746    BKNI_LeaveCriticalSection();   
747
748    return BERR_SUCCESS;
749}
750
751
752/******************************************************************************
753 BHAB_3461_P_DisableInterrupts()
754******************************************************************************/ 
755BERR_Code BHAB_3461_P_DisableInterrupts(
756    BHAB_Handle handle   /* [in] BHAB Handle */
757)
758{   
759    BERR_Code retCode = BERR_SUCCESS; 
760    BSTD_UNUSED(handle);
761   
762    return retCode; 
763}
764
765
766/******************************************************************************
767 BHAB_3461_P_EnableHabDoneInterrupt()
768******************************************************************************/ 
769BERR_Code BHAB_3461_P_EnableHabDoneInterrupt(
770    BHAB_Handle handle /* [in] BHAB PI Handle */
771)
772{ 
773    BERR_Code retCode = BERR_SUCCESS; 
774    BSTD_UNUSED(handle);
775   
776    return retCode;
777}
778
779
780/******************************************************************************
781 BHAB_3461_P_EnableInitDoneInterrupt()
782******************************************************************************/ 
783BERR_Code BHAB_3461_P_EnableInitDoneInterrupt(
784    BHAB_Handle handle /* [in] BHAB PI Handle */
785)
786{ 
787    BERR_Code retCode = BERR_SUCCESS;
788    BSTD_UNUSED(handle);
789   
790    return retCode;
791}
792
793
794/******************************************************************************
795 BERR_3461_Code BHAB_P_WaitForEvent()
796******************************************************************************/
797BERR_Code BHAB_3461_P_WaitForEvent(
798    BHAB_Handle handle,             /* [in] BHAB PI Handle */
799    BKNI_EventHandle hEvent,   /* [in] event to wait on */
800    int timeoutMsec            /* [in] timeout in milliseconds */
801)
802{   
803    BERR_Code retCode = BERR_SUCCESS;
804    BHAB_3461_P_Handle *p3461 = (BHAB_3461_P_Handle *)(handle->pImpl);
805 
806  while (1)
807    { 
808        BHAB_3461_P_EnableHostInterrupt(handle, true);
809        retCode = BKNI_WaitForEvent(p3461->hApiEvent, timeoutMsec);
810        if ( retCode != BERR_SUCCESS ) { break; }
811        BHAB_3461_P_EnableHostInterrupt(handle, false);
812        BHAB_3461_P_DecodeInterrupt(handle);       
813
814        retCode = BKNI_WaitForEvent(hEvent, 0);
815        if (retCode == BERR_SUCCESS || retCode == BERR_OS_ERROR) { break; }
816    }
817  BHAB_3461_P_EnableHostInterrupt(handle, true);
818
819    return retCode;
820
821}
822
823
824/******************************************************************************
825 BHAB_3461_P_RunAp()
826******************************************************************************/
827BERR_Code BHAB_3461_P_RunAp(BHAB_Handle handle)
828{
829    BERR_Code retCode = BERR_SUCCESS;
830    uint32_t buf;
831   
832    BHAB_3461_P_EnableHostInterrupt(handle, true);
833
834    /* start running the AP */
835    BHAB_CHK_RETCODE(BHAB_3461_ReadRegister(handle, BCHP_LEAP_CTRL_CTRL, &buf));
836    buf &= ~0x02; 
837    BHAB_CHK_RETCODE(BHAB_3461_WriteRegister(handle, BCHP_LEAP_CTRL_CTRL, &buf)); 
838
839done:
840    return retCode;
841}
842
843
844/******************************************************************************
845 BHAB_3461_P_ResetAp()
846******************************************************************************/
847BERR_Code BHAB_3461_P_ResetAp(BHAB_Handle handle)
848{   
849   
850    BERR_Code retCode = BERR_SUCCESS;
851    uint32_t buf;
852
853   
854    /* clear LEAP_HOST_IRQ and LEAP_CTRL_SPARE put LEAP in reset (write 0x3) */
855    buf  = 0;
856    BHAB_CHK_RETCODE(BHAB_3461_WriteRegister(handle, BCHP_LEAP_CTRL_HOST_IRQ, &buf )); 
857    BHAB_CHK_RETCODE(BHAB_3461_WriteRegister(handle, BCHP_LEAP_CTRL_SPARE, &buf));     
858   
859    BHAB_CHK_RETCODE(BHAB_3461_ReadRegister(handle, BCHP_LEAP_CTRL_CTRL, &buf));
860    buf &= ~0x02;
861    buf |= 0x02;
862    BHAB_CHK_RETCODE(BHAB_3461_WriteRegister(handle, BCHP_LEAP_CTRL_CTRL, &buf));
863
864done:
865    return retCode;
866}
867
868
869/******************************************************************************
870 BHAB_3461_P_ReadHab()
871******************************************************************************/
872BERR_Code BHAB_3461_P_ReadHab(BHAB_Handle handle, uint8_t addr, uint8_t *buf, uint8_t n)
873{
874   
875    BERR_Code retCode = BERR_SUCCESS;
876
877    if ((addr & BHAB_HAB_SIZE) || (n & BHAB_HAB_SIZE))
878        return BERR_TRACE(BERR_INVALID_PARAMETER);
879
880    if ((addr + n) > BHAB_HAB_SIZE)
881        return BERR_TRACE(BERR_INVALID_PARAMETER);
882   
883    BHAB_CHK_RETCODE(BHAB_3461_ReadMemory(handle, BCHP_LEAP_HAB_MEM_WORDi_ARRAY_BASE, buf, n));
884
885done:
886    return retCode;
887}
888
889
890/******************************************************************************
891 BHAB_3461_P_WriteHab()
892******************************************************************************/
893BERR_Code BHAB_3461_P_WriteHab(BHAB_Handle handle, uint8_t addr, uint8_t *buf, uint8_t n)
894{
895    BERR_Code retCode = BERR_SUCCESS;
896   
897    if ((addr & BHAB_HAB_SIZE) || (n & BHAB_HAB_SIZE))
898        return BERR_TRACE(BERR_INVALID_PARAMETER);
899
900    if ((addr + n) > BHAB_HAB_SIZE)
901        return BERR_TRACE(BERR_INVALID_PARAMETER);
902   
903    BHAB_CHK_RETCODE(BHAB_3461_WriteMemory(handle, BCHP_LEAP_HAB_MEM_WORDi_ARRAY_BASE, buf, n));
904
905done:
906    return retCode;
907}
908
909
910/******************************************************************************
911 BHAB_3461_P_ServiceHab()
912******************************************************************************/
913BERR_Code BHAB_3461_P_ServiceHab(
914    BHAB_Handle handle,   /* [in] BHAB PI Handle */
915    uint8_t *read_buf,  /* [out] holds the data read from the HAB */ 
916    uint8_t read_len,   /* [in] number of bytes to read from the HAB */
917    bool bCheckForAck,  /* [in] true = determine if the AP has serviced the command */
918    uint8_t ack_byte    /* [in] value of the ack byte to expect */
919)
920{   
921    BERR_Code retCode = BERR_SUCCESS;
922    uint32_t sb;   
923
924    BHAB_3461_P_Handle *p3461 = (BHAB_3461_P_Handle *)(handle->pImpl);
925       
926    BHAB_3461_P_EnableHostInterrupt(handle, false);
927
928    if (BERR_SUCCESS == BKNI_WaitForEvent(p3461->hHabDoneEvent, 0))
929    {
930        BDBG_WRN(("Discarded a HabDoneEvent"));   
931    }
932
933    sb=0x1;
934    BHAB_CHK_RETCODE(BHAB_3461_WriteRegister(handle, BCHP_LEAP_CTRL_HAB_REQUEST, &sb));
935   
936    if (BHAB_3461_P_WaitForEvent(handle, p3461->hHabDoneEvent, 5850) == BERR_TIMEOUT)
937    {
938        BDBG_WRN(("HAB timeout\n"));   
939        BERR_TRACE(retCode = BHAB_ERR_HAB_TIMEOUT);
940        goto done;
941    }
942   
943    if (read_len > 0)
944    {
945        BHAB_CHK_RETCODE(BHAB_3461_P_ReadHab(handle, 0, read_buf, read_len));
946        if (bCheckForAck)
947        {
948            if (ack_byte != read_buf[0])
949            {
950                BDBG_WRN(("HAB command not serviced!\n"));
951                BERR_TRACE(retCode = BHAB_ERR_HAB_NO_ACK);
952            }
953        }
954    }
955
956done:
957    return retCode;
958}
959
960
961/******************************************************************************
962 BHAB_3461_P_DecodeInterrupt()
963******************************************************************************/
964BERR_Code BHAB_3461_P_DecodeInterrupt(BHAB_Handle handle)
965{ 
966    BERR_Code retCode = BERR_SUCCESS;
967    BHAB_3461_P_Handle *p3461 = (BHAB_3461_P_Handle *)(handle->pImpl);
968    uint32_t   buf, sb;
969   
970    BHAB_P_CallbackInfo *callback;
971
972    BHAB_CHK_RETCODE(BHAB_3461_ReadRegister(handle, BCHP_LEAP_CTRL_HOST_IRQ, &buf));
973    BDBG_MSG(("1. BHAB_3461_P_DecodeInterrupt IRQ register =    0x%x", buf ));
974    if(buf == 0) return retCode;
975   
976    /*HAB DONE INTERRUPT*/
977    if (buf & BHAB_HAB_DONE)
978    {
979        BDBG_MSG(("HAB_DONE"));   
980        BKNI_SetEvent(p3461->hHabDoneEvent);           
981    }
982   
983    /*INIT DONE INTERRUPT*/
984    if (buf & BHAB_AP_INIT_DONE)
985    {
986        BDBG_MSG(("AP INIT DONE"));   
987        BKNI_SetEvent(p3461->hInitDoneEvent);
988    }
989   
990    if(buf & BHAB_ADS_CHN0_OUT_OF_LOCK)
991    {
992        if(p3461->InterruptCallbackInfo[BHAB_DevId_eADS0].func){
993            BDBG_WRN(("Channel 0 out of Lock"));       
994            callback = &p3461->InterruptCallbackInfo[BHAB_DevId_eADS0];     
995            callback->parm2 = (int) BHAB_Interrupt_eLockChange;       
996            BKNI_EnterCriticalSection();
997            callback->func(callback->pParm1, callback->parm2);
998            BKNI_LeaveCriticalSection();
999        }
1000        else {
1001            BDBG_MSG(("ADS callback not installed. "));
1002        }
1003    }
1004
1005    if(buf & BHAB_ADS_CHN0_IN_LOCK)
1006    {
1007        if(p3461->InterruptCallbackInfo[BHAB_DevId_eADS0].func){   
1008            BDBG_WRN(("Channel 0 In Lock"));       
1009            callback = &p3461->InterruptCallbackInfo[BHAB_DevId_eADS0];     
1010            callback->parm2 = (int) BHAB_Interrupt_eLockChange;       
1011            BKNI_EnterCriticalSection();
1012            callback->func(callback->pParm1, callback->parm2);
1013            BKNI_LeaveCriticalSection();
1014        }
1015        else {
1016            BDBG_MSG(("ADS callback not installed. "));
1017        }           
1018    }   
1019   
1020    if (buf & BHAB_ADS_STATUS_RDY)
1021    {
1022        if(p3461->InterruptCallbackInfo[BHAB_DevId_eADS0].func){   
1023            BDBG_WRN(("ADS Status Ready"));         
1024            callback = &p3461->InterruptCallbackInfo[BHAB_DevId_eADS0];     
1025            callback->parm2 = (int) BHAB_Interrupt_eQamAsyncStatusReady; 
1026            BKNI_EnterCriticalSection();
1027            callback->func(callback->pParm1, callback->parm2);
1028            BKNI_LeaveCriticalSection();
1029        }
1030        else {
1031            BDBG_MSG(("ADS callback not installed. "));
1032        }           
1033    } 
1034
1035    if(buf & BHAB_T2_OUT_OF_LOCK)
1036    {
1037        if(p3461->InterruptCallbackInfo[BHAB_DevId_eTC20].func){   
1038            BDBG_WRN(("T2 out of Lock"));
1039            callback = &p3461->InterruptCallbackInfo[BHAB_DevId_eTC20];       
1040            callback->parm2 = (int) BHAB_Interrupt_eLockChange;       
1041            BKNI_EnterCriticalSection();
1042            callback->func(callback->pParm1, callback->parm2);
1043            BKNI_LeaveCriticalSection();
1044        }
1045        else {
1046            BDBG_MSG(("T2 callback not installed. "));
1047        }         
1048    }
1049
1050    if(buf & BHAB_T2_IN_LOCK)
1051    {
1052        if(p3461->InterruptCallbackInfo[BHAB_DevId_eTC20].func){       
1053            BDBG_WRN(("T2 In Lock"));
1054            callback = &p3461->InterruptCallbackInfo[BHAB_DevId_eTC20];       
1055            callback->parm2 = (int) BHAB_Interrupt_eLockChange;       
1056            BKNI_EnterCriticalSection();
1057            callback->func(callback->pParm1, callback->parm2);
1058            BKNI_LeaveCriticalSection();
1059        }
1060        else {
1061            BDBG_MSG(("T2 callback not installed. "));
1062        }             
1063    } 
1064
1065    if (buf & BHAB_T2_STATUS_RDY)
1066    {
1067        if(p3461->InterruptCallbackInfo[BHAB_DevId_eTC20].func){     
1068            BDBG_WRN(("T2 Status Ready"));   
1069            callback = &p3461->InterruptCallbackInfo[BHAB_DevId_eTC20];     
1070            callback->parm2 = (int) BHAB_Interrupt_eTc2AsyncStatusReady; 
1071            BKNI_EnterCriticalSection();
1072            callback->func(callback->pParm1, callback->parm2);
1073            BKNI_LeaveCriticalSection(); 
1074        }
1075        else {
1076            BDBG_MSG(("T2 callback not installed. ")); 
1077        }     
1078    }
1079 
1080    if(buf & BHAB_THD_OUT_OF_LOCK)
1081    {
1082        if(p3461->InterruptCallbackInfo[BHAB_DevId_eTHD0].func){   
1083            BDBG_WRN(("THD out of Lock"));
1084            callback = &p3461->InterruptCallbackInfo[BHAB_DevId_eTHD0];       
1085            callback->parm2 = (int) BHAB_Interrupt_eLockChange;       
1086            BKNI_EnterCriticalSection();
1087            callback->func(callback->pParm1, callback->parm2);
1088            BKNI_LeaveCriticalSection();
1089        }
1090        else {
1091            BDBG_MSG(("THD callback not installed. "));
1092        }         
1093    }
1094
1095    if(buf & BHAB_THD_IN_LOCK)
1096    {
1097        if(p3461->InterruptCallbackInfo[BHAB_DevId_eTHD0].func){       
1098            BDBG_WRN(("THD In Lock"));
1099            callback = &p3461->InterruptCallbackInfo[BHAB_DevId_eTHD0];       
1100            callback->parm2 = (int) BHAB_Interrupt_eLockChange;       
1101            BKNI_EnterCriticalSection();
1102            callback->func(callback->pParm1, callback->parm2);
1103            BKNI_LeaveCriticalSection();
1104        }
1105        else {
1106            BDBG_MSG(("THD callback not installed. "));
1107        }             
1108    } 
1109
1110    if (buf & BHAB_THD_STATUS_RDY)
1111    {
1112        if(p3461->InterruptCallbackInfo[BHAB_DevId_eTHD0].func){     
1113            BDBG_WRN(("THD Status Ready"));   
1114            callback = &p3461->InterruptCallbackInfo[BHAB_DevId_eTHD0];     
1115            callback->parm2 = (int) BHAB_Interrupt_eThdAsyncStatusReady; 
1116            BKNI_EnterCriticalSection();
1117            callback->func(callback->pParm1, callback->parm2);
1118            BKNI_LeaveCriticalSection(); 
1119        }
1120        else {
1121            BDBG_MSG(("THD callback not installed. ")); 
1122        }     
1123    }
1124   
1125    /* clear LEAP_HOST_IRQ and LEAP_CTRL_SPARE */
1126    sb=0;
1127    BHAB_CHK_RETCODE(BHAB_3461_WriteRegister(handle, BCHP_LEAP_CTRL_HOST_IRQ, &sb));
1128done:
1129    return retCode;
1130}
1131
1132
1133/******************************************************************************
1134 BHAB_3461_P_DecodeError()
1135******************************************************************************/
1136BERR_Code BHAB_3461_P_DecodeError(
1137    BHAB_Handle handle,           /* [in] BHAB PI Handle */
1138    BHAB_ApStatus *pApStatus /* [in] AP status returned by BHAB_GetApStatus */
1139)
1140{
1141    BERR_Code retCode = BERR_SUCCESS;
1142    uint8_t sb;
1143    BSTD_UNUSED(handle);
1144
1145    if (*pApStatus & BHAB_AP_ERROR)
1146        retCode = BHAB_ERR_AP_UNKNOWN;
1147       
1148    else if (*pApStatus & BHAB_HAB_DONE)
1149    {
1150        sb = *pApStatus & BHAB_HAB_DONE;
1151       
1152        switch (sb)
1153        {
1154        case 1:
1155          break;
1156         
1157        case 2:
1158          retCode = BHAB_ERR_HAB_ERR;
1159          break;         
1160
1161        case 3:
1162          retCode = BHAB_ERR_HAB_ERR;
1163          break;
1164
1165        case 4:
1166          retCode = BHAB_ERR_HAB_ERR;
1167          break;
1168
1169        case 5:
1170          retCode = BHAB_ERR_HAB_TIMEOUT;
1171          break;
1172
1173        case 6:
1174          retCode = BHAB_ERR_HAB_ERR;
1175          break;
1176         
1177        default:
1178          BDBG_WRN(("unknown MSG1 (=0x%02X)\n", sb));
1179          retCode = BHAB_ERR_AP_UNKNOWN;
1180          break;
1181        }
1182    }
1183   
1184    return retCode;
1185}
1186
1187
1188/******************************************************************************
1189 BHAB_3461_P_CheckHab()
1190******************************************************************************/
1191BERR_Code BHAB_3461_P_CheckHab(
1192    BHAB_Handle handle    /* [in] BHAB Handle */
1193)
1194{
1195    BERR_Code retCode = BERR_SUCCESS;
1196    BHAB_ApStatus status = 0;
1197
1198    BHAB_CHK_RETCODE(BHAB_3461_GetApStatus(handle, &status));
1199    if ((status & BHAB_HAB_DONE) == 0x1) {
1200        retCode = BERR_SUCCESS;
1201    }
1202    else
1203    {
1204        BERR_TRACE(retCode = BHAB_3461_P_DecodeError(handle, &status));
1205    }
1206   
1207done:
1208    return retCode;
1209}
1210
1211
1212/******************************************************************************
1213 BHAB_3461_GetWatchDogTimer()
1214******************************************************************************/
1215BERR_Code BHAB_3461_GetWatchDogTimer(
1216    BHAB_Handle handle,    /* [in] BHAB Handle */
1217    BHAB_WatchDogTimerSettings *wdtSettings
1218)
1219{
1220    BERR_Code retCode = BERR_SUCCESS;
1221    BSTD_UNUSED(handle);
1222    BSTD_UNUSED(wdtSettings);
1223   
1224     return retCode;
1225}
1226
1227
1228/******************************************************************************
1229 BHAB_3461_SetWatchDogTimer()
1230******************************************************************************/
1231BERR_Code BHAB_3461_SetWatchDogTimer(
1232    BHAB_Handle handle,    /* [in] BHAB Handle */
1233    const BHAB_WatchDogTimerSettings *wdtSettings
1234)
1235{
1236    BERR_Code retCode = BERR_SUCCESS;
1237    BSTD_UNUSED(handle);
1238    BSTD_UNUSED(wdtSettings);
1239   
1240    return retCode;
1241}
1242
1243
1244/******************************************************************************
1245 BHAB_3461_GetNmiConfig()
1246******************************************************************************/
1247BERR_Code BHAB_3461_GetNmiConfig(
1248    BHAB_Handle handle,    /* [in] BHAB Handle */
1249    BHAB_NmiSettings *nmiSettings
1250)
1251{
1252    BERR_Code retCode = BERR_SUCCESS;
1253    BSTD_UNUSED(handle);
1254    BSTD_UNUSED(nmiSettings);
1255   
1256    return retCode;
1257}
1258
1259
1260/******************************************************************************
1261 BHAB_3461_SetNmiConfig()
1262******************************************************************************/
1263BERR_Code BHAB_3461_SetNmiConfig(
1264    BHAB_Handle handle,    /* [in] BHAB Handle */
1265    const BHAB_NmiSettings *nmiSettings
1266)
1267{
1268    BERR_Code retCode = BERR_SUCCESS;
1269    BSTD_UNUSED(handle);
1270    BSTD_UNUSED(nmiSettings);
1271   
1272    return retCode;
1273}
1274
1275/***************************************************************************
1276 BHAB_3461_GetConfigSettings()
1277****************************************************************************/
1278BERR_Code BHAB_3461_GetConfigSettings(
1279    BHAB_Handle handle,           /* [in] Device handle */
1280    BHAB_ConfigSettings *settings)     /* [out] HAB config settings. */
1281{
1282    BERR_Code retCode = BERR_SUCCESS;
1283    BHAB_3461_P_Handle *p3461 = (BHAB_3461_P_Handle *)(handle->pImpl);
1284   
1285    settings->daisyChain = p3461->daisyChain; 
1286   
1287    return retCode;   
1288}
1289   
1290/***************************************************************************
1291 BHAB_3461_SetConfigSettings()
1292****************************************************************************/
1293BERR_Code BHAB_3461_SetConfigSettings(
1294    BHAB_Handle handle,           /* [in] Device handle */
1295    const BHAB_ConfigSettings *settings)     /* [in] HAB config settings. */
1296{
1297    BERR_Code retCode = BERR_SUCCESS;
1298    BHAB_3461_P_Handle *p3461 = (BHAB_3461_P_Handle *)(handle->pImpl);
1299    uint8_t buf[9] = HAB_MSG_HDR(BHAB_WRITE_DAISY, 0x4, BHAB_CORE_TYPE, BHAB_CORE_ID);
1300   
1301    if(settings->daisyChain){
1302        buf[4] = (((uint8_t)settings->daisyChain & 0x3) - 1) | 0x4;
1303    }
1304
1305    BHAB_CHK_RETCODE(BHAB_3461_SendHabCommand(handle, buf, 9, buf, 1, false, true, 9)); 
1306   
1307    p3461->daisyChain = settings->daisyChain;   
1308   
1309done:   
1310    return retCode;   
1311}
Note: See TracBrowser for help on using the repository browser.