📄 api.c
字号:
TNR_NO_ERROR, the operation completed without error.See Also: TNR_Init()*****************************************************************************/static TNR_ErrorCode_t TNR_Term(TNR_Handle_t Handle){ /* Deallocate control block */ memory_deallocate(API_HANDLE(Handle)->MemoryPartition, Handle); return ST_NO_ERROR;} /* TNR_Term() *//*****************************************************************************Name: TNR_SetFrequency()Description: Sets the frequency on the tuner device. The frequency must be a multiple of the tuner step value (usually 125KHz) -- the new frequency value may not be an exact match for the required frequency.Parameters: Tnr_p, pointer to the TNR device. NewFrequency_p, pointer to caller supplied area to store new value.Return Value: TNR_NO_ERROR, the operation completed without error. STI2C_xxxx, there was a problem accessing the device.See Also: Nothing.*****************************************************************************/static TNR_ErrorCode_t TNR_SetFrequency(TNR_Handle_t Handle, U32 Frequency, U32 *NewFrequency_p){ TNR_ErrorCode_t Error = TNR_NO_ERROR; U32 Steps; U32 Prescaler, NCnt, ACnt, F; /* Calculate number of steps for nominated frequency */ Steps = ((Frequency * 500) / API_HANDLE(Handle)->FreqFactor); Steps = (Steps + (500 * API_HANDLE(Handle)->Status.IntermediateFrequency)) / (API_HANDLE(Handle)->Status.TunerStep / 2); /* Communications depends on PLL type */ switch (API_HANDLE(Handle)->PLLType) { case TNR_PLL_5522: case TNR_PLL_5655: API_HANDLE(Handle)->WriteBuffer[0] = (U8)((Steps & 0x00007F00) >> 8); API_HANDLE(Handle)->WriteBuffer[1] = (U8)(Steps & 0x000000FF); break; case TNR_PLL_5659: API_HANDLE(Handle)->WriteBuffer[0] = (U8)((Steps & 0x00007F00) >> 8); API_HANDLE(Handle)->WriteBuffer[1] = (U8)(Steps & 0x000000FF); API_HANDLE(Handle)->WriteBuffer[2] = (U8)((((U32)API_HANDLE(Handle)->WriteBuffer[2]) & 0xFF9F) | (Steps >> 10)); break; case TNR_PLL_TUA6100: Prescaler = (API_HANDLE(Handle)->WriteBuffer[1] & 0x40) ? 64 : 32; NCnt = Steps / Prescaler; ACnt = Steps - (NCnt * Prescaler); API_HANDLE(Handle)->WriteBuffer[1] = API_HANDLE(Handle)->WriteBuffer[1] | ((U8)((NCnt & 0x600) >> 9)); API_HANDLE(Handle)->WriteBuffer[2] = (U8)((NCnt & 0x1FE) >> 1); API_HANDLE(Handle)->WriteBuffer[3] = (U8)(((NCnt & 0x01) << 7) | (ACnt & 0x7F)); F = CalculateFrequency(API_HANDLE(Handle)); API_HANDLE(Handle)->WriteBuffer[1] = (API_HANDLE(Handle)->WriteBuffer[1] & 0x7F) | ((F>1525000) ? 0x80 : 0x00); API_HANDLE(Handle)->WriteBuffer[1] = (API_HANDLE(Handle)->WriteBuffer[1] & 0xCF) | ((F>1435000) ? 0x80 : 0x20); break; default: break; } /* Update device with new frequency */ Error = TNR_ReadWrite(Handle,I2C_WRITE,4); /* Set new frequency of device */ *NewFrequency_p = API_HANDLE(Handle)->Status.Frequency = CalculateFrequency(API_HANDLE(Handle)); return Error;} /* TNR_SetFrequency() *//*****************************************************************************Name: TNR_GetStatus()Description: Reads the status of the TNR device.Parameters: Tnr_p, pointer to the TNR device. Status_p, caller supplied area to read the status data.Return Value: TNR_NO_ERROR, the operation completed without error. STI2C_xxxx, there was a problem accessing the device.See Also: Nothing.*****************************************************************************/static TNR_ErrorCode_t TNR_GetStatus(TNR_Handle_t Handle, TNR_Status_t *Status_p){ TNR_ErrorCode_t Error = TNR_NO_ERROR; *Status_p = API_HANDLE(Handle)->Status; return Error;} /* TNR_GetStatus() *//*****************************************************************************Name: TNR_GetStatus()Description: Reads the status of the TNR device and ascertains whether the tuner is locked.Parameters: Tnr_p, pointer to the TNR device. Locked_p, memory to set to TRUE or FALSE to indicate locked status.Return Value: TNR_NO_ERROR, the operation completed without error. STI2C_xxxx, there was a problem accessing the device.See Also: Nothing.*****************************************************************************/static TNR_ErrorCode_t TNR_IsTunerLocked(TNR_Handle_t Handle, BOOL *Locked_p){ TNR_ErrorCode_t Error = TNR_NO_ERROR; U8 RxStatus; U8 SubAddr; U8 BitMask; I2C_Operation_t OpType; /* Assume not locked */ *Locked_p = FALSE; switch (API_HANDLE(Handle)->PLLType) { case TNR_PLL_5522: case TNR_PLL_5655: case TNR_PLL_5659: BitMask = 0x40; OpType = I2C_READ; break; case TNR_PLL_TUA6100: BitMask = 0x80; SubAddr = 0x80; OpType = I2C_SUBADDR_READ; break; default: break; } /* Read 'locked' status */ Error = TNR_ReadWrite(Handle,OpType,1); /* Check status bits */ if ((RxStatus & BitMask) != 0) *Locked_p = TRUE; return Error;} /* TNR_IsTunerLocked() *//*****************************************************************************Name: TNR_SetBandWidth()Description: Selects the best fit bandwidth filtering based on the passed in bandwidth value.Parameters: Handle, pointer to the TNR device. BandWidth_p, pointer to caller supplied area to store new value. NewBandWidth_p, pointer to new bandwidth setting.Return Value: TNR_NO_ERROR, the operation completed without error.See Also: Nothing.*****************************************************************************/static TNR_ErrorCode_t TNR_SetBandWidth(TNR_Handle_t Handle, U32 BandWidth, U32 *NewBandWidth_p){ U8 i = 1; /* Find closest (largest) bandwidth to requested value */ while( API_HANDLE(Handle)->BandWidth[i] != 0 && (BandWidth > API_HANDLE(Handle)->BandWidth[i]) ) i++; /* Check whether or not we found a valid band (i.e. no zero) */ if (API_HANDLE(Handle)->BandWidth[i] == 0) i = 0; /* Use default band */ /* For EVALMAX we must update the command sent to the device for * selecting narrow or wide band filtering */ if (API_HANDLE(Handle)->TunerType == TNR_DEVICE_EVALMAX) { /* For i=0 - narrow, i=1 - wide */ API_HANDLE(Handle)->WriteBuffer[3] = (API_HANDLE(Handle)->WriteBuffer[3] & 0xFE) | i; } /* Update status */ *NewBandWidth_p = API_HANDLE(Handle)->Status.Bandwidth = API_HANDLE(Handle)->BandWidth[i]; return TNR_NO_ERROR;} /* TNR_SetBandWidth() */static __inline U32 CalculateSteps(TNR_ControlBlock_t *Tnr_p){ U32 Steps, NCnt, ACnt, Prescaler; switch (Tnr_p->PLLType) { case TNR_PLL_5522: case TNR_PLL_5655: Steps = ((U32)Tnr_p->WriteBuffer[0] & 0x0000007F) << 8; Steps |= (U32)Tnr_p->WriteBuffer[1] & 0x000000FF; break; case TNR_PLL_5659: Steps = ((U32)Tnr_p->WriteBuffer[0] & 0x0000007F) << 8; Steps |= ((U32)Tnr_p->WriteBuffer[1] & 0x000000FF); Steps |= (((U32)Tnr_p->WriteBuffer[2] & 0x00000060 ) << 10); break; case TNR_PLL_TUA6100: Prescaler = (Tnr_p->WriteBuffer[1] & 0x40) ? 64 : 32; /* Prescaler = 64 if high 32 if low */ NCnt = (((U32)Tnr_p->WriteBuffer[1] & 0x3) << 9) | (((U32)Tnr_p->WriteBuffer[2] & 0xFF) << 1) | (((U32)Tnr_p->WriteBuffer[3] & 0x80) >> 7); /* N counter value */ ACnt = (U32)Tnr_p->WriteBuffer[3] & 0x7F; /* A counter value */ Steps = (Prescaler * NCnt) + ACnt; break; default: break; } return Steps;}static __inline U32 CalculateFrequency(TNR_ControlBlock_t *Tnr_p){ U32 F; F = ((CalculateSteps(Tnr_p) * (Tnr_p->Status.TunerStep / 2)) - 500 * Tnr_p->Status.IntermediateFrequency) / 500; F *= Tnr_p->FreqFactor; return F;}/* Exported Map Table ------------------------------------------------------------ */TNR_MapTable_t __GenericTunerMapTable ={ TNR_Init, TNR_Term, TNR_SetFrequency, TNR_GetStatus, TNR_IsTunerLocked, TNR_SetBandWidth};/* End of api.c */
⌨️ 快捷键说明
复制代码
Ctrl + C
搜索代码
Ctrl + F
全屏模式
F11
切换主题
Ctrl + Shift + D
显示快捷键
?
增大字号
Ctrl + =
减小字号
Ctrl + -