reformatted
This commit is contained in:
206
spi/dspi.c
206
spi/dspi.c
@@ -30,79 +30,79 @@
|
||||
|
||||
struct baudrate
|
||||
{
|
||||
int br_divisor;
|
||||
int pbr_divisor;
|
||||
int divider;
|
||||
int br_divisor;
|
||||
int pbr_divisor;
|
||||
int divider;
|
||||
};
|
||||
|
||||
static const int system_clock = 132000000; /* System clock in Hz */
|
||||
|
||||
struct baudrate baudrates[] =
|
||||
static struct baudrate baudrates[] =
|
||||
{
|
||||
{ 0b0000, 0b00, 4 },
|
||||
{ 0b0000, 0b01, 6 },
|
||||
{ 0b0001, 0b00, 8 },
|
||||
{ 0b0000, 0b10, 10 },
|
||||
{ 0b0001, 0b01, 12 },
|
||||
{ 0b0010, 0b00, 12 },
|
||||
{ 0b0000, 0b11, 14 },
|
||||
{ 0b0011, 0b00, 16 },
|
||||
{ 0b0010, 0b01, 18 },
|
||||
{ 0b0001, 0b10, 20 },
|
||||
{ 0b0011, 0b01, 24 },
|
||||
{ 0b0001, 0b11, 28 },
|
||||
{ 0b0010, 0b10, 30 },
|
||||
{ 0b0100, 0b00, 32 },
|
||||
{ 0b0011, 0b10, 40 },
|
||||
{ 0b0010, 0b11, 42 },
|
||||
{ 0b0100, 0b01, 48 },
|
||||
{ 0b0011, 0b11, 56 },
|
||||
{ 0b0101, 0b00, 64 },
|
||||
{ 0b0100, 0b10, 80 },
|
||||
{ 0b0101, 0b01, 96 },
|
||||
{ 0b0100, 0b11, 112 },
|
||||
{ 0b0110, 0b00, 128 },
|
||||
{ 0b0101, 0b10, 160 },
|
||||
{ 0b0110, 0b01, 192 },
|
||||
{ 0b0101, 0b11, 224 },
|
||||
{ 0b0111, 0b00, 256 },
|
||||
{ 0b0110, 0b10, 320 },
|
||||
{ 0b0111, 0b01, 384 },
|
||||
{ 0b0110, 0b11, 448 },
|
||||
{ 0b1000, 0b00, 512 },
|
||||
{ 0b0111, 0b10, 640 },
|
||||
{ 0b1000, 0b01, 768 },
|
||||
{ 0b0111, 0b11, 896 },
|
||||
{ 0b1001, 0b00, 1024 },
|
||||
{ 0b1000, 0b10, 1280 },
|
||||
{ 0b1001, 0b01, 1536 },
|
||||
{ 0b1000, 0b11, 1792 },
|
||||
{ 0b1010, 0b00, 2048 },
|
||||
{ 0b1001, 0b10, 2560 },
|
||||
{ 0b1010, 0b01, 3072 },
|
||||
{ 0b1001, 0b11, 3584 },
|
||||
{ 0b1011, 0b00, 4096 },
|
||||
{ 0b1010, 0b10, 5120 },
|
||||
{ 0b1011, 0b01, 6144 },
|
||||
{ 0b1010, 0b11, 7168 },
|
||||
{ 0b1100, 0b00, 8192 },
|
||||
{ 0b1011, 0b10, 10240 },
|
||||
{ 0b1100, 0b01, 12288 },
|
||||
{ 0b1011, 0b11, 14336 },
|
||||
{ 0b1101, 0b00, 16384 },
|
||||
{ 0b1100, 0b10, 20480 },
|
||||
{ 0b1101, 0b01, 24576 },
|
||||
{ 0b1100, 0b11, 28672 },
|
||||
{ 0b1110, 0b00, 32768 },
|
||||
{ 0b1101, 0b10, 40960 },
|
||||
{ 0b1110, 0b01, 49152 },
|
||||
{ 0b1101, 0b11, 57344 },
|
||||
{ 0b1111, 0b00, 65536 },
|
||||
{ 0b1110, 0b10, 81920 },
|
||||
{ 0b1111, 0b01, 98304 },
|
||||
{ 0b1110, 0b11, 114688 },
|
||||
{ 0b1111, 0b10, 163840 },
|
||||
{ 0b1111, 0b11, 229376 },
|
||||
{ 0b0000, 0b00, 4 },
|
||||
{ 0b0000, 0b01, 6 },
|
||||
{ 0b0001, 0b00, 8 },
|
||||
{ 0b0000, 0b10, 10 },
|
||||
{ 0b0001, 0b01, 12 },
|
||||
{ 0b0010, 0b00, 12 },
|
||||
{ 0b0000, 0b11, 14 },
|
||||
{ 0b0011, 0b00, 16 },
|
||||
{ 0b0010, 0b01, 18 },
|
||||
{ 0b0001, 0b10, 20 },
|
||||
{ 0b0011, 0b01, 24 },
|
||||
{ 0b0001, 0b11, 28 },
|
||||
{ 0b0010, 0b10, 30 },
|
||||
{ 0b0100, 0b00, 32 },
|
||||
{ 0b0011, 0b10, 40 },
|
||||
{ 0b0010, 0b11, 42 },
|
||||
{ 0b0100, 0b01, 48 },
|
||||
{ 0b0011, 0b11, 56 },
|
||||
{ 0b0101, 0b00, 64 },
|
||||
{ 0b0100, 0b10, 80 },
|
||||
{ 0b0101, 0b01, 96 },
|
||||
{ 0b0100, 0b11, 112 },
|
||||
{ 0b0110, 0b00, 128 },
|
||||
{ 0b0101, 0b10, 160 },
|
||||
{ 0b0110, 0b01, 192 },
|
||||
{ 0b0101, 0b11, 224 },
|
||||
{ 0b0111, 0b00, 256 },
|
||||
{ 0b0110, 0b10, 320 },
|
||||
{ 0b0111, 0b01, 384 },
|
||||
{ 0b0110, 0b11, 448 },
|
||||
{ 0b1000, 0b00, 512 },
|
||||
{ 0b0111, 0b10, 640 },
|
||||
{ 0b1000, 0b01, 768 },
|
||||
{ 0b0111, 0b11, 896 },
|
||||
{ 0b1001, 0b00, 1024 },
|
||||
{ 0b1000, 0b10, 1280 },
|
||||
{ 0b1001, 0b01, 1536 },
|
||||
{ 0b1000, 0b11, 1792 },
|
||||
{ 0b1010, 0b00, 2048 },
|
||||
{ 0b1001, 0b10, 2560 },
|
||||
{ 0b1010, 0b01, 3072 },
|
||||
{ 0b1001, 0b11, 3584 },
|
||||
{ 0b1011, 0b00, 4096 },
|
||||
{ 0b1010, 0b10, 5120 },
|
||||
{ 0b1011, 0b01, 6144 },
|
||||
{ 0b1010, 0b11, 7168 },
|
||||
{ 0b1100, 0b00, 8192 },
|
||||
{ 0b1011, 0b10, 10240 },
|
||||
{ 0b1100, 0b01, 12288 },
|
||||
{ 0b1011, 0b11, 14336 },
|
||||
{ 0b1101, 0b00, 16384 },
|
||||
{ 0b1100, 0b10, 20480 },
|
||||
{ 0b1101, 0b01, 24576 },
|
||||
{ 0b1100, 0b11, 28672 },
|
||||
{ 0b1110, 0b00, 32768 },
|
||||
{ 0b1101, 0b10, 40960 },
|
||||
{ 0b1110, 0b01, 49152 },
|
||||
{ 0b1101, 0b11, 57344 },
|
||||
{ 0b1111, 0b00, 65536 },
|
||||
{ 0b1110, 0b10, 81920 },
|
||||
{ 0b1111, 0b01, 98304 },
|
||||
{ 0b1110, 0b11, 114688 },
|
||||
{ 0b1111, 0b10, 163840 },
|
||||
{ 0b1111, 0b11, 229376 },
|
||||
};
|
||||
|
||||
/*
|
||||
@@ -110,28 +110,28 @@ struct baudrate baudrates[] =
|
||||
*/
|
||||
int dspi_set_baudrate(int rate)
|
||||
{
|
||||
int set_baudrate = 0;
|
||||
int br;
|
||||
int pbr;
|
||||
int i;
|
||||
int set_baudrate = 0;
|
||||
int br;
|
||||
int pbr;
|
||||
int i;
|
||||
|
||||
for (i = sizeof(baudrates) / sizeof(struct baudrate) - 1; i >= 0; i--)
|
||||
{
|
||||
set_baudrate = system_clock / baudrates[i].divider;
|
||||
for (i = sizeof(baudrates) / sizeof(struct baudrate) - 1; i >= 0; i--)
|
||||
{
|
||||
set_baudrate = system_clock / baudrates[i].divider;
|
||||
|
||||
if (set_baudrate > rate)
|
||||
{
|
||||
continue;
|
||||
}
|
||||
br = baudrates[i].br_divisor;
|
||||
pbr = baudrates[i].pbr_divisor;
|
||||
if (set_baudrate > rate)
|
||||
{
|
||||
continue;
|
||||
}
|
||||
br = baudrates[i].br_divisor;
|
||||
pbr = baudrates[i].pbr_divisor;
|
||||
|
||||
/* TODO: set br and pbr here */
|
||||
/* TODO: set br and pbr here */
|
||||
|
||||
return set_baudrate;
|
||||
}
|
||||
return set_baudrate;
|
||||
}
|
||||
|
||||
return 0;
|
||||
return 0;
|
||||
}
|
||||
|
||||
static uint32_t dspi_fifo_val = MCF_DSPI_DTFR_CTCNT;
|
||||
@@ -141,20 +141,20 @@ static uint32_t dspi_fifo_val = MCF_DSPI_DTFR_CTCNT;
|
||||
*/
|
||||
uint8_t dspi_xchg_byte(int device, uint8_t byte, int last)
|
||||
{
|
||||
uint32_t fifo;
|
||||
uint8_t res;
|
||||
uint32_t fifo;
|
||||
uint8_t res;
|
||||
|
||||
fifo = dspi_fifo_val | (byte & 0xff); /* transfer bytes only */
|
||||
fifo |= (last ? MCF_DSPI_DTFR_EOQ : 0); /* mark last transfer */
|
||||
MCF_DSPI_DTFR = fifo;
|
||||
while (! (MCF_DSPI_DSR & MCF_DSPI_DSR_TCF)); /* wait until DSPI transfer complete */
|
||||
fifo = MCF_DSPI_DRFR; /* read transferred word */
|
||||
fifo = dspi_fifo_val | (byte & 0xff); /* transfer bytes only */
|
||||
fifo |= (last ? MCF_DSPI_DTFR_EOQ : 0); /* mark last transfer */
|
||||
MCF_DSPI_DTFR = fifo;
|
||||
while (! (MCF_DSPI_DSR & MCF_DSPI_DSR_TCF)); /* wait until DSPI transfer complete */
|
||||
fifo = MCF_DSPI_DRFR; /* read transferred word */
|
||||
|
||||
MCF_DSPI_DSR = -1; /* clear DSPI status register */
|
||||
MCF_DSPI_DSR = -1; /* clear DSPI status register */
|
||||
|
||||
res = fifo & 0xff;
|
||||
res = fifo & 0xff;
|
||||
|
||||
return res;
|
||||
return res;
|
||||
}
|
||||
|
||||
/* Receive multiple byte with 0xff as output
|
||||
@@ -164,11 +164,11 @@ uint8_t dspi_xchg_byte(int device, uint8_t byte, int last)
|
||||
*/
|
||||
static void dspi_rcv_byte_multi(int device, uint8_t *buff, uint32_t count)
|
||||
{
|
||||
int i;
|
||||
int i;
|
||||
|
||||
for (i = 0; i < count - 1; i++)
|
||||
*buff++ = dspi_xchg_byte(device, 0xff, 0);
|
||||
*buff++ = dspi_xchg_byte(device, 0xff, 1); /* transfer last byte and stop transmission */
|
||||
for (i = 0; i < count - 1; i++)
|
||||
*buff++ = dspi_xchg_byte(device, 0xff, 0);
|
||||
*buff++ = dspi_xchg_byte(device, 0xff, 1); /* transfer last byte and stop transmission */
|
||||
}
|
||||
|
||||
/* Send multiple byte, discard input
|
||||
@@ -178,10 +178,10 @@ static void dspi_rcv_byte_multi(int device, uint8_t *buff, uint32_t count)
|
||||
*/
|
||||
static void dspi_xmt_byte_multi(int device, const uint8_t *buff, uint32_t btx)
|
||||
{
|
||||
int i;
|
||||
int i;
|
||||
|
||||
for (i = 0; i < btx - 1; i++)
|
||||
dspi_xchg_byte(device, *buff++, 0);
|
||||
dspi_xchg_byte(device, *buff++, 1); /* transfer last byte and indicate end of transmission */
|
||||
for (i = 0; i < btx - 1; i++)
|
||||
dspi_xchg_byte(device, *buff++, 0);
|
||||
dspi_xchg_byte(device, *buff++, 1); /* transfer last byte and indicate end of transmission */
|
||||
}
|
||||
|
||||
|
||||
138
spi/sd_card.c
138
spi/sd_card.c
@@ -41,81 +41,81 @@
|
||||
*/
|
||||
void sd_card_init(void)
|
||||
{
|
||||
DRESULT res;
|
||||
FATFS fs;
|
||||
FRESULT fres;
|
||||
DRESULT res;
|
||||
FATFS fs;
|
||||
FRESULT fres;
|
||||
|
||||
disk_initialize(0);
|
||||
res = disk_status(0);
|
||||
xprintf("disk status of SD card is %d\r\n", res);
|
||||
if (res == RES_OK)
|
||||
{
|
||||
fres = f_mount(0, &fs);
|
||||
xprintf("mount status of SD card fs is %d\r\n", fres);
|
||||
if (fres == FR_OK)
|
||||
{
|
||||
DIR directory;
|
||||
FIL file;
|
||||
disk_initialize(0);
|
||||
res = disk_status(0);
|
||||
xprintf("disk status of SD card is %d\r\n", res);
|
||||
if (res == RES_OK)
|
||||
{
|
||||
fres = f_mount(0, &fs);
|
||||
xprintf("mount status of SD card fs is %d\r\n", fres);
|
||||
if (fres == FR_OK)
|
||||
{
|
||||
DIR directory;
|
||||
FIL file;
|
||||
|
||||
fres = f_opendir(&directory, "\\");
|
||||
if (fres == FR_OK)
|
||||
{
|
||||
FILINFO fi;
|
||||
fres = f_opendir(&directory, "\\");
|
||||
if (fres == FR_OK)
|
||||
{
|
||||
FILINFO fi;
|
||||
|
||||
while (((fres = f_readdir(&directory, &fi)) == FR_OK) && fi.fname[0])
|
||||
{
|
||||
xprintf("%13.13s %d\r\n", fi.fname, fi.fsize);
|
||||
}
|
||||
}
|
||||
else
|
||||
{
|
||||
xprintf("could not open directory \"\\\" on SD-card! Error code: %d\r\n", fres);
|
||||
}
|
||||
while (((fres = f_readdir(&directory, &fi)) == FR_OK) && fi.fname[0])
|
||||
{
|
||||
xprintf("%13.13s %d\r\n", fi.fname, fi.fsize);
|
||||
}
|
||||
}
|
||||
else
|
||||
{
|
||||
xprintf("could not open directory \"\\\" on SD-card! Error code: %d\r\n", fres);
|
||||
}
|
||||
|
||||
/*
|
||||
* let's see if we find our boot flashing executable on disk
|
||||
*/
|
||||
fres = f_open(&file, FLASHCODE_NAME, FA_READ);
|
||||
if (fres == FR_OK)
|
||||
{
|
||||
/*
|
||||
* yes, load and execute it
|
||||
*
|
||||
* FIXME: we will need some kind of user confirmation here
|
||||
* to avoid unwanted flashing or "bootsector viruses" before going productive
|
||||
*/
|
||||
uint32_t size; /* length of code piece read */
|
||||
uint32_t total_size = 0L;
|
||||
int32_t start_time = MCF_SLT_SCNT(0);
|
||||
int32_t end_time;
|
||||
int32_t time = 0;
|
||||
/*
|
||||
* let's see if we find our boot flashing executable on disk
|
||||
*/
|
||||
fres = f_open(&file, FLASHCODE_NAME, FA_READ);
|
||||
if (fres == FR_OK)
|
||||
{
|
||||
/*
|
||||
* yes, load and execute it
|
||||
*
|
||||
* FIXME: we will need some kind of user confirmation here
|
||||
* to avoid unwanted flashing or "bootsector viruses" before going productive
|
||||
*/
|
||||
uint32_t size; /* length of code piece read */
|
||||
uint32_t total_size = 0L;
|
||||
int32_t start_time = MCF_SLT_SCNT(0);
|
||||
int32_t end_time;
|
||||
int32_t time = 0;
|
||||
|
||||
while ((fres = f_read(&file, (void *) FLASHCODE_ADDRESS, 1024 * 1000, &size)) == FR_OK && size > 0)
|
||||
{
|
||||
total_size += size / 1024;
|
||||
xprintf("read hunk of %d bytes, total_size = %d kBytes\r\n", size, total_size);
|
||||
}
|
||||
end_time = MCF_SLT_SCNT(0);
|
||||
time = (end_time - start_time) / 132L;
|
||||
xprintf("result of f_read: %ld, %ld kbytes read\r\n", fres, total_size);
|
||||
xprintf("time to load %s: %ld s\r\n", FLASHCODE_NAME, time / 1000 / 100);
|
||||
xprintf("equals to about %ld kBytes/second\r\n", total_size / (time / 1000 / 100));
|
||||
while ((fres = f_read(&file, (void *) FLASHCODE_ADDRESS, 1024 * 1000, &size)) == FR_OK && size > 0)
|
||||
{
|
||||
total_size += size / 1024;
|
||||
xprintf("read hunk of %d bytes, total_size = %d kBytes\r\n", size, total_size);
|
||||
}
|
||||
end_time = MCF_SLT_SCNT(0);
|
||||
time = (end_time - start_time) / 132L;
|
||||
xprintf("result of f_read: %ld, %ld kbytes read\r\n", fres, total_size);
|
||||
xprintf("time to load %s: %ld s\r\n", FLASHCODE_NAME, time / 1000 / 100);
|
||||
xprintf("equals to about %ld kBytes/second\r\n", total_size / (time / 1000 / 100));
|
||||
|
||||
}
|
||||
f_close(&file);
|
||||
}
|
||||
f_close(&file);
|
||||
|
||||
fres = f_open(&file, WELCOME_NAME, FA_READ);
|
||||
if (fres == FR_OK)
|
||||
{
|
||||
char line[128];
|
||||
fres = f_open(&file, WELCOME_NAME, FA_READ);
|
||||
if (fres == FR_OK)
|
||||
{
|
||||
char line[128];
|
||||
|
||||
while (f_gets(line, sizeof(line), &file))
|
||||
{
|
||||
xprintf("%s", line);
|
||||
}
|
||||
}
|
||||
f_close(&file);
|
||||
}
|
||||
f_mount(0, 0L); /* release work area */
|
||||
}
|
||||
while (f_gets(line, sizeof(line), &file))
|
||||
{
|
||||
xprintf("%s", line);
|
||||
}
|
||||
}
|
||||
f_close(&file);
|
||||
}
|
||||
f_mount(0, 0L); /* release work area */
|
||||
}
|
||||
}
|
||||
|
||||
Reference in New Issue
Block a user