⭐ 欢迎来到虫虫下载站! | 📦 资源下载 📁 资源专辑 ℹ️ 关于我们
⭐ 虫虫下载站

📄 smt_acm3.c

📁 GM5621原代码
💻 C
字号:
/*
   $Workfile:   smt_acm3.c  $
   $Revision:   1.0  $
   $Date:   Jan 03 2006 03:26:36  $
*/

//******************************************************************
//
//    Copyright (C) 2005.  GENESIS MICROCHIP INC.
// All rights reserved.  No part of this program may be reproduced
//
// Genesis Microchip Inc., 165 Commerce Valley Dr. West
//    Thornhill, Ontario, Canada, L3T 7V8
//
//================================================================
//
// MODULE:      smt_acm3.c
//
//******************************************************************

//#include "CommLink\smt.h"
//#include "CommLink\smt_acm3.h"
//#include "StdLibInc\gm_ACM3D.h"
//#include "StdLibInc\gm_Register.h"
#include "inc\all.h"

#define _DEBUG_MSG
#ifdef _DEBUG_MSG
	#define msg(x,y)		gm_Print(x,y)
#else
	#define msg(x,y)
#endif

#if (USE_SMT && USE_ACM_3D)

//Marco to remove compilation error due to inconsistent name between GSEL of Cortez and Insam
#define ERR_SEND	gmd_ERR_SEND
#define OK			gmd_OK
#define ERR_PARAM	gmd_ERR_PARAM

static BYTE ACM3_SMT_Write(BYTE B_TransId, BYTE * Bp_msg, BYTE comm_use,
						BYTE far * Bp_Context, BYTE B_NextTMsg);
static BYTE ACM3_SMT_Read(BYTE B_TransId, BYTE * Bp_msg, BYTE comm_use,
						BYTE far * Bp_Context, BYTE B_NextTMsg);

