Beispiel #1
0
main()

{
	report_start();
        
//	svgactrl_test(0x80000600, 1, 0, 0x40200000, -1, 0, 0);

        base_test();

	gpio_test(0x80000900);
	gpio_test(0x80000a00); 

        report_end();
}
Beispiel #2
0
static int __init gpio_test_init(void)
{
    printk(KERN_INFO "\nGPIO Test Module Initialized\n\n");
    /* Create the proc entry */
    create_gpio_proc(PROC_FILE);
    gpio_test();
    return 0;
}
Beispiel #3
0
void do_debug()
{
#if 0
	switch (fw_args->debug_ops)
	{
	case 1:      //sdram check
		gpio_init_4760();
		serial_init();
		sdram_init_4760();
		REG8(USB_REG_INDEX) = 1;
		REG32(USB_FIFO_EP1) = check_sdram(fw_args->start, fw_args->size);
		REG32(USB_FIFO_EP1) = 0x0;
		REG8(USB_REG_INCSR) |= USB_INCSR_INPKTRDY;
		break;
	case 2:      //set gpio
		gpio_test(1, fw_args->pin_num);
		break;
	case 3:      //clear gpio
		gpio_test(0, fw_args->pin_num);
		break;
	}
#endif
}
/* start the main program */
void main() 
{
   UART_Init(9600);
   UART_TxString("\n\rTest menu Utra x51 v1.1\r\n 1:GPIO Blink\r\n 2:LCD \n\r 3:7-Segment\n\r 4:RTC\n\r 5:EEPROM\n\r 6:ADC\n\r 7:Keypad \n\r Enter option:");
   UART_TxString("\n\rReset the board after test is done");
   mm_option = UART_RxChar();
   while(1)
    {
 	  	switch(mm_option)
		{
		 case '1': gpio_test(); break;
		 case '2': LCD_test(); break;
		 case '3': seg_test(); break;
		 case '4': rtc_test(); break; 
		 case '5': eeprom_test(); break; //eeprom
		 case '6': adc_test(); break;
		 case '7': keypad_test();break;
		 default:break;
		}
	}
}
/* start the main program */
void main() 
{
   UART_Init(9600);
   UART_TxString("\n\rPIC Ultra baord menu v2.0\r\n 1:GPIO Blink\r\n 2:LCD 8-bit \n\r 3:LCD 4-bit\n\r 4:7-Segment\n\r 5:RTC\n\r 6:EEPROM\n\r 7:ADC\n\r 8:Keypad \n\r Enter option:");
   UART_TxString("\n\rReset the board after test is done");
   mm_option = UART_RxChar();
   while(1)
    {
 	  	switch(mm_option)
		{
		 case '1': gpio_test(); break;
		 case '2': LCD_8bit_test(); break;
		 case '3': LCD_4bit_test(); break;
		 case '4': seg_test(); break;
		 case '5': rtc_test(); break;
		 case '6': eeprom_test(); break; //eeprom
		 case '7': adc_test(); break;
		 case '8': keypad_test();break;
		 default:break;
		}
	}
}
Beispiel #6
0
int main( int argc, const char *argv[] )
{
    gpio_config_t   led_config;
    gpio_config_t   btn_config;
    gpio_config_t   dip_config;
    gpio_t          leds;
    gpio_t          btns;
    gpio_t          dips;

    led_config.base = GPIOLED_BASEADDR;
    led_config.dual = 0;
    led_config.intr = 1;
    led_config.bits = 4;

    btn_config.base = GPIOBTN_BASEADDR;
    btn_config.dual = 0;
    btn_config.intr = 1;
    btn_config.bits = 5;

    dip_config.base = GPIODIP_BASEADDR;
    dip_config.dual = 0;
    dip_config.intr = 1;
    dip_config.bits = 4;

    gpio_create( &leds, &led_config );
    gpio_create( &btns, &btn_config );
    gpio_create( &dips, &dip_config );

    gpio_test( &leds, &btns, &dips );

    gpio_destroy( &leds );
    gpio_destroy( &btns );
    gpio_destroy( &dips );

    return 0;
}
Beispiel #7
0
/*
 * gpio_test_ext():
 *
 * addr   - core address
 * imask  - value of imask generic
 * pirq   - value of pirq generic
 * irqgen - value of irqgen generic
 *
 * This test also makes use of IRQMP. irqmp_test() must 
 * be run before this test in order to initialize irqmp_base.
 *
 * This test requires that the GPIO lines have external pull-ups
 *
 */
