+++ /dev/null
-// Copyright (C) 2013 Michael McMaster <michael@codesrc.com>\r
-//\r
-// This file is part of SCSI2SD.\r
-//\r
-// SCSI2SD is free software: you can redistribute it and/or modify\r
-// it under the terms of the GNU General Public License as published by\r
-// the Free Software Foundation, either version 3 of the License, or\r
-// (at your option) any later version.\r
-//\r
-// SCSI2SD is distributed in the hope that it will be useful,\r
-// but WITHOUT ANY WARRANTY; without even the implied warranty of\r
-// MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the\r
-// GNU General Public License for more details.\r
-//\r
-// You should have received a copy of the GNU General Public License\r
-// along with SCSI2SD. If not, see <http://www.gnu.org/licenses/>.\r
-\r
-#include "loopback.h"\r
-#include "scsi.h"\r
-#include "device.h"\r
-#include "scsiPhy.h"\r
-\r
-// Return true if all inputs are un-asserted (1)\r
-// Note that CyPins returns non-zero if pin is active. It does NOT\r
-// necessarily return 1.\r
-static int test_initial_inputs(void)\r
-{\r
- uint8 dbx = scsiReadDBxPins();\r
- int result =\r
- (dbx == 0xFF) &&\r
- CyPins_ReadPin(SCSI_In_DBP) &&\r
- CyPins_ReadPin(SCSI_ATN_INT) &&\r
- CyPins_ReadPin(SCSI_In_BSY) &&\r
- CyPins_ReadPin(SCSI_In_ACK) &&\r
- CyPins_ReadPin(SCSI_RST_INT) &&\r
- CyPins_ReadPin(SCSI_In_MSG) &&\r
- CyPins_ReadPin(SCSI_In_SEL) &&\r
- CyPins_ReadPin(SCSI_In_CD) &&\r
- CyPins_ReadPin(SCSI_In_REQ) &&\r
- CyPins_ReadPin(SCSI_In_IO);\r
-\r
- return result;\r
-}\r
-\r
-/* Not currently possible to write directly to the output pins\r
-static int test_data_lines(void)\r
-{\r
- int result = 1;\r
- int i;\r
- for (i = 0; i < 8; ++i)\r
- {\r
- // We write using Active High\r
- SCSI_Out_DBx_Write(1 << i);\r
- CyDelay(1); // ms\r
- \r
- // And expect an Active Low response.\r
- uint8 dbx = SCSI_In_DBx_Read();\r
- result = result && (dbx == (0xFF ^ (1 << i)));\r
- }\r
- SCSI_Out_DBx_Write(0);\r
- return result;\r
-}\r
-*/\r
-\r
-static int test_data_10MHz(void)\r
-{\r
- // 10MHz = 100ns period.\r
- // We'll try and go high -> low -> high in 100ns.\r
- // At 66MHz, 50ns ~= 3 cycles.\r
- \r
- int result = 1;\r
- int i;\r
- for (i = 0; i < 100; ++i)\r
- {\r
- uint8 dbx;\r
- // We write using Active High\r
- SCSI_Out_DBx_Write(0xFF);\r
- CyDelayCycles(3);\r
- // And expect an Active Low response.\r
- dbx = SCSI_In_DBx_Read();\r
- result = result && (dbx == 0);\r
- \r
- // We write using Active High\r
- SCSI_Out_DBx_Write(0);\r
- CyDelayCycles(3);\r
- // And expect an Active Low response.\r
- dbx = SCSI_In_DBx_Read();\r
- result = result && (dbx == 0xFF);\r
- }\r
- SCSI_Out_DBx_Write(0);\r
- return result;\r
-}\r
-\r
-static int test_ATN_interrupt(void)\r
-{\r
- int result = 1;\r
- int i;\r
- \r
- scsiDev.atnFlag = 0;\r
- for (i = 0; i < 100 && result; ++i)\r
- {\r
- // We write using Active High\r
- CyPins_SetPin(SCSI_Out_ATN);\r
- CyDelayCycles(2);\r
- result &= scsiDev.atnFlag == 1;\r
- scsiDev.atnFlag = 0;\r
- CyPins_ClearPin(SCSI_Out_ATN);\r
- result &= scsiDev.atnFlag == 0;\r
- }\r
- return result;\r
-}\r
-\r
-static void test_error(void)\r
-{\r
- // Toggle LED.\r
- while (1)\r
- {\r
- LED1_Write(0);\r
- CyDelay(250); // ms\r
- LED1_Write(1);\r
- CyDelay(250); // ms\r
- }\r
-}\r
-\r
-static void test_success(void)\r
-{\r
- // Toggle LED.\r
- while (1)\r
- {\r
- LED1_Write(0);\r
- CyDelay(1000); // ms\r
- LED1_Write(1);\r
- CyDelay(1000); // ms\r
- }\r
-}\r
-void scsi2sd_test_loopback(void)\r
-{\r
- if (!test_initial_inputs() ||\r
- //!test_data_lines() ||\r
- !test_data_10MHz() ||\r
- !test_ATN_interrupt())\r
- {\r
- test_error();\r
- }\r
- else\r
- {\r
- test_success();\r
- }\r
-}\r
+++ /dev/null
-// Copyright (C) 2013 Michael McMaster <michael@codesrc.com>\r
-//\r
-// This file is part of SCSI2SD.\r
-//\r
-// SCSI2SD is free software: you can redistribute it and/or modify\r
-// it under the terms of the GNU General Public License as published by\r
-// the Free Software Foundation, either version 3 of the License, or\r
-// (at your option) any later version.\r
-//\r
-// SCSI2SD is distributed in the hope that it will be useful,\r
-// but WITHOUT ANY WARRANTY; without even the implied warranty of\r
-// MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the\r
-// GNU General Public License for more details.\r
-//\r
-// You should have received a copy of the GNU General Public License\r
-// along with SCSI2SD. If not, see <http://www.gnu.org/licenses/>.\r
-\r
-#ifndef SCSI2SD_LOOPBACK_H\r
-#define SCSI2SD_LOOPBACK_H\r
-\r
-// Loopback test\r
-// Ensure we can read-back whatever we write to the SCSI bus.\r
-// This testing should be performed in isolation, with the\r
-// terminator jumper and terminator power jumper installed.\r
-// ie. do not connect a SCSI cable and plug us in to another\r
-// device.\r
-void scsi2sd_test_loopback(void);\r
-\r
-\r
-#endif // SCSI2SD_POST_H\r