mirror of
https://github.com/erichelgeson/BlueSCSI.git
synced 2025-08-05 08:25:46 +00:00
Compare commits
72 Commits
v1.1-20220
...
v1.1-20220
Author | SHA1 | Date | |
---|---|---|---|
|
f7075df6d8 | ||
|
3b7aa0d160 | ||
|
8e4b4ee512 | ||
|
557f34e5da | ||
|
11901d6a0d | ||
|
1cfaf00594 | ||
|
07961108c7 | ||
|
b01c2ffd7c | ||
|
d5405ab5f0 | ||
|
bfa59a1fa4 | ||
|
f69cff42e4 | ||
|
9b2b3f689f | ||
|
eeacf3e746 | ||
|
e52957315e | ||
|
2641e80fac | ||
|
437b2531ca | ||
|
dcbb7df80d | ||
|
1aecf323e1 | ||
|
d6ff7017c9 | ||
|
8167ddea6c | ||
|
2338d8f153 | ||
|
b16dc558dc | ||
|
a5c6edadc3 | ||
|
79d5b12110 | ||
|
d6fb46d387 | ||
|
c2c3397b72 | ||
|
906b8be9aa | ||
|
3c258451fa | ||
|
7cdddf7371 | ||
|
20cb5d8552 | ||
|
5c0724703b | ||
|
61ae8a59db | ||
|
19cc9ad169 | ||
|
14321e3ba6 | ||
|
b0799bc327 | ||
|
2127b14863 | ||
|
3ef2474ae8 | ||
|
9d1b58cdb6 | ||
|
1f03996977 | ||
|
73fc0ed2bf | ||
|
94a22bb45e | ||
|
c8d47218b1 | ||
|
853956e441 | ||
|
69e69cad3a | ||
|
bbd91936fb | ||
|
c04027c8ca | ||
|
b898d9684f | ||
|
38904285d4 | ||
|
8a27bcc585 | ||
|
c5447a4098 | ||
|
408e155a63 | ||
|
f7799fb225 | ||
|
845954edeb | ||
|
7b7f19413c | ||
|
961ae0b8b7 | ||
|
aa751dc3b8 | ||
|
fff520959e | ||
|
2f08b9fa73 | ||
|
24e1612fc7 | ||
|
a566c9bbb0 | ||
|
9a4e3dc886 | ||
|
27c424d2f9 | ||
|
3158391c86 | ||
|
ceb6da764b | ||
|
b4b0ce711f | ||
|
77698d0a68 | ||
|
d593c0817c | ||
|
adca34aeb8 | ||
|
693ab2a5c0 | ||
|
4d3ee87c56 | ||
|
ba1b3df680 | ||
|
22eb2c8d3e |
1
.gitignore
vendored
1
.gitignore
vendored
@@ -2,3 +2,4 @@
|
||||
.DS_Store
|
||||
.vscode/
|
||||
workspace.code-workspace
|
||||
dist/
|
||||
|
@@ -63,7 +63,7 @@ https://github.com/erichelgeson/BlueSCSI/wiki/Troubleshooting
|
||||
|
||||
#### 1.1-a Desktop
|
||||
|
||||
* Binky! There are now resistors and pin outs for Power and Activity LED's
|
||||
* Blinky! There are now resistors and pin outs for Power and Activity LED's
|
||||
* Resistor nets flipped all the same way
|
||||
* 50 pin allows for right angle connector
|
||||
* SD Card facing out the back - gives some better options for mounting and access
|
||||
|
14
dist.sh
Normal file
14
dist.sh
Normal file
@@ -0,0 +1,14 @@
|
||||
#!/usr/bin/env bash
|
||||
|
||||
set -e
|
||||
set -x
|
||||
|
||||
DATE=$(date +%Y%m%d)
|
||||
VERSION="v1.1-$DATE"
|
||||
mkdir -p dist
|
||||
rm -f dist/*.bin
|
||||
|
||||
for f in $(ls .pio/build/*/firmware.bin); do
|
||||
NAME="BlueSCSI-$VERSION-$(echo $f | cut -d\/ -f3).bin"
|
||||
cp $f dist/$NAME
|
||||
done
|
@@ -3,25 +3,25 @@
|
||||
|
||||
## Introduction
|
||||
|
||||
1.0-c was a small change to fix an issue with machines that provide low or no `TERMPOWER` over the SCSI bus. If you recived a Fully Assembled BlueSCSI after April 1st, 2021 then this was done for you. If you have a kit labled 1.0-b you can make these modifications to become a 1.0-c.
|
||||
1.0-c was a small change to fix an issue with machines that provide low or no `TERMPOWER` over the SCSI bus. If you received a fully-assembled BlueSCSI after April 1st, 2021 then this was done for you. If you have a kit labeled 1.0-b you can make these modifications to become a 1.0-c.
|
||||
|
||||
## Steps
|
||||
|
||||
### Disconnect `TERMPOWER` from 220 Pull Up Jupmer
|
||||
### Disconnect `TERMPOWER` from 220 Pull Up Jumper
|
||||
|
||||
Use a cutting tool to cut the small trace between the `TERMPOWR` and 220 Pull Up Jumper pictured below.
|
||||
|
||||
Make sure continiutiy from `TERMPOWER` to the diode still flows correctly but is disconnected from the jumper.
|
||||
Make sure continuity from `TERMPOWER` to the diode still flows correctly but is disconnected from the jumper.
|
||||
|
||||
image::images/1.0-b-bodge-1.jpg[]
|
||||
|
||||
### Connect 5V to 220 Pull Up Jupmer
|
||||
### Connect 5V to 220 Pull Up Jumper
|
||||
|
||||
Now we will provide pull up from the 5v provided by the BluePill.
|
||||
Now we will provide pull up from the 5V provided by the BluePill.
|
||||
|
||||
image::images/1.0-b-bodge-2.png[]
|
||||
|
||||
### Complete!
|
||||
|
||||
Thats it! 5v to the Pull Up resistors will now work when powered externally.
|
||||
That’s it! 5V to the Pull Up resistors will now work when powered externally.
|
||||
|
||||
|
@@ -1,66 +1,5 @@
|
||||
# Assembly
|
||||
|
||||
## Before you start
|
||||
Instructions have moved to the wiki
|
||||
|
||||
Read through all instructions before starting.
|
||||
|
||||
## Videos
|
||||
|
||||
The community has created a few assembly videos:
|
||||
* [Stephen Arsenault - BlueSCSI Kit Assembly](https://www.youtube.com/watch?v=G6lwCfLQwd8) 2:52
|
||||
* [Joe's Computer Museum - A New Challenger - BlueSCSI - #MARCHintosh Review](https://www.youtube.com/watch?v=d_8VVmvvlNI) 26:52
|
||||
* [Geeky Bit - Tutorial - BlueSCSI Assembly](https://www.youtube.com/watch?v=-nF9FYFgVHM) 20:35
|
||||
|
||||
## Building
|
||||
|
||||
1. Solder on the surface mount SD Card holder. Use the [Drag Solder](https://youtu.be/Z_KL4fWOMug) technique.
|
||||
- Once on, check continuity of all connections. Fixing this after the BluePill is on will be difficult.
|
||||
- Ensure the SD card fits and you dont have too much solder on the sides or contacts
|
||||
2. Solder the diodes to the **bottom** of the board. Be sure they are flush as possible to the bottom.
|
||||

|
||||
3. Solder the header pins on to the BluePill. Then BluePill pill to the BlueSCSI PCB.
|
||||
- Correct orientation is having the USB connector of the BluePill should be over the SD Card holder.
|
||||
- **NOTE**: Consider adding headers to the board if you would like to have the BluePill removable.
|
||||
4. Solder on the resistor nets. Pin one is marked on the board and the resistors.
|
||||
- 220 RNETS (`RN1` & `RN3`) are closest to the BluePill
|
||||
- **NOTE** PIN one on each - they are opposite of eachtoher. See photo.
|
||||
- 330 RNETS (`RN2` & `RN4`) are furthest from the BluePill
|
||||
- **NOTE** PIN one on each - they are opposite of eachtoher. See photo.
|
||||

|
||||
5. Solder on the Termination Jumpers & place the jumpers on to enable Termiation
|
||||
6. Solder the 50 Pin headers on.
|
||||
1. Note Pin 1 and Box header on the silk screen.
|
||||
7. Optional - Solder on the berg connector. Only needed if your machine does not supply enough power via the SCSI bus.
|
||||
8. Optional - Solder on the debug headers near the SD card. Only nessissarry if re-programming.
|
||||
|
||||
### Fully Assembled
|
||||

|
||||
|
||||
### Version 1.0-b & 1.0-c BOM
|
||||
|
||||
#### Mouser Cart
|
||||
|
||||
https://www.mouser.com/ProjectManager/ProjectDetail.aspx?AccessID=c5cc83feff
|
||||
|
||||
#### Parts
|
||||
|
||||
STM32F103C8T6 (U1) aka BluePill board. Beware of fake/scams. Look for reviews. Amazon, ebay, etc.
|
||||
|
||||
* 2x 330 (RN2, RN4) Resistor nets https://www.mouser.com/ProductDetail/652-4610X-1LF-330
|
||||
|
||||
* 2x 220 (RN1, RN3) Resistor nets https://www.mouser.com/ProductDetail/652-4610X-1LF-220
|
||||
|
||||
* 2x Diodes https://www.mouser.com/ProductDetail/583-1N5818-T
|
||||
|
||||
* SD Card Holder (J1) https://www.mouser.com/ProductDetail/538-104031-0811
|
||||
|
||||
* Headers https://www.mouser.com/ProductDetail/872-920-0011-01
|
||||
|
||||
* 50 PIN SCSI header https://www.mouser.com/ProductDetail/517-30350-6002/
|
||||
- May substitute with 2 rows of headers from above.
|
||||
- **Note on Right angle connectors** - it appears Right angle headers are notched differently then the pin out. Be sure to note PIN 1/red stripe on the cable match up.
|
||||
|
||||
### Optional
|
||||
|
||||
Floppy/Berg Power header https://www.mouser.com/ProductDetail/571-1718254
|
||||
- Required if your machine does not supply power via TERM POWER. For example a Mac Plus or Mac with a Analog/PSU board that has not been recapped.
|
||||
https://github.com/erichelgeson/BlueSCSI/wiki/Assembly
|
||||
|
@@ -1,7 +1,7 @@
|
||||
|
||||
# Build Your Own
|
||||
|
||||
These instructions will guide you thorugh purchasing all of the parts needed to assemble kits for yourselves and for friends! Please note the hardware is licensed non-comercial.
|
||||
These instructions will guide you through purchasing all of the parts needed to assemble kits for yourselves and for friends! Please note the hardware is licensed non-commercial.
|
||||
|
||||
If you'd like to buy the kits pre-packaged/pre-flashed or fully assembled we have a network of makers here to help you out at https://scsi.blue
|
||||
|
||||
@@ -11,11 +11,11 @@ Updated for 1.0-c.
|
||||
|
||||
### PCB's
|
||||
|
||||
Grab the latest Gerbers. Gerber files tell the PCB manufactuer how to create the BlueSCSI boards.
|
||||
Grab the latest Gerbers. Gerber files tell the PCB manufacturer how to create the BlueSCSI boards.
|
||||
|
||||
https://github.com/erichelgeson/BlueSCSI/tree/main/hw/
|
||||
|
||||
Order the boards from https://jlcpcb.com/ or your manufactuer of choice.
|
||||
Order the boards from https://jlcpcb.com/ or your manufacturer of choice.
|
||||
|
||||
### Components
|
||||
|
||||
@@ -55,6 +55,6 @@ https://github.com/erichelgeson/BlueSCSI#flashing
|
||||
|
||||
## Usage
|
||||
|
||||
Be sure to follow the usage instructions for getting your drive images setup:
|
||||
Be sure to follow the usage instructions for getting your drive images set up:
|
||||
|
||||
https://github.com/erichelgeson/BlueSCSI#usage
|
||||
|
@@ -1,20 +1,15 @@
|
||||
; PlatformIO Project Configuration File https://docs.platformio.org/page/projectconf.html
|
||||
|
||||
[env:genericSTM32F103C8]
|
||||
platform = ststm32
|
||||
board = genericSTM32F103C8
|
||||
board_build.mcu = stm32f103c8t6
|
||||
board_build.core = maple
|
||||
[platformio]
|
||||
default_envs = STM32F1
|
||||
|
||||
[env]
|
||||
framework = arduino
|
||||
lib_deps =
|
||||
greiman/SdFat @ ^2.0.6
|
||||
upload_protocol = stlink
|
||||
; Different gcc versions produce much different binaries in terms of speed.
|
||||
platform_packages = platformio/toolchain-gccarmnoneeabi@1.90301.200702
|
||||
|
||||
build_unflags =
|
||||
-Os
|
||||
-DARDUINO_ARCH_STM32F1
|
||||
build_flags =
|
||||
-w
|
||||
-DARDUINO_GENERIC_STM32F103C
|
||||
@@ -23,9 +18,78 @@ build_flags =
|
||||
-DARDUINO_ARCH_STM32
|
||||
-DDEBUG_LEVEL=DEBUG_NONE
|
||||
-O2
|
||||
-D BUILD_TAGS="\"\""
|
||||
build_unflags =
|
||||
-Os
|
||||
-DARDUINO_ARCH_STM32F1
|
||||
upload_flags = -c set CPUTAPID 0
|
||||
|
||||
; Work around for clones.
|
||||
; https://community.platformio.org/t/cannot-upload-to-stm32-bluepill-board-over-stlink-v2/3492/25
|
||||
[env:STM32F1]
|
||||
platform = ststm32
|
||||
board = genericSTM32F103C8
|
||||
board_build.mcu = stm32f103c8t6
|
||||
board_build.core = maple
|
||||
|
||||
[env:STM32F1-XCVR]
|
||||
extends = env:STM32F1
|
||||
build_flags = ${env.build_flags}
|
||||
-DXCVR
|
||||
-D BUILD_TAGS="\"-XCVR\""
|
||||
|
||||
[env:STM32F1-USB-128MHz]
|
||||
# Max overclock for STM32
|
||||
# Can use for APM32F1 as well.
|
||||
extends = env:STM32F1-USB
|
||||
board_build.f_cpu = 128000000L
|
||||
build_flags = ${env.build_flags}
|
||||
-D BUILD_TAGS="\"-USB-128MHz\""
|
||||
|
||||
[env:STM32F1-USB-96MHz]
|
||||
# Slight overclock for STM32
|
||||
# Use for APM32F1's - it's default clock is 96MHz and runs unstable at 72MHz(STM32F1's default)
|
||||
extends = env:STM32F1-USB
|
||||
# Explicilty define the multiplier as maple only handles a few cases.
|
||||
build_flags = ${env.build_flags}
|
||||
-D BUILD_TAGS="\"-USB-96MHz\""
|
||||
-D PIO_FRAMEWORK_ARDUINO_ENABLE_CDC
|
||||
-D USBCON
|
||||
-D USBD_VID=0x0483
|
||||
-D USB_MANUFACTURER="Unknown"
|
||||
-D USB_PRODUCT="\"BLUEPILL_F103C8\""
|
||||
-D HAL_PCD_MODULE_ENABLED
|
||||
-DBOARD_RCC_PLLMUL=RCC_PLLMUL_12 #96000000L
|
||||
|
||||
# TODO: Find out why USB build flags get trampled when extending an extended env.
|
||||
[env:STM32F1-USB]
|
||||
platform = ststm32
|
||||
board = genericSTM32F103C8
|
||||
board_build.mcu = stm32f103c8t6
|
||||
board_build.core = maple
|
||||
board_build.f_cpu = 128000000L
|
||||
framework = arduino
|
||||
lib_deps =
|
||||
greiman/SdFat @ ^2.0.6
|
||||
upload_protocol = dfu
|
||||
; Different gcc versions produce much different binaries in terms of speed.
|
||||
platform_packages = platformio/toolchain-gccarmnoneeabi@1.90301.200702
|
||||
build_flags =
|
||||
-D BUILD_TAGS="\"-USB\""
|
||||
-D PIO_FRAMEWORK_ARDUINO_ENABLE_CDC
|
||||
-D USBCON
|
||||
-D USBD_VID=0x0483
|
||||
-D USB_MANUFACTURER="Unknown"
|
||||
-D USB_PRODUCT="\"BLUEPILL_F103C8\""
|
||||
-D HAL_PCD_MODULE_ENABLED
|
||||
-w
|
||||
-DARDUINO_GENERIC_STM32F103C
|
||||
-DARDUINO_LIB_DISCOVERY_PHASE
|
||||
-DARDUINO=10813
|
||||
-DARDUINO_ARCH_STM32
|
||||
-DDEBUG_LEVEL=DEBUG_NONE
|
||||
-O2
|
||||
build_unflags =
|
||||
-Os
|
||||
-DARDUINO_ARCH_STM32F1
|
||||
upload_flags = -c set CPUTAPID 0
|
||||
|
||||
; [env:debug]
|
||||
|
1497
src/BlueSCSI.cpp
1497
src/BlueSCSI.cpp
File diff suppressed because it is too large
Load Diff
323
src/BlueSCSI.h
Normal file
323
src/BlueSCSI.h
Normal file
@@ -0,0 +1,323 @@
|
||||
#ifndef __BLUESCSI_H__
|
||||
#define __BLUESCSI_H__
|
||||
|
||||
#include <Arduino.h> // For Platform.IO
|
||||
#include <SdFat.h>
|
||||
|
||||
// SCSI config
|
||||
#define MAX_SCSIID 7 // Maximum number of supported SCSI-IDs (The minimum is 0)
|
||||
#define MAX_SCSILUN 1 // Maximum number of LUNs supported (The minimum is 0)
|
||||
#define NUM_SCSIID MAX_SCSIID // Number of enabled SCSI IDs
|
||||
#define NUM_SCSILUN 1 // Number of enabled LUNs
|
||||
#define READ_PARITY_CHECK 0 // Perform read parity check (unverified)
|
||||
#define DEFAULT_SCSI_ID 1
|
||||
#define DEFAULT_SCSI_LUN 0
|
||||
#define SCSI_BUF_SIZE 512 // Size of the SCSI Buffer
|
||||
#define HDD_BLOCK_SIZE 512
|
||||
#define OPTICAL_BLOCK_SIZE 2048
|
||||
|
||||
// HDD format
|
||||
#define MAX_BLOCKSIZE 4096 // Maximum BLOCK size
|
||||
|
||||
// SDFAT
|
||||
#define SD1_CONFIG SdSpiConfig(PA4, DEDICATED_SPI, SD_SCK_MHZ(SPI_FULL_SPEED), &SPI)
|
||||
|
||||
// LED ERRORS
|
||||
#define ERROR_FALSE_INIT 3
|
||||
#define ERROR_NO_SDCARD 5
|
||||
|
||||
|
||||
#if DEBUG
|
||||
#define LOG(XX) Serial.print(XX)
|
||||
#define LOGHEX(XX) Serial.print(XX, HEX)
|
||||
#define LOGN(XX) Serial.println(XX)
|
||||
#define LOGHEXN(XX) Serial.println(XX, HEX)
|
||||
#else
|
||||
#define LOG(XX) //Serial.print(XX)
|
||||
#define LOGHEX(XX) //Serial.print(XX, HEX)
|
||||
#define LOGN(XX) //Serial.println(XX)
|
||||
#define LOGHEXN(XX) //Serial.println(XX, HEX)
|
||||
#endif
|
||||
|
||||
#define active 1
|
||||
#define inactive 0
|
||||
#define high 0
|
||||
#define low 1
|
||||
|
||||
#define isHigh(XX) ((XX) == high)
|
||||
#define isLow(XX) ((XX) != high)
|
||||
|
||||
#define gpio_mode(pin,val) gpio_set_mode(PIN_MAP[pin].gpio_device, PIN_MAP[pin].gpio_bit, val);
|
||||
#define gpio_write(pin,val) gpio_write_bit(PIN_MAP[pin].gpio_device, PIN_MAP[pin].gpio_bit, val)
|
||||
#define gpio_read(pin) gpio_read_bit(PIN_MAP[pin].gpio_device, PIN_MAP[pin].gpio_bit)
|
||||
|
||||
//#define DB0 PB8 // SCSI:DB0
|
||||
//#define DB1 PB9 // SCSI:DB1
|
||||
//#define DB2 PB10 // SCSI:DB2
|
||||
//#define DB3 PB11 // SCSI:DB3
|
||||
//#define DB4 PB12 // SCSI:DB4
|
||||
//#define DB5 PB13 // SCSI:DB5
|
||||
//#define DB6 PB14 // SCSI:DB6
|
||||
//#define DB7 PB15 // SCSI:DB7
|
||||
//#define DBP PB0 // SCSI:DBP
|
||||
#define ATN PA8 // SCSI:ATN
|
||||
#define BSY PA9 // SCSI:BSY
|
||||
#define ACK PA10 // SCSI:ACK
|
||||
#define RST PA15 // SCSI:RST
|
||||
#define MSG PB3 // SCSI:MSG
|
||||
#define SEL PB4 // SCSI:SEL
|
||||
#define CD PB5 // SCSI:C/D
|
||||
#define REQ PB6 // SCSI:REQ
|
||||
#define IO PB7 // SCSI:I/O
|
||||
|
||||
#define SD_CS PA4 // SDCARD:CS
|
||||
#define LED PC13 // LED
|
||||
#define LED2 PA0 // External LED
|
||||
|
||||
// Image Set Selector
|
||||
#ifdef XCVR
|
||||
#define IMAGE_SELECT1 PC14
|
||||
#define IMAGE_SELECT2 PC15
|
||||
#else
|
||||
#define IMAGE_SELECT1 PA1
|
||||
#define IMAGE_SELECT2 PB1
|
||||
#endif
|
||||
|
||||
// GPIO register port
|
||||
#define PAREG GPIOA->regs
|
||||
#define PBREG GPIOB->regs
|
||||
#define PCREG GPIOC->regs
|
||||
|
||||
// LED control
|
||||
#define LED_ON() PCREG->BSRR = 0b00100000000000000000000000000000; PAREG->BSRR = 0b00000000000000000000000000000001;
|
||||
#define LED_OFF() PCREG->BSRR = 0b00000000000000000010000000000000; PAREG->BSRR = 0b00000000000000010000000000000000;
|
||||
|
||||
// Virtual pin (Arduio compatibility is slow, so make it MCU-dependent)
|
||||
#define PA(BIT) (BIT)
|
||||
#define PB(BIT) (BIT+16)
|
||||
// Virtual pin decoding
|
||||
#define GPIOREG(VPIN) ((VPIN)>=16?PBREG:PAREG)
|
||||
#define BITMASK(VPIN) (1<<((VPIN)&15))
|
||||
|
||||
#define vATN PA(8) // SCSI:ATN
|
||||
#define vBSY PA(9) // SCSI:BSY
|
||||
#define vACK PA(10) // SCSI:ACK
|
||||
#define vRST PA(15) // SCSI:RST
|
||||
#define vMSG PB(3) // SCSI:MSG
|
||||
#define vSEL PB(4) // SCSI:SEL
|
||||
#define vCD PB(5) // SCSI:C/D
|
||||
#define vREQ PB(6) // SCSI:REQ
|
||||
#define vIO PB(7) // SCSI:I/O
|
||||
#define vSD_CS PA(4) // SDCARD:CS
|
||||
|
||||
// SCSI output pin control: opendrain active LOW (direct pin drive)
|
||||
#define SCSI_OUT(VPIN,ACTIVE) { GPIOREG(VPIN)->BSRR = BITMASK(VPIN)<<((ACTIVE)?16:0); }
|
||||
|
||||
// SCSI input pin check (inactive=0,avtive=1)
|
||||
#define SCSI_IN(VPIN) ((~GPIOREG(VPIN)->IDR>>(VPIN&15))&1)
|
||||
|
||||
#define NOP(x) for(unsigned _nopcount = x; _nopcount; _nopcount--) { asm("NOP"); }
|
||||
|
||||
/* SCSI Timing delays */
|
||||
// Due to limitations in timing granularity all of these are "very" rough estimates
|
||||
#define SCSI_BUS_SETTLE() NOP(30); // spec 400ns ours ~420us
|
||||
#define SCSI_DATA_RELEASE() NOP(30); // spec 400ns ours ~420us
|
||||
#define SCSI_HOLD_TIME() asm("NOP"); asm("NOP"); asm("NOP"); // spec 45ns ours ~42ns
|
||||
#define SCSI_DESKEW() // asm("NOP"); asm("NOP"); asm("NOP"); // spec 45ns ours ~42ns
|
||||
#define SCSI_CABLE_SKEW() // asm("NOP"); // spec 10ns ours ~14ns
|
||||
#define SCSI_RESET_HOLD() asm("NOP"); asm("NOP"); // spec 25ns ours ~28ns
|
||||
#define SCSI_DISCONNECTION_DELAY() NOP(15); // spec 200ns ours ~210ns
|
||||
|
||||
/* SCSI phases
|
||||
+=============-===============-==================================-============+
|
||||
| Signal | Phase name | Direction of transfer | Comment |
|
||||
|-------------| | | |
|
||||
| MSG|C/D|I/O | | | |
|
||||
|----+---+----+---------------+----------------------------------+------------|
|
||||
| 0 | 0 | 0 | DATA OUT | Initiator to target \ | Data |
|
||||
| 0 | 0 | 1 | DATA IN | Initiator from target / | phase |
|
||||
| 0 | 1 | 0 | COMMAND | Initiator to target | |
|
||||
| 0 | 1 | 1 | STATUS | Initiator from target | |
|
||||
| 1 | 0 | 0 | * | | |
|
||||
| 1 | 0 | 1 | * | | |
|
||||
| 1 | 1 | 0 | MESSAGE OUT | Initiator to target \ | Message |
|
||||
| 1 | 1 | 1 | MESSAGE IN | Initiator from target / | phase |
|
||||
|-----------------------------------------------------------------------------|
|
||||
| Key: 0 = False, 1 = True, * = Reserved for future standardization |
|
||||
+=============================================================================+
|
||||
*/
|
||||
// SCSI phase change as single write to port B
|
||||
#define SCSIPHASEMASK(MSGACTIVE, CDACTIVE, IOACTIVE) ((BITMASK(vMSG)<<((MSGACTIVE)?16:0)) | (BITMASK(vCD)<<((CDACTIVE)?16:0)) | (BITMASK(vIO)<<((IOACTIVE)?16:0)))
|
||||
|
||||
#define SCSI_PHASE_DATAOUT SCSIPHASEMASK(inactive, inactive, inactive)
|
||||
#define SCSI_PHASE_DATAIN SCSIPHASEMASK(inactive, inactive, active)
|
||||
#define SCSI_PHASE_COMMAND SCSIPHASEMASK(inactive, active, inactive)
|
||||
#define SCSI_PHASE_STATUS SCSIPHASEMASK(inactive, active, active)
|
||||
#define SCSI_PHASE_MESSAGEOUT SCSIPHASEMASK(active, active, inactive)
|
||||
#define SCSI_PHASE_MESSAGEIN SCSIPHASEMASK(active, active, active)
|
||||
|
||||
#define SCSI_PHASE_CHANGE(MASK) { PBREG->BSRR = (MASK); }
|
||||
|
||||
#ifdef XCVR
|
||||
#define TR_TARGET PA1 // Target Transceiver Control Pin
|
||||
#define TR_DBP PA2 // Data Pins Transceiver Control Pin
|
||||
#define TR_INITIATOR PA3 // Initiator Transciever Control Pin
|
||||
|
||||
#define vTR_TARGET PA(1) // Target Transceiver Control Pin
|
||||
#define vTR_DBP PA(2) // Data Pins Transceiver Control Pin
|
||||
#define vTR_INITIATOR PA(3) // Initiator Transciever Control Pin
|
||||
|
||||
#define TR_INPUT 1
|
||||
#define TR_OUTPUT 0
|
||||
|
||||
// Transceiver control definitions
|
||||
#define TRANSCEIVER_IO_SET(VPIN,TR_INPUT) { GPIOREG(VPIN)->BSRR = BITMASK(VPIN) << ((TR_INPUT) ? 16 : 0); }
|
||||
|
||||
// Turn on the output only for BSY
|
||||
#define SCSI_BSY_ACTIVE() { gpio_mode(BSY, GPIO_OUTPUT_PP); SCSI_OUT(vBSY, active) }
|
||||
|
||||
#define SCSI_TARGET_ACTIVE() { gpio_mode(REQ, GPIO_OUTPUT_PP); gpio_mode(MSG, GPIO_OUTPUT_PP); gpio_mode(CD, GPIO_OUTPUT_PP); gpio_mode(IO, GPIO_OUTPUT_PP); gpio_mode(BSY, GPIO_OUTPUT_PP); TRANSCEIVER_IO_SET(vTR_TARGET,TR_OUTPUT);}
|
||||
// BSY,REQ,MSG,CD,IO Turn off output, BSY is the last input
|
||||
#define SCSI_TARGET_INACTIVE() { pinMode(REQ, INPUT); pinMode(MSG, INPUT); pinMode(CD, INPUT); pinMode(IO, INPUT); pinMode(BSY, INPUT); TRANSCEIVER_IO_SET(vTR_TARGET,TR_INPUT); }
|
||||
|
||||
#define DB_MODE_OUT 1 // push-pull mode
|
||||
#define DB_MODE_IN 4 // floating inputs
|
||||
|
||||
#else
|
||||
|
||||
// GPIO mode
|
||||
// IN , FLOAT : 4
|
||||
// IN , PU/PD : 8
|
||||
// OUT, PUSH/PULL : 3
|
||||
// OUT, OD : 1
|
||||
#define DB_MODE_OUT 3
|
||||
//#define DB_MODE_OUT 7
|
||||
#define DB_MODE_IN 8
|
||||
|
||||
|
||||
// Turn on the output only for BSY
|
||||
#define SCSI_BSY_ACTIVE() { gpio_mode(BSY, GPIO_OUTPUT_OD); SCSI_OUT(vBSY, active) }
|
||||
// BSY,REQ,MSG,CD,IO Turn on the output (no change required for OD)
|
||||
#define SCSI_TARGET_ACTIVE() { if (DB_MODE_OUT != 7) gpio_mode(REQ, GPIO_OUTPUT_PP); }
|
||||
// BSY,REQ,MSG,CD,IO Turn off output, BSY is the last input
|
||||
#define SCSI_TARGET_INACTIVE() { if (DB_MODE_OUT == 7) SCSI_OUT(vREQ,inactive) else { if (DB_MODE_IN == 8) gpio_mode(REQ, GPIO_INPUT_PU) else gpio_mode(REQ, GPIO_INPUT_FLOATING)} PBREG->BSRR = 0b000000000000000011101000; SCSI_OUT(vBSY,inactive); gpio_mode(BSY, GPIO_INPUT_PU); }
|
||||
|
||||
#endif
|
||||
|
||||
// Put DB and DP in output mode
|
||||
#define SCSI_DB_OUTPUT() { PBREG->CRL=(PBREG->CRL &0xfffffff0)|DB_MODE_OUT; PBREG->CRH = 0x11111111*DB_MODE_OUT; }
|
||||
// Put DB and DP in input mode
|
||||
#define SCSI_DB_INPUT() { PBREG->CRL=(PBREG->CRL &0xfffffff0)|DB_MODE_IN ; PBREG->CRH = 0x11111111*DB_MODE_IN; }
|
||||
|
||||
// HDDiamge file
|
||||
#define HDIMG_ID_POS 2 // Position to embed ID number
|
||||
#define HDIMG_LUN_POS 3 // Position to embed LUN numbers
|
||||
#define HDIMG_BLK_POS 5 // Position to embed block size numbers
|
||||
#define MAX_FILE_PATH 32 // Maximum file name length
|
||||
|
||||
/*
|
||||
* Data byte to BSRR register setting value and parity table
|
||||
*/
|
||||
|
||||
// Parity bit generation
|
||||
#define PTY(V) (1^((V)^((V)>>1)^((V)>>2)^((V)>>3)^((V)>>4)^((V)>>5)^((V)>>6)^((V)>>7))&1)
|
||||
|
||||
// Data byte to BSRR register setting value conversion table
|
||||
// BSRR[31:24] = DB[7:0]
|
||||
// BSRR[ 16] = PTY(DB)
|
||||
// BSRR[15: 8] = ~DB[7:0]
|
||||
// BSRR[ 0] = ~PTY(DB)
|
||||
|
||||
// Set DBP, set REQ = inactive
|
||||
#define DBP(D) ((((((uint32_t)(D)<<8)|PTY(D))*0x00010001)^0x0000ff01)|BITMASK(vREQ))
|
||||
//#define DBP(D) ((((((uint32_t)(D)<<8)|PTY(D))*0x00010001)^0x0000ff01))
|
||||
|
||||
|
||||
//#define DBP8(D) DBP(D),DBP(D+1),DBP(D+2),DBP(D+3),DBP(D+4),DBP(D+5),DBP(D+6),DBP(D+7)
|
||||
//#define DBP32(D) DBP8(D),DBP8(D+8),DBP8(D+16),DBP8(D+24)
|
||||
|
||||
// BSRR register control value that simultaneously performs DB set, DP set, and REQ = H (inactrive)
|
||||
uint32_t db_bsrr[256];
|
||||
// Parity bit acquisition
|
||||
#define PARITY(DB) (db_bsrr[DB]&1)
|
||||
|
||||
// Macro cleaning
|
||||
//#undef DBP32
|
||||
//#undef DBP8
|
||||
//#undef DBP
|
||||
//#undef PTY
|
||||
|
||||
// #define GET_CDB6_LBA(x) ((x[2] & 01f) << 16) | (x[3] << 8) | x[4]
|
||||
#define READ_DATA_BUS() (byte)((~(uint32_t)GPIOB->regs->IDR)>>8)
|
||||
|
||||
enum SCSI_DEVICE_TYPE
|
||||
{
|
||||
SCSI_DEVICE_HDD,
|
||||
SCSI_DEVICE_OPTICAL,
|
||||
};
|
||||
|
||||
#define CDROM_RAW_SECTORSIZE 2352
|
||||
#define CDROM_COMMON_SECTORSIZE 2048
|
||||
|
||||
struct SCSI_INQUIRY_DATA
|
||||
{
|
||||
union
|
||||
{
|
||||
struct {
|
||||
// bitfields are in REVERSE order for ARM
|
||||
// byte 0
|
||||
byte peripheral_device_type:5;
|
||||
byte peripheral_qualifier:3;
|
||||
// byte 1
|
||||
byte reserved_byte2:7;
|
||||
byte rmb:1;
|
||||
// byte 2
|
||||
byte ansi_version:3;
|
||||
byte always_zero_byte3:5;
|
||||
// byte 3
|
||||
byte response_format:4;
|
||||
byte reserved_byte4:2;
|
||||
byte tiop:1;
|
||||
byte always_zero_byte4:1;
|
||||
// byte 4
|
||||
byte additional_length;
|
||||
// byte 5-6
|
||||
byte reserved_byte5;
|
||||
byte reserved_byte6;
|
||||
// byte 7
|
||||
byte sync:1;
|
||||
byte always_zero_byte7_more:4;
|
||||
byte always_zero_byte7:3;
|
||||
// byte 8-15
|
||||
char vendor[8];
|
||||
// byte 16-31
|
||||
char product[16];
|
||||
// byte 32-35
|
||||
char revision[4];
|
||||
// byte 36
|
||||
byte release;
|
||||
// 37-46
|
||||
char revision_date[10];
|
||||
};
|
||||
// raw bytes
|
||||
byte raw[64];
|
||||
};
|
||||
};
|
||||
|
||||
// HDD image
|
||||
typedef __attribute__((aligned(4))) struct _SCSI_DEVICE
|
||||
{
|
||||
FsFile *m_file; // File object
|
||||
uint64_t m_fileSize; // File size
|
||||
size_t m_blocksize; // SCSI BLOCK size
|
||||
uint8_t m_type; // SCSI device type
|
||||
uint32_t m_blockcount; // blockcount
|
||||
bool m_raw; // Raw disk
|
||||
SCSI_INQUIRY_DATA inquiry_block; // SCSI information
|
||||
uint8_t m_senseKey; // Sense key
|
||||
uint16_t m_additional_sense_code; // ASC/ASCQ
|
||||
bool m_mode2; // MODE2 CDROM
|
||||
} SCSI_DEVICE;
|
||||
|
||||
|
||||
#endif
|
84
src/scsi_cmds.h
Normal file
84
src/scsi_cmds.h
Normal file
@@ -0,0 +1,84 @@
|
||||
#ifndef __SCSI_CMDS_H__
|
||||
#define __SCSI_CMDS_H__
|
||||
|
||||
// defines for SCSI commands
|
||||
#define SCSI_TEST_UNIT_READY 0
|
||||
#define SCSI_REZERO_UNIT 0x1
|
||||
#define SCSI_REQUEST_SENSE 0x3
|
||||
#define SCSI_FORMAT_UNIT4 0x4
|
||||
#define SCSI_FORMAT_UNIT6 0x6
|
||||
#define SCSI_REASSIGN_BLOCKS 0x7
|
||||
#define SCSI_READ6 0x8
|
||||
#define SCSI_WRITE6 0xA
|
||||
#define SCSI_SEEK6 0xB
|
||||
#define SCSI_INQUIRY 0x12
|
||||
#define SCSI_MODE_SELECT6 0x15
|
||||
#define SCSI_RESERVE 0x16
|
||||
#define SCSI_RELEASE 0x17
|
||||
#define SCSI_COPY 0x18
|
||||
#define SCSI_MODE_SENSE6 0x1A
|
||||
#define SCSI_START_STOP_UNIT 0x1B
|
||||
#define SCSI_RECV_DIAG_RESULTS 0x1C
|
||||
#define SCSI_SEND_DIAG 0x1D
|
||||
#define SCSI_PREVENT_ALLOW_REMOVAL 0x1E
|
||||
#define SCSI_READ_CAPACITY 0x25
|
||||
#define SCSI_READ10 0x28
|
||||
#define SCSI_WRITE10 0x2A
|
||||
#define SCSI_SEEK10 0x2B
|
||||
#define SCSI_WRITE_AND_VERIFY 0x2E
|
||||
#define SCSI_VERIFY10 0x2F
|
||||
#define SCSI_SEARCH_DATA_HIGH 0x30
|
||||
#define SCSI_SEARCH_DATA_EQUAL 0x31
|
||||
#define SCSI_SEARCH_DATA_LOW 0x32
|
||||
#define SCSI_SET_LIMITS 0x33
|
||||
#define SCSI_PREFETCH 0x34
|
||||
#define SCSI_SYNCHRONIZE_CACHE 0x35
|
||||
#define SCSI_LOCK_UNLOCK_CACHE 0x36
|
||||
#define SCSI_READ_DEFECT_DATA 0x37
|
||||
#define SCSI_COMPARE 0x39
|
||||
#define SCSI_COPY_AND_VERIFY 0x3A
|
||||
#define SCSI_WRITE_BUFFER 0x3B
|
||||
#define SCSI_READ_BUFFER 0x3C
|
||||
#define SCSI_READ_LONG 0x3E
|
||||
#define SCSI_WRITE_LONG 0x3F
|
||||
#define SCSI_CHANGE_DEFINITION 0x40
|
||||
#define SCSI_WRITE_SAME 0x41
|
||||
#define SCSI_LOG_SELECT 0x4C
|
||||
#define SCSI_LOG_SENSE 0x4D
|
||||
#define SCSI_MODE_SELECT10 0x55
|
||||
#define SCSI_MODE_SENSE10 0x5A
|
||||
#define SCSI_READ12 0xA8
|
||||
#define SCSI_VERIFY12 0xAF
|
||||
|
||||
|
||||
#define SCSI_TOC_LENGTH 20 // length for default CDROM TOC
|
||||
|
||||
// SCSI CDROM commands
|
||||
#define SCSI_AUDIO_SCAN1 0xBA
|
||||
#define SCSI_AUDIO_SCAN2 0xCD
|
||||
#define SCSI_PAUSE_RESUME 0x4B
|
||||
#define SCSI_PLAY_AUDIO10 0x45
|
||||
#define SCSI_PLAY_AUDIO12 0xA5
|
||||
#define SCSI_PLAY_AUDIO_MSF 0x47
|
||||
#define SCSI_PLAY_AUDIO_TRACK_IDX 0x48
|
||||
#define SCSI_PLAY_TRACK_RELATIVE10 0x49
|
||||
#define SCSI_PLAY_TRACK_RELATIVE12 0xA9
|
||||
#define SCSI_READ_CD 0xBE
|
||||
#define SCSI_READ_CD_DD 0xD8
|
||||
#define SCSI_READ_CD_MSF 0xB9
|
||||
#define SCSI_READ_CDDA_MSF 0xD9
|
||||
#define SCSI_READ_CDXA 0xDB
|
||||
#define SCSI_READ_ALL_SUBCODE 0xDF
|
||||
#define SCSI_READ_HEADER 0x44
|
||||
#define SCSI_READ_SUBCHANNEL 0x42
|
||||
#define SCSI_READ_TOC 0x43
|
||||
#define SCSI_READ_DISC_INFORMATION 0x51
|
||||
#define SCSI_READ_DVD_STRUCTURE 0xAD
|
||||
#define SCSI_SET_CDROM_SPEED1 0xBB
|
||||
#define SCSI_SET_CDROM_SPEED2 0xDA
|
||||
#define SCSI_STOP_PLAY_SCAN 0x4E
|
||||
#define SCSI_READ_CDP 0xE4
|
||||
#define SCSI_READ_DRIVE_STATUS 0xE0
|
||||
#define SCSI_WRITE_CDP 0xE3
|
||||
|
||||
#endif // __SCSI_CMDS_H__
|
9
src/scsi_mode.h
Normal file
9
src/scsi_mode.h
Normal file
@@ -0,0 +1,9 @@
|
||||
#ifndef __SCSI_MODE_H__
|
||||
#define __SCSI_MODE_H__
|
||||
|
||||
#define MODE_COMBINED_HEADER_DATA 0x00
|
||||
#define MODE_NOT_SUPPORTED 0x01
|
||||
#define MODE_DATA 0x02
|
||||
#define MODE_DESCRIPTOR 0x03
|
||||
|
||||
#endif
|
46
src/scsi_sense.h
Normal file
46
src/scsi_sense.h
Normal file
@@ -0,0 +1,46 @@
|
||||
#ifndef __SCSI_SENSE_H__
|
||||
#define __SCSI_SENSE_H__
|
||||
|
||||
#define SCSI_SENSE_NO_SENSE 0
|
||||
#define SCSI_SENSE_RECOVERED_ERROR 0x1
|
||||
#define SCSI_SENSE_NOT_READY 0x2
|
||||
#define SCSI_SENSE_MEDUIM_ERROR 0x3
|
||||
#define SCSI_SENSE_HARDWARE_ERROR 0x4
|
||||
#define SCSI_SENSE_ILLEGAL_REQUEST 0x5
|
||||
#define SCSI_SENSE_UNIT_ATTENTION 0x6
|
||||
#define SCSI_SENSE_DATA_PROTECT 0x7
|
||||
#define SCSI_SENSE_BLANK_CHECK 0x8
|
||||
#define SCSI_SENSE_VENDOR_SPECIFIC 0x9
|
||||
#define SCSI_SENSE_COPY_ABORTED 0xa
|
||||
#define SCSI_SENSE_ABORTED_COMMAND 0xb
|
||||
#define SCSI_SENSE_EQUAL 0xc
|
||||
#define SCSI_SENSE_VOLUME_OVERFLOW 0xd
|
||||
#define SCSI_SENSE_MISCOMPARE 0xe
|
||||
#define SCSI_SENSE_RESERVED 0xf
|
||||
|
||||
|
||||
#define SCSI_ASC_INVALID_OPERATION_CODE 0x2000
|
||||
#define SCSI_ASC_LOGICAL_BLOCK_ADDRESS_OUT_OF_RANGE 0x2100
|
||||
#define SCSI_ASC_INVALID_FIELD_IN_CDB 0x2400
|
||||
#define SCSI_ASC_LOGICAL_UNIT_NOT_SUPPORTED 0x2500
|
||||
#define SCSI_ASC_INVALID_FIELD_PARAMETER_LIST 0x2600
|
||||
#define SCSI_ASC_WRITE_PROTECTED 0x2700
|
||||
#define SCSI_ASC_CANNOT_READ_MEDIUM_UNKNOWN_FORMAT 0x3001
|
||||
#define SCSI_ASC_CANNOT_READ_MEDIUM_INCOMPATIBLE_FORMAT 0x3002
|
||||
#define SCSI_ASC_MEDIUM_NOT_PRESENT 0x3A00
|
||||
#define SCSI_ASC_LUN_NOT_READY_MANUAL_INTERVENTION_REQUIRED 0x0403
|
||||
|
||||
|
||||
// SCSI mode page codes
|
||||
#define SCSI_SENSE_MODE_VENDOR 0x00
|
||||
#define SCSI_SENSE_MODE_READ_WRITE_ERROR_RECOVERY 0x01
|
||||
#define SCSI_SENSE_MODE_DISCONNECT_RECONNECT 0x02
|
||||
#define SCSI_SENSE_MODE_FORMAT_DEVICE 0x03
|
||||
#define SCSI_SENSE_MODE_DISK_GEOMETRY 0x04
|
||||
#define SCSI_SENSE_MODE_FLEXABLE_GEOMETRY 0x05
|
||||
#define SCSI_SENSE_MODE_VENDOR_APPLE 0x30
|
||||
|
||||
#define SCSI_SENSE_MODE_ALL 0x3F
|
||||
|
||||
|
||||
#endif
|
14
src/scsi_status.h
Normal file
14
src/scsi_status.h
Normal file
@@ -0,0 +1,14 @@
|
||||
#ifndef __SCSI_STATUS_H__
|
||||
#define __SCSI_STATUS_H__
|
||||
|
||||
#define SCSI_STATUS_GOOD 0
|
||||
#define SCSI_STATUS_CHECK_CONDITION 0x2
|
||||
#define SCSI_STATUS_CONDITION_MET 0x4
|
||||
#define SCSI_STATUS_BUSY 0x8
|
||||
#define SCSI_STATUS_INTERMEDIATE 0x16
|
||||
#define SCSI_STATUS_INTERMEDIATE_CONDITION_MET 0x20
|
||||
#define SCSI_STATUS_RESERVATION_CONFLICT 0x24
|
||||
#define SCSI_STATUS_COMMAND_TERMINATED 0x34
|
||||
#define SCSI_STATUS_QUEUE_FULL 0x40
|
||||
|
||||
#endif
|
Reference in New Issue
Block a user