Cleanup in SD driver.

This commit is contained in:
Serge Vakulenko
2015-09-26 23:32:12 -07:00
parent 5cb608d7e1
commit dc75784799
16 changed files with 44 additions and 52 deletions

View File

@@ -48,8 +48,8 @@ controller spi4 # SD card
# because of a mod on the board we use power=B13, otherwise it shall be D12
device sd0 at spi4
pins RF3, RB13 # select pin, enable pin
options "SD0_MHZ=10" # speed 10 MHz
signal "SD0_ENA" pin RB13 # SD enable signal
options "SD_MHZ=10" # speed 10 MHz
signal "SD_ENA" pin RB13 # SD enable signal
# ADC driver
device adc

View File

@@ -6,7 +6,7 @@ PARAM += -DSD_ENABLED
PARAM += -DADC_ENABLED
PARAM += -DPWM_ENABLED
PARAM += -DSDRAMP_ENABLED
PARAM += -DSD0_ENA_PORT=TRISB -DSD0_ENA_PIN=13
PARAM += -DSD_ENA_PORT=TRISB -DSD_ENA_PIN=13
PARAM += -DLED_TTY_PORT=TRISA -DLED_TTY_PIN=14
PARAM += -DLED_SWAP_PORT=TRISC -DLED_SWAP_PIN=14
PARAM += -DLED_DISK_PORT=TRISC -DLED_DISK_PIN=13
@@ -14,7 +14,7 @@ PARAM += -DLED_KERNEL_PORT=TRISA -DLED_KERNEL_PIN=15
PARAM += -DNMOUNT=3
PARAM += -DPARTITION='sdramp0:sa@2048,fs@14000'
PARAM += -DKERNEL_EXECUTABLE_RAM
PARAM += -DSD0_MHZ=10
PARAM += -DSD_MHZ=10
PARAM += -DCONS_MINOR=2
PARAM += -DCONS_MAJOR=UART_MAJOR
PARAM += -DBUS_DIV=1
@@ -66,7 +66,7 @@ OBJS = exec_aout.o exec_conf.o exec_elf.o exec_script.o exec_subr.o \
ufs_namei.o ufs_subr.o ufs_syscalls.o ufs_syscalls2.o \
vfs_vnops.o vm_sched.o vm_swap.o vm_swp.o clock.o cons.o devsw.o \
exception.o machdep.o mem.o signal.o swap.o sysctl.o adc.o pwm.o \
sd.o rd_sdramp.o sdram.o spi.o spi_bus.o uart.o
sd.o sdramp.o sdram.o spi.o spi_bus.o uart.o
CFILES = $S/kernel/exec_aout.c $S/kernel/exec_conf.c $S/kernel/exec_elf.c \
$S/kernel/exec_script.c $S/kernel/exec_subr.c \
@@ -92,7 +92,7 @@ CFILES = $S/kernel/exec_aout.c $S/kernel/exec_conf.c $S/kernel/exec_elf.c \
$S/pic32/devsw.c $S/pic32/exception.c $S/pic32/machdep.c \
$S/pic32/mem.c $S/pic32/signal.c $S/pic32/swap.c \
$S/pic32/sysctl.c $S/pic32/adc.c $S/pic32/pwm.c $S/pic32/sd.c \
$S/pic32/rd_sdramp.c $S/pic32/spi.c $S/pic32/spi_bus.c \
$S/pic32/sdramp.c $S/pic32/spi.c $S/pic32/spi_bus.c \
$S/pic32/uart.c swapunix.c
# load lines for config "xxx" will be emitted as:
@@ -334,7 +334,7 @@ pwm.o: $S/pic32/pwm.c
sd.o: $S/pic32/sd.c
${COMPILE_C}
rd_sdramp.o: $S/pic32/rd_sdramp.c
sdramp.o: $S/pic32/sdramp.c
${COMPILE_C}
sdram.o: $S/pic32/sdram.S

View File

@@ -74,7 +74,7 @@ controller spi2 # SD card
# microSD card
device sd0 at spi2 pin RC14 # select pin
options "SD0_MHZ=10" # speed 10 MHz
options "SD_MHZ=10" # speed 10 MHz
signal "SD0_ENA" pin RA5 # SD card enable signal
# General purpose I/O ports

View File

@@ -43,4 +43,4 @@ controller spi2 # SD card
# SD card
device sd0 at spi2 pin RD1 # select pin
options "SD0_MHZ=16" # speed 16 MHz
options "SD_MHZ=16" # speed 16 MHz

View File

@@ -6,7 +6,7 @@ PARAM += -DSD_ENABLED
PARAM += -DLED_TTY_PORT=TRISD -DLED_TTY_PIN=12
PARAM += -DLED_DISK_PORT=TRISD -DLED_DISK_PIN=2
PARAM += -DLED_KERNEL_PORT=TRISD -DLED_KERNEL_PIN=3
PARAM += -DSD0_MHZ=16
PARAM += -DSD_MHZ=16
PARAM += -DCONS_MINOR=0
PARAM += -DCONS_MAJOR=UART_MAJOR
PARAM += -DBUS_DIV=1

