scsiPhy.cpp 17 KB

123456789101112131415161718192021222324252627282930313233343536373839404142434445464748495051525354555657585960616263646566676869707172737475767778798081828384858687888990919293949596979899100101102103104105106107108109110111112113114115116117118119120121122123124125126127128129130131132133134135136137138139140141142143144145146147148149150151152153154155156157158159160161162163164165166167168169170171172173174175176177178179180181182183184185186187188189190191192193194195196197198199200201202203204205206207208209210211212213214215216217218219220221222223224225226227228229230231232233234235236237238239240241242243244245246247248249250251252253254255256257258259260261262263264265266267268269270271272273274275276277278279280281282283284285286287288289290291292293294295296297298299300301302303304305306307308309310311312313314315316317318319320321322323324325326327328329330331332333334335336337338339340341342343344345346347348349350351352353354355356357358359360361362363364365366367368369370371372373374375376377378379380381382383384385386387388389390391392393394395396397398399400401402403404405406407408409410411412413414415416417418419420421422423424425426427428429430431432433434435436437438439440441442443444445446447448449450451452453454455456457458459460461462463464465466467468469470471472473474475476477478479480481482483484485486487488489490491492493494495496497498499500501502503504505506507508509510511512513514515516517518519520521522523524525526527528529530531532533534535536537538539540541542543544545546547548549550551552553554555556557558559560561562563564565566567568569570571572573574575576577578579580581582583584585586587588589590591592593594595596597598599600601602603604605606607608609610611612613614615616617618619620621622623624625626627628629630631632633634635636637638639640641642643644645646647648
  1. /**
  2. * SCSI2SD V6 - Copyright (C) 2013 Michael McMaster <michael@codesrc.com>
  3. * ZuluSCSI™ - Copyright (c) 2022-2025 Rabbit Hole Computing™
  4. *
  5. * This file is licensed under the GPL version 3 or any later version.  
  6. * It is derived from scsiPhy.c in SCSI2SD V6.
  7. *
  8. * https://www.gnu.org/licenses/gpl-3.0.html
  9. * ----
  10. * This program is free software: you can redistribute it and/or modify
  11. * it under the terms of the GNU General Public License as published by
  12. * the Free Software Foundation, either version 3 of the License, or
  13. * (at your option) any later version. 
  14. *
  15. * This program is distributed in the hope that it will be useful,
  16. * but WITHOUT ANY WARRANTY; without even the implied warranty of
  17. * MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE.  See the
  18. * GNU General Public License for more details. 
  19. *
  20. * You should have received a copy of the GNU General Public License
  21. * along with this program.  If not, see <https://www.gnu.org/licenses/>.
  22. **/
  23. // Implements the low level interface to SCSI bus
  24. // Partially derived from scsiPhy.c from SCSI2SD-V6
  25. #include "scsiPhy.h"
  26. #include "ZuluSCSI_platform.h"
  27. #include "scsi_accel_asm.h"
  28. #include "scsi_accel_dma.h"
  29. #include "scsi_accel_greenpak.h"
  30. #include "scsi_accel_sync.h"
  31. #include "ZuluSCSI_log.h"
  32. #include "ZuluSCSI_log_trace.h"
  33. #include "ZuluSCSI_config.h"
  34. #include "ZuluSCSI_settings.h"
  35. #include <minIni.h>
  36. #include <scsi2sd.h>
  37. extern "C" {
  38. #include <scsi.h>
  39. #include <scsi2sd_time.h>
  40. }
  41. // Acceleration mode in use
  42. static enum {
  43. PHY_MODE_BEST_AVAILABLE = 0,
  44. PHY_MODE_PIO = 1,
  45. PHY_MODE_DMA_TIMER = 2,
  46. PHY_MODE_GREENPAK_PIO = 3,
  47. PHY_MODE_GREENPAK_DMA = 4
  48. } g_scsi_phy_mode;
  49. static const char *g_scsi_phy_mode_names[] = {
  50. "Unknown", "PIO", "DMA_TIMER", "GREENPAK_PIO", "GREENPAK_DMA"
  51. };
  52. // State of polling write request
  53. static struct {
  54. const uint8_t *data;
  55. uint32_t count;
  56. bool use_sync_mode;
  57. } g_scsi_writereq;
  58. static void init_irqs();
  59. /***********************/
  60. /* SCSI status signals */
  61. /***********************/
  62. extern "C" bool scsiStatusATN()
  63. {
  64. return SCSI_IN(ATN);
  65. }
  66. extern "C" bool scsiStatusBSY()
  67. {
  68. return SCSI_IN(BSY);
  69. }
  70. /************************/
  71. /* SCSI selection logic */
  72. /************************/
  73. volatile uint8_t g_scsi_sts_selection;
  74. volatile uint8_t g_scsi_ctrl_bsy;
  75. static void scsi_bsy_deassert_interrupt()
  76. {
  77. if (!SCSI_IN(BSY) && ((g_moved_select_in && SCSI_IN(ODE_SEL)) || (!g_moved_select_in && SCSI_IN(SEL))))
  78. {
  79. uint8_t sel_bits = SCSI_IN_DATA();
  80. int sel_id = -1;
  81. for (int i = 0; i < S2S_MAX_TARGETS; i++)
  82. {
  83. if (scsiDev.targets[i].targetId <= 7 && scsiDev.targets[i].cfg)
  84. {
  85. if (sel_bits & (1 << scsiDev.targets[i].targetId))
  86. {
  87. sel_id = scsiDev.targets[i].targetId;
  88. break;
  89. }
  90. }
  91. }
  92. if (sel_id >= 0)
  93. {
  94. uint8_t atn_flag = SCSI_IN(ATN) ? SCSI_STS_SELECTION_ATN : 0;
  95. g_scsi_sts_selection = SCSI_STS_SELECTION_SUCCEEDED | atn_flag | sel_id;
  96. }
  97. // selFlag is required for Philips P2000C which releases it after 600ns
  98. // without waiting for BSY.
  99. // Also required for some early Mac Plus roms
  100. scsiDev.selFlag = *SCSI_STS_SELECTED;
  101. }
  102. }
  103. extern "C" bool scsiStatusSEL()
  104. {
  105. if (g_scsi_ctrl_bsy)
  106. {
  107. // We don't have direct register access to BSY bit like SCSI2SD scsi.c expects.
  108. // Instead update the state here.
  109. // Releasing happens with bus release.
  110. g_scsi_ctrl_bsy = 0;
  111. SCSI_OUT(BSY, 1);
  112. }
  113. if (g_moved_select_in)
  114. {
  115. return SCSI_IN(ODE_SEL);
  116. }
  117. return SCSI_IN(SEL);
  118. }
  119. /************************/
  120. /* SCSI bus reset logic */
  121. /************************/
  122. static void scsi_rst_assert_interrupt()
  123. {
  124. bool rst1 = SCSI_IN(RST);
  125. delay_ns(500);
  126. bool rst2 = SCSI_IN(RST);
  127. if (rst1 && rst2)
  128. {
  129. dbgmsg("BUS RESET");
  130. scsiDev.resetFlag = 1;
  131. }
  132. }
  133. static void selectPhyMode()
  134. {
  135. int oldmode = g_scsi_phy_mode;
  136. // Read overriding setting from configuration file
  137. int wanted_mode = g_scsi_settings.getSystem()->phyMode;
  138. // Default: software GPIO bitbang, available on all revisions
  139. g_scsi_phy_mode = PHY_MODE_PIO;
  140. // Timer based DMA bitbang, available on V1.1, 2.8 MB/s
  141. #ifdef SCSI_ACCEL_DMA_AVAILABLE
  142. if (wanted_mode == PHY_MODE_BEST_AVAILABLE || wanted_mode == PHY_MODE_DMA_TIMER)
  143. {
  144. g_scsi_phy_mode = PHY_MODE_DMA_TIMER;
  145. }
  146. #endif
  147. // GreenPAK with software write, available on V1.1 with extra chip, 3.5 MB/s
  148. if (wanted_mode == PHY_MODE_BEST_AVAILABLE || wanted_mode == PHY_MODE_GREENPAK_PIO)
  149. {
  150. if (greenpak_is_ready())
  151. {
  152. g_scsi_phy_mode = PHY_MODE_GREENPAK_PIO;
  153. }
  154. }
  155. // GreenPAK with DMA write, available on V1.1 with extra chip
  156. #ifdef SCSI_ACCEL_DMA_AVAILABLE
  157. if (wanted_mode == PHY_MODE_BEST_AVAILABLE || wanted_mode == PHY_MODE_GREENPAK_DMA)
  158. {
  159. if (greenpak_is_ready())
  160. {
  161. g_scsi_phy_mode = PHY_MODE_GREENPAK_DMA;
  162. }
  163. }
  164. #endif
  165. if (g_scsi_phy_mode != oldmode)
  166. {
  167. logmsg("SCSI PHY operating mode: ", g_scsi_phy_mode_names[g_scsi_phy_mode]);
  168. }
  169. }
  170. extern "C" void scsiPhyReset(void)
  171. {
  172. SCSI_RELEASE_OUTPUTS();
  173. scsi_accel_dma_stopWrite();
  174. g_scsi_sts_selection = 0;
  175. g_scsi_ctrl_bsy = 0;
  176. g_scsi_writereq.count = 0;
  177. init_irqs();
  178. #ifdef SCSI_SYNC_MODE_AVAILABLE
  179. scsi_accel_sync_init();
  180. #endif
  181. selectPhyMode();
  182. if (g_scsi_phy_mode == PHY_MODE_DMA_TIMER)
  183. {
  184. scsi_accel_timer_dma_init();
  185. }
  186. else if (g_scsi_phy_mode == PHY_MODE_GREENPAK_DMA)
  187. {
  188. scsi_accel_greenpak_dma_init();
  189. }
  190. }
  191. /************************/
  192. /* SCSI bus phase logic */
  193. /************************/
  194. static SCSI_PHASE g_scsi_phase;
  195. extern "C" void scsiEnterPhase(int phase)
  196. {
  197. int delay = scsiEnterPhaseImmediate(phase);
  198. if (delay > 0)
  199. {
  200. s2s_delay_ns(delay);
  201. }
  202. }
  203. // Change state and return nanosecond delay to wait
  204. extern "C" uint32_t scsiEnterPhaseImmediate(int phase)
  205. {
  206. if (phase != g_scsi_phase)
  207. {
  208. // ANSI INCITS 362-2002 SPI-3 10.7.1:
  209. // Phase changes are not allowed while REQ or ACK is asserted.
  210. while (likely(!scsiDev.resetFlag) && SCSI_IN(ACK)) {}
  211. if (scsiDev.compatMode < COMPAT_SCSI2 && (phase == DATA_IN || phase == DATA_OUT))
  212. {
  213. // Akai S1000/S3000 seems to need extra delay before changing to data phase
  214. // after a command. The code in ZuluSCSI_disk.cpp tries to do this while waiting
  215. // for SD card, to avoid any extra latency.
  216. s2s_delay_ns(400000);
  217. }
  218. int oldphase = g_scsi_phase;
  219. g_scsi_phase = (SCSI_PHASE)phase;
  220. scsiLogPhaseChange(phase);
  221. if (phase < 0)
  222. {
  223. // Other communication on bus or reset state
  224. SCSI_RELEASE_OUTPUTS();
  225. return 0;
  226. }
  227. else
  228. {
  229. SCSI_OUT(MSG, phase & __scsiphase_msg);
  230. SCSI_OUT(CD, phase & __scsiphase_cd);
  231. SCSI_OUT(IO, phase & __scsiphase_io);
  232. int delayNs = 400; // Bus settle delay
  233. if ((oldphase & __scsiphase_io) != (phase & __scsiphase_io))
  234. {
  235. delayNs += 400; // Data release delay
  236. }
  237. if (scsiDev.compatMode < COMPAT_SCSI2)
  238. {
  239. // EMU EMAX needs 100uS ! 10uS is not enough.
  240. delayNs += 100000;
  241. }
  242. return delayNs;
  243. }
  244. }
  245. else
  246. {
  247. return 0;
  248. }
  249. }
  250. // Release all signals
  251. void scsiEnterBusFree(void)
  252. {
  253. g_scsi_phase = BUS_FREE;
  254. g_scsi_sts_selection = 0;
  255. g_scsi_ctrl_bsy = 0;
  256. scsiDev.cdbLen = 0;
  257. SCSI_RELEASE_OUTPUTS();
  258. }
  259. /********************/
  260. /* Transmit to host */
  261. /********************/
  262. #define SCSI_WAIT_ACTIVE(pin) \
  263. if (!SCSI_IN(pin)) { \
  264. if (!SCSI_IN(pin)) { \
  265. while(!SCSI_IN(pin) && !scsiDev.resetFlag); \
  266. } \
  267. }
  268. #define SCSI_WAIT_INACTIVE(pin) \
  269. if (SCSI_IN(pin)) { \
  270. if (SCSI_IN(pin)) { \
  271. while(SCSI_IN(pin) && !scsiDev.resetFlag); \
  272. } \
  273. }
  274. static inline void scsiWriteOneByte(uint8_t value)
  275. {
  276. SCSI_OUT_DATA(value);
  277. delay_100ns(); // DB setup time before REQ
  278. SCSI_OUT(REQ, 1);
  279. SCSI_WAIT_ACTIVE(ACK);
  280. SCSI_RELEASE_DATA_REQ(); // Release data and REQ
  281. SCSI_WAIT_INACTIVE(ACK);
  282. }
  283. extern "C" void scsiWriteByte(uint8_t value)
  284. {
  285. scsiLogDataIn(&value, 1);
  286. scsiWriteOneByte(value);
  287. }
  288. extern "C" void scsiWrite(const uint8_t* data, uint32_t count)
  289. {
  290. scsiStartWrite(data, count);
  291. scsiFinishWrite();
  292. }
  293. extern "C" void scsiStartWrite(const uint8_t* data, uint32_t count)
  294. {
  295. scsiLogDataIn(data, count);
  296. g_scsi_writereq.use_sync_mode = (g_scsi_phase == DATA_IN && scsiDev.target->syncOffset > 0);
  297. if (g_scsi_phy_mode == PHY_MODE_PIO
  298. || g_scsi_phy_mode == PHY_MODE_GREENPAK_PIO
  299. || g_scsi_writereq.use_sync_mode)
  300. {
  301. // Software based bit-banging.
  302. // Write requests are queued and then executed in isWriteFinished() callback.
  303. // This allows better parallelism with SD card transfers.
  304. if (g_scsi_writereq.count)
  305. {
  306. if (data == g_scsi_writereq.data + g_scsi_writereq.count)
  307. {
  308. // Combine with previous one
  309. g_scsi_writereq.count += count;
  310. return;
  311. }
  312. else
  313. {
  314. // Actually execute previous request
  315. scsiFinishWrite();
  316. }
  317. }
  318. g_scsi_writereq.data = data;
  319. g_scsi_writereq.count = count;
  320. }
  321. else if (g_scsi_phy_mode == PHY_MODE_DMA_TIMER || g_scsi_phy_mode == PHY_MODE_GREENPAK_DMA)
  322. {
  323. // Accelerated writes using DMA and timers
  324. scsi_accel_dma_startWrite(data, count, &scsiDev.resetFlag);
  325. }
  326. else
  327. {
  328. logmsg("Unknown SCSI PHY mode: ", (int)g_scsi_phy_mode);
  329. }
  330. }
  331. static void processPollingWrite(uint32_t count)
  332. {
  333. if (count > g_scsi_writereq.count)
  334. count = g_scsi_writereq.count;
  335. const uint8_t *data = g_scsi_writereq.data;
  336. uint32_t count_words = count / 4;
  337. if (g_scsi_writereq.use_sync_mode)
  338. {
  339. // Synchronous mode transfer
  340. scsi_accel_sync_send(data, count, &scsiDev.resetFlag);
  341. }
  342. else if (count_words * 4 == count)
  343. {
  344. if (g_scsi_phy_mode == PHY_MODE_GREENPAK_PIO)
  345. {
  346. // GreenPAK PIO accelerated asynchronous transfer
  347. scsi_accel_greenpak_send((const uint32_t*)data, count_words, &scsiDev.resetFlag);
  348. }
  349. else
  350. {
  351. // Assembler optimized asynchronous transfer
  352. scsi_accel_asm_send((const uint32_t*)data, count_words, &scsiDev.resetFlag);
  353. }
  354. }
  355. else
  356. {
  357. // Use simple loop for unaligned transfers
  358. for (uint32_t i = 0; i < count; i++)
  359. {
  360. if (scsiDev.resetFlag) break;
  361. scsiWriteOneByte(data[i]);
  362. }
  363. }
  364. g_scsi_writereq.count -= count;
  365. if (g_scsi_writereq.count)
  366. {
  367. g_scsi_writereq.data += count;
  368. }
  369. else
  370. {
  371. g_scsi_writereq.data = NULL;
  372. }
  373. }
  374. static bool isPollingWriteFinished(const uint8_t *data)
  375. {
  376. if (g_scsi_writereq.count)
  377. {
  378. if (data == NULL)
  379. {
  380. return false;
  381. }
  382. else if (data >= g_scsi_writereq.data &&
  383. data < g_scsi_writereq.data + g_scsi_writereq.count)
  384. {
  385. return false;
  386. }
  387. }
  388. return true;
  389. }
  390. extern "C" bool scsiIsWriteFinished(const uint8_t *data)
  391. {
  392. // Check if there is still a polling transfer in progress
  393. if (!isPollingWriteFinished(data))
  394. {
  395. if (check_sd_read_done())
  396. {
  397. // Current SD card transfer is finished so return early
  398. // to start a new transfer before doing SCSI data transfer.
  399. // This is faster because the SD transfer can run on background,
  400. // but PIO mode SCSI transfer cannot.
  401. return false;
  402. }
  403. // Process the transfer piece-by-piece while waiting
  404. // for SD card to react.
  405. int max_count = g_scsi_writereq.count / 8;
  406. // Always transfer whole sectors without pause to avoid problems with some SCSI hosts.
  407. int bytesPerSector = 512;
  408. if (scsiDev.target)
  409. {
  410. bytesPerSector = scsiDev.target->liveCfg.bytesPerSector;
  411. }
  412. if (max_count % bytesPerSector != 0) max_count -= (max_count % bytesPerSector);
  413. if (max_count < bytesPerSector) max_count = bytesPerSector;
  414. // Avoid SysTick interrupt pauses during the transfer
  415. SysTick_Handle_PreEmptively();
  416. processPollingWrite(max_count);
  417. return isPollingWriteFinished(data);
  418. }
  419. if (g_scsi_phy_mode == PHY_MODE_DMA_TIMER || g_scsi_phy_mode == PHY_MODE_GREENPAK_DMA)
  420. {
  421. return scsi_accel_dma_isWriteFinished(data);
  422. }
  423. else
  424. {
  425. return true;
  426. }
  427. }
  428. extern "C" void scsiFinishWrite()
  429. {
  430. if (g_scsi_writereq.count)
  431. {
  432. // Finish previously started polling write request.
  433. processPollingWrite(g_scsi_writereq.count);
  434. }
  435. if (g_scsi_phy_mode == PHY_MODE_DMA_TIMER || g_scsi_phy_mode == PHY_MODE_GREENPAK_DMA)
  436. {
  437. scsi_accel_dma_finishWrite(&scsiDev.resetFlag);
  438. }
  439. }
  440. /*********************/
  441. /* Receive from host */
  442. /*********************/
  443. static inline uint8_t scsiReadOneByte(void)
  444. {
  445. SCSI_OUT(REQ, 1);
  446. SCSI_WAIT_ACTIVE(ACK);
  447. delay_100ns();
  448. uint8_t r = SCSI_IN_DATA();
  449. SCSI_OUT(REQ, 0);
  450. SCSI_WAIT_INACTIVE(ACK);
  451. return r;
  452. }
  453. extern "C" uint8_t scsiReadByte(void)
  454. {
  455. uint8_t r = scsiReadOneByte();
  456. scsiLogDataOut(&r, 1);
  457. return r;
  458. }
  459. extern "C" void scsiRead(uint8_t* data, uint32_t count, int* parityError)
  460. {
  461. *parityError = 0;
  462. uint32_t count_words = count / 4;
  463. bool use_greenpak = (g_scsi_phy_mode == PHY_MODE_GREENPAK_DMA || g_scsi_phy_mode == PHY_MODE_GREENPAK_PIO);
  464. SysTick_Handle_PreEmptively();
  465. if (g_scsi_phase == DATA_OUT && scsiDev.target->syncOffset > 0)
  466. {
  467. // Synchronous data transfer
  468. scsi_accel_sync_recv(data, count, parityError, &scsiDev.resetFlag);
  469. }
  470. else if (count_words * 4 == count && count_words >= 2 && use_greenpak)
  471. {
  472. // GreenPAK accelerated receive can handle a multiple of 4 bytes with minimum of 8 bytes.
  473. scsi_accel_greenpak_recv((uint32_t*)data, count_words, &scsiDev.resetFlag);
  474. }
  475. else if (count_words * 4 == count && count_words >= 1)
  476. {
  477. // Optimized ASM subroutine can handle multiple of 4 bytes with minimum of 4 bytes.
  478. scsi_accel_asm_recv((uint32_t*)data, count_words, &scsiDev.resetFlag);
  479. }
  480. else
  481. {
  482. // Use a simple loop for short and unaligned transfers
  483. for (uint32_t i = 0; i < count; i++)
  484. {
  485. if (scsiDev.resetFlag) break;
  486. data[i] = scsiReadOneByte();
  487. }
  488. }
  489. scsiLogDataOut(data, count);
  490. }
  491. /**********************/
  492. /* Interrupt handlers */
  493. /**********************/
  494. extern "C"
  495. void SCSI_RST_IRQ (void)
  496. {
  497. if (exti_interrupt_flag_get(SCSI_RST_EXTI))
  498. {
  499. exti_interrupt_flag_clear(SCSI_RST_EXTI);
  500. scsi_rst_assert_interrupt();
  501. }
  502. if (exti_interrupt_flag_get(SCSI_BSY_EXTI))
  503. {
  504. exti_interrupt_flag_clear(SCSI_BSY_EXTI);
  505. scsi_bsy_deassert_interrupt();
  506. }
  507. if ((g_moved_select_in && exti_interrupt_flag_get(SCSI_ODE_SEL_EXTI)) ||
  508. (!g_moved_select_in && exti_interrupt_flag_get(SCSI_SEL_EXTI))
  509. )
  510. {
  511. // Check BSY line status when SEL goes active.
  512. // This is needed to handle SCSI-1 hosts that use the single initiator mode.
  513. // The host will just assert the SEL directly, without asserting BSY first.
  514. exti_interrupt_flag_clear(g_moved_select_in ? SCSI_ODE_SEL_EXTI : SCSI_SEL_EXTI);
  515. scsi_bsy_deassert_interrupt();
  516. }
  517. }
  518. #if SCSI_RST_IRQn != SCSI_BSY_IRQn
  519. extern "C"
  520. void SCSI_BSY_IRQ (void)
  521. {
  522. SCSI_RST_IRQ();
  523. }
  524. #endif
  525. #if (SCSI_SEL_IRQn != SCSI_RST_IRQn) && (SCSI_SEL_IRQn != SCSI_BSY_IRQn)
  526. extern "C"
  527. void SCSI_SEL_IRQ (void)
  528. {
  529. SCSI_RST_IRQ();
  530. }
  531. #endif
  532. static void init_irqs()
  533. {
  534. // Falling edge of RST pin
  535. gpio_exti_source_select(SCSI_RST_EXTI_SOURCE_PORT, SCSI_RST_EXTI_SOURCE_PIN);
  536. exti_init(SCSI_RST_EXTI, EXTI_INTERRUPT, EXTI_TRIG_FALLING);
  537. NVIC_SetPriority(SCSI_RST_IRQn, 1);
  538. NVIC_EnableIRQ(SCSI_RST_IRQn);
  539. // Rising edge of BSY pin
  540. gpio_exti_source_select(SCSI_BSY_EXTI_SOURCE_PORT, SCSI_BSY_EXTI_SOURCE_PIN);
  541. exti_init(SCSI_BSY_EXTI, EXTI_INTERRUPT, EXTI_TRIG_RISING);
  542. NVIC_SetPriority(SCSI_BSY_IRQn, 1);
  543. NVIC_EnableIRQ(SCSI_BSY_IRQn);
  544. // Falling edge of SEL pin
  545. if (g_moved_select_in)
  546. {
  547. gpio_exti_source_select(SCSI_ODE_SEL_EXTI_SOURCE_PORT, SCSI_ODE_SEL_EXTI_SOURCE_PIN);
  548. exti_init(SCSI_ODE_SEL_EXTI, EXTI_INTERRUPT, EXTI_TRIG_FALLING);
  549. NVIC_SetPriority(SCSI_ODE_SEL_IRQn, 1);
  550. NVIC_EnableIRQ(SCSI_ODE_SEL_IRQn);
  551. }
  552. else
  553. {
  554. gpio_exti_source_select(SCSI_SEL_EXTI_SOURCE_PORT, SCSI_SEL_EXTI_SOURCE_PIN);
  555. exti_init(SCSI_SEL_EXTI, EXTI_INTERRUPT, EXTI_TRIG_FALLING);
  556. NVIC_SetPriority(SCSI_SEL_IRQn, 1);
  557. NVIC_EnableIRQ(SCSI_SEL_IRQn);
  558. }
  559. }