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

📄 hamaro_reg.c

📁 机顶盒Hamaro解调器驱动。包含自动搜台
💻 C
📖 第 1 页 / 共 5 页
字号:
				{
					(*p_nim->SBWrite)(handle, sub_address, 0x00, &p_nim->iostatus); 
				}
			}
        }
        break;

		case HAMARO_REGT_MINT: /* > 1 to 4 byte(s) wide */
		{
			unsigned char startbit = p_register_map[reg_field_index].start_bit;
            signed char bitcnt = (signed char)(p_register_map[reg_field_index].bit_count);
			unsigned char mask;

			if (startbit > 7)
			{
				startbit -= 8;
			}

			/* Read write the multiple bit (> 8 bits) value */
			while (bytes < p_register_map[reg_field_index].bit_count)
			{
#if HAMARO_INCLUDE_VIPER
				if (io_method == HAMARO_VIPER_I2C_IO)
				{
					/* Set special control register to repeater mode. It will go off after one serial bus transaction.*/
					if (HAMARO_TUNER_CX24128_RepeaterModeReadData(p_nim, handle, (unsigned char)(sub_address+offset), &data_read) == False)
					{
						return (False);
					}
				}
#endif /* HAMARO_INCLUDE_VIPER */
				if (io_method == HAMARO_DEMOD_I2C_IO)
				{
					data_read = (unsigned char)((*p_nim->SBRead)(handle, (unsigned char)(sub_address+offset), &p_nim->iostatus)); 

					/* Watch for special-case error, read error during write */
					if (p_nim->iostatus != 0UL)
					{
						/* Hardware write error */
						HAMARO_DRIVER_SET_ERROR(p_nim, HAMARO_REG_HDWR_REWTERR);
						return (False);
					}
				}

				/* mask data that must be retained */
				data_read = (unsigned char)(data_read & (unsigned char)(~p_register_map[reg_field_index].p_hw_mask[index]));
				if ((long)value < 0) 
				{
					/* Take the 2's complement. */
					value = value + (1UL << bitcnt);
				}

				bitcnt = (signed char)(bitcnt - (startbit + 1));

				if (bitcnt > 0)
				{
					data_write = (unsigned char)(value >> bitcnt);
					mask = (unsigned char)(p_register_map[reg_field_index].p_hw_mask[index]);
					data_write &= p_register_map[reg_field_index].p_hw_mask[index];
				}
				else
				{
                    mask = (unsigned char)(p_register_map[reg_field_index].p_hw_mask[index]);
					//data_write = (unsigned char)((value << (0 - bitcnt)) & p_register_map[reg_field_index].p_hw_mask[index]);
					data_write = (unsigned char)(value & p_register_map[reg_field_index].p_hw_mask[index]);
				}
				startbit = 7;
				data_read |= data_write;

#if HAMARO_INCLUDE_VIPER
				if (io_method == HAMARO_VIPER_I2C_IO)
				{
					/* write back the modified value. */
					/* Set special control register to repeater mode. It will go off after one serial bus transaction.*/
					if (HAMARO_TUNER_CX24128_RepeaterModeWriteData(p_nim, handle, (unsigned char)(sub_address+offset), data_read) == False)
					{
						return (False);
					}
				}
#endif /* HAMARO_INCLUDE_VIPER */

				if (io_method == HAMARO_DEMOD_I2C_IO)
				{
					(*p_nim->SBWrite)(handle, (unsigned char)(sub_address+offset), data_read, &p_nim->iostatus); 
					
					/* Watch for special-case error, read error during write */
					if (p_nim->iostatus != 0UL)
					{
						/* Hardware write error */
						HAMARO_DRIVER_SET_ERROR(p_nim, HAMARO_REG_HDWR_REWTERR);
						return (False);
					}
				}

				offset++;
				index++;
				if (index == HAMARO_MAX_REGISTER_LEN)
				{
					break;
				}
				bytes += 8;
			}
		}
		break;

        case HAMARO_REGT_EOLIST:
        default:
        break;
    }
    /* SB Write error */
    if (p_nim->iostatus != 0UL)
    {
      /* write error writing to hardware */
      HAMARO_DRIVER_SET_ERROR(p_nim, HAMARO_IO_WRITERR);
      return (False);
    }

    return (True);
} /* HAMARO_RegisterWrite */

