Subversion Repositories freemyipod

Rev

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

Rev 273 Rev 280
Line 27... Line 27...
27
#include "thread.h"
27
#include "thread.h"
28
#include "clockgates.h"
28
#include "clockgates.h"
29
 
29
 
30
 
30
 
31
static struct mutex spimutex[3];
31
static struct mutex spimutex[3];
-
 
32
static struct wakeup spiwakeup[3];
32
 
33
 
33
 
34
 
34
void spi_prepare(int port)
35
void spi_prepare(int port)
35
{
36
{
36
    mutex_lock(&spimutex[port], TIMEOUT_BLOCK);
37
    mutex_lock(&spimutex[port], TIMEOUT_BLOCK);
Line 61... Line 62...
61
 
62
 
62
void spi_read(int port, uint32_t size, void* buf)
63
void spi_read(int port, uint32_t size, void* buf)
63
{
64
{
64
    uint8_t* buffer = (uint8_t*)buf;
65
    uint8_t* buffer = (uint8_t*)buf;
65
    SPIRXLIMIT(port) = size;
66
    SPIRXLIMIT(port) = size;
66
    SPISETUP(port) |= 1;
-
 
67
    while (size--)
67
    if (size < 0x100)
68
    {
68
    {
-
 
69
        SPISETUP(port) |= 1;
-
 
70
        while (size--)
-
 
71
        {
69
        while (!(SPISTATUS(port) & 0x3e00)) yield();
72
            while (!(SPISTATUS(port) & 0x3e00)) yield();
70
        *buffer++ = SPIRXDATA(port);
73
            *buffer++ = SPIRXDATA(port);
-
 
74
        }
-
 
75
        SPISETUP(port) &= ~1;
-
 
76
        return;
71
    }
77
    }
-
 
78
    SPISETUP(port) |= 0x41;
-
 
79
    void* addr = (void*)((uint32_t)buf + size);
-
 
80
    struct dma_lli* lli = (struct dma_lli*)(((uint32_t)addr - 0x10) & ~0xf);
-
 
81
    struct dma_lli* nextlli = NULL;
-
 
82
    while (addr > buf)
-
 
83
    {
-
 
84
        size = (uint32_t)addr - (uint32_t)buf;
-
 
85
        if (size > 0xfff) size = 0xfff;
-
 
86
        else lli = (struct dma_lli*)((int)&DMAC0CLLI(port + 5));
-
 
87
        addr = (void*)((uint32_t)addr - size);
-
 
88
        lli->srcaddr = (void*)((int)&SPIRXDATA(port));
-
 
89
        lli->dstaddr = addr;
-
 
90
        lli->nextlli = nextlli;
-
 
91
        lli->control = 0x78000000 | size | (nextlli == NULL ? 0x80000000 : 0);
-
 
92
        nextlli = lli;
-
 
93
        lli = &lli[-1];
-
 
94
    }
-
 
95
    clean_dcache();
-
 
96
    DMAC0CCONFIG(port + 5) = 0x9001 | (SPIDMA(port) << 1);
-
 
97
    wakeup_wait(&spiwakeup[port], TIMEOUT_BLOCK);
72
    SPISETUP(port) &= ~1;
98
    SPISETUP(port) &= ~0x41;
-
 
99
}
-
 
100
 
-
 
101
void INT_DMAC0C5()
-
 
102
{
-
 
103
    DMAC0INTTCCLR = 1 << 5;
-
 
104
    wakeup_signal(&spiwakeup[0]);
73
}
105
}
74
 
106
 
-
 
107
void INT_DMAC0C6()
-
 
108
{
-
 
109
    DMAC0INTTCCLR = 1 << 6;
-
 
110
    wakeup_signal(&spiwakeup[1]);
-
 
111
}
-
 
112
 
-
 
113
void INT_DMAC0C7()
-
 
114
{
-
 
115
    DMAC0INTTCCLR = 1 << 7;
-
 
116
    wakeup_signal(&spiwakeup[2]);
-
 
117
}