View File

@@ -44,7 +44,7 @@ controller spi1 # SD card
# SD card
device sd0 at spi1 pin RB1 # select pin
options "SD0_MHZ=10" # speed 10 MHz
options "SD_MHZ=10" # speed 10 MHz
# General purpose I/O ports
# Flags define a mask of available pins

View File

@@ -16,7 +16,7 @@ PARAM += -DLED_SWAP_PORT=TRISA -DLED_SWAP_PIN=3
PARAM += -DLED_TTY_PORT=TRISA -DLED_TTY_PIN=2
PARAM += -DLED_KERNEL_PORT=TRISA -DLED_KERNEL_PIN=1
PARAM += -DLED_DISK_PORT=TRISA -DLED_DISK_PIN=0
PARAM += -DSD0_MHZ=10
PARAM += -DSD_MHZ=10
PARAM += -DCONS_MINOR=1
PARAM += -DCONS_MAJOR=UART_MAJOR
PARAM += -DBUS_DIV=1

View File

@@ -44,7 +44,7 @@ controller spi2 # SD card
# microSD card
device sd0 at spi2 pin RC14 # select pin
options "SD0_MHZ=10" # speed 10 MHz
options "SD_MHZ=10" # speed 10 MHz
# General purpose I/O ports
# Flags define a mask of available pins

View File

@@ -15,7 +15,7 @@ PARAM += -DGPIO6_ENABLED
PARAM += -DADC_ENABLED
PARAM += -DPWM_ENABLED
PARAM += -DLED_KERNEL_PORT=TRISA -DLED_KERNEL_PIN=3
PARAM += -DSD0_MHZ=10
PARAM += -DSD_MHZ=10
PARAM += -DCONS_MINOR=0
PARAM += -DCONS_MAJOR=UART_MAJOR
PARAM += -DBUS_DIV=1

View File

@@ -47,7 +47,7 @@ controller spi1 # SD card
# microSD card
device sd0 at spi1 pin RA9 # select pin
options "SD0_MHZ=8" # speed 8 MHz
options "SD_MHZ=8" # speed 8 MHz
# General purpose I/O ports
# Flags define a mask of available pins

View File

@@ -17,7 +17,7 @@ PARAM += -DGPIO_CLEAR_PORT=TRISD -DGPIO_CLEAR_PIN=2
PARAM += -DLED_TTY_PORT=TRISA -DLED_TTY_PIN=1 -DLED_TTY_INVERT
PARAM += -DLED_SWAP_PORT=TRISD -DLED_SWAP_PIN=9 -DLED_SWAP_INVERT
PARAM += -DLED_KERNEL_PORT=TRISA -DLED_KERNEL_PIN=0 -DLED_KERNEL_INVERT
PARAM += -DSD0_MHZ=8
PARAM += -DSD_MHZ=8
PARAM += -DUSB_NUM_STRING_DESCRIPTORS=3
PARAM += -DUSB_MAX_EP_NUMBER=3
PARAM += -DCONS_MAJOR=UARTUSB_MAJOR

View File

@@ -39,7 +39,7 @@ controller spi2 # SD card
# microSD card
device sd0 at spi2 pin RG9 # select pin
options "SD0_MHZ=10" # speed 10 MHz
options "SD_MHZ=10" # speed 10 MHz
# ADC driver
device adc

View File

@@ -6,7 +6,7 @@ PARAM += -DSD_ENABLED
PARAM += -DADC_ENABLED
PARAM += -DPWM_ENABLED
PARAM += -DHXTFT_ENABLED
PARAM += -DSD0_MHZ=10
PARAM += -DSD_MHZ=10
PARAM += -DCONS_MINOR=0
PARAM += -DCONS_MAJOR=UART_MAJOR
PARAM += -DBUS_DIV=1

View File