/*******************************************************************************************************
 * Name: HAMARO_RegisterRead
 * 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_RegisterRead(HAMARO_NIM*         p_nim,
				   unsigned short     reg_field_index, 
				   unsigned long*     p_value,
				   HAMARO_IO_METHOD    io_method)
{
    register int   bytes  = 0;    /* counts 8-bits read */
    unsigned char  offset = 0;  
	unsigned char  index  = 0;
    unsigned char  reg_buffer[HAMARO_MAX_REGISTER_LEN];
	unsigned char  sub_address = 0;
	unsigned char  bits_per_read;
	unsigned char  bytes_per_read;

	unsigned long  handle;
	const HAMARO_REGISTER_MAP*  p_register_map;
	unsigned char startbit = 0; 

    /* Validation */
    if (p_nim == 0) /* bad pointer */
    {
        return (False);
    }

    if (p_value == 0)
    {
        return (False);
    }
    *p_value = 0;

	/* Initialization */
	switch (io_method)
	{
		case HAMARO_DEMOD_I2C_IO:
			handle = p_nim->demod_handle;
			p_register_map = hamaro_demod_register_map;
			bits_per_read = 8;
			bytes_per_read = 1;
			break;

#if HAMARO_INCLUDE_VIPER
		case HAMARO_VIPER_I2C_IO:
			handle = p_nim->tuner.cx24128.tuner_handle;
			p_register_map = hamaro_viper_register_map;
			bits_per_read = 8;
			bytes_per_read = 1;
			break;
#endif /* HAMARO_INCLUDE_VIPER */
		default:
			return (False);
	}	

    /* Verify that index passed points to the correct register record */
    if (p_register_map[reg_field_index].bit_field != reg_field_index)
    {
        HAMARO_DRIVER_SET_ERROR (p_nim, HAMARO_REG_MATCH_IDX);
        return (False);
    }

    /* Register write-only */
    if (p_register_map[reg_field_index].access_level == HAMARO_REG_WO ||
        p_register_map[reg_field_index].access_level == HAMARO_REG_UNUSED)
    {
        HAMARO_DRIVER_SET_ERROR(p_nim, HAMARO_REG_HDWR_REGWTO);
        return (False);
    }

    /* Read the register(s) */
    p_nim->iostatus = 0UL; /* clear io error return value */

	sub_address = (unsigned char)(p_register_map[reg_field_index].address);

	if (io_method == HAMARO_DEMOD_I2C_IO)
	{
		sub_address = (unsigned char)(sub_address + p_nim->register_offset);
	}
#if HAMARO_INCLUDE_VIPER
	else if (io_method == HAMARO_VIPER_I2C_IO)
	{
		sub_address = (unsigned char)(sub_address + p_nim->tuner.cx24128.register_offset);
	}
#endif /* HAMARO_INCLUDE_VIPER */

	startbit = p_register_map[reg_field_index].start_bit;

    /* Read the multiple bit (> bits_per_read bits) value */
    while (bytes < p_register_map[reg_field_index].bit_count && p_nim->iostatus != 1UL)
    {
#if HAMARO_INCLUDE_VIPER
		if (io_method == HAMARO_VIPER_I2C_IO)
		{
			/* Enable Repeater mode again */
			if (HAMARO_TUNER_CX24128_RepeaterModeReadData(p_nim, handle, (unsigned char)(sub_address+offset), &reg_buffer[index]) == False)
			{
				return (False);
			}
		}
#endif /* HAMARO_INCLUDE_VIPER */

		if (io_method == HAMARO_DEMOD_I2C_IO)
		{
			reg_buffer[index] = (unsigned char)((*p_nim->SBRead)(handle, (unsigned char)(sub_address+offset), &p_nim->iostatus)); 

			if (p_nim->iostatus != 0UL)
			{
				/* hardware read error */
				HAMARO_DRIVER_SET_ERROR(p_nim, HAMARO_IO_READERR);
				return (False);
			}
		}

        offset++;
		index = (unsigned char)(index + bytes_per_read);
        if (index == HAMARO_MAX_REGISTER_LEN)

⌨️ 快捷键说明

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