1
0
mirror of git://projects.qi-hardware.com/ben-blinkenlights.git synced 2024-10-04 05:30:24 +03:00
ben-blinkenlights/lpc111x-isp/lpc111x.c

106 lines
1.9 KiB
C
Raw Normal View History

/*
* lpc111x-isp/lpc111x.c - LPC111x/LPC11Cxx ISP programmer
*
* Written 2012 by Werner Almesberger
* Copyright 2012 Werner Almesberger
*
* This program is free software; you can redistribute it and/or modify
* it under the terms of the GNU General Public License as published by
* the Free Software Foundation; either version 2 of the License, or
* (at your option) any later version.
*/
#include <stdlib.h>
#include <stdio.h>
#include <unistd.h>
#include <string.h>
#include <termios.h>
#include <fcntl.h>
#include <errno.h>
#include <ubb/ubb.h>
#include <ubb/swuart.h>
#define TGT_nRESET UBB_CMD
#define TGT_nISP UBB_DAT1
#define TGT_TX UBB_DAT3
#define TGT_RX UBB_DAT2
#define HOST_RX TGT_TX
#define HOST_TX TGT_RX
static void dump(uint8_t *s, int len)
{
const uint8_t *end = s+len;
for (end = s+len; s != end; s++) {
if (*s >= ' ' && *s <= '~')
printf("%c", *s);
else if (*s == 10)
printf(s+1 == end ? "\n" : "\\n");
else if (*s == 13)
;
else
printf("\\%02o", *s);
}
if (len && end[-1] != '\n')
printf("...\n");
}
static void at_exit(void)
{
ubb_close(0);
}
int main(int argc, char **argv)
{
uint8_t reply[1000];
int got;
if (ubb_open(0) < 0) {
perror("ubb_open");
exit(1);
}
atexit(at_exit);
ubb_power(1);
usleep(100*1000);
SET(TGT_nRESET);
OUT(TGT_nRESET);
CLR(TGT_nISP);
OUT(TGT_nISP);
swuart_open(HOST_TX, HOST_RX, 115200);
CLR(TGT_nRESET);
usleep(10); /* DS Table 9 pg 29 says min 50 ns */
SET(TGT_nRESET);
usleep(5*1000); /* UM 26.3.1 pg 408 says max 3 ms */
got = swuart_trx("?", 1, reply, sizeof(reply), 1000, 100);
dump(reply, got);
got = swuart_trx("Synchronized\r\n", 14,
reply, sizeof(reply), 1000, 100);
dump(reply, got);
got = swuart_trx("12000\r\n", 7,
reply, sizeof(reply), 1000, 100);
dump(reply, got);
got = swuart_trx("J\r\n", 7,
reply, sizeof(reply), 1000, 100);
dump(reply, got);
return 0;
}