@@ -1,15 +1,24 @@
/*
* SecureDigital flash drive on SPI port.
* SD or SDHC card connected to SPI port.
*
* These cards are known to work:
* 1) NCP SD 256Mb - type 1, 249856 kbytes, 244 Mbytes
* 2) Patriot SD 2Gb - type 2, 1902592 kbytes, 1858 Mbytes
* 3) Wintec microSD 2Gb - type 2, 1969152 kbytes, 1923 Mbytes
* 4) Transcend SDHC 4Gb - type 3, 3905536 kbytes, 3814 Mbytes
* 5) Verbatim SD 2Gb - type 2, 1927168 kbytes, 1882 Mbytes
* 6) SanDisk SDHC 4Gb - type 3, 3931136 kbytes, 3833 Mbytes
* Up to two cards can be connected to the same SPI port.
* PC-compatible partition table is supported.
* The following device numbers are used:
*
* Copyright (C) 2010 Serge Vakulenko, <serge@vak.ru>
* Major Minor Device Partition
* ----------------------------------------------
* 0 0 sd0 Main SD card, whole volume
* 0 1 sd0a 1-st partition, usually root FS
* 0 2 sd0b 2-nd partition, usually swap
* 0 3 sd0c 3-rd partition
* 0 4 sd0d 4-th partition
* 0 8 sd1 Second SD card, whole volume
* 0 9 sd1a 1-st partition
* 0 10 sd1b 2-nd partition
* 0 11 sd1c 3-rd partition
* 0 12 sd1d 4-th partition
*
* Copyright (C) 2010-2015 Serge Vakulenko, <serge@vak.ru>
*
* Permission to use, copy, modify, and distribute this software
* and its documentation for any purpose and without fee is hereby
@@ -49,11 +58,8 @@
#define NSD 2
#define SECTSIZE 512
#define SPI_ENHANCED /* use SPI fifo */
#ifndef SD0_MHZ
#define SD0_MHZ 13 /* speed 13.33 MHz */
#endif
#ifndef SD1_MHZ
#define SD1_MHZ 13 /* speed 13.33 MHz */
#ifndef SD_MHZ
#define SD_MHZ 13 /* speed 13.33 MHz */
#endif
#define TIMO_WAIT_WDONE 400000
@@ -330,7 +336,7 @@ static int card_init(int unit)
}
/* Fast speed. */
spi_brg(io, SD0_MHZ * 1000);
spi_brg(io, SD_MHZ * 1000);
return 1;
}
@@ -709,7 +715,6 @@ int sdopen(dev_t dev, int flags, int mode)
}
}
du->openpart |= mask;
//printf("--- %s: OK\n", __func__);
return 0;
}
@@ -752,17 +757,15 @@ void sdstrategy(struct buf *bp)
int unit = sdunit(bp->b_dev);
struct disk *du = &sddrives[unit];
int offset = bp->b_blkno;
struct diskpart *p = &du->part[sdpart(bp->b_dev)];
long nblk = btod(bp->b_bcount);
int s;
/*
* Determine the size of the transfer, and make sure it is
* within the boundaries of the partition.
*/
struct diskpart *p = &du->part[sdpart(bp->b_dev)];
long nblk = btod(bp->b_bcount);
offset += p->dp_offset >> 1;
//printf("--- %s: sdpart=%u, offset=%u, psize=%u, nblk=%u\n", __func__, sdpart(bp->b_dev), offset, p->dp_size, nblk);
if (offset == 0 &&
! (bp->b_flags & B_READ) && ! du->label_writable)
{
@@ -770,7 +773,6 @@ void sdstrategy(struct buf *bp)
bp->b_error = EROFS;
bad: bp->b_flags |= B_ERROR;
biodone(bp);
//printf("--- %s: error\n", __func__);
return;
}
if (bp->b_blkno + nblk > p->dp_size) {
@@ -778,7 +780,6 @@ bad: bp->b_flags |= B_ERROR;
if (bp->b_blkno == p->dp_size) {
bp->b_resid = bp->b_bcount;
biodone(bp);
//printf("--- %s: done EOF\n", __func__);
return;
}
/* or truncate if part of it fits */
@@ -822,7 +823,6 @@ bad: bp->b_flags |= B_ERROR;
dk_busy &= ~(1 << du->dkindex);
#endif
splx(s);
//printf("--- %s: OK\n", __func__);
}
int sdioctl(dev_t dev, u_int cmd, caddr_t addr, int flag)
@@ -849,7 +849,6 @@ int sdioctl(dev_t dev, u_int cmd, caddr_t addr, int flag)
case DIOCGETPART:
/* Get partition table entry. */
dp = &sddrives[unit].part[part];
//printf("--- %s: DIOCGETPART unit = %d, part = %d, type = %u, size = %u\n", __func__, unit, part, dp->dp_type, dp->dp_size);
*(struct diskpart*) addr = *dp;
break;
@@ -889,7 +888,7 @@ sd_probe(config)
/* Disable power to the SD card. */
sd_release(unit);
spi_brg(io, SD0_MHZ * 1000);
spi_brg(io, SD_MHZ * 1000);
spi_set(io, PIC32_SPICON_CKE);
#ifdef UCB_METER
@@ -901,10 +900,3 @@ sd_probe(config)
struct driver sddriver = {
"sd", sd_probe,
};
#if 0
//TODO:
sdclose,
#endif

View File

@@ -41,7 +41,7 @@ controller spi2 # SD card
# microSD card
device sd0 at spi2 pin RD4 # select pin RD4
options "SD0_MHZ=10" # speed 10 MHz
options "SD_MHZ=10" # speed 10 MHz
# General purpose I/O ports
# Flags define a mask of available pins

View File

@@ -15,7 +15,7 @@ PARAM += -DPWM_ENABLED
PARAM += -DLED_TTY_PORT=TRISA -DLED_TTY_PIN=1
PARAM += -DLED_DISK_PORT=TRISF -DLED_DISK_PIN=0
PARAM += -DLED_KERNEL_PORT=TRISA -DLED_KERNEL_PIN=0
PARAM += -DSD0_MHZ=10
PARAM += -DSD_MHZ=10
PARAM += -DCONS_MINOR=0
PARAM += -DCONS_MAJOR=UART_MAJOR
PARAM += -DBUS_DIV=1