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

📄 hamaro_reg.c

📁 机顶盒Hamaro解调器驱动。包含自动搜台
💻 C
📖 第 1 页 / 共 5 页
字号:
        {
            break;
        }
        bytes += bits_per_read;
    }
    
    /* Translate: raw data read from the hardware registers to data used by the driver*/  
    switch(p_register_map[reg_field_index].reg_type)
    {
		case HAMARO_REGT_BITHL: /* Latch -> this bit is latched hi, then immediately low */
		{
			*p_value = (unsigned char)p_register_map[reg_field_index].p_hw_mask[0];
			break;
		}
        case HAMARO_REGT_BIT:
		case HAMARO_REGT_NULL:
        case HAMARO_REGT_BYTE:
		{
			if (p_register_map[reg_field_index].bit_count == 0x01) /* single bit */
			{
				/* Mask the bit to 1 or 0 */
				if ((reg_buffer[0] & p_register_map[reg_field_index].p_hw_mask[0]) != 0)            
				{
					*p_value = 0x01;
				}
				else
				{
					*p_value = 0x00;
				}
				break;
			}
			else
			{
				/* Min 2 bits, max 8 bits */
				unsigned char temp;

				/* mask useful bits from raw, shift rt (make range 0..2^bit_count) */
				temp = (unsigned char)(reg_buffer[0] & (unsigned char)p_register_map[reg_field_index].p_hw_mask[0]);            
				temp = (unsigned char)(temp >> (startbit-(p_register_map[reg_field_index].bit_count-1)));
				*p_value = (unsigned char)temp;
				break;
			}
		}
        case  HAMARO_REGT_MINT:
        {
            unsigned short byte_count;
            unsigned char  bit_value; 
            unsigned char  byte_index; 
            unsigned char  bit_mask;

			/* count the number of hardware reg bytes that comprise the register in question */
            for (byte_count = 0; byte_count < HAMARO_MAX_REGISTER_LEN; byte_count++)  
            {
                if (p_register_map[reg_field_index].p_hw_mask[byte_count] == 0x00)  
                {
                    break;
                }
            }

            /* Convert multiple byte value from spread bits to compressed */
            for (byte_index = 0; byte_index < byte_count; byte_index++)
            {
                for (bit_mask = 0x80; bit_mask != 0; bit_mask >>= 1)
                {
                    if ((p_register_map[reg_field_index].p_hw_mask[byte_index]  & bit_mask) != 0)
                    {
                        bit_value = (unsigned char)((bit_mask & reg_buffer[byte_index]) != 0 ? 1UL : 0UL);
                        *p_value  = ((*p_value << 1) | bit_value);
                    }
                }
            }
            break;
        }

        default:
			HAMARO_DRIVER_SET_ERROR(p_nim, HAMARO_REG_VERFY_REGDTP);
			return(False);
    }  /* switch(... */

    return (True);
} /* HAMARO_RegisterRead */
#if HAMARO_INCLUDE_RATTLER
/*******************************************************************************************************
 *                 R E G I S T E R    I N T E R F A C E    F U N C T I O N S
 *******************************************************************************************************/
/* ===                                Register Functions                                            ===*/
/*******************************************************************************************************
 * Name: HAMARO_TunerRegisterWrite
 *
 * Description:
 * 	This function writes to a bit-field or a byte in the special control area. This function is NOT 
 *     applicable for Page0 address space since it is read-only.
 * Return Value:
 * 	TRUE - operation successful; FALSE - otherwise.
 *
 * I/O	Parameters	                         Descriptions
 * IN	HAMARO_NIM*               p_nim	     Pointer to HAMARO_NIM structure allocated by application
 * IN	REGISTER_BIT_FIELD reg_field_index	 Index that uniquely identifies the value within a register 
 *                                           (or spanning multiple 8-bit registers while reading from Page0). 
 * IN	unsigned long      value	         Value to be written.
 *******************************************************************************************************/
BOOL 
HAMARO_TunerRegisterWrite(HAMARO_NIM*       p_nim,
					unsigned short   reg_field_index, 
					unsigned long    value,
					HAMARO_IO_METHOD  io_method)
{
    if(HAMARO_TUNER_CX24128_RepeaterModeWriteData(p_nim, p_nim->tuner.cx24128.tuner_handle, reg_field_index, value) == False)
     {
        return(False);
     }
     return (True);
}
/*******************************************************************************************************
 * Name: HAMARO_TunerRegisterRead
 * Description:
 * 	This function reads from a bit-field or a byte in the special control area. This function is NOT 
 *   applicable for Page0 address space since it is read-only.
 * Return Value:
 * 	TRUE - operation successful; FALSE - otherwise.
 *
 * I/O	Parameters	                        Descriptions
 * IN	HAMARO_NIM*               p_nim	        Pointer to HAMARO_NIM structure allocated by application
 * IN	unsigned short     reg_field_index	Index that uniquely identifies the value within a register 
 *                                          or one that spans multiple 8-bit registers beginning form 
 *                                          the address that corresponds to this reg_field_index. 
 * IN	unsigned long*     p_value	        Value read from the Page0 or Special control address.
 * IN   HAMARO_IO_METHOD          io_method		Use specified io method for serial read/write.
 *   
 *******************************************************************************************************/