int gpio_test_irq_mask(int addr, int imask, int pirq, int irqgen, int iomask)
{
        int width, k, i, numirq;

        /* Perform simple test first, get back width of port */
        width = gpio_test(addr);
        
        report_subtest(2);

        /* Initialize interrupts */
        irqmp_base->irqlevel = 0;       /* clear level reg */
        irqmp_base->irqmask = 0;      /* mask all interrupts */
        irqmp_base->irqclear = -1;      /* clear all pending interrupts */

        /* Set up interrupt handler */
        if (irqgen == 0) {
                /* Fixed mapping IO[i] = interrupt pirq + i */
                for (i=pirq ? 1 : 0; i <width; i++) {
                        if ((iomask & (1 << i)) == 0) continue;
                        if ((pirq+i) < 32) {
                                catch_interrupt(gpio_irqhandler, pirq+i);
                                /* Enable interrupt on IRQMP */
                                irqmp_base->irqmask |= (1 << (pirq+i));
                        }
                }
        } else if (irqgen == 1) {
                /* One shared interrupt pirq */
                catch_interrupt(gpio_irqhandler, pirq);
                /* Enable interrupt on IRQMP */
                irqmp_base->irqmask = (1 << pirq);

        } else {
                /* Core can map lines to irqgen interrupt lines */
                for (i=0; i < irqgen; i++) {
                        if ((pirq+i) < 32) {
                                catch_interrupt(gpio_irqhandler, pirq+i);
                                /* Enable interrupt on IRQMP */
                                irqmp_base->irqmask |= (1 << (pirq+i));
                        }
                }
        }

        pio[1] = 0; /* Prepare to drive all lines low */
        pio[4] = 0;  /* Interrupt level = low */
        pio[5] = -1; /* Edge */
        pio[3] = (-1) & iomask; /* Enable all interrupts */

        /* Iterate once for irqgen = 0, 1 and irqgen times for other values */
        for (k = 0; k < (irqgen ? irqgen : 1); k++) {

                /* Possibly remap interrupts */
                for (i = 0; (irqgen > 1) && (i < ((width+3)/4)); i++) {
                        pio[8+i] = (k << 24) | (k << 16) | (k << 8) | k;
                }

                /* Initialize interrupt counting */
                irqtbl[0] = 1;
                numirq = 0;

                /* Assert interrupts */
                for (i = (irqgen != 0 || pirq != 0) ? 0 : 1; i < width; i++) {

                        if ((iomask & (1 << i)) == 0) continue;

                        /* Drive line i low */
                        pio[2] = (1 << i);
                
                        /* 
                         * Wait for interrupt, or skip to next if interrupt is masked. 
                         * Test may lock here if imask is wrong or core/connection is 
                         * bad.
                         */
                        while((imask & (1 << i)) && pio[2]);
                }
                pio[2] = 0;

        
                /* Check interrupts */
                for (i = (irqgen != 0 || pirq != 0) ? 0 : 1; i < width; i++) {
                        /* Skip lines that cannot generate irqs */
                        if ((iomask & (1 << i)) == 0) continue;
                        if ((imask & (1 << i)) == 0)
                                continue;
                        numirq++;
                
                        /* 
                         * With irqgen = 0 the interrupt asserted should equal the
                         * io line plus pirq offset. For the other modes, pirq+k should
                         * have been asserted
                         */
                        if (((irqgen == 0) && (irqtbl[numirq] != (pirq+i+0x10))) ||
                            ((irqgen != 0) && (irqtbl[numirq] != (pirq+k+0x10))))
                                fail(4+i+32*k);                
                }
                /*
                 *  The number of expected interrupts in all cases is the same as
                 *  the number of I/O lines with interrupt generation capabilities
                 */
                if ((irqtbl[0] - numirq) != 1) fail(3);
        }
        pio[3] = 0; /* Mask all interrupts on GRGPIO */

        irqmp_base->irqmask = 0x0;  /* mask all interrupts */
        irqmp_base->irqclear = -1;  /* clear all pending interrupts */

        return 0;
}
Beispiel #8
0
/*
 * Open device and perform command
 */
