summaryrefslogtreecommitdiff
diff options
context:
space:
mode:
authorChristian König <chrissi@zweiundvierzig.(none)>2010-07-11 13:53:16 +0200
committerChristian König <chrissi@zweiundvierzig.(none)>2010-07-11 13:53:16 +0200
commit7f4a17bcd3f2b94d8faa01e4520fdd90f530ef4e (patch)
tree33d213a1af876ff318b426fcfa3049bccbeaafea
parent18180f963b3c19a821db6a0dece26fbee791431d (diff)
Timing adjustment in hardware communication
-rw-r--r--lib/msp430.c34
1 files changed, 27 insertions, 7 deletions
diff --git a/lib/msp430.c b/lib/msp430.c
index 58f31f5..73d5363 100644
--- a/lib/msp430.c
+++ b/lib/msp430.c
@@ -25,11 +25,15 @@
#include "cec.h"
#include "../msp430/cec_state.h"
+//#define DEBUG 1
+#undef DEBUG
+
#define BUFFER_SIZE 32
#define I2C_ADDR 0x60
#define RX_DELAY 10000
-#define TX_BIT_DELAY 2400
+#define TX_DELAY 100000
+#define TX_BYTE_DELAY 24000
#define TX_RETRY 128
#define EDID_BLOCK_SEL 0x30
@@ -48,9 +52,25 @@ struct MSP430_Hardware
static ssize_t Fill_Buffer(struct MSP430_Hardware* hw)
{
+ int result;
+
hw->index = 0;
memset(hw->buffer, 0, BUFFER_SIZE);
- return read(hw->i2c, hw->buffer, BUFFER_SIZE);
+ result = read(hw->i2c, hw->buffer, BUFFER_SIZE);
+
+#ifdef DEBUG
+ if(result < 0) {
+ fprintf(stderr, "result\t%d\n", result);
+ } else {
+ int i;
+ for(i=0; i<BUFFER_SIZE; i++) {
+ fprintf(stderr, "0x%X ", hw->buffer[i]);
+ }
+ fprintf(stderr, "\n");
+ }
+#endif
+
+ return result;
}
static int Buffer_Empty(struct MSP430_Hardware* hw)
@@ -107,7 +127,7 @@ static int Transmit(struct CEC_Device* device, struct CEC_Packet* packet)
if(write(hw->i2c, ((void*)packet)+1, packet->length) != packet->length)
return 0;
- usleep(packet->length * TX_BIT_DELAY * 10);
+ usleep(TX_DELAY + (packet->length * TX_BYTE_DELAY));
for(retry=0; retry<TX_RETRY; retry++)
{
@@ -200,10 +220,10 @@ static struct CEC_Physical_Address Get_Addr(struct CEC_Device* device)
byte[1] = Read_DDC(hw, 128*i + data + 5);
struct CEC_Physical_Address result;
- result.a = byte[0] & 0xF;
- result.b = byte[0] >> 4;
- result.c = byte[1] & 0xF;
- result.d = byte[1] >> 4;
+ result.a = byte[0] >> 4;
+ result.b = byte[0] & 0xF;
+ result.c = byte[1] >> 4;
+ result.d = byte[1] & 0xF;
return result;
}
data += type & 0x1F;