//******************************************************************************
//
// FUNCTION     :   BYTE ACM3_SMT_MsgHandler(MsgPacket_t *message, BYTE comm_use)
// USAGE        :   This function parse the SMT messages for ACM3 feature
//
// INPUT        :   MsgPacket_t *message = SMT message
//                  BYTE comm_use  = SERIAL_USE or DDC2BI_USE
// OUTPUT       :   OK = if no error, ERR_SEND = if error is found
//
//******************************************************************************
BYTE ACM3_SMT_MsgHandler(MsgPacket_t *message, BYTE comm_use)
{
	BYTE * Bp_msg = (BYTE *)message;
	BYTE B_Success = ERR_SEND;
	//gmt_MsgStruct  OutMsg;
	BYTE B_TransId;
	BYTE B_ContextStatus;
	BYTE far * Bp_Context = NULL_PTR;
	BYTE B_ContextCnt = 0;
	WORD W_CurrentCmd = ACM3_UNUSEDCMD;

	B_TransId = message->control;

	// get buffer pointer from SMT driver
	B_ContextStatus = SMT_GetBuffer( B_TransId, (BYTE far * far *)&Bp_Context, ACM3_CONTEXT_SIZE );

	// If B_ContextStatus is FIRST_REQUEST clear Bp_Context buffer
	if ( B_ContextStatus == FIRST_REQUEST )
	{
		for( B_ContextCnt = 0; B_ContextCnt < ACM3_CONTEXT_SIZE; B_ContextCnt++ )
			*(Bp_Context + B_ContextCnt) = 0;
		W_CurrentCmd = (Bp_msg[5] << 8) + Bp_msg[4];
		*(Bp_Context + 0) = Bp_msg[4]; 
		*(Bp_Context + 1) = Bp_msg[5];
	}
	else if ( B_ContextStatus == NEXT_REQUEST )
	{
		W_CurrentCmd = ((*(Bp_Context + 1))<<8) + (*(Bp_Context + 0));
	}
	else if (B_ContextStatus == NO_MEMORY) // do we have valid allocated memory ?
	{
		// send replay
		Bp_msg[0] = SMTDEBUG = 6;		// message length
		Bp_msg[1] = SMTDEBUG = CMD_SMTProtocol;	// GProbe SMT comand
		//Bp_msg[2] = EvOdd;	// return even/odd flag
		Bp_msg[3] = SMTDEBUG = B_TransId;
		Bp_msg[4] = SMTDEBUG = ACM3_ERROR;
		gm_CommsSendReply((gmt_MsgStruct far*)Bp_msg, comm_use);
		return ERR_PARAM;
	}

	switch( W_CurrentCmd )
	{
		case ACM3_GETMAXREGION:
			// send replay
			SMTCHECKSUM(0xa0);
			Bp_msg[0] = SMTDEBUG = 7;		// message length
			Bp_msg[3] = SMTDEBUG = B_TransId;
			Bp_msg[4] = SMTDEBUG = ACM3_OK;
			Bp_msg[5] = SMTDEBUG = ACM3_REGION_NUM; // the supported by HW number of regions
			gm_CommsSendReply((gmt_MsgStruct far*)Bp_msg, comm_use);
			break;

		case ACM3_GETMAXREGIONSPERTRANS:
			// send replay
			SMTCHECKSUM(0xa1);
			Bp_msg[0] = SMTDEBUG = 7;		// message length
			Bp_msg[3] = SMTDEBUG = B_TransId;
			Bp_msg[4] = SMTDEBUG = ACM3_OK;
			Bp_msg[5] = SMTDEBUG = 1; // the supported number of region's data per transaction
			gm_CommsSendReply((gmt_MsgStruct far*)Bp_msg, comm_use);
			break;

		case ACM3_WRITEANDRUN:
			B_Success = ACM3_SMT_Write( B_TransId, Bp_msg, comm_use, Bp_Context,
											B_ContextStatus);
			break;

		case ACM3_READALL:
			B_Success = ACM3_SMT_Read( B_TransId, Bp_msg, comm_use, Bp_Context,
											B_ContextStatus);
			break;

		case ACM3_SETWINDOW:	// set window to show ACM3
			{
				BYTE B_WindowCtrl;

				B_WindowCtrl = Bp_msg[ 6 ];
				gm_ACM3DUpdateCtrl( (B_WindowCtrl?1:0), (B_WindowCtrl | ACM_WIN_CTRL));
				B_Success = OK;
				// send replay
				Bp_msg[0] = SMTDEBUG = 6;		// message length
				Bp_msg[3] = SMTDEBUG = B_TransId;
				Bp_msg[4] = SMTDEBUG = ACM3_OK;
				gm_CommsSendReply((gmt_MsgStruct far*)Bp_msg, comm_use);
			}
			break;

		default:
			// send replay
			Bp_msg[0] = SMTDEBUG = 6;		// message length
			Bp_msg[3] = SMTDEBUG = B_TransId;
			Bp_msg[4] = SMTDEBUG = ACM3_ERROR;
			gm_CommsSendReply((gmt_MsgStruct far*)Bp_msg, comm_use);
			break;
	};
	return B_Success;
}


