diff --git a/sys/pic32/32mxsdram/Config b/sys/pic32/32mxsdram/Config index 9935104..a230067 100644 --- a/sys/pic32/32mxsdram/Config +++ b/sys/pic32/32mxsdram/Config @@ -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 diff --git a/sys/pic32/32mxsdram/Makefile b/sys/pic32/32mxsdram/Makefile index c1f3395..b0e7a1f 100644 --- a/sys/pic32/32mxsdram/Makefile +++ b/sys/pic32/32mxsdram/Makefile @@ -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 diff --git a/sys/pic32/Config.generic b/sys/pic32/Config.generic index 2b300ed..d0d13dc 100644 --- a/sys/pic32/Config.generic +++ b/sys/pic32/Config.generic @@ -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 diff --git a/sys/pic32/baremetal/Config b/sys/pic32/baremetal/Config index 815e4c3..bd5e881 100644 --- a/sys/pic32/baremetal/Config +++ b/sys/pic32/baremetal/Config @@ -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 diff --git a/sys/pic32/baremetal/Makefile b/sys/pic32/baremetal/Makefile index c5c3fb0..5fc6d6e 100644 --- a/sys/pic32/baremetal/Makefile +++ b/sys/pic32/baremetal/Makefile @@ -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 diff --git a/sys/pic32/explorer16/Config b/sys/pic32/explorer16/Config index 7b4d722..d7df268 100644 --- a/sys/pic32/explorer16/Config +++ b/sys/pic32/explorer16/Config @@ -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 diff --git a/sys/pic32/explorer16/Makefile b/sys/pic32/explorer16/Makefile index fcf0444..4f76960 100644 --- a/sys/pic32/explorer16/Makefile +++ b/sys/pic32/explorer16/Makefile @@ -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 diff --git a/sys/pic32/max32/Config b/sys/pic32/max32/Config index ed07ed5..558a250 100644 --- a/sys/pic32/max32/Config +++ b/sys/pic32/max32/Config @@ -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 diff --git a/sys/pic32/max32/Makefile b/sys/pic32/max32/Makefile index 4bc6152..bd0eb5d 100644 --- a/sys/pic32/max32/Makefile +++ b/sys/pic32/max32/Makefile @@ -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 diff --git a/sys/pic32/mmb-mx7/Config b/sys/pic32/mmb-mx7/Config index 2f187f1..d648892 100644 --- a/sys/pic32/mmb-mx7/Config +++ b/sys/pic32/mmb-mx7/Config @@ -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 diff --git a/sys/pic32/mmb-mx7/Makefile b/sys/pic32/mmb-mx7/Makefile index d3a22c3..afea736 100644 --- a/sys/pic32/mmb-mx7/Makefile +++ b/sys/pic32/mmb-mx7/Makefile @@ -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 diff --git a/sys/pic32/picadillo/Config b/sys/pic32/picadillo/Config index fac6280..790c72c 100644 --- a/sys/pic32/picadillo/Config +++ b/sys/pic32/picadillo/Config @@ -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 diff --git a/sys/pic32/picadillo/Makefile b/sys/pic32/picadillo/Makefile index b2372dc..2ee4a4e 100644 --- a/sys/pic32/picadillo/Makefile +++ b/sys/pic32/picadillo/Makefile @@ -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 diff --git a/sys/pic32/sd.c b/sys/pic32/sd.c index 8ffa21a..40bf127 100644 --- a/sys/pic32/sd.c +++ b/sys/pic32/sd.c @@ -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, + * 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, * * 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 diff --git a/sys/pic32/wf32/Config b/sys/pic32/wf32/Config index 211c49e..f34d622 100644 --- a/sys/pic32/wf32/Config +++ b/sys/pic32/wf32/Config @@ -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 diff --git a/sys/pic32/wf32/Makefile b/sys/pic32/wf32/Makefile index 3c64347..0e694de 100644 --- a/sys/pic32/wf32/Makefile +++ b/sys/pic32/wf32/Makefile @@ -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