Subversion Repositories freemyipod

Rev

Rev 273 | Show entire file | Ignore whitespace | Details | Blame | Last modification | View Log | RSS feed

Rev 273 Rev 386
Line 36... Line 36...
36
}
36
}
37
 
37
 
38
void i2c_send(uint32_t bus, uint32_t device, uint32_t address, const uint8_t* data, uint32_t length)
38
void i2c_send(uint32_t bus, uint32_t device, uint32_t address, const uint8_t* data, uint32_t length)
39
{
39
{
40
    mutex_lock(&i2cmutex, TIMEOUT_BLOCK);
40
    mutex_lock(&i2cmutex, TIMEOUT_BLOCK);
-
 
41
    while (IIC10(bus));
41
    IICDS(bus) = device & ~1;
42
    IICDS(bus) = device & ~1;
-
 
43
    while (IIC10(bus));
42
    IICSTAT(bus) = 0xF0;
44
    IICSTAT(bus) = 0xF0;
-
 
45
    while (IIC10(bus));
43
    IICCON(bus) = 0xB7;
46
    IICCON(bus) = 0xB7;
44
    while ((IICCON(bus) & 0x10) == 0) yield();
47
    while ((IICCON(bus) & 0x10) == 0) yield();
45
    if (address >= 0)
48
    if (address >= 0)
46
    {
49
    {
47
        /* write address */
50
        /* write address */
-
 
51
        while (IIC10(bus));
48
        IICDS(bus) = address;
52
        IICDS(bus) = address;
-
 
53
        while (IIC10(bus));
49
        IICCON(bus) = 0xB7;
54
        IICCON(bus) = 0xB7;
50
        while ((IICCON(bus) & 0x10) == 0) yield();
55
        while ((IICCON(bus) & 0x10) == 0) yield();
51
    }
56
    }
52
    /* write data */
57
    /* write data */
53
    while (length--)
58
    while (length--)
54
    {
59
    {
-
 
60
        while (IIC10(bus));
55
        IICDS(bus) = *data++;
61
        IICDS(bus) = *data++;
-
 
62
        while (IIC10(bus));
56
        IICCON(bus) = 0xB7;
63
        IICCON(bus) = 0xB7;
57
        while ((IICCON(bus) & 0x10) == 0) yield();
64
        while ((IICCON(bus) & 0x10) == 0) yield();
58
    }
65
    }
59
    /* STOP */
66
    /* STOP */
-
 
67
    while (IIC10(bus));
60
    IICSTAT(bus) = 0xD0;
68
    IICSTAT(bus) = 0xD0;
-
 
69
    while (IIC10(bus));
61
    IICCON(bus) = 0xB7;
70
    IICCON(bus) = 0xB7;
62
    while ((IICSTAT(bus) & (1 << 5)) != 0) yield();
71
    while ((IICSTAT(bus) & (1 << 5)) != 0) yield();
63
    mutex_unlock(&i2cmutex);
72
    mutex_unlock(&i2cmutex);
64
}
73
}
65
 
74
 
Line 67... Line 76...
67
{
76
{
68
    mutex_lock(&i2cmutex, TIMEOUT_BLOCK);
77
    mutex_lock(&i2cmutex, TIMEOUT_BLOCK);
69
    if (address >= 0)
78
    if (address >= 0)
70
    {
79
    {
71
        /* START */
80
        /* START */
-
 
81
        while (IIC10(bus));
72
        IICDS(bus) = device & ~1;
82
        IICDS(bus) = device & ~1;
-
 
83
        while (IIC10(bus));
73
        IICSTAT(bus) = 0xF0;
84
        IICSTAT(bus) = 0xF0;
-
 
85
        while (IIC10(bus));
74
        IICCON(bus) = 0xB7;
86
        IICCON(bus) = 0xB7;
75
        while ((IICCON(bus) & 0x10) == 0) yield();
87
        while ((IICCON(bus) & 0x10) == 0) yield();
76
        /* write address */
88
        /* write address */
-
 
89
        while (IIC10(bus));
77
        IICDS(bus) = address;
90
        IICDS(bus) = address;
-
 
91
        while (IIC10(bus));
78
        IICCON(bus) = 0xB7;
92
        IICCON(bus) = 0xB7;
79
        while ((IICCON(bus) & 0x10) == 0) yield();
93
        while ((IICCON(bus) & 0x10) == 0) yield();
80
    }
94
    }
81
    /* (repeated) START */
95
    /* (repeated) START */
-
 
96
    while (IIC10(bus));
82
    IICDS(bus) = device | 1;
97
    IICDS(bus) = device | 1;
-
 
98
    while (IIC10(bus));
83
    IICSTAT(bus) = 0xB0;
99
    IICSTAT(bus) = 0xB0;
-
 
100
    while (IIC10(bus));
84
    IICCON(bus) = 0xB7;
101
    IICCON(bus) = 0xB7;
85
    while ((IICCON(bus) & 0x10) == 0) yield();
102
    while ((IICCON(bus) & 0x10) == 0) yield();
86
    while (length--)
103
    while (length--)
87
    {
104
    {
-
 
105
        while (IIC10(bus));
88
        IICCON(bus) = (length == 0) ? 0x37 : 0xB7; /* NACK or ACK */
106
        IICCON(bus) = (length == 0) ? 0x37 : 0xB7; /* NACK or ACK */
89
        while ((IICCON(bus) & 0x10) == 0) yield();
107
        while ((IICCON(bus) & 0x10) == 0) yield();
90
        *data++ = IICDS(bus);
108
        *data++ = IICDS(bus);
91
    }
109
    }
92
    /* STOP */
110
    /* STOP */
-
 
111
    while (IIC10(bus));
93
    IICSTAT(bus) = 0x90;
112
    IICSTAT(bus) = 0x90;
-
 
113
    while (IIC10(bus));
94
    IICCON(bus) = 0xB7;
114
    IICCON(bus) = 0xB7;
95
    while ((IICSTAT(bus) & (1 << 5)) != 0) yield();
115
    while ((IICSTAT(bus) & (1 << 5)) != 0) yield();
96
    mutex_unlock(&i2cmutex);
116
    mutex_unlock(&i2cmutex);
97
}
117
}
98
 
118