📄 tidtv_msp430.c
字号:
/*******************************************************************************
* @ModuleName :: TiDTV_MSP430.c
*
* @Copyright :: Copyright 2005- Texas Instruments, Inc.
*
* @Description :: User defined MCU Command Parsers
*
* @History ::
*---------------------------------------
* 07-24-2005 W.Shi Created
*******************************************************************************/
#include <stdio.h>
#include <string.h>
#include "ucos_ii.h"
#include "TvpArch.h"
#include "TvpDefs.h"
#include "Tvp9000.h"
#include "TvpError.h"
#include "TvpInt.h"
#include "TvpHdm.h"
#include "TvpInt926.h"
#include "TvpUarts.h"
#include "TvpEbi.h"
#include "TvpTpp.h"
#include "TvpIrrf.h"
#include "TvpGpio.h"
#include "TvpVideo.h"
#include "TvpAudio.h"
#include "TvpEncoder.h"
#include "TiDTV_DataType.h"
#include "TiDTV_SysCtrl.h"
#include "TiDTV_UserApi.h"
#include "TiDTV_Buffers.h"
#include "TiDTV_PSIP.h"
#include "TVP9K_I2C_Def.h"
#include "TVP9K_NV_Def.h"
#include "TiDTV_GLib.h"
#include "TiDTV_GUI.h"
#include "TiDTV_McuComm.h"
#include "TiDTV_IrKey.h"
#include "TiDTV_AvInput.h"
#include "TvpI2c.h"
#define MSP430_I2C_CHANNEL TVP_I2C_0
#define MSP430_I2C_DEVICE_ADDR 0xD8
/*******************************************************************************
* @RoutineName:: TiDTV_McuCmdDispatch
*
* @Description:: MCU Commands Dispatcher
*
* @Input :: none
*
* @Output :: none
*
* @Return :: none
*******************************************************************************/
void TiDTV_McuCmdDispatch(void)
{
UCHAR Status[2];
UCHAR i,count;
TiDTV_I2cRead(MSP430_I2C_CHANNEL, 0, MSP430_I2C_DEVICE_ADDR, 1, 0x32, 2, &Status[0], OS_TICKS_PER_SEC / 2);
// Status dispatch;
// TiDTV_MenuTaskStatus() == OS_NO_ERR
switch(Status[1])
{
case 0x01: //TI_DTV_IR_KEY_POWER:
//TiDTV_PutKeyCode(TI_DTV_IR_KEY_POWER);
TiDTV_PowerOff();
break;
case 0x06: //TI_DTV_IR_KEY_INPUT:06 // TV/Video Input Selection
TiDTV_PutKeyCode(TI_DTV_IR_KEY_INPUT);
break;
case 0x04: //TI_DTV_IR_KEY_CH_UP:04
if(TiDTV_MenuTaskStatus() == OS_NO_ERR)
TiDTV_PutKeyCode(TI_DTV_IR_KEY_UP);
else
TiDTV_PutKeyCode(TI_DTV_IR_KEY_CH_UP);
break;
case 0x09: //TI_DTV_IR_KEY_CH_DOWN:09
if(TiDTV_MenuTaskStatus() == OS_NO_ERR)
TiDTV_PutKeyCode(TI_DTV_IR_KEY_DOWN);
else
TiDTV_PutKeyCode(TI_DTV_IR_KEY_CH_UP);
break;
case 0x08: //TI_DTV_IR_KEY_VOL_UP: // Volume Up (++)08
if(TiDTV_MenuTaskStatus() == OS_NO_ERR)
TiDTV_PutKeyCode(TI_DTV_IR_KEY_LEFT);
else
TiDTV_PutKeyCode(TI_DTV_IR_KEY_VOL_UP);
break;
case 0x07: //TI_DTV_IR_KEY_VOL_DOWN: // Volume Down (--)07
if(TiDTV_MenuTaskStatus() == OS_NO_ERR)
TiDTV_PutKeyCode(TI_DTV_IR_KEY_RIGHT);
else
TiDTV_PutKeyCode(TI_DTV_IR_KEY_VOL_DOWN);
break;
case 0x05: //TI_DTV_IR_KEY_MENU:05
TiDTV_PutKeyCode(TI_DTV_IR_KEY_MENU);
break;
}
OSTimeDly(OS_TICKS_PER_SEC/100);
i=tvpGpioRead()&0x08;
if(i!=0)
{
for(count=0; count<20; count++)
{
i = tvpGpioRead()&0x08;
OSTimeDly(OS_TICKS_PER_SEC/50);
TiDTV_I2cRead(MSP430_I2C_CHANNEL, 0, MSP430_I2C_DEVICE_ADDR, 1, 0x32, 2, &Status[0], OS_TICKS_PER_SEC / 2);
}
}
}
/*******************************************************************************
* @RoutineName:: TiDTV_PutDataMsp430
*
* @Description:: Store data to the Msp430 flash memery
*
* @Input :: pTxData ---data buffer
* Address --- Msp430 flash memery address (should be even)
* LengthBuff --- the length of data buffer
* @Output :: none
*
* @Return :: none
*******************************************************************************/
void TiDTV_PutDataMsp430(UCHAR *pTxData, UINT16 Address, UINT16 LengthBuff)
{
UCHAR Databuf[14];
int i,temp;
UCHAR Length;
UINT16 AddressFlash;
temp = (int)(LengthBuff/10);
//AddressFlash = Address;
Databuf[0] = 0x33;
Databuf[1] = 10;
Databuf[2] = 0x80;
Databuf[3] = 0x00; //command for write Msp430
for(i=0; i<LengthBuff/10; i++)
{
memcpy(Databuf+4, pTxData+i*10,10);
AddressFlash = Address +10*i;
Databuf[2] = (UCHAR)(AddressFlash);
Databuf[3] = (UCHAR)(AddressFlash>>8);
TiDTV_I2cWrite(MSP430_I2C_CHANNEL, 0,MSP430_I2C_DEVICE_ADDR,14,Databuf, OS_TICKS_PER_SEC / 2);
OSTimeDly( OS_TICKS_PER_SEC/10);
}
Length = LengthBuff%10;
AddressFlash = Address+temp*10;
Databuf[1] = Length;
Databuf[2] = (UCHAR)(AddressFlash);
Databuf[3] = (UCHAR)(AddressFlash>>8);
memcpy(Databuf+4, pTxData+temp*10,Length);
TiDTV_I2cWrite(MSP430_I2C_CHANNEL, 0,MSP430_I2C_DEVICE_ADDR,Length+4,Databuf, OS_TICKS_PER_SEC / 2);
}
/*******************************************************************************
* @RoutineName:: TiDTV_GetDataMsp430
*
* @Description:: get data from the Msp430 flash memery
*
* @Input :: pTxData ---data buffer
* Address --- Msp430 flash memery address (should be even)
* LengthBuff --- the length of data buffer
* @Output :: none
*
* @Return :: none
*******************************************************************************/
void TiDTV_GetDataMsp430(UCHAR *pRxData, UINT16 Address, UINT16 LengthBuff)
{
UCHAR Databuff[14];
UCHAR command[6];
int i,temp;
UINT16 AddressFlash;
UCHAR Length;
temp = (int)(LengthBuff/10);
command[0] = MSP430_I2C_DEVICE_ADDR;
command[1] = 0x34;
command[2] = 10;
command[5] = MSP430_I2C_DEVICE_ADDR+1;
OSTimeDly( OS_TICKS_PER_SEC/10);
for(i=0;i<temp;i++)
{
AddressFlash = Address+i*10;
command[3] = (UCHAR)(AddressFlash);
command[4] = (UCHAR)(AddressFlash>>8);
TiDTV_I2cReadAfterWrite(MSP430_I2C_CHANNEL, 0, 6, command, 14, Databuff, OS_TICKS_PER_SEC / 2);
OSTimeDly( OS_TICKS_PER_SEC/10);
memcpy(pRxData+10*i,Databuff+4,10);
}
Length = LengthBuff%10;
command[2] = Length;
AddressFlash = Address + temp*10;
command[3] = (UCHAR)(AddressFlash);
command[4] = (UCHAR)(AddressFlash>>8);
TiDTV_I2cReadAfterWrite(MSP430_I2C_CHANNEL, 0, 6, command, Length+4, Databuff, OS_TICKS_PER_SEC / 2);
memcpy(pRxData +temp*10, Databuff+4, Length);
}
/*******************************************************************************
* @RoutineName:: TiDTV_SetPWMMsp430
*
* @Description:: updata pwm value to changer backlight
*
* @Input :: Value --- the pwm pulse space rate
*
*
* @Output :: none
*
* @Return :: none
*******************************************************************************/
void TiDTV_SetPWMMsp430(UCHAR Value)
{
UCHAR Datebuf[3];
Datebuf[0]=0x37;
Datebuf[1]=Value;
TiDTV_I2cWrite(MSP430_I2C_CHANNEL, 0, MSP430_I2C_DEVICE_ADDR,2,Datebuf, OS_TICKS_PER_SEC / 2);
}
/*******************************************************************************
* @RoutineName:: TiDTV_SetRTCMsp430
*
* @Description:: set Rtc to the Msp430
*
* @Input :: Value --- 4byte data second
*
*
* @Output :: none
*
* @Return :: none
*******************************************************************************/
void TiDTV_SetRTCMsp430(ULONG Value)
{
UCHAR Databuf[5];
Databuf[0] = 0x35;
Databuf[1] = (UCHAR)Value;
Databuf[2] = (UCHAR)Value>>8;
Databuf[3] = (UCHAR)Value>>16;
Databuf[4] = (UCHAR)Value>>24;
TiDTV_I2cWrite(MSP430_I2C_CHANNEL, 0, MSP430_I2C_DEVICE_ADDR,5,Databuf, OS_TICKS_PER_SEC / 2);
}
/*******************************************************************************
* @RoutineName:: TiDTV_SetPWMMsp430
*
* @Description:: get RTC from Msp430
*
* @Input :: none
*
* @Output :: none
*
* @Return :: value 4byte data second
*******************************************************************************/
ULONG TiDTV_GetRTCMsp430(void)
{
UCHAR Databuf[5];
ULONG temp =0;
TiDTV_I2cRead(MSP430_I2C_CHANNEL, 0, MSP430_I2C_DEVICE_ADDR, 1,0x36,5, &Databuf[0], OS_TICKS_PER_SEC / 2);
temp = (ULONG)Databuf[4]<<24 & 0xff000000;
temp |= (ULONG)Databuf[3]<<16 & 0xff0000;
temp |= (ULONG)Databuf[2]<<8 & 0xff00;
temp |= (ULONG)Databuf[1];
return(temp);
}
⌨️ 快捷键说明
复制代码
Ctrl + C
搜索代码
Ctrl + F
全屏模式
F11
切换主题
Ctrl + Shift + D
显示快捷键
?
增大字号
Ctrl + =
减小字号
Ctrl + -