//******************************************************************************
//
// FUNCTION     :   static BYTE ACM3_SMT_Write(BYTE B_TransId, BYTE * Bp_msg, BYTE comm_use)
// USAGE        :   This function parses the SMT ACM3_WRITEANDRUN message
//
// INPUT        :   BYTE * Bp_msg points to SMT message
// OUTPUT       :   OK = if no error, ERR_ = if error is found
//
//******************************************************************************
static BYTE ACM3_SMT_Write(BYTE B_TransId, BYTE * Bp_msg,
						BYTE comm_use, BYTE far * Bp_Context, BYTE B_NextTMsg)
{
	BYTE B_Region;
	BYTE B_ContextCnt = 0;
	BYTE B_SrcCnt = 0;
	BYTE * Bp_Src = Bp_msg;
	BYTE B_SrcSize; // sub GProbe header and footer
	gmt_ACM3DRegionDef gma_RegionDefs[ACM3_REGION_NUM] =
	{
	//	W_HueCenter, B_HueAperture,	B_R1, B_R2, B_Y1, B_Y2, B_HueFade, B_SatFade, B_LumiFade
	{0, 0, 0, 0, 0, 0, 0, 0, 0}, 
	{0, 0, 0, 0, 0, 0, 0, 0, 0}, 
	{0, 0, 0, 0, 0, 0, 0, 0, 0}, 
	{0, 0, 0, 0, 0, 0, 0, 0, 0}, 
	{0, 0, 0, 0, 0, 0, 0, 0, 0}, 
	{0, 0, 0, 0, 0, 0, 0, 0, 0}, 
	{0, 0, 0, 0, 0, 0, 0, 0, 0}, 
	{0, 0, 0, 0, 0, 0, 0, 0, 0}, 
	};
	gmt_ACM3DCorrectionParams gma_CorrectionParamDefs[ACM3_REGION_NUM] =
	{
	// 	sB_HueOffs, sB_HueGain, sB_SatOffs, sB_SatGain, sB_LumiOffs, sB_LumiGain, sB_U_Vect, sB_V_Vect, B_Alpha
	{ 0, 0, 0, 0, 0, 0, 0, 0, 0}, 
	{ 0, 0, 0, 0, 0, 0, 0, 0, 0}, 
	{ 0, 0, 0, 0, 0, 0, 0, 0, 0}, 
	{ 0, 0, 0, 0, 0, 0, 0, 0, 0}, 
	{ 0, 0, 0, 0, 0, 0, 0, 0, 0}, 
	{ 0, 0, 0, 0, 0, 0, 0, 0, 0}, 
	{ 0, 0, 0, 0, 0, 0, 0, 0, 0}, 
	{ 0, 0, 0, 0, 0, 0, 0, 0, 0}, 
	};
   
	B_ContextCnt = *(Bp_Context + 2);
	if (B_NextTMsg)
	{
		Bp_Src = Bp_Src + 4; // to skip Gprobe header
		B_SrcSize = Bp_msg[0] - 5;
	}
	else
	{
		Bp_Src = Bp_Src + 6; // to skip Gprobe header
		B_SrcSize = Bp_msg[0] - 7;
	}
	
	while(B_SrcCnt < B_SrcSize)
	{
		*(Bp_Context + 3 + B_ContextCnt) = *(Bp_Src + B_SrcCnt);
		B_ContextCnt++; 
		(*(Bp_Context + 2))++; // data counter
		B_SrcCnt++;

		if( B_ContextCnt >= (ACM3_CONTEXT_SIZE - 1))
		{
			//
			// region is filled out, ready to write to HW
			//
			B_Region = Bp_Context[ REGION_B ];
			if(( B_Region > ACM3_REGION_NUM ) || (B_Region == 0))
			{
				// send replay
				Bp_msg[0] = 6;		// message length
				Bp_msg[3] = B_TransId;
				Bp_msg[4] = ACM3_INVALIDPARAM;
				gm_CommsSendReply((gmt_MsgStruct far*)Bp_msg, comm_use);
				return ERR_PARAM;
			}
			else 
				B_Region--;
			
			// read all data, update recieved region data and write them back
			// Set pointers to temporary arrays
			gm_ACM3DSetRegionDefinitionTablePtr((gmt_ACM3DRegionDef far *)&gma_RegionDefs);
			gm_ACM3DSetCorrectionParamsTablePtr((gmt_ACM3DCorrectionParams far *)&gma_CorrectionParamDefs);
			gm_ACM3DReadAll(); // read ACM3D data to these arrays (all 8 regiones)
			// copy values one-by-one
			gma_RegionDefs[B_Region].W_HueCenter = 
				(Bp_Context[HUE_CENT_HB]<<8)+Bp_Context[HUE_CENT_LB];
			gma_RegionDefs[B_Region].B_HueAperture = Bp_Context[HUE_APERT_LB];
			gma_RegionDefs[B_Region].B_HueFade = Bp_Context[HUE_FADE_LB];
			gma_RegionDefs[B_Region].B_Y1 = Bp_Context[LUMI_Y1_LB];
			gma_RegionDefs[B_Region].B_Y2 = Bp_Context[LUMI_Y2_LB];
			gma_RegionDefs[B_Region].B_LumiFade = Bp_Context[LUMI_FADE_LB];
			gma_RegionDefs[B_Region].B_R1 = Bp_Context[SAT_R1_LB];
			gma_RegionDefs[B_Region].B_R2 = Bp_Context[SAT_R2_LB];
			gma_RegionDefs[B_Region].B_SatFade = Bp_Context[SAT_FADE_LB];

			gma_CorrectionParamDefs[B_Region].sB_HueGain = Bp_Context[HUE_GAIN_LB];
			gma_CorrectionParamDefs[B_Region].sB_HueOffs = Bp_Context[HUE_OFFS_LB];
			gma_CorrectionParamDefs[B_Region].sB_LumiGain = Bp_Context[LUMI_GAIN_LB];
			gma_CorrectionParamDefs[B_Region].sB_LumiOffs = Bp_Context[LUMI_OFFS_LB];
			gma_CorrectionParamDefs[B_Region].sB_SatGain = Bp_Context[SAT_GAIN_LB];
			gma_CorrectionParamDefs[B_Region].sB_SatOffs = Bp_Context[SAT_OFFS_LB];
			gma_CorrectionParamDefs[B_Region].sB_U_Vect = Bp_Context[U_VECT_LB];
			gma_CorrectionParamDefs[B_Region].sB_V_Vect = Bp_Context[V_VECT_LB];
			gma_CorrectionParamDefs[B_Region].B_Alpha = Bp_Context[ALPHA_LB];

			// when all data are ready, initialize ACM3	
			gm_ACM3DInit();

			B_ContextCnt = 0; // clear local counter 
			*(Bp_Context + 2) = 0; // clear counter in context
		}
	}

	// send replay
	Bp_msg[0] = 6;		// message length
	Bp_msg[3] = B_TransId;
	Bp_msg[4] = ACM3_OK;
	gm_CommsSendReply((gmt_MsgStruct far*)Bp_msg, comm_use);
	return OK; 
}

