sysmobts_v2: Add code that might or might switch the board into ubl mode
This commit is contained in:
parent
5d8f84bc7b
commit
2fa58b6e40
14
src/main.c
14
src/main.c
|
@ -338,6 +338,15 @@ main(int argc, char *argv[])
|
|||
if (ret)
|
||||
return ret;
|
||||
|
||||
/* Put the board in UART boot and reset it */
|
||||
set_rts(0);
|
||||
set_dtr(1);
|
||||
usleep(500 * 1000);
|
||||
set_rts(1);
|
||||
usleep(500 * 1000);
|
||||
set_rts(0);
|
||||
usleep(500 * 1000);
|
||||
|
||||
/* Wait for the device to send the BOOTME sequence.
|
||||
* If the UBL is already running, it will send BOOTPSP. */
|
||||
found = wait_for_message("BOOTME", "BOOTPSP", NULL);
|
||||
|
@ -412,6 +421,11 @@ main(int argc, char *argv[])
|
|||
ret = 0;
|
||||
|
||||
end:
|
||||
set_dtr(0);
|
||||
set_rts(1);
|
||||
usleep(100 * 1000);
|
||||
set_rts(0);
|
||||
|
||||
/* Close serial port. */
|
||||
serial_port_close();
|
||||
return ret;
|
||||
|
|
25
src/serial.c
25
src/serial.c
|
@ -31,6 +31,7 @@
|
|||
#include <ctype.h> /* For isdigit() and friends... */
|
||||
#include <sys/time.h>
|
||||
#include <sys/wait.h>
|
||||
#include <sys/ioctl.h>
|
||||
|
||||
#include "common.h"
|
||||
#include "serial.h"
|
||||
|
@ -192,6 +193,30 @@ serial_port_close(void)
|
|||
}
|
||||
}
|
||||
|
||||
int
|
||||
set_dtr(int dtr)
|
||||
{
|
||||
int status;
|
||||
|
||||
ioctl(serial_port.fd, TIOCMGET, &status);
|
||||
if (dtr) status &= ~TIOCM_DTR;
|
||||
else status |= TIOCM_DTR;
|
||||
ioctl(serial_port.fd, TIOCMSET, &status);
|
||||
return EXIT_SUCCESS;
|
||||
}
|
||||
|
||||
int
|
||||
set_rts(int rts)
|
||||
{
|
||||
int status;
|
||||
|
||||
ioctl(serial_port.fd, TIOCMGET, &status);
|
||||
if (rts) status &= ~TIOCM_RTS;
|
||||
else status |= TIOCM_RTS;
|
||||
ioctl(serial_port.fd, TIOCMSET, &status);
|
||||
return EXIT_SUCCESS;
|
||||
}
|
||||
|
||||
int
|
||||
send_message(const char *msg)
|
||||
{
|
||||
|
|
|
@ -30,6 +30,12 @@ serial_port_open(const char *port, const int baud_rate_index);
|
|||
void
|
||||
serial_port_close(void);
|
||||
|
||||
int
|
||||
set_dtr(int dtr);
|
||||
|
||||
int
|
||||
set_rts(int rts);
|
||||
|
||||
int
|
||||
send_message(const char *msg);
|
||||
|
||||
|
|
Loading…
Reference in New Issue