Exemplo n.º 1
0
Arquivo: main.c Projeto: 1i7/snippets
int main(void)
{
    uint8_t addr1, addr2; /* i2c addresses */
    uint16_t x, y;
    char buf[128]; /* temporary string buffer for various stuff */

    /* uart stuff */
    char rcvbuf[32], c;
    uint8_t rcvbufpos = 0;

    init_board();
    ov7670_init();

    printf("Camtest says hi!\n");
    printf("System clock: [%d]\n", SystemCoreClock);

    UART0_PrintString("Camtest says hi!\r\n");
    while (1) {
        c = UART0_Getchar();
        if (c == EOF) {
            continue;
        } else if ((c >= 32) && (c <= 126)) {
            rcvbuf[rcvbufpos++] = c;
        } else if (c == 13) {
            rcvbuf[rcvbufpos++] = 0;
            rcvbufpos = 0;
            if (strcmp(rcvbuf, "getimage") == 0) {
                ov7670_readframe();
                UART0_PrintString("OK\r\n");
            } else if (strlen(rcvbuf) >= 9 &&
                    strncmp(rcvbuf, "getline ", 8) == 0) {
                y = atoi(rcvbuf + 8);
                for (x = 0; x < 160; x ++) {
                    UART0_Sendchar(qqvgaframe1[x + (y * 160)]);
                    UART0_Sendchar(qqvgaframe2[x + (y * 160)]);
                }
            } else if (strlen(rcvbuf) == 9 &&
                    strncmp(rcvbuf, "regr 0x", 7) == 0) {
                addr1 = strtoul(rcvbuf + 7, NULL, 16);
                sprintf(buf, "0x%.2x 0x%.2x\r\n", addr1, ov7670_get(addr1));
                printf("%s", buf);
                UART0_PrintString(buf);
            } else if (strlen(rcvbuf) == 14 &&
                    strncmp(rcvbuf, "regw 0x", 7) == 0) {
                strncpy(buf, rcvbuf + 7, 2);
                buf[2] = 0;
                addr1 = strtoul((char *) buf, NULL, 16);
                addr2 = strtoul(rcvbuf + 12, NULL, 16);
                ov7670_set(addr1, addr2);
                sprintf(buf, "0x%.2x 0x%.2x\r\n", addr1, addr2);
                UART0_PrintString(buf);
            } else {
                UART0_PrintString("ERR\r\n");
                printf("Unknown command: [%s]\n", rcvbuf);
            }
        }
    }

    return 0;
}
Exemplo n.º 2
0
int main(void)
{
	char incoming;
	OT_init();
	EthernetInit();
	UART0_Init(9600);

	TimerInit(0, 1000);
	TimerInit(3, 120000000);
	//delayMs(0,1000);
	//enable_timer(3);

	while(1)
	{
		EthernetHandle();

		//UARTHandle();
		if(UART0_Available())
		{
			UARTLED_ON;
			incoming = UART0_Getchar();
			gw_char(incoming);
			UARTLED_OFF;
		}
	}
}
Exemplo n.º 3
0
void vTinyshTask(void * pvParameters)
{
	int again = 1;
	unsigned char c;
	tinysh_set_prompt(":>");
	tinysh_add_command(&myfoocmd);
	tinysh_add_command(&ctxcmd);
	tinysh_add_command(&item1);
	tinysh_add_command(&item2);
	{
	tinysh_cmd_t quitcmd={0, "quit", "exit shell", 0, reset_to_0, (void *) &again,0,0};	
	tinysh_add_command(&quitcmd);
	}

	
	while(again)
	{
		c=UART0_Getchar();
		tinysh_char_in((unsigned char) c);
		
	}
	printf("\n\rTinysh exiting\n\r");
	while(1);
}
Exemplo n.º 4
0
void write_file_cli(int argc, char** argv)
{
	char* filename;
	char a,b,c;
	int quit =1;
	signed char retval;
	File output;
	MESSAGE("opening file\n\r");
	retval = file_fopen(&output, &(efs.myFs), argv[1], 'w');
	MESSAGE("opened file\n\r");
	switch(retval)
	{
		case -2: //File already exists, open it for appending
			MESSAGE("File already exists, append to it?(Y/N):");
			c = UART0_Getchar();
			if(c == 'Y' || c == 'y')
			{
				if(file_fopen(&output, &(efs.myFs), argv[1], 'a') == -3)
				{
					MESSAGE("No more space!\n\r");
					return;
				}
				else
				{
					MESSAGE("appended to %s\n\r", argv[1]);
				}
			
			}
			else
				return;
			break;
		case -3:
			MESSAGE("No more space!\n\r");
			return;

		case 0:
			MESSAGE("file opened successfully\n\r");
			break;
		default:
			MESSAGE("unknown error occured\n\r");
	}
	MESSAGE("chars are being entered into the file until ~`! is recieved:\n\r");
	a = 0;
	b = 0;
	c = 0;
	
	while(quit)
	{
		a = UART0_Getchar();
		if(a == '~')
		{
			b = UART0_Getchar();
			if(b == '`')
			{
				c = UART0_Getchar();
				if(c == '!')
				{
					quit = 1;
					MESSAGE("quit recieved\n\r");
					file_fclose(&output);
					return;
				}
				else
				{
					file_write(&output, 1, &a);
					file_write(&output, 1, &b);
					file_write(&output, 1, &c);
				}
			}
			else
			{
				file_write(&output, 1, &a);
				file_write(&output, 1, &b);
			}
	
		}
		else
		{

			file_write(&output, 1, &a);

		}
		

	}

}