BOOL 
HAMARO_TunerRegisterRead(HAMARO_NIM*         p_nim,
				   unsigned short     reg_field_index, 
				   unsigned long*     p_value,
				   HAMARO_IO_METHOD    io_method)
{
    if(HAMARO_TUNER_CX24128_RepeaterModeReadData(p_nim, p_nim->tuner.cx24128.tuner_handle, reg_field_index, (unsigned char *)p_value)== False)
     {
        return(False);
     }
     return (True);
}
#endif
#if HAMARO_INCLUDE_DEBUG
/*******************************************************************************************************/
/* RegisterVerifyMap() */
/*******************************************************************************************************/
static BOOL 
RegisterVerifyMap(HAMARO_NIM *nim)   /* function to verify register map (run at start of driver) */
{
  /* performs initialization-time checking of register structure */
  int  i;
  static char  *rvm_msg = "RegisterVerifyMap()";

  for (i = 0 ; i < CX2430X_REG_COUNT ; i++)
  {
    /* test that index number matches the count */
    if (hamaro_demod_register_map[i].bit_field != (HAMARO_REGIDX)i)
    {
        /* read error reading hardware */
        HAMARO_DRIVER_SET_ERROR_MSG(nim,HAMARO_REG_VERFY_IDX,rvm_msg,i);
        return(False);
    }

    /* test that address is within valid range */
    if (hamaro_demod_register_map[i].address > HAMARO_MAX_HAMARO_ADDR)
    {
        /* read error reading hardware */
        HAMARO_DRIVER_SET_ERROR_MSG(nim,HAMARO_REG_VERFY_IDX,rvm_msg,i);
        return(False);
    }

    /* test that the various enum flags are valid */
    if (RegisterVerifyRegRW(nim,i) == False)  return(False);
    if (RegisterVerifyRegFilter(nim,i) == False)  return(False);
    if (RegisterVerifyRegDataType(nim,i) == False)  return(False);

    /* test that starting bit number is valid in conjunction with bit_count */
    if (RegisterVerifyRegBitCount(nim,i) == False)  return(False);

    /* test that default_value and testsetting are within the range of pow(2,bit-length) */
    if (RegisterVerifyRegDefault(nim,i) == False)  return(False);
  }

  return(True);

}  /* RegisterVerifyMap() */


/*******************************************************************************************************/
/* RegMapTest() - verifies the register map once */
/*******************************************************************************************************/
BOOL RegMapTest (HAMARO_NIM *nim)
{
	static int regmap_test = False;    /* allows test code to be run once at start-up */

	/* verify register map once at start-up */
	if (regmap_test == False)
	{
		regmap_test = True;

		if (RegisterVerifyMap(nim) != True)
		{
			/* tell exactly where the error occurred! */
			nim->errfname = (char*)hamaro_demod_register_map[nim->errline].regname;
			return(False);
		}
	}
	return (True);
}


/*******************************************************************************************************/
/* RegisterVerifyRegRW() */
/*******************************************************************************************************/
static BOOL  RegisterVerifyRegRW(             /* function to verify register settings */
HAMARO_NIM   *nim,                            /* pointer to nim */
int   idx)                             /* register to test */
{
  static char  *rvm_msg = "RegisterVerifyRegRW()";

  switch (hamaro_demod_register_map[idx].access_level)
  {
    case  HAMARO_REG_RW:
    case  HAMARO_REG_RO:
    case  HAMARO_REG_WO:
    {
      /* above constitute valid values for regrw in reg.map */
      break;
    }
    case  HAMARO_REG_UNUSED:
    default:
    {
      /* invalid setting in reg.map, report to app */
        HAMARO_DRIVER_SET_ERROR_MSG(nim,HAMARO_REG_VERFY_IDX,rvm_msg,idx);
        return(False);
    }
  }  /* switch(... */

  return(True);

}  /* RegisterVerifyRegRW() */


/*******************************************************************************************************/
/* RegisterVerifyRegFilter() */
/*******************************************************************************************************/
static BOOL  RegisterVerifyRegFilter(         /* function to verify reg.map filter setting */
HAMARO_NIM   *nim,                            /* pointer to nim */
int   idx)                             /* register to test */
{

⌨️ 快捷键说明

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