Esempio n. 1
0
int rl78_cmd_baud_rate_set(port_handle_t fd, int baud, float voltage)
{
    unsigned char buf[2];
    int baud_code;
    switch (baud)
    {
    default:
        fprintf(stderr, "Unsupported baudrate %ubps. Using default baudrate 115200bps.\n", baud);
        baud = 115200;
    case 115200:
        baud_code = RL78_BAUD_115200;
        break;
    case 250000:
        baud_code = RL78_BAUD_250000;
        break;
    case 500000:
        baud_code = RL78_BAUD_500000;
        break;
    case 1000000:
        baud_code = RL78_BAUD_1000000;
        break;
    }
    buf[0] = baud_code;
    buf[1] = (int)(voltage * 10);
    if (3 <= verbose_level)
    {
        printf("Send \"Set Baud Rate\" command (baud=%ubps, voltage=%1.1fV)\n", baud, voltage);
    }
    rl78_send_cmd(fd, CMD_BAUD_RATE_SET, buf, 2);
    int len = 0;
    unsigned char data[3];
    int rc = rl78_recv(fd, &data, &len, 3);
    if (RESPONSE_OK != rc)
    {
        fprintf(stderr, "FAILED\n");
        return rc;
    }
    if (STATUS_ACK != data[0])
    {
        fprintf(stderr, "ACK not received\n");
        return data[0];
    }
    if (3 <= verbose_level)
    {
        printf("\tOK\n");
        printf("\tFrequency: %u MHz\n", data[1]);
        printf("\tMode: %s\n", 0 == data[2] ? "full-speed mode" : "wide-voltage mode");
    }
    /* If no need to change baudrate, just exit */
    if (115200 == baud)
    {
        return 0;
    }
    return serial_set_baud(fd, baud);
}
Esempio n. 2
0
/** Creates a basic fd, setting baud to 9600, raw data i/o (no flow
    control, no fancy character handling. Configures it for blocking
    reads.

    Returns the fd, -1 on error
**/
int serial_open(const char *port, int baud, int blocking)
{
    struct termios opts;

    int flags = O_RDWR | O_NOCTTY;
    if (!blocking)
        flags |= O_NONBLOCK;

    int fd=open(port, flags, 0);
    if (fd==-1)
        return -1;

    if (tcgetattr(fd, &opts))
    {
        printf("*** %i\n",fd);
        perror("tcgetattr");
        return -1;
    }

    cfsetispeed(&opts, serial_translate_baud(9600));
    cfsetospeed(&opts, serial_translate_baud(9600));

    cfmakeraw(&opts);
        
    // set one stop bit
    opts.c_cflag &= ~CSTOPB;

    if (tcsetattr(fd,TCSANOW,&opts)) {
        perror("tcsetattr");
        return -1;
    }

    tcflush(fd, TCIOFLUSH);

    serial_set_baud(fd, baud);
    return fd;
}
Esempio n. 3
0
/* Symbol for common u-boot code to call.
 * Setup the baudrate (brg: baudrate generator).
 */
void serial_setbrg(void)
{
	DECLARE_GLOBAL_DATA_PTR;
	serial_set_baud(gd->baudrate);
}