int
main(int argc, char **argv)
{
	struct k8048 k;
	char *execdup, *execname;

	/* Initialise to NULL/0 */
	memset(&k, 0, sizeof(k));

	/* Get exec name */
	execdup = (char *)strdup(argv[0]);
	if (execdup == NULL) {
		printf("%s: fatal error: strdup failed\n", __func__);
		io_exit(&k, EX_OSERR); /* Panic */
	}
	execname = basename(execdup);
	if (execname == NULL) {
		printf("%s: fatal error: basename failed\n", __func__);
		io_exit(&k, EX_OSERR); /* Panic */
	}

	/* Get configuration */
	getconf(&k);
	
	/* Command: k8048 */
	if (strcmp(execname, "k8048") == 0) {
		resetuid(&k);
		usage_k8048(&k);
	}
#ifdef TTY
	/* Command: kload */
	if (strcmp(execname, "kload") == 0) {
		resetuid(&k);
		if (argc < 3)
			usage_kload(&k, "Missing arg");
		if (argc > 5)
			usage_kload(&k, "Too many args");

		int prog_mode = tolower((int)argv[1][0]);
		if (prog_mode != 'p' && prog_mode != 'v')
			usage_kload(&k, "Invalid mode");

		if (argv[2][0] == '/' && strstr(argv[2], "/dev/tty") != argv[2])
			usage_kload(&k, "Invalid tty");

		char file[STRLEN];
		strcpy(file, "-");
		if (argc >= 4)
			strncpy(file, argv[3], STRMAX);

		int target = 'n';
		if (argc == 5) {
			target = tolower((int)argv[4][0]);
			if (target != 'a')
				usage_kload(&k, "Invalid target");
		}

		io_signal_on(k); // !SIGPIPE
		stk500v2_load(&k, prog_mode, argv[2], file, target);
		io_exit(&k, EX_OK);
	}
#endif
	/* Open device */
	if (io_open(&k) < 0) {
#ifdef KTEST
		if (strcmp(execname, "ktest") == 0)
			usage_ktest(&k, io_error(&k));
#endif
		usage(&k, execname, io_error(&k));
	}

	/* Raise priority */
	setpriority(PRIO_PROCESS, 0, -20);

	/* Reset user */
	resetuid(&k);
#ifdef KCTRL
	/* Command: kctrl */
	if (strcmp(execname, "kctrl") == 0) {
		if (argc < 2)
			usage_kctrl(&k, "Missing arg");
		if (argc > 2)
			usage_kctrl(&k, "Too many args");
		if (strcasecmp(argv[1], "RUN") == 0) {
			io_close(&k, HIGH);
			printf("RUN\n");
		} else if (strcasecmp(argv[1], "STOP") == 0) {
			io_close(&k, LOW);
			printf("STOP\n");
		} else if (strcasecmp(argv[1], "RESTORE") == 0) {
			io_set_vpp(&k, LOW);
			io_usleep(&k, 10);
			io_close(&k, HIGH);
			printf("RESTORE\n");
		}
		io_exit(&k, EX_OK);
	}
#endif
#ifdef KTEST
	/* Command: ktest */
	if (strcmp(execname, "ktest") == 0) {
		if (argc < 3)
			usage_ktest(&k, "Missing args");
		if (argc > 3)
			usage_ktest(&k, "Too many args");
		int32_t testarg = strtol(argv[2], NULL, 0);
		if (testarg < 0)
			usage_ktest(&k, "Invalid arg");

		if (strcasecmp(argv[1], "VPP") == 0) 
			io_test0(&k, 0, testarg);
		else if (strcasecmp(argv[1], "PGC") == 0)
			io_test0(&k, 1, testarg);
		else if (strcasecmp(argv[1], "PGD") == 0)
			io_test0(&k, 2, testarg);
		else if (strcasecmp(argv[1], "PGM") == 0)
			io_test0(&k, 3, testarg);
		else if (argv[1][0] >= '0' && argv[1][0] <= '9') {
			int32_t test = strtol(argv[1], NULL, 0);
			switch (test) {
#ifdef RPI
			case 0: gpio_test(&k, testarg);break;
#endif
			case 1: io_test1(&k, testarg); break;
			case 2: io_test2(&k, testarg); break;
			case 3: io_test3(&k, testarg); break;
			case 4: io_test4(&k, testarg); break;
#if defined(KTEST) && defined(KIO)
			case 5: io_test5(&k, testarg); break;
#endif
			default:usage_ktest(&k, "Invalid arg");break;
			}
		} else {
			usage_ktest(&k, "Invalid arg");
		}
		io_exit(&k, EX_OK);
	}
#endif
	/* Determine arch: k12 | k14 | k16 | k24 | k32 */
	if (pic_arch(&k, execname) == 0)
		usage_k8048(&k);
	if (argc < 2)
		usage(&k, execname, "Missing arg(s)");

	/* Device selection */
	int argv1 = tolower((int)argv[1][0]);
	if (argv1 == 's') { /* Select device */
		if (argc < 3) {
			pic_selector(&k);
			io_exit(&k, EX_OK);
		}
		if (mystrcasestr(argv[2], "dspic") == argv[2]) {
			strncpy(k.devicename, argv[2], STRLEN);
		} else if (mystrcasestr(argv[2], "pic") == argv[2]) {
			strncpy(k.devicename, argv[2], STRLEN);
		} else {
			int32_t temp = strtol(argv[2], NULL, 0);
			if (temp < 10 || temp > 33) {
				usage(&k, execname, "Invalid arg [select]");
			}
			if (temp == 30 || temp == 33) {
				strcpy(k.devicename, "dspic");
				strncpy(&k.devicename[5], argv[2], STRLEN - 5);
			} else {
				strcpy(k.devicename, "pic");
				strncpy(&k.devicename[3], argv[2], STRLEN - 3);
			}
		}
		argc -= 2;
		argv += 2;
		if (argc < 2)
			usage(&k, execname, "Missing arg(s)");
	} else if (k.pic->arch == ARCH12BIT) {
		usage(&k, execname, "Missing select");
	}

	/* Key entry */
	argv1 = tolower((int)argv[1][0]);
	if (argv1 == 'l') {			/* LVP 32-bit key entry */
		if (k.pic->arch == ARCH12BIT) {
			usage(&k, execname, "Invalid arg [lvp]");
		}
		/* ARCH14BIT || ARCH16BIT || ARCH24BIT || ARCH32BIT */
		k.key = LVPKEY;
		argc -= 1;
		argv += 1;
		if (argc < 2)
			usage(&k, execname, "Missing arg(s)");
	}
	else if (argv1 == 'h') {		/* HVP 32-bit key entry */
		if (k.pic->arch == ARCH12BIT || k.pic->arch == ARCH14BIT || k.pic->arch == ARCH32BIT) {
			usage(&k, execname, "Invalid arg [hvp]");
		}
		/* ARCH16BIT || ARCH24BIT */
		k.key = HVPKEY;
		argc -= 1;
		argv += 1;
		if (argc < 2)
			usage(&k, execname, "Missing arg(s)");
	}
	else if (k.pic->arch == ARCH32BIT) {	/* LVP 32-bit key entry */
		/* ARCH32BIT */
		k.key = LVPKEY;
	}
	else {					/* No key entry */
		/* ARCH12BIT || ARCH14BIT || ARCH16BIT || ARCH24BIT */
		k.key = NOKEY;
	}

	/* Command */
	argv1 = tolower((int)argv[1][0]);
	int argv11 = tolower((int)argv[1][1]);
	switch (argv1) {
	case 'b':	if (argv11 == 'o') {		/* BOOT */
				uint32_t addr = UINT32_MAX, words = UINT32_MAX;
				if (argc > 4)
					usage(&k, execname, "Too many args [boot]");
				if (argc >= 3) {
					words = strtoul(argv[2], NULL, 0);
					if (words == 0)
						usage(&k, execname, "Invalid arg [boot]");
				}
				if (argc == 4) {
					addr = strtoul(argv[3], NULL, 0);
				}
				pic_dumpboot(&k, addr, words);
			} else {			/* BLANK */
				if (argc > 2)
					usage(&k, execname, "Too many args [blank]");
				if (areyousure("Blank device"))
					pic_blank(&k);
			}
			break;

	case 'c':	if (argc > 3)
				usage(&k, execname, "Too many args [config]");
			if (argc == 2)
				pic_dumpconfig(&k);
			else
				pic_writebandgap(&k, strtoul(argv[2], NULL, 0));
			break;
	
	case 'd':	if (argv11 == 'a') {		/* DATA */
				if (argc > 2)
					usage(&k, execname, "Too many args [data]");
				pic_dumpdata(&k);
			} else if (argv11 == 'e') { 	/* DEBUG */
				printf("Hello world!\n");
			} else {			/* DUMP */
				if (argc > 2)
					usage(&k, execname, "Too many args [dump]");
				pic_dumpdevice(&k);
			}
			break;

	case 'e':	if (argv11 == 'r') {		/* ERASE FLASH | ID | ROW[NROWS] */
				uint32_t row = 0, nrows = 1;
				char prompt[STRLEN] = {0}, *endptr = NULL;

				if (argc < 3)
					usage(&k, execname, "Missing arg [erase]");
				if (argc > 4)
					usage(&k, execname, "Too many args [erase]");
				
				int argv2 = tolower((int)argv[2][0]);
				switch (argv2) {
				case 'i': /* IDLOCATION    */
				case 'u': /* USERID/CONFIG */
					row = PIC_ERASE_ID;
					strncpy(prompt, "Erase id", STRLEN);
					break;
				case 'c': /* CONFIG */
					row = PIC_ERASE_CONFIG;
					strncpy(prompt, "Erase config", STRLEN);
					break;
				case 'e': /* EEPROM */
					row = PIC_ERASE_EEPROM;
					strncpy(prompt, "Erase EEPROM", STRLEN);
					break;
				case 'f': /* FLASH */
					nrows = UINT32_MAX;
					strncpy(prompt, "Erase program flash", STRLEN);
					break;
				default:  /* FLASH ROW */
					row = strtoul(argv[2], &endptr, 0);
					if (endptr == argv[2])
						usage(&k, execname, "Invalid arg [erase]");
					if (argc == 4) {
						nrows = strtoul(argv[3], NULL, 0);
						if (nrows == 0)
							usage(&k, execname, "Invalid arg [erase]");
					}
					snprintf(prompt, STRLEN, "Erase %u row(s) at row %u",
						nrows, row);
					break;
				}
				if (areyousure(prompt))
					pic_erase(&k, row, nrows);
			} else if (argv11 == 'x') {	/* EXECUTIVE */
				uint32_t addr = UINT32_MAX, words = UINT32_MAX;
				if (argc > 4)
					usage(&k, execname, "Too many args [executive]");
				if (argc >= 3) {
					words = strtoul(argv[2], NULL, 0);
					if (words == 0)
						usage(&k, execname, "Invalid arg [executive]");
				}
				if (argc == 4) {
					addr = strtoul(argv[3], NULL, 0);
				}
				pic_dumpexec(&k, addr, words);
			} else {			/* EEPROM */
				if (argc > 2)
					usage(&k, execname, "Too many args [eeprom]");
				pic_dumpdata(&k);
			}
			break;

	case 'f':	{
			uint32_t words = UINT32_MAX, addr = UINT32_MAX;
			if (argc > 4)
				usage(&k, execname, "Too many args [program flash]");
			if (argc >= 3) {
				words = strtoul(argv[2], NULL, 0);
				if (words == 0)
					usage(&k, execname, "Invalid arg [program flash]");
			}
			if (argc == 4) {
				addr = strtoul(argv[3], NULL, 0);
			}
			pic_dumpprogram(&k, addr, words);
			}
			break;

	case 'i':	if (argc > 2)
				usage(&k, execname, "Too many args [id]");
			pic_dumpdeviceid(&k);
			break;

	case 'o':	if (argc > 3)
				usage(&k, execname, "Too many args [osccal]");
			if (argc == 2)
				pic_dumposccal(&k);
			else
				pic_writeosccal(&k, strtoul(argv[2], NULL, 0));
			break;

	case 'p':	{
			int blank = 1;
			if (argc > 4)
				usage(&k, execname, "Too many args [program]");
			if (argc == 4) switch (argv[3][0]) {
				case 'n':
				case 'N':
				case '0': blank = 0;
					break;
				case 'y':
				case 'Y':
				case '1': blank = 1;
					break;
				default:usage(&k, execname, "Invalid arg [program]");
					break;
			}
			if (argc < 3)
				pic_program(&k, "-", 1);
			else
				pic_program(&k, argv[2], blank);
			}
			break;

	case 'v':	if (argv11 == 'i') {		/* VIEW */
				if (argc > 3)
					usage(&k, execname, "Too many args [view]");
				if (argc < 3)
					pic_view(&k, "-");
				else
					pic_view(&k, argv[2]);
			} else {			/* VERIFY */
				if (argc > 3)
					usage(&k, execname, "Too many args [verify]");
				if (argc < 3)
					pic_verify(&k, "-");
				else
					pic_verify(&k, argv[2]);
			}
			break;
#ifdef TTY
	case '/':	if (strstr(argv[1], "/dev/tty") != argv[1]) {
				usage(&k, execname, "Invalid device [TTY]");
			}
			if (strstr(argv[1], k.device) != NULL) {
				usage(&k, execname, "Device in use [TTY]");
			}
			stk500v2_listen(&k, argv[1], 0);
			break;

	case '8':	stk500v2_listen(&k, "0.0.0.0", 8048);
			break;
#endif
	default:	usage(&k, execname, "Unknown operation");
			break;
	}

	free(execdup);
	io_exit(&k, EX_OK);
}