//******************************************************************************
//
// FUNCTION     :   static BYTE ACM3_SMT_Read(BYTE B_TransId, BYTE * Bp_msg, BYTE comm_use)
// USAGE        :   This function executes the SMT ACM3_READ message
//
// INPUT        :   BYTE * Bp_msg points to SMT message
// OUTPUT       :   OK = if no error, ERR_SEND = if error is found
//
//******************************************************************************
static BYTE ACM3_SMT_Read(BYTE B_TransId, BYTE * Bp_msg, BYTE comm_use,
					BYTE far * Bp_Context, BYTE B_NextTMsg)
{
	BYTE B_Region;
	BYTE B_Offs;
	gmt_ACM3DRegionDef gma_RegionDefs[ACM3_REGION_NUM] = 
	{
	//	W_HueCenter, B_HueAperture,	B_R1, B_R2, B_Y1, B_Y2, B_HueFade, B_SatFade, B_LumiFade
	{0, 0, 0, 0, 0, 0, 0, 0, 0}, 
	{0, 0, 0, 0, 0, 0, 0, 0, 0}, 
	{0, 0, 0, 0, 0, 0, 0, 0, 0}, 
	{0, 0, 0, 0, 0, 0, 0, 0, 0}, 
	{0, 0, 0, 0, 0, 0, 0, 0, 0}, 
	{0, 0, 0, 0, 0, 0, 0, 0, 0}, 
	{0, 0, 0, 0, 0, 0, 0, 0, 0}, 
	{0, 0, 0, 0, 0, 0, 0, 0, 0}, 
	};
	gmt_ACM3DCorrectionParams gma_CorrectionParamDefs[ACM3_REGION_NUM] = 
	{
	// 	sB_HueOffs, sB_HueGain, sB_SatOffs, sB_SatGain, sB_LumiOffs, sB_LumiGain, sB_U_Vect, sB_V_Vect, B_Alpha
	{ 0, 0, 0, 0, 0, 0, 0, 0, 0}, 
	{ 0, 0, 0, 0, 0, 0, 0, 0, 0}, 
	{ 0, 0, 0, 0, 0, 0, 0, 0, 0}, 
	{ 0, 0, 0, 0, 0, 0, 0, 0, 0}, 
	{ 0, 0, 0, 0, 0, 0, 0, 0, 0}, 
	{ 0, 0, 0, 0, 0, 0, 0, 0, 0}, 
	{ 0, 0, 0, 0, 0, 0, 0, 0, 0}, 
	{ 0, 0, 0, 0, 0, 0, 0, 0, 0}, 
	};

	if (B_NextTMsg)
	{
		B_Region = *(Bp_Context + 2);
	}
	else
	{
		B_Region = 0;
		*(Bp_Context + 2) = B_Region;
	}

	// to differentiate between first and other messages
	B_Offs = ( B_Region == 0 ) ? 1 : 0;

	// Set pointers to temporary arrays
	gm_ACM3DSetRegionDefinitionTablePtr((gmt_ACM3DRegionDef far *)&gma_RegionDefs);
	gm_ACM3DSetCorrectionParamsTablePtr((gmt_ACM3DCorrectionParams far *)&gma_CorrectionParamDefs);

	// read ACM3D data to these arrays (all 8 regiones)
	gm_ACM3DReadAll();

	// copy data from arrays to buffer to replay to SMT master
	// copy values one-by-one
	Bp_msg[B_Offs + 4] = B_Region + 1;
	Bp_msg[B_Offs+1+HUE_CENT_LB] = (BYTE)(0xFF & gma_RegionDefs[B_Region].W_HueCenter);
	Bp_msg[B_Offs+1+HUE_CENT_HB] = (BYTE)(0xFF & (gma_RegionDefs[B_Region].W_HueCenter>>8));
	Bp_msg[B_Offs+1+HUE_APERT_LB] = (BYTE)(0xFF & gma_RegionDefs[B_Region].B_HueAperture);
	Bp_msg[B_Offs+1+HUE_APERT_HB] = 0;
	Bp_msg[B_Offs+1+HUE_FADE_LB] = (BYTE)(0xFF & gma_RegionDefs[B_Region].B_HueFade);
	Bp_msg[B_Offs+1+HUE_FADE_HB] = 0;
	Bp_msg[B_Offs+1+LUMI_Y1_LB] = (BYTE)(0xFF & gma_RegionDefs[B_Region].B_Y1);
	Bp_msg[B_Offs+1+LUMI_Y1_HB] = 0;
	Bp_msg[B_Offs+1+LUMI_Y2_LB] = (BYTE)(0xFF & gma_RegionDefs[B_Region].B_Y2);
	Bp_msg[B_Offs+1+LUMI_Y2_HB] = 0;
	Bp_msg[B_Offs+1+LUMI_FADE_LB] = (BYTE)(0xFF & gma_RegionDefs[B_Region].B_LumiFade);
	Bp_msg[B_Offs+1+LUMI_FADE_HB] = 0;
	Bp_msg[B_Offs+1+SAT_R1_LB] = (BYTE)(0xFF & gma_RegionDefs[B_Region].B_R1);
	Bp_msg[B_Offs+1+SAT_R1_HB] = 0;
	Bp_msg[B_Offs+1+SAT_R2_LB] = (BYTE)(0xFF & gma_RegionDefs[B_Region].B_R2);
	Bp_msg[B_Offs+1+SAT_R2_HB] = 0;
	Bp_msg[B_Offs+1+SAT_FADE_LB] = (BYTE)(0xFF & gma_RegionDefs[B_Region].B_SatFade);
	Bp_msg[B_Offs+1+SAT_FADE_HB] = 0;

	Bp_msg[B_Offs+1+HUE_GAIN_LB] = (BYTE)(0xFF & gma_CorrectionParamDefs[B_Region].sB_HueGain);
	Bp_msg[B_Offs+1+HUE_GAIN_HB] = ((gma_CorrectionParamDefs[B_Region].sB_HueGain & BIT3)==BIT3)?0xFF:0x00;
	Bp_msg[B_Offs+1+HUE_OFFS_LB] = (BYTE)(0xFF & gma_CorrectionParamDefs[B_Region].sB_HueOffs);
	Bp_msg[B_Offs+1+HUE_OFFS_HB] = ((gma_CorrectionParamDefs[B_Region].sB_HueOffs & BIT7)==BIT7)?0xFF:0x00;
	Bp_msg[B_Offs+1+LUMI_GAIN_LB] = (BYTE)(0xFF & gma_CorrectionParamDefs[B_Region].sB_LumiGain);
	Bp_msg[B_Offs+1+LUMI_GAIN_HB] = 0x00;
	Bp_msg[B_Offs+1+LUMI_OFFS_LB] = (BYTE)(0xFF & gma_CorrectionParamDefs[B_Region].sB_LumiOffs);
	Bp_msg[B_Offs+1+LUMI_OFFS_HB] = ((gma_CorrectionParamDefs[B_Region].sB_LumiOffs & BIT7)==BIT7)?0xFF:0x00;
	Bp_msg[B_Offs+1+SAT_GAIN_LB] = (BYTE)(0xFF & gma_CorrectionParamDefs[B_Region].sB_SatGain);
	Bp_msg[B_Offs+1+SAT_GAIN_HB] = 0x00;
	Bp_msg[B_Offs+1+SAT_OFFS_LB] = (BYTE)(0xFF & gma_CorrectionParamDefs[B_Region].sB_SatOffs);
	Bp_msg[B_Offs+1+SAT_OFFS_HB] = ((gma_CorrectionParamDefs[B_Region].sB_SatOffs & BIT7)==BIT7)?0xFF:0x00;

	Bp_msg[B_Offs+1+U_VECT_LB] = (BYTE)(0xFF & gma_CorrectionParamDefs[B_Region].sB_U_Vect);
	Bp_msg[B_Offs+1+U_VECT_HB] = ((gma_CorrectionParamDefs[B_Region].sB_U_Vect & BIT7)==BIT7)?0xFF:0x00;
	Bp_msg[B_Offs+1+V_VECT_LB] = (BYTE)(0xFF & gma_CorrectionParamDefs[B_Region].sB_V_Vect);
	Bp_msg[B_Offs+1+V_VECT_HB] = ((gma_CorrectionParamDefs[B_Region].sB_V_Vect & BIT7)==BIT7)?0xFF:0x00;
	Bp_msg[B_Offs+1+ALPHA_LB] = (BYTE)(0xFF & gma_CorrectionParamDefs[B_Region].B_Alpha);
	Bp_msg[B_Offs+1+ALPHA_HB] = 0;

	// to indicate the last transport message
	if ( B_Region == ACM3_REGION_NUM-1 )
	{
		Bp_msg[2] = Bp_msg[2] & (~MORE_DATA_BIT);
	}
	else
	{
		Bp_msg[2] = Bp_msg[2] | MORE_DATA_BIT;	
	}

	// send replay
	Bp_msg[0] = SMT_REGION_DATA_SIZE + B_Offs + 1 + 5;		// message length
	Bp_msg[3] = B_TransId;
	Bp_msg[4] = ACM3_OK;
	gm_CommsSendReply((gmt_MsgStruct far*)Bp_msg, comm_use);

	B_Region++;
	*(Bp_Context + 2) = B_Region;
	return OK; 
}

#endif


⌨️ 快捷键说明

复制代码 Ctrl + C
搜索代码 Ctrl + F
全屏模式 F11
切换主题 Ctrl + Shift + D
显示快捷键 ?
增大字号 Ctrl + =
减小字号 Ctrl + -