*/
+#include "isp_utils.h"
+
+extern int trace_on;
+
+#define SERIAL_BUFSIZE 128
+
+#define SYNCHRO_START "?"
+#define SYNCHRO "Synchronized"
+
+
+int isp_ret_code(char* buf)
+{
+ if (trace_on) {
+ /* FIXME : Find how return code are sent (binary or ASCII) */
+ printf("Received code: '0x%02x'\n", *buf);
+ }
+ return 0;
+}
+
+
+/* Connect or reconnect to the target.
+ * Return positive or NULL value when connection is OK, or negative value otherwise.
+ */
+int isp_connect()
+{
+ char buf[SERIAL_BUFSIZE];
+
+ /* Send synchronize request */
+ if (isp_serial_write(SYNCHRO_START, strlen(SYNCHRO_START)) != strlen(SYNCHRO_START)) {
+ printf("Unable to send synchronize request.\n");
+ return -5;
+ }
+
+ /* Wait for answer */
+ if (isp_serial_read(buf, SERIAL_BUFSIZE, strlen(SYNCHRO)) < 0) {
+ printf("Error reading synchronize answer.\n");
+ return -4;
+ }
+
+ /* Check answer, and acknoledge if OK */
+ if (strncmp(SYNCHRO, buf, strlen(SYNCHRO)) == 0) {
+ isp_serial_write(SYNCHRO, strlen(SYNCHRO));
+ } else {
+ printf("Unable to synchronize.\n");
+ return -1;
+ }
+
+ /* Empty read buffer (maybe echo is on ?) */
+ usleep( 5000 );
+ isp_serial_read(buf, SERIAL_BUFSIZE, 0);
+
+ /* FIXME : Do we always turn off echo ? */
+ /* and turn off echo */
+ isp_serial_write("A 0\r\n", 5);
+
+ return 1;
+}
+
+/* Handle one command
+ * Return positive or NULL value when command handling is OK, or negative value otherwise.
+ */
+int isp_handle_command(char* cmd, int arg_count, char** args)
+{
+ return 1;
+}
+
--- /dev/null
+/*********************************************************************
+ *
+ * LPC1114 ISP Commands
+ *
+ *********************************************************************/
+
+/* List of commands to be supported :
+ synchronize
+ unlock
+ set-baud-rate
+ echo
+ write-to-ram
+ read-memory
+ prepare-for-write
+ copy-ram-to-flash
+ go
+ erase
+ blank-check
+ read-part-id
+ read-boot-version
+ compare
+ read-uid
+*/
+
+#ifndef ISP_COMMADS_H
+#define ISP_COMMADS_H
+
+int isp_ret_code(char* buf);
+
+/* Connect or reconnect to the target.
+ * Return positive or NULL value when connection is OK, or negative value otherwise.
+ */
+int isp_connect();
+
+/* Handle one command
+ * Return positive or NULL value when command handling is OK, or negative value otherwise.
+ */
+int isp_handle_command(char* cmd, int arg_count, char** args);
+
+#endif /* ISP_COMMADS_H */
+
#include <ctype.h>
#include "isp_utils.h"
+#include "isp_commands.h"
#define PROG_NAME "LPC11xx ISP"
#define VERSION "0.01"
fprintf(stderr, "-----------------------------------------------------------------------\n");
}
-#define SERIAL_BUFSIZE 128
-
-#define SYNCHRO_START "?"
-#define SYNCHRO "Synchronized"
-
#define SERIAL_BAUD B115200
int trace_on = 0;
-int isp_ret_code(char* buf)
-{
- if (trace_on) {
- /* FIXME : Find how return code are sent (binary or ASCII) */
- printf("Received code: '0x%02x'\n", *buf);
- }
- return 0;
-}
-
-
-/* Connect or reconnect to the target.
- * Return positive value when connection is OK, or negative value otherwise.
- */
-int isp_connect()
-{
- char buf[SERIAL_BUFSIZE];
-
- /* Send synchronize request */
- if (isp_serial_write(SYNCHRO_START, strlen(SYNCHRO_START)) != strlen(SYNCHRO_START)) {
- printf("Unable to send synchronize request.\n");
- return -5;
- }
-
- /* Wait for answer */
- if (isp_serial_read(buf, SERIAL_BUFSIZE, strlen(SYNCHRO)) < 0) {
- printf("Error reading synchronize answer.\n");
- return -4;
- }
-
- /* Check answer, and acknoledge if OK */
- if (strncmp(SYNCHRO, buf, strlen(SYNCHRO)) == 0) {
- isp_serial_write(SYNCHRO, strlen(SYNCHRO));
- } else {
- printf("Unable to synchronize.\n");
- return -1;
- }
-
- /* Empty read buffer (maybe echo is on ?) */
- usleep( 5000 );
- isp_serial_read(buf, SERIAL_BUFSIZE, 0);
-
- /* FIXME : Do we always turn off echo ? */
- /* and turn off echo */
- isp_serial_write("A 0\r\n", 5);
-
- return 1;
-}
-
-
int main(int argc, char** argv)
{
int baudrate = SERIAL_BAUD;
}
/* FIXME : call command handler */
+ if (command != NULL) {
+ int err = 0;
+ err = isp_handle_command(command, nb_cmd_args, cmd_args);
+ if (err >= 0) {
+ if (trace_on) {
+ printf("Command \"%s\" handled OK.\n", command);
+ }
+ } else {
+ printf("Error handling command \"%s\" : %d\n", command, err);
+ }
+ } else {
+ printf("No command given. use -h or --help for help on available commands.\n");
+ }
if (cmd_args != NULL) {