Ejemplo n.º 1
0
/* Setup the UART used for communication with the host / master (the module is slave) */
void dtplug_protocol_set_dtplug_comm_uart(uint8_t uart_num, struct dtplug_protocol_handle* handle)
{
	void* decoder = dtplug_protocol_decoder_0;

	/* Basic parameter checks */
	if (uart_num >= DTPP_MAX_HANDLERS) {
		return;
	}
	if (handle == NULL) {
		return;
	}

	/* Configure and register handle and configure uart */
	handle->rx_packet = handle->packets;
	handle->packet_ok = NULL;
	handle->done_with_old_packet = 1;
	handle->uart = uart_num;
	dtpp_handles[uart_num] = handle;
	switch (uart_num) {
		case 1:
			decoder = dtplug_protocol_decoder_1;
			break;
		case 0:
		default:
			break;
	}
	uart_on(uart_num, 115200, decoder);
}
Ejemplo n.º 2
0
int main(void) {
	system_init();
	uart_on(0, 115200, NULL);
	adc_on();

	while (1) {
		chenillard(500);
		/* ADC Test */
		adc_display(LPC_ADC_NUM(0), 0);
		TMP36_display(LPC_ADC_NUM(1), 0);
	}
	return 0;
}
Ejemplo n.º 3
0
int main(void) {
	system_init();
	uart_on(0, 115200, NULL);
	adc_on();

	uprintf(0, "System started\n");
	msleep(5);
	watchdog_config(&wdconf);
	uprintf(0, "Watchdog started\n");

	while (1) {
		watchdog_feed();
		chenillard(50);
		/* ADC Test */
		adc_display(LPC_ADC_NUM(0), 0);
	}
	return 0;
}
Ejemplo n.º 4
0
/* Event loop */
void start_serial(void) {

    int eof = 0;

    /* Compute optimal buffer size depending on desired latency. */
    int usec_per_byte = (10 * (1000000 / baud_rate));

    LOG("latency = %d bytes\r\n", latency_bytes);


    /* Setup PK2 with target off.  FIXME: connect to running target! */
    reset_hold(reset_target);
    target_off(power_target);
    if (power_target) set_vdd(5.0);

    /* Start target. */
    target_on(power_target);
    reset_release();

    /* Check if votage is ok. */
    LOG("status %04X\r\n", get_status());

    /* Go */
    if (-1 == fcntl(input_fd, F_SETFL, O_NONBLOCK))  { 
        RAISE_ERROR("Can't set input_fd O_NONBLOCK.\r\n"); 
    }

    struct termios options;
    struct termios savedOptions;

    tcgetattr(input_fd, &savedOptions);
    tcgetattr(input_fd, &options);
    cfmakeraw(&options);
    options.c_cflag |= (CLOCAL | CREAD);
    options.c_lflag |= ISIG;
    if (tcsetattr(input_fd, TCSANOW, &options) != 0) {
        fprintf(stderr, "Can't set up console\r\n");
    }


    uart_on(baud_rate);
    fprintf(stderr, "Connected to PICkit2 Serial.\r\n");
    if (pty_mode == 1) {
        fprintf(stderr, "CTRL-C to exit.\r\n");
    } else {
        fprintf(stderr, "CTRL-C to exit, CTRL-D to disconnect input.\r\n");
    }
    while(!stop) {

        if (eof) {
            /* If input is closed we cn just poll the output. */
            LOG("EOF\r\n");
            usleep(usec_per_byte);
            transfer_output(output_fd);
        }
        else {
            /* When there's room in the buffer, always respond immediately
               to input data. */
            struct timeval timeout;
            fd_set inset;

            timeout.tv_sec = 0;
            timeout.tv_usec = usec_per_byte * latency_bytes;
            FD_ZERO(&inset);
            FD_SET(input_fd, &inset);
            if (-1 == (select(1+input_fd, &inset, NULL, NULL, &timeout))) {
                if (errno != EINTR) {
                    RAISE_ERROR("select() error\r\n");
                }
            }

            /* If there's data, read as much as possible. */
            if (FD_ISSET(input_fd, &inset)) {
                int rv;
                rv = transfer_input(input_fd, latency_bytes);
                if (rv == -1) { 
                    if (errno == EAGAIN) break;
                    RAISE_ERROR("read(): %s\r\n",strerror(errno)); 
                }
                if (rv == 0) {
                    eof = 1;
                    if (exit_on_eof) break;
                }
                
                /* Simple rate limiting mechanism: per transfer, wait for
                   as long as it takes to transfer the bytes.  Note that
                   this can be made more efficient when we track an
                   estimate of the number of elements in the upload
                   buffer, keeping the buffer full instead of empty. */
                
                while(rv--) {
                    if (stop) break;
                    usleep(usec_per_byte);
                }
            }
        }
        transfer_output(output_fd);
    }


    if (tcsetattr(input_fd, TCSANOW, &savedOptions) != 0) {
        fprintf(stderr, "Can't clean up console\r\n");
    }
    /* Cleanup */
    uart_off();
    reset_pk2();
}