You can not select more than 25 topics Topics must start with a letter or number, can include dashes ('-') and can be up to 35 characters long.

583 lines
26 KiB

//#############################################################################################################################################################
// idiBus_Chip_2560_TEST_ARDUINO
// MegaCore : ATmega1280 / ATmega2560
// BOD 2.7V, Bootloader Yes(USART0), Clock External 16MHz, 115200, Programmer STK500 as ISP
// board : idiBus_Chip_2560_testing_rev_0_1
//#############################################################################################################################################################
// настраиваемые параметры
// #define chip 1280 // 1280 or 1260
#define chip 2560 // 1280 or 1260
#define rev 5 // board revision
// #define rev 7
// #define rev 8
#define time_delay_def 250 // время исполнения визуальных шагов теста, команды s, f, d
#define time_delay_fast 10
#define time_delay_slow 1000
#define adc_level_med_l 1667 // уровни проверки ADC
#define adc_level_med_h 2500
#define adc_level_delta 32
#define adc_level_log_0 16
#define adc_level_log_1 4080
//#############################################################################################################################################################
uint16_t TIME_DALAY;
String CMD;
#define COMMAND_SIZE 100
char COMMAND[COMMAND_SIZE];
uint16_t TOTAL_ERROR;
//#############################################################################################################################################################
// базовые 0-35
#define _GPIO19 0
#define _GPIO17 1
#define _GPIO15 2
#define _GPIO13 3
#define _GPIO11 4
#define _GPIO9 5
#define _GPIO7 6
#define _GPIO5 7
#define _GPIO3 8
#define _GPIO18 9
#define _GPIO16 10
#define _GPIO14 11
#define _GPIO12 12
#define _GPIO10 13
#define _GPIO8 14
#define _GPIO6 15
#define _GPIO4 16
#define _GPIO2 17
#define _IRTD_CNTRL 18
#define _UART3_TX 19
#define _UART3_RX 20
#define _UART2_RX 21
#define _UART2_TX 22
#define _UART2_RTEN 23
#define _SSL_0 24
#define _SSL_1 25
#define _SSL_2 26
#define _GPIO0 27
#define _SG_CNTRL 28
#define _UART1_RX 29
#define _UART1_TX 30
#define _UART1_RTEN 31
#define _SSH_0 32
#define _SSH_1 33
#define _SSH_2 34
#define _GPIO1 35
// альтернативные 36-48
#define _GPIO11A 36
#define _GPIO9A 37
#define _GPIO7A 38
#define _GPIO5A 39
#define _GPIO3A 40
#define _GPIO10A 41
#define _GPIO8A 42
#define _GPIO6A 43
#define _GPIO4A 44
#define _GPIO2A 45
#define _GPIO0A 46
#define _GPIO1A 47
#define _API0A 48
// дополнительные 49-55
#define _JTAG_TCK 49
#define _JTAG_TDO 50
#define _JTAG_TMS 51
#define _JTAG_TDI 52
#define _SPI_MISO 53
#define _SPI_SCK 54
#define _SPI_MOSI 55
// незадействованные 56-73
#define _PH2 56
#define _PB0 57
#define _PB4 58
#define _PG3 59
#define _PG4 60
#define _PL2 61
#define _PL5 62
#define _PD4 63
#define _PD5 64
#define _PD6 65
#define _PJ2 66
#define _PJ3 67
#define _PJ4 68
#define _PJ5 69
#define _PJ6 70
#define _PJ7 71
#define _PF2 72
#define _PF3 73
// USART0
#define _UART0_RX 74
#define _UART0_TX 75
// ADC PK0-7
#define _API0 76
#define _API1 77
#define _API2 78
#define _API3 79
#define _API4 80
#define _API5 81
#define _API6 82
#define _API7 83
#define _LTD_SGNL 84
#define _IRTD_SGNL 85
//#############################################################################################################################################################
typedef struct
{ // GPIOs
volatile unsigned char *PORT;
volatile unsigned char *PIN;
volatile unsigned char *DDR;
volatile unsigned char BIT;
String NAME;
} GPIO_type;
#define GPIO_COUNT 86
GPIO_type GPIO[GPIO_COUNT];
//#############################################################################################################################################################
void GPIO_INIT(void)
{
// базовые 0-35
GPIO[_GPIO19]= (GPIO_type) {&PORTA, &PINA, &DDRA, 0, "GPIO19"};
GPIO[_GPIO17]= (GPIO_type) {&PORTA, &PINA, &DDRA, 2, "GPIO17"};
GPIO[_GPIO15]= (GPIO_type) {&PORTA, &PINA, &DDRA, 4, "GPIO15"};
GPIO[_GPIO13]= (GPIO_type) {&PORTA, &PINA, &DDRA, 6, "GPIO13"};
GPIO[_GPIO11]= (GPIO_type) {&PORTG, &PING, &DDRG, 2, "GPIO11"};
GPIO[_GPIO9]= (GPIO_type) {&PORTC, &PINC, &DDRC, 6, "GPIO9"};
GPIO[_GPIO7]= (GPIO_type) {&PORTC, &PINC, &DDRC, 4, "GPIO7"};
GPIO[_GPIO5]= (GPIO_type) {&PORTC, &PINC, &DDRC, 2, "GPIO5"};
GPIO[_GPIO3]= (GPIO_type) {&PORTC, &PINC, &DDRC, 0, "GPIO3"};
GPIO[_GPIO18]= (GPIO_type) {&PORTA, &PINA, &DDRA, 1, "GPIO18"};
GPIO[_GPIO16]= (GPIO_type) {&PORTA, &PINA, &DDRA, 3, "GPIO16"};
GPIO[_GPIO14]= (GPIO_type) {&PORTA, &PINA, &DDRA, 5, "GPIO14"};
GPIO[_GPIO12]= (GPIO_type) {&PORTA, &PINA, &DDRA, 7, "GPIO12"};
GPIO[_GPIO10]= (GPIO_type) {&PORTC, &PINC, &DDRC, 7, "GPIO10"};
GPIO[_GPIO8]= (GPIO_type) {&PORTC, &PINC, &DDRC, 5, "GPIO8"};
GPIO[_GPIO6]= (GPIO_type) {&PORTC, &PINC, &DDRC, 3, "GPIO6"};
GPIO[_GPIO4]= (GPIO_type) {&PORTC, &PINC, &DDRC, 1, "GPIO4"};
GPIO[_GPIO2]= (GPIO_type) {&PORTG, &PING, &DDRG, 1, "GPIO2"};
GPIO[_IRTD_CNTRL]=(GPIO_type) {&PORTE, &PINE, &DDRE, 4, "IRTD_CNTRL"};
GPIO[_UART3_TX ]=(GPIO_type) {&PORTJ, &PINJ, &DDRJ, 1, "UART3_TX"};
GPIO[_UART3_RX ]=(GPIO_type) {&PORTJ, &PINJ, &DDRJ, 0, "UART3_RX"};
GPIO[_UART2_RX ]=(GPIO_type) {&PORTH, &PINH, &DDRH, 0, "UART2_RX"};
GPIO[_UART2_TX ]=(GPIO_type) {&PORTH, &PINH, &DDRH, 1, "UART2_TX"};
GPIO[_UART2_RTEN]=(GPIO_type) {&PORTH, &PINH, &DDRH, 3, "UART2_RTEN"};
GPIO[_SSL_0]= (GPIO_type) {&PORTH, &PINH, &DDRH, 4, "SSL_0"};
GPIO[_SSL_1]= (GPIO_type) {&PORTH, &PINH, &DDRH, 5, "SSL_1"};
GPIO[_SSL_2]= (GPIO_type) {&PORTH, &PINH, &DDRH, 6, "SSL_2"};
GPIO[_GPIO0]= (GPIO_type) {&PORTD, &PIND, &DDRD, 7, "GPIO0"};
GPIO[_SG_CNTRL]= (GPIO_type) {&PORTE, &PINE, &DDRE, 3, "SG_CNTRL"};
GPIO[_UART1_RX]= (GPIO_type) {&PORTD, &PIND, &DDRD, 2, "UART1_RX"};
GPIO[_UART1_TX]= (GPIO_type) {&PORTD, &PIND, &DDRD, 3, "UART1_TX"};
GPIO[_UART1_RTEN]=(GPIO_type) {&PORTL, &PINL, &DDRL, 6, "UART1_RTEN"};
GPIO[_SSH_0]= (GPIO_type) {&PORTL, &PINL, &DDRL, 7, "SSH_0"};
GPIO[_SSH_1]= (GPIO_type) {&PORTD, &PIND, &DDRD, 0, "SSH_1"};
GPIO[_SSH_2]= (GPIO_type) {&PORTD, &PIND, &DDRD, 1, "SSH_2"};
GPIO[_GPIO1]= (GPIO_type) {&PORTG, &PING, &DDRG, 0, "GPIO1"};
// альтернативные 36-48
GPIO[_GPIO11A]= (GPIO_type) {&PORTE, &PINE, &DDRE, 2, "GPIO11A"};
GPIO[_GPIO9A]= (GPIO_type) {&PORTE, &PINE, &DDRE, 7, "GPIO9A"};
GPIO[_GPIO7A]= (GPIO_type) {&PORTB, &PINB, &DDRB, 6, "GPIO7A"};
GPIO[_GPIO5A]= (GPIO_type) {&PORTG, &PING, &DDRG, 5, "GPIO5A"};
GPIO[_GPIO3A]= (GPIO_type) {&PORTH, &PINH, &DDRH, 7, "GPIO3A"};
GPIO[_GPIO10A]= (GPIO_type) {&PORTE, &PINE, &DDRE, 6, "GPIO10A"};
GPIO[_GPIO8A]= (GPIO_type) {&PORTB, &PINB, &DDRB, 5, "GPIO8A"};
GPIO[_GPIO6A]= (GPIO_type) {&PORTL, &PINL, &DDRL, 4, "GPIO6A"};
GPIO[_GPIO4A]= (GPIO_type) {&PORTB, &PINB, &DDRB, 7, "GPIO4A"};
GPIO[_GPIO2A]= (GPIO_type) {&PORTL, &PINL, &DDRL, 0, "GPIO2A"};
GPIO[_GPIO0A]= (GPIO_type) {&PORTL, &PINL, &DDRL, 3, "GPIO0A"};
GPIO[_GPIO1A]= (GPIO_type) {&PORTL, &PINL, &DDRL, 1, "GPIO1A"};
GPIO[_API0A]= (GPIO_type) {&PORTE, &PINE, &DDRE, 5, "API0A"};
// дополнительные 49-55
GPIO[_JTAG_TCK]= (GPIO_type) {&PORTF, &PINF, &DDRF, 4, "JTAG_TCK"};
GPIO[_JTAG_TDO]= (GPIO_type) {&PORTF, &PINF, &DDRF, 6, "JTAG_TDO"};
GPIO[_JTAG_TMS]= (GPIO_type) {&PORTF, &PINF, &DDRF, 5, "JTAG_TMS"};
GPIO[_JTAG_TDI]= (GPIO_type) {&PORTF, &PINF, &DDRF, 7, "JTAG_TDI"};
GPIO[_SPI_MISO]= (GPIO_type) {&PORTB, &PINB, &DDRB, 3, "SPI_MISO"};
GPIO[_SPI_SCK]= (GPIO_type) {&PORTB, &PINB, &DDRB, 1, "SPI_SCK"};
GPIO[_SPI_MOSI]= (GPIO_type) {&PORTB, &PINB, &DDRB, 2, "SPI_MOSI"};
// незадействованные 56-73
GPIO[_PH2]= (GPIO_type) {&PORTH, &PINH, &DDRH, 2, "PH2"};
GPIO[_PB0]= (GPIO_type) {&PORTB, &PINB, &DDRB, 0, "PB0"};
GPIO[_PB4]= (GPIO_type) {&PORTB, &PINB, &DDRB, 4, "PB4"};
GPIO[_PG3]= (GPIO_type) {&PORTG, &PING, &DDRG, 3, "PG3"};
GPIO[_PG4]= (GPIO_type) {&PORTG, &PING, &DDRG, 4, "PG4"};
GPIO[_PL2]= (GPIO_type) {&PORTL, &PINL, &DDRL, 2, "PL2"};
GPIO[_PL5]= (GPIO_type) {&PORTL, &PINL, &DDRL, 5, "PL5"};
GPIO[_PD4]= (GPIO_type) {&PORTD, &PIND, &DDRD, 4, "PD4"};
GPIO[_PD5]= (GPIO_type) {&PORTD, &PIND, &DDRD, 5, "PD5"};
GPIO[_PD6]= (GPIO_type) {&PORTD, &PIND, &DDRD, 6, "PD6"};
GPIO[_PJ2]= (GPIO_type) {&PORTJ, &PINJ, &DDRJ, 2, "PJ2"};
GPIO[_PJ3]= (GPIO_type) {&PORTJ, &PINJ, &DDRJ, 3, "PJ3"};
GPIO[_PJ4]= (GPIO_type) {&PORTJ, &PINJ, &DDRJ, 4, "PJ4"};
GPIO[_PJ5]= (GPIO_type) {&PORTJ, &PINJ, &DDRJ, 5, "PJ5"};
GPIO[_PJ6]= (GPIO_type) {&PORTJ, &PINJ, &DDRJ, 6, "PJ6"};
GPIO[_PJ7]= (GPIO_type) {&PORTJ, &PINJ, &DDRJ, 7, "PJ7"};
GPIO[_PF2]= (GPIO_type) {&PORTF, &PINF, &DDRF, 2, "PF2"};
GPIO[_PF3]= (GPIO_type) {&PORTF, &PINF, &DDRF, 3, "PF3"};
// USART0
GPIO[_UART0_RX]= (GPIO_type) {&PORTE, &PINE, &DDRE, 0, "UART0_RX"};
GPIO[_UART0_TX]= (GPIO_type) {&PORTE, &PINE, &DDRE, 1, "UART0_TX"};
// ADC PK0-7
GPIO[_API0]= (GPIO_type) {&PORTK, &PINK, &DDRK, 7, "API0"};
GPIO[_API1]= (GPIO_type) {&PORTK, &PINK, &DDRK, 6, "API1"};
GPIO[_API2]= (GPIO_type) {&PORTK, &PINK, &DDRK, 5, "API2"};
GPIO[_API3]= (GPIO_type) {&PORTK, &PINK, &DDRK, 4, "API3"};
GPIO[_API4]= (GPIO_type) {&PORTK, &PINK, &DDRK, 3, "API4"};
GPIO[_API5]= (GPIO_type) {&PORTK, &PINK, &DDRK, 2, "API5"};
GPIO[_API6]= (GPIO_type) {&PORTK, &PINK, &DDRK, 1, "API6"};
GPIO[_API7]= (GPIO_type) {&PORTK, &PINK, &DDRK, 0, "API7"};
GPIO[_LTD_SGNL]= (GPIO_type) {&PORTF, &PINF, &DDRF, 1, "TD_SGNL"};
GPIO[_IRTD_SGNL]= (GPIO_type) {&PORTF, &PINF, &DDRF, 0, "IRTD_SGNL"};
}
//#############################################################################################################################################################
uint8_t GPIO_TEST(GPIO_type *IO, uint16_t DELAY_MS)
{ // проверка на установление логических уровней
uint8_t ERR=0;
if (DELAY_MS!=0)
{
*IO->PORT|=(1<<IO->BIT); *IO->DDR|=(1<<IO->BIT);
_delay_us(1);
if ((*IO->PIN&(1<<IO->BIT))==0) { Serial.println(); Serial.print("! Error "+IO->NAME+"===0 !"); ERR++; }
delay(DELAY_MS);
*IO->PORT&=~(1<<IO->BIT);
_delay_us(1);
if ((*IO->PIN&(1<<IO->BIT))!=0) { Serial.println(); Serial.print("! Error "+IO->NAME+"===1 !"); ERR++; }
} else *IO->PORT&=~(1<<IO->BIT);
*IO->DDR&=~(1<<IO->BIT);
TOTAL_ERROR+=ERR;
return ERR;
}
//#############################################################################################################################################################
uint8_t GPIO_TEST_SHORT(GPIO_type *IO1, GPIO_type *IO2)
{ // проверка на отсутствие замыкание
uint8_t ERR=0;
// соседний в 1
*IO2->PORT|= (1<<IO2->BIT); *IO2->DDR|= (1<<IO2->BIT);
// тестируемый в 0, потом на вход Z
*IO1->PORT&=~(1<<IO1->BIT); *IO1->DDR|= (1<<IO1->BIT);
_delay_us(1);
*IO1->DDR&=~(1<<IO1->BIT);
// проверка
if ((*IO1->PIN&(1<<IO1->BIT))!=0) { Serial.println(); Serial.print("! Error "+IO1->NAME+"==="+IO2->NAME+" !"); ERR++; }
// все z
*IO1->PORT&=~(1<<IO1->BIT); *IO1->DDR&= ~(1<<IO1->BIT);
*IO2->PORT&=~(1<<IO2->BIT); *IO2->DDR&= ~(1<<IO2->BIT);
_delay_us(5);
TOTAL_ERROR+=ERR;
return ERR;
}
//#############################################################################################################################################################
uint8_t GPIO_TEST_CONNECT(GPIO_type *IO1, GPIO_type *IO2)
{ // проверка на замыкание для V.7 и V.8
uint8_t ERR=0;
// основной в 1
*IO2->PORT|= (1<<IO2->BIT); *IO2->DDR|= (1<<IO2->BIT);
_delay_us(1);
// тестируемый на вход Z
*IO1->PORT&=~(1<<IO1->BIT); *IO1->DDR&= ~(1<<IO1->BIT);
// проверка
if ((*IO1->PIN&(1<<IO1->BIT))!=0)
{
*IO2->PORT&=~(1<<IO2->BIT); *IO2->DDR|= (1<<IO2->BIT); _delay_us(1); // основной в 0
if ((*IO1->PIN&(1<<IO1->BIT))!=0) ERR++;
} else ERR++;
if (ERR!=0) { Serial.println(); Serial.print("! Error, "+IO1->NAME+" not connected to "+IO2->NAME+" !"); }
// все z
*IO1->PORT&=~(1<<IO1->BIT); *IO1->DDR&= ~(1<<IO1->BIT);
*IO2->PORT&=~(1<<IO2->BIT); *IO2->DDR&= ~(1<<IO2->BIT);
_delay_us(5);
TOTAL_ERROR+=ERR;
return ERR;
}
//#############################################################################################################################################################
uint8_t ADC_CHECK(uint8_t CHANNEL, String NAME, uint16_t MED, uint16_t DELTA)
{ // чтение данных с АЦП
uint8_t ERR=0;
uint16_t DATA;
uint16_t MIN=MED-DELTA;
uint16_t MAX=MED+DELTA;
// normal mode
pinMode(CHANNEL, INPUT);
delay(1);
DATA=analogRead(CHANNEL)<<2;
if (DATA<MIN) { Serial.println(); Serial.print("! Error "+NAME+"="+String(DATA)+" mV, < "+String(MIN)+" mV !"); ERR++; }
if (DATA>MAX) { Serial.println(); Serial.print("! Error "+NAME+"="+String(DATA)+" mV, > "+String(MAX)+" mV !"); ERR++; }
// Serial.println(NAME+String(DATA));
// pull up
pinMode(CHANNEL, OUTPUT);
digitalWrite(CHANNEL, HIGH);
delay(1);
DATA=analogRead(CHANNEL)<<2;
if (DATA<adc_level_log_1) { Serial.println(); Serial.print("! Error "+NAME+"="+String(DATA)+" mV, < "+String(adc_level_log_1)+" mV !"); ERR++; }
// pull down
pinMode(CHANNEL, OUTPUT);
digitalWrite(CHANNEL, LOW);
delay(1);
DATA=analogRead(CHANNEL)<<2;
if (DATA>adc_level_log_0) { Serial.println(); Serial.print("! Error "+NAME+"="+String(DATA)+" mV, > "+String(adc_level_log_0)+" mV !"); ERR++; }
// hi-z
pinMode(CHANNEL, INPUT);
TOTAL_ERROR+=ERR;
return ERR;
}
//#############################################################################################################################################################
void setup()
{ // начальная инициализация
Serial.setTimeout(50);
Serial.begin(115200);
Serial.println("*** idiBus_Chip_"+String(chip)+"_rev_0."+String(rev)+", ready ***");
GPIO_INIT(); for (uint8_t I=0; I<GPIO_COUNT; I++) GPIO_TEST(&GPIO[I], 0); // инициализация портов
TIME_DALAY=time_delay_def;
TOTAL_ERROR=0;
CMD="AE"; // запуск тестов при старте
_delay_ms(1500);
}
//#############################################################################################################################################################
void loop()
{
CMD+=Serial.readString();
if (CMD.length()>COMMAND_SIZE) { Serial.println("> Error, to long command !"); CMD=""; }
if (CMD.length()!=0)
{
CMD.toCharArray(COMMAND,COMMAND_SIZE, 0); CMD.remove(0, 1);
switch (COMMAND[0])
{
case '1' :
{
Serial.print("> Test 1 - base IO leds : ");
uint16_t ERRORS=0;
for (uint8_t I=0; I<=35; I++) ERRORS+=GPIO_TEST(&GPIO[I], TIME_DALAY);
if (ERRORS==0) Serial.println("OK"); else { Serial.println(); Serial.println(String(ERRORS)+" ERROR !"); }
break;
}
case '2' :
{
Serial.print("> Test 2 - additional IO : ");
uint16_t ERRORS=0;
for (uint8_t I=36; I<=48; I++) ERRORS+=GPIO_TEST(&GPIO[I], TIME_DALAY);
if (ERRORS==0) Serial.println("OK"); else { Serial.println(); Serial.println(String(ERRORS)+" ERROR !"); }
break;
}
case '3' :
{
Serial.print("> Test 3 - programming IO : ");
uint16_t ERRORS=0;
for (uint8_t I=49; I<=55; I++) ERRORS+=GPIO_TEST(&GPIO[I], 1);
if (ERRORS==0) Serial.println("OK"); else { Serial.println(); Serial.println(String(ERRORS)+" ERROR !"); }
break;
}
case '4' :
{
Serial.print("> Test 4 - unused IO : ");
uint16_t ERRORS=0;
for (uint8_t I=56; I<=73; I++) ERRORS+=GPIO_TEST(&GPIO[I], 1);
if (ERRORS==0) Serial.println("OK"); else { Serial.println(); Serial.println(String(ERRORS)+" ERROR !"); }
break;
}
case '5' :
{
Serial.print("> Test 5 - ADC : ");
uint16_t ERRORS=0;
ERRORS+=ADC_CHECK(A8, "API7", adc_level_med_h, adc_level_delta);
ERRORS+=ADC_CHECK(A9, "API6", adc_level_med_l, adc_level_delta);
ERRORS+=ADC_CHECK(A10, "API5", adc_level_med_h, adc_level_delta);
ERRORS+=ADC_CHECK(A11, "API4", adc_level_med_l, adc_level_delta);
ERRORS+=ADC_CHECK(A12, "API3", adc_level_med_h, adc_level_delta);
ERRORS+=ADC_CHECK(A13, "API2", adc_level_med_l, adc_level_delta);
ERRORS+=ADC_CHECK(A14, "API1", adc_level_med_h, adc_level_delta);
ERRORS+=ADC_CHECK(A15, "API0", adc_level_med_l, adc_level_delta);
ERRORS+=ADC_CHECK(A0, "IRTD_SGNL", adc_level_med_h, adc_level_delta);
ERRORS+=ADC_CHECK(A1, "LTD_SGNL", adc_level_med_l, adc_level_delta);
if (ERRORS==0) Serial.println("OK"); else { Serial.println(); Serial.println(String(ERRORS)+" ERROR !"); }
break;
}
case '6' :
{
Serial.print("> Test 6 - shorted IO : ");
uint16_t ERRORS=0;
// pins 1-26
ERRORS+=GPIO_TEST_SHORT(&GPIO[_GPIO5], &GPIO[_UART0_RX]);
//ERRORS+=GPIO_TEST_SHORT(&GPIO[_UART0_RX], &GPIO[_UART0_TX]);
//ERRORS+=GPIO_TEST_SHORT(&GPIO[_UART0_TX], &GPIO[_GPIO11]);
ERRORS+=GPIO_TEST_SHORT(&GPIO[_GPIO11], &GPIO[_SG_CNTRL]);
ERRORS+=GPIO_TEST_SHORT(&GPIO[_SG_CNTRL], &GPIO[_IRTD_CNTRL]);
ERRORS+=GPIO_TEST_SHORT(&GPIO[_IRTD_CNTRL], &GPIO[_API0A]);
ERRORS+=GPIO_TEST_SHORT(&GPIO[_API0A], &GPIO[_GPIO10A]);
ERRORS+=GPIO_TEST_SHORT(&GPIO[_GPIO10A], &GPIO[_GPIO9A]);
ERRORS+=GPIO_TEST_SHORT(&GPIO[_GPIO9A], &GPIO[_GPIO10A]);
ERRORS+=GPIO_TEST_SHORT(&GPIO[_UART2_RX], &GPIO[_UART2_TX]);
ERRORS+=GPIO_TEST_SHORT(&GPIO[_UART2_TX], &GPIO[_UART2_RX]);
ERRORS+=GPIO_TEST_SHORT(&GPIO[_UART2_RTEN], &GPIO[_SSL_0]);
ERRORS+=GPIO_TEST_SHORT(&GPIO[_SSL_0], &GPIO[_SSL_1]);
ERRORS+=GPIO_TEST_SHORT(&GPIO[_SSL_1], &GPIO[_SSL_2]);
ERRORS+=GPIO_TEST_SHORT(&GPIO[_SSL_2], &GPIO[_PB0]);
ERRORS+=GPIO_TEST_SHORT(&GPIO[_PB0], &GPIO[_SPI_SCK]);
ERRORS+=GPIO_TEST_SHORT(&GPIO[_SPI_SCK], &GPIO[_SPI_MOSI]);
ERRORS+=GPIO_TEST_SHORT(&GPIO[_SPI_MOSI], &GPIO[_SPI_MISO]);
ERRORS+=GPIO_TEST_SHORT(&GPIO[_SPI_MISO], &GPIO[_PB4]);
ERRORS+=GPIO_TEST_SHORT(&GPIO[_PB4], &GPIO[_GPIO8A]);
ERRORS+=GPIO_TEST_SHORT(&GPIO[_GPIO8A], &GPIO[_GPIO7A]);
ERRORS+=GPIO_TEST_SHORT(&GPIO[_GPIO7A], &GPIO[_GPIO4]);
// pins 26-51
ERRORS+=GPIO_TEST_SHORT(&GPIO[_GPIO4], &GPIO[_GPIO3]);
ERRORS+=GPIO_TEST_SHORT(&GPIO[_GPIO3], &GPIO[_PG3]);
ERRORS+=GPIO_TEST_SHORT(&GPIO[_PG3], &GPIO[_PG4]);
ERRORS+=GPIO_TEST_SHORT(&GPIO[_GPIO2A], &GPIO[_GPIO1A]);
ERRORS+=GPIO_TEST_SHORT(&GPIO[_GPIO1A], &GPIO[_PL2]);
ERRORS+=GPIO_TEST_SHORT(&GPIO[_PL2], &GPIO[_GPIO0A]);
ERRORS+=GPIO_TEST_SHORT(&GPIO[_GPIO0A], &GPIO[_GPIO6A]);
ERRORS+=GPIO_TEST_SHORT(&GPIO[_GPIO6A], &GPIO[_PL5]);
ERRORS+=GPIO_TEST_SHORT(&GPIO[_PL5], &GPIO[_UART1_RTEN]);
ERRORS+=GPIO_TEST_SHORT(&GPIO[_UART1_RTEN], &GPIO[_SSH_0]);
ERRORS+=GPIO_TEST_SHORT(&GPIO[_SSH_0], &GPIO[_SSH_1]);
ERRORS+=GPIO_TEST_SHORT(&GPIO[_SSH_1], &GPIO[_SSH_2]);
ERRORS+=GPIO_TEST_SHORT(&GPIO[_SSH_2], &GPIO[_UART1_RX]);
ERRORS+=GPIO_TEST_SHORT(&GPIO[_UART1_RX], &GPIO[_UART1_TX]);
ERRORS+=GPIO_TEST_SHORT(&GPIO[_UART1_TX], &GPIO[_PD4]);
ERRORS+=GPIO_TEST_SHORT(&GPIO[_PD4], &GPIO[_PD5]);
ERRORS+=GPIO_TEST_SHORT(&GPIO[_PD5], &GPIO[_PD6]);
ERRORS+=GPIO_TEST_SHORT(&GPIO[_PD6], &GPIO[_GPIO0]);
ERRORS+=GPIO_TEST_SHORT(&GPIO[_GPIO0], &GPIO[_GPIO1]);
// pins 51-76
ERRORS+=GPIO_TEST_SHORT(&GPIO[_GPIO1], &GPIO[_GPIO2]);
ERRORS+=GPIO_TEST_SHORT(&GPIO[_GPIO2], &GPIO[_GPIO3]);
ERRORS+=GPIO_TEST_SHORT(&GPIO[_GPIO3], &GPIO[_GPIO4]);
ERRORS+=GPIO_TEST_SHORT(&GPIO[_GPIO4], &GPIO[_GPIO5]);
ERRORS+=GPIO_TEST_SHORT(&GPIO[_GPIO5], &GPIO[_GPIO6]);
ERRORS+=GPIO_TEST_SHORT(&GPIO[_GPIO6], &GPIO[_GPIO7]);
ERRORS+=GPIO_TEST_SHORT(&GPIO[_GPIO7], &GPIO[_GPIO8]);
ERRORS+=GPIO_TEST_SHORT(&GPIO[_GPIO8], &GPIO[_GPIO9]);
ERRORS+=GPIO_TEST_SHORT(&GPIO[_GPIO9], &GPIO[_GPIO10]);
ERRORS+=GPIO_TEST_SHORT(&GPIO[_UART3_RX], &GPIO[_UART3_TX]);
ERRORS+=GPIO_TEST_SHORT(&GPIO[_UART3_TX], &GPIO[_PJ2]);
ERRORS+=GPIO_TEST_SHORT(&GPIO[_PJ2], &GPIO[_PJ3]);
ERRORS+=GPIO_TEST_SHORT(&GPIO[_PJ3], &GPIO[_PJ4]);
ERRORS+=GPIO_TEST_SHORT(&GPIO[_PJ4], &GPIO[_PJ5]);
ERRORS+=GPIO_TEST_SHORT(&GPIO[_PJ5], &GPIO[_PJ6]);
ERRORS+=GPIO_TEST_SHORT(&GPIO[_PJ6], &GPIO[_GPIO11]);
ERRORS+=GPIO_TEST_SHORT(&GPIO[_GPIO11], &GPIO[_GPIO12]);
ERRORS+=GPIO_TEST_SHORT(&GPIO[_GPIO12], &GPIO[_GPIO13]);
ERRORS+=GPIO_TEST_SHORT(&GPIO[_GPIO13], &GPIO[_GPIO14]);
ERRORS+=GPIO_TEST_SHORT(&GPIO[_GPIO14], &GPIO[_GPIO15]);
ERRORS+=GPIO_TEST_SHORT(&GPIO[_GPIO15], &GPIO[_GPIO16]);
ERRORS+=GPIO_TEST_SHORT(&GPIO[_GPIO16], &GPIO[_GPIO17]);
// pins 76-97
ERRORS+=GPIO_TEST_SHORT(&GPIO[_GPIO17], &GPIO[_GPIO18]);
ERRORS+=GPIO_TEST_SHORT(&GPIO[_GPIO18], &GPIO[_GPIO19]);
ERRORS+=GPIO_TEST_SHORT(&GPIO[_GPIO19], &GPIO[_PJ7]);
ERRORS+=GPIO_TEST_SHORT(&GPIO[_API0], &GPIO[_API1]);
ERRORS+=GPIO_TEST_SHORT(&GPIO[_API1], &GPIO[_API2]);
ERRORS+=GPIO_TEST_SHORT(&GPIO[_API2], &GPIO[_API3]);
ERRORS+=GPIO_TEST_SHORT(&GPIO[_API3], &GPIO[_API4]);
ERRORS+=GPIO_TEST_SHORT(&GPIO[_API4], &GPIO[_API5]);
ERRORS+=GPIO_TEST_SHORT(&GPIO[_API5], &GPIO[_API6]);
ERRORS+=GPIO_TEST_SHORT(&GPIO[_API6], &GPIO[_API7]);
ERRORS+=GPIO_TEST_SHORT(&GPIO[_API7], &GPIO[_JTAG_TDI]);
ERRORS+=GPIO_TEST_SHORT(&GPIO[_JTAG_TDI], &GPIO[_JTAG_TDO]);
ERRORS+=GPIO_TEST_SHORT(&GPIO[_JTAG_TDO], &GPIO[_JTAG_TMS]);
ERRORS+=GPIO_TEST_SHORT(&GPIO[_JTAG_TMS], &GPIO[_JTAG_TCK]);
ERRORS+=GPIO_TEST_SHORT(&GPIO[_JTAG_TCK], &GPIO[_PF3]);
ERRORS+=GPIO_TEST_SHORT(&GPIO[_PF3], &GPIO[_PF2]);
ERRORS+=GPIO_TEST_SHORT(&GPIO[_PF2], &GPIO[_LTD_SGNL]);
ERRORS+=GPIO_TEST_SHORT(&GPIO[_LTD_SGNL], &GPIO[_IRTD_SGNL]);
if (ERRORS==0) Serial.println("OK"); else { Serial.println(); Serial.println(String(ERRORS)+" ERROR !"); }
break;
}
case '7' :
{
Serial.print("> Test 7 - connected additional IO : ");
uint16_t ERRORS=0;
// pins 1-26
if (rev==8) ERRORS+=GPIO_TEST_CONNECT(&GPIO[_API0A], &GPIO[_API0]);
ERRORS+=GPIO_TEST_CONNECT(&GPIO[_GPIO0A], &GPIO[_GPIO0]);
ERRORS+=GPIO_TEST_CONNECT(&GPIO[_GPIO1A], &GPIO[_GPIO1]);
ERRORS+=GPIO_TEST_CONNECT(&GPIO[_GPIO2A], &GPIO[_GPIO2]);
ERRORS+=GPIO_TEST_CONNECT(&GPIO[_GPIO3A], &GPIO[_GPIO3]);
ERRORS+=GPIO_TEST_CONNECT(&GPIO[_GPIO4A], &GPIO[_GPIO4]);
ERRORS+=GPIO_TEST_CONNECT(&GPIO[_GPIO5A], &GPIO[_GPIO5]);
ERRORS+=GPIO_TEST_CONNECT(&GPIO[_GPIO6A], &GPIO[_GPIO6]);
ERRORS+=GPIO_TEST_CONNECT(&GPIO[_GPIO7A], &GPIO[_GPIO7]);
ERRORS+=GPIO_TEST_CONNECT(&GPIO[_GPIO8A], &GPIO[_GPIO8]);
ERRORS+=GPIO_TEST_CONNECT(&GPIO[_GPIO9A], &GPIO[_GPIO9]);
ERRORS+=GPIO_TEST_CONNECT(&GPIO[_GPIO10A], &GPIO[_GPIO10]);
ERRORS+=GPIO_TEST_CONNECT(&GPIO[_GPIO11A], &GPIO[_GPIO11]);
if (ERRORS==0) Serial.println("OK"); else { Serial.println(); Serial.println(String(ERRORS)+" ERROR !"); }
break;
}
case 'f' :
{
TIME_DALAY=time_delay_fast;
Serial.println("> Set fast speed "+String(TIME_DALAY)+" ms");
break;
}
case 'd' :
{
TIME_DALAY=time_delay_def;
Serial.println("> Set default speed "+String(TIME_DALAY)+" ms");
break;
}
case 's' :
{
TIME_DALAY=time_delay_slow;
Serial.println("> Set slow speed "+String(TIME_DALAY)+" ms");
break;
}
case 'A' :
{
Serial.println("> Run all tests");
switch (rev)
{
case 5 : { CMD="13456"+CMD; break; }
case 7 : { CMD="1234567"+CMD; break; }
case 8 : { CMD="1234567"+CMD; break; }
default : { CMD="1234567"+CMD; break; }
}
break;
}
case 'R' :
{
Serial.println("> Repeat tests");
CMD=CMD+"R"+CMD;
break;
}
case 'P' :
{
Serial.println("> Pause 1000 ms");
_delay_ms(1000);
break;
}
case 'B' :
{
Serial.println("> Break all tests");
CMD="";
break;
}
case 'E' :
{
if (TOTAL_ERROR==0) Serial.println("> OK, no ERROR"); else Serial.println("> Total ERROR="+String(TOTAL_ERROR)+" !");
TOTAL_ERROR=0;
break;
}
case 'H' :
{
Serial.println("*****************************************************************");
Serial.println("Help:");
Serial.println("1 - base IO leds");
Serial.println("2 - additional IO");
Serial.println("3 - programming IO");
Serial.println("4 - unused IO");
Serial.println("5 - ADC");
Serial.println("6 - shorted IO");
Serial.println("7 - connected additional IO");
Serial.println("f - Set fast speed");
Serial.println("d - Set default speed");
Serial.println("s - Set slow speed");
Serial.println("A - Run all tests");
Serial.println("R - Repeat tests");
Serial.println("P - Pause 1000 ms");
Serial.println("B - Break all tests");
Serial.println("E - print TOTAL_ERROR");
Serial.println("H - help");
Serial.println("*****************************************************************");
break;
}
default : { Serial.println("> Error, use command : 1, 2, 3, 4, 5, 6, 7, f, s, d, A, R, P, B, E, H - help"); break; }
}
}
}
//#############################################################################################################################################################