Автор работы: Пользователь скрыл имя, 17 Января 2012 в 14:29, курсовая работа
В настоящее время только Philips производит более 150 наименований I2C-совместимых устройств, функционально предназначенных работы в электронном оборудовании различного назначения. В их числе ИС памяти, видеопроцессоров и модулей обработки аудио- и видео-сигналов, АЦП и ЦАП, драйверы ЖК-индикаторов, процессоры со встоенным аппаратным контроллером I2C шины и многое другое.
Введение 5
1 Шина управления I2C 10
2 Исследование драйвера 14
Заключение 15
Список использованных источников 16
904 }
905
906 s32 i2c_smbus_write_byte(struct i2c_client *client, u8 value)
907 {
908 return i2c_smbus_xfer(client->adapter
909 I2C_SMBUS_WRITE, value, I2C_SMBUS_BYTE, NULL);
910 }
911
912 s32 i2c_smbus_read_byte_data(
913 {
914 union i2c_smbus_data data;
915 if (i2c_smbus_xfer(client->adapte
916 I2C_SMBUS_READ,command, I2C_SMBUS_BYTE_DATA,&data))
917 return -1;
918 else
919 return 0x0FF & data.byte;
920 }
921
922 s32 i2c_smbus_write_byte_data(
923 value)
924 {
925 union i2c_smbus_data data;
926 data.byte = value;
927 return i2c_smbus_xfer(client->adapter
928 I2C_SMBUS_WRITE,command,
929 I2C_SMBUS_BYTE_DATA,&data);
930 }
931
932 s32 i2c_smbus_read_word_data(
933 {
934 union i2c_smbus_data data;
935 if (i2c_smbus_xfer(client->adapte
936 I2C_SMBUS_READ,command, I2C_SMBUS_WORD_DATA, &data))
937 return -1;
938 else
939 return 0x0FFFF & data.word;
940 }
941
942 s32 i2c_smbus_write_word_data(
943 value)
944 {
945 union i2c_smbus_data data;
946 data.word = value;
947 return i2c_smbus_xfer(client->adapter
948 I2C_SMBUS_WRITE,command,
949 I2C_SMBUS_WORD_DATA,&data);
950 }
951
952 s32 i2c_smbus_write_block_data(
953 u8 length, u8 *values)
954 {
955 union i2c_smbus_data data;
956 int i;
957 if (length > I2C_SMBUS_BLOCK_MAX)
958 length = I2C_SMBUS_BLOCK_MAX;
959 for (i = 1; i <= length; i++)
960 data.block[i] = values[i-1];
961 data.block[0] = length;
962 return i2c_smbus_xfer(client->adapter
963 I2C_SMBUS_WRITE,command,
964 I2C_SMBUS_BLOCK_DATA,&data);
965 }
966
967 /* Returns the number of read bytes */
968 s32 i2c_smbus_read_i2c_block_data(
969
970 {
971 union i2c_smbus_data data;
972 int i;
973 if (i2c_smbus_xfer(client->adapte
974 I2C_SMBUS_READ,command,
975
I2C_SMBUS_I2C_BLOCK_DATA,&data
976 return -1;
977 else {
978 for (i = 1; i <= data.block[0]; i++)
979 values[i-1] = data.block[i];
980 return data.block[0];
981 }
982 }
983
984 /* Simulate a SMBus command using the i2c protocol
985 No checking of parameters is done! */
986 static s32 i2c_smbus_xfer_emulated(struct i2c_adapter * adapter, u16 addr,
987
988
989
990 {
991 /* So we need to generate a series of msgs. In the case of writing, we
992 need to use only one message; when reading, we need two. We
993 initialize
994 most things with sane defaults, to keep the code below somewhat
995 simpler. */
996 unsigned char
msgbuf0[I2C_SMBUS_BLOCK_MAX+3]
997 unsigned char
msgbuf1[I2C_SMBUS_BLOCK_MAX+2]
998 int num = read_write == I2C_SMBUS_READ?2:1;
999 struct i2c_msg msg[2] = { { addr, flags, 1, msgbuf0 },
1000 { addr, flags | I2C_M_RD, 0, msgbuf1 }
1001 };
1002 int i;
1003 u8 partial_pec = 0;
1004
1005 msgbuf0[0] = command;
1006 switch(size) {
1007 case I2C_SMBUS_QUICK:
1008 msg[0].len = 0;
1009 /* Special case: The read/write field is used as data */
1010
msg[0].flags = flags | (read_write==I2C_SMBUS_READ)?
1011 num = 1;
1012 break;
1013 case I2C_SMBUS_BYTE:
1014 if (read_write == I2C_SMBUS_READ) {
1015 /* Special case: only a read! */
1016 msg[0].flags = I2C_M_RD | flags;
1017 num = 1;
1018 }
1019 break;
1020 case I2C_SMBUS_BYTE_DATA:
1021 if (read_write == I2C_SMBUS_READ)
1022 msg[1].len = 1;
1023 else {
1024 msg[0].len = 2;
1025 msgbuf0[1] = data->byte;
1026 }
1027 break;
1028 case I2C_SMBUS_WORD_DATA:
1029 if (read_write == I2C_SMBUS_READ)
1030 msg[1].len = 2;
1031 else {
1032 msg[0].len=3;
1033 msgbuf0[1] = data->word & 0xff;
1034 msgbuf0[2] = (data->word >> 8) & 0xff;
1035 }
1036 break;
1037 case I2C_SMBUS_PROC_CALL:
1038 num = 2; /* Special case */
1039 read_write = I2C_SMBUS_READ;
1040 msg[0].len = 3;
1041 msg[1].len = 2;
1042 msgbuf0[1] = data->word & 0xff;
1043 msgbuf0[2] = (data->word >> 8) & 0xff;
1044 break;
1045 case I2C_SMBUS_BLOCK_DATA:
1046 if (read_write == I2C_SMBUS_READ) {
Информация о работе Исследование драйвера ядра Linux для шины I2C