clean up tools folder
This commit is contained in:
1 parent
acdd263ca6
commit
a6c5651bd2
19 files changed
-3973
No files matched your search
@@ -1,56 +0,0 @@
|
||||
CC = gcc
|
||||
LD = gcc
|
||||
CFLAGS += -O0 -g3 -Wall -std=gnu99
|
||||
LIBS += -lusb-1.0
|
||||
OBJDIR = _build
|
||||
|
||||
|
||||
|
||||
ifeq ($(OS),Windows_NT)
|
||||
LIBS += -Llibusb-1.0
|
||||
BINFILE = bfutil.exe
|
||||
BINDIR := win32
|
||||
COPYDLL = cp libusb-1.0/libusb-1.0.dll $(BINDIR)/libusb-1.0.dll
|
||||
else
|
||||
BINFILE = bfutil
|
||||
COPYDLL =
|
||||
|
||||
OS := $(shell uname -s)
|
||||
ifeq ($(OS),Linux)
|
||||
ifeq ($(MBIT),32)
|
||||
BINDIR :=linux32
|
||||
CFLAGS +=-m32
|
||||
else
|
||||
LBITS := $(shell getconf LONG_BIT)
|
||||
ifeq ($(LBITS),64)
|
||||
BINDIR := linux64
|
||||
else
|
||||
BINDIR := linux32
|
||||
endif
|
||||
endif
|
||||
endif
|
||||
ifeq ($(OS),Darwin)
|
||||
BINDIR := macos
|
||||
endif
|
||||
endif
|
||||
|
||||
BINDIR := ../binaries/$(BINDIR)
|
||||
$(info $(BINDIR))
|
||||
|
||||
all: clean $(OBJDIR) bfutil
|
||||
|
||||
.PHONY: $(OBJDIR)
|
||||
$(OBJDIR):
|
||||
@mkdir -p $(OBJDIR)
|
||||
@mkdir -p $(BINDIR)
|
||||
|
||||
$(OBJDIR)/%.o: %.c
|
||||
$(CC) -c -o $@ $< $(CFLAGS)
|
||||
|
||||
bfutil: $(OBJDIR)/bfutil.o
|
||||
$(LD) -o $(BINDIR)/$(BINFILE) $^ $(CFLAGS) $(LIBS)
|
||||
$(COPYDLL)
|
||||
|
||||
clean:
|
||||
@rm -rf $(OBJDIR)
|
||||
@rm -f $(BINDIR)/$(BINFILE)
|
||||
@@ -1,313 +0,0 @@
|
||||
/**************************************************************************/
|
||||
/*!
|
||||
@file bfutil.c (Bluefruit Util)
|
||||
@author hathach (tinyusb.org)
|
||||
|
||||
@section LICENSE
|
||||
|
||||
Software License Agreement (BSD License)
|
||||
|
||||
Copyright (c) 2018, Adafruit Industries (adafruit.com)
|
||||
All rights reserved.
|
||||
|
||||
Redistribution and use in source and binary forms, with or without
|
||||
modification, are permitted provided that the following conditions are met:
|
||||
1. Redistributions of source code must retain the above copyright
|
||||
notice, this list of conditions and the following disclaimer.
|
||||
2. Redistributions in binary form must reproduce the above copyright
|
||||
notice, this list of conditions and the following disclaimer in the
|
||||
documentation and/or other materials provided with the distribution.
|
||||
3. Neither the name of the copyright holders nor the
|
||||
names of its contributors may be used to endorse or promote products
|
||||
derived from this software without specific prior written permission.
|
||||
|
||||
THIS SOFTWARE IS PROVIDED BY THE COPYRIGHT HOLDERS ''AS IS'' AND ANY
|
||||
EXPRESS OR IMPLIED WARRANTIES, INCLUDING, BUT NOT LIMITED TO, THE IMPLIED
|
||||
WARRANTIES OF MERCHANTABILITY AND FITNESS FOR A PARTICULAR PURPOSE ARE
|
||||
DISCLAIMED. IN NO EVENT SHALL THE COPYRIGHT HOLDER BE LIABLE FOR ANY
|
||||
DIRECT, INDIRECT, INCIDENTAL, SPECIAL, EXEMPLARY, OR CONSEQUENTIAL DAMAGES
|
||||
(INCLUDING, BUT NOT LIMITED TO, PROCUREMENT OF SUBSTITUTE GOODS OR SERVICES;
|
||||
LOSS OF USE, DATA, OR PROFITS; OR BUSINESS INTERRUPTION) HOWEVER CAUSED AND
|
||||
ON ANY THEORY OF LIABILITY, WHETHER IN CONTRACT, STRICT LIABILITY, OR TORT
|
||||
(INCLUDING NEGLIGENCE OR OTHERWISE) ARISING IN ANY WAY OUT OF THE USE OF THIS
|
||||
SOFTWARE, EVEN IF ADVISED OF THE POSSIBILITY OF SUCH DAMAGE.
|
||||
*/
|
||||
/**************************************************************************/
|
||||
|
||||
#include <stdbool.h>
|
||||
#include <stdint.h>
|
||||
#include <stdio.h>
|
||||
#include <stdlib.h>
|
||||
|
||||
#include <assert.h>
|
||||
#include <string.h>
|
||||
|
||||
#include "libusb-1.0/libusb.h"
|
||||
|
||||
#if defined(_WIN32)
|
||||
|
||||
#include <windows.h>
|
||||
static inline void sleep_ms(int ms)
|
||||
{
|
||||
Sleep(ms);
|
||||
}
|
||||
|
||||
|
||||
#else
|
||||
|
||||
#include <unistd.h>
|
||||
static inline void sleep_ms(int ms)
|
||||
{
|
||||
usleep(ms*1000);
|
||||
}
|
||||
|
||||
#endif
|
||||
|
||||
/*------------------------------------------------------------------*/
|
||||
/* MACRO TYPEDEF CONSTANT ENUM
|
||||
*------------------------------------------------------------------*/
|
||||
#define ASSERT(x) assert( (x) == LIBUSB_SUCCESS )
|
||||
|
||||
enum
|
||||
{
|
||||
RESET_DELAY = 1000, // 1 second delay
|
||||
RESET_MSC_DELAY = 2000, // MSC available require more time for USB to enumerate
|
||||
};
|
||||
|
||||
enum
|
||||
{
|
||||
ARDUINO_ADDR = 0x080C0000,
|
||||
FEATHERLIB_ADDR = 0x08010000
|
||||
};
|
||||
|
||||
enum
|
||||
{
|
||||
USB_VID = 0xcafe,
|
||||
USB_PID = 0x4011,
|
||||
|
||||
USB_PID_MSC = 0x8010,
|
||||
USB_DFU_PID = 0x0008,
|
||||
};
|
||||
|
||||
// SDEP Command Type
|
||||
enum
|
||||
{
|
||||
SDEP_MSGTYPE_COMMAND = 0x10,
|
||||
SDEP_MSGTYPE_RESPONSE = 0x20,
|
||||
SDEP_MSGTYPE_ALERT = 0x40,
|
||||
SDEP_MSGTYPE_ERROR = 0x80,
|
||||
};
|
||||
|
||||
// SDEP Command Constant
|
||||
enum
|
||||
{
|
||||
// General Purpose
|
||||
SDEP_CMD_RESET = 0x0001, // HW reset
|
||||
SDEP_CMD_FACTORYRESET = 0x0002, // Factory reset
|
||||
SDEP_CMD_DFU = 0x0003, // Enter DFU mode
|
||||
SDEP_CMD_INFO = 0x0004, // System information
|
||||
SDEP_CMD_NVM_RESET = 0x0005, // Reset DCT
|
||||
SDEP_CMD_ERROR_STRING = 0x0006, // Get descriptive error string
|
||||
SDEP_CMD_COMMAND_STRING = 0x0007, // Get descriptive SDEP command string
|
||||
SDEP_CMD_SFLASH_ERASEALL = 0x0008, // Erase SPI flash memory
|
||||
|
||||
// DEBUG Commands
|
||||
SDEP_CMD_STACKDUMP = 0x0300, // Dump the stack
|
||||
SDEP_CMD_STACKSIZE = 0x0301, // Get stack size
|
||||
SDEP_CMD_HEAPDUMP = 0x0302, // Dump the heap
|
||||
SDEP_CMD_HEAPSIZE = 0x0303, // Get heap size
|
||||
SDEP_CMD_THREADLIST_PRINT = 0x0304, // Get thread information
|
||||
SDEP_CMD_THREAD_INFO = 0x0305, // Get thread info
|
||||
SDEP_CMD_ARDUINO_HEAPSIZE = 0x0306, // Get Arduino heap size
|
||||
};
|
||||
|
||||
|
||||
/*------------------------------------------------------------------*/
|
||||
/* VARIABLE DECLARATION
|
||||
*------------------------------------------------------------------*/
|
||||
libusb_device_handle* udev = NULL;
|
||||
|
||||
bool _dfu_mode = false;
|
||||
bool _msc_enbled = false;
|
||||
|
||||
/*------------------------------------------------------------------*/
|
||||
/* FUNCTION DECLARATION
|
||||
*------------------------------------------------------------------*/
|
||||
void print_help(void);
|
||||
void sdep_syscmd(uint16_t cmd);
|
||||
|
||||
void arduino_upgrade(char* dfu_util, char* binfile);
|
||||
void featherlib_upgrade(char* dfu_util, char* binfile);
|
||||
|
||||
struct {
|
||||
const char* command;
|
||||
uint16_t sdep_cmdid;
|
||||
void (*func) (char*, char*);
|
||||
}cmd_table[] =
|
||||
{
|
||||
{ "arduino_upgrade" , 0 , arduino_upgrade },
|
||||
{ "enter_dfu" , SDEP_CMD_DFU , NULL },
|
||||
{ "erase_spiflash" , SDEP_CMD_SFLASH_ERASEALL , NULL },
|
||||
{ "factory_reset" , SDEP_CMD_FACTORYRESET , NULL },
|
||||
{ "featherlib_upgrade" , 0 , featherlib_upgrade },
|
||||
{ "info" , SDEP_CMD_INFO , NULL },
|
||||
{ "nvm_reset" , SDEP_CMD_NVM_RESET , NULL },
|
||||
{ "reboot" , SDEP_CMD_RESET , NULL },
|
||||
};
|
||||
|
||||
/*------------------------------------------------------------------*/
|
||||
/* IMPLEMENTATION
|
||||
*------------------------------------------------------------------*/
|
||||
int main(int argc, char *argv[])
|
||||
{
|
||||
char* command = argv[1];
|
||||
|
||||
if ( argc <= 1 || (!strcmp("--help", command)) )
|
||||
{
|
||||
print_help();
|
||||
return 0;
|
||||
}
|
||||
|
||||
ASSERT( libusb_init(NULL) );
|
||||
|
||||
// Open device, try with all PIDs
|
||||
udev = libusb_open_device_with_vid_pid(NULL, USB_VID, USB_PID);
|
||||
|
||||
if (!udev)
|
||||
{
|
||||
udev = libusb_open_device_with_vid_pid(NULL, USB_VID, USB_PID_MSC);
|
||||
if (udev) _msc_enbled = true;
|
||||
}
|
||||
|
||||
if (!udev)
|
||||
{
|
||||
udev = libusb_open_device_with_vid_pid(NULL, USB_VID, USB_DFU_PID);
|
||||
if(udev) _dfu_mode = true;
|
||||
}
|
||||
|
||||
if (!udev)
|
||||
{
|
||||
printf("Bluefruit Feather Board is not detected !!!\n");
|
||||
return 0;
|
||||
}
|
||||
|
||||
printf("Bluefruit Feather Board opened !!!\n");
|
||||
return 0;
|
||||
|
||||
for(int i=0; i<sizeof(cmd_table)/sizeof(cmd_table[0]); i++)
|
||||
{
|
||||
if (!strcmp(cmd_table[i].command, command))
|
||||
{
|
||||
// Execute SDEP commnad by ID
|
||||
if ( cmd_table[i].sdep_cmdid )
|
||||
{
|
||||
// skip if command is ENTER_DFU and we are already in dfu mode
|
||||
if ( !((cmd_table[i].sdep_cmdid == SDEP_CMD_DFU) && _dfu_mode) )
|
||||
{
|
||||
sdep_syscmd(cmd_table[i].sdep_cmdid);
|
||||
}
|
||||
}
|
||||
// Execute function by pointer
|
||||
else if ( cmd_table[i].func )
|
||||
{
|
||||
// cmd_table[i].func();
|
||||
}else
|
||||
{
|
||||
assert(0);
|
||||
}
|
||||
|
||||
break;
|
||||
}
|
||||
}
|
||||
|
||||
// close usb if not closed already
|
||||
if (udev)
|
||||
{
|
||||
libusb_close(udev);
|
||||
libusb_exit(NULL);
|
||||
}
|
||||
|
||||
return 0;
|
||||
}
|
||||
|
||||
/*------------------------------------------------------------------*/
|
||||
/*
|
||||
*------------------------------------------------------------------*/
|
||||
|
||||
void sdep_syscmd(uint16_t cmd)
|
||||
{
|
||||
assert( cmd <= SDEP_CMD_SFLASH_ERASEALL);
|
||||
|
||||
ASSERT( libusb_control_transfer(udev, 0x40, SDEP_MSGTYPE_COMMAND, cmd, 0, NULL, 0, 0) );
|
||||
|
||||
// For system commands, only INFO has response data
|
||||
if ( cmd == SDEP_CMD_INFO )
|
||||
{
|
||||
char info[512] = { 0 };
|
||||
int len;
|
||||
|
||||
sleep_ms(100);
|
||||
len = libusb_control_transfer(udev, 0xC0, SDEP_MSGTYPE_RESPONSE, cmd, 0, (unsigned char*) info, sizeof(info), 0);
|
||||
|
||||
if ( len <= 0 )
|
||||
{
|
||||
printf("error = %d\n", len);
|
||||
}else
|
||||
{
|
||||
printf("%s\n", info+4);
|
||||
}
|
||||
}
|
||||
}
|
||||
|
||||
void download_bin(char* dfu_util, char* binfile, uint32_t addr)
|
||||
{
|
||||
// Enter DFU mode first
|
||||
if (!_dfu_mode)
|
||||
{
|
||||
sdep_syscmd(SDEP_CMD_DFU);
|
||||
|
||||
// Close libusb since dfu-util need to access to upload
|
||||
libusb_close(udev);
|
||||
libusb_exit(NULL);
|
||||
udev = NULL;
|
||||
|
||||
sleep_ms(RESET_DELAY);
|
||||
}
|
||||
|
||||
char cmd[1024];
|
||||
sprintf(cmd, "%s -d 0x239A:0x0008 -a 0 -s 0x%08X:leave -D \"%s\"", dfu_util, addr, binfile);
|
||||
|
||||
system(cmd);
|
||||
|
||||
// Also print out the dfu-util command for debug purpose
|
||||
puts("Flash command");
|
||||
puts(cmd);
|
||||
|
||||
// Delay a bit before return, otherwise enumeration time will cause
|
||||
// Arduino IDE fails to re-open Serial
|
||||
sleep_ms ( _msc_enbled ? RESET_MSC_DELAY : RESET_DELAY );
|
||||
}
|
||||
|
||||
void arduino_upgrade(char* dfu_util, char* binfile)
|
||||
{
|
||||
download_bin(dfu_util, binfile, ARDUINO_ADDR);
|
||||
}
|
||||
|
||||
void featherlib_upgrade(char* dfu_util, char* binfile)
|
||||
{
|
||||
download_bin(dfu_util, binfile, FEATHERLIB_ADDR);
|
||||
}
|
||||
|
||||
|
||||
void print_help(void)
|
||||
{
|
||||
printf("Usage: feather_dfu.py [OPTIONS] COMMAND [ARGS]...\n\n");
|
||||
printf("Options:\n");
|
||||
printf(" --help Show this message and exit.\n\n");
|
||||
|
||||
printf("Commands:\n");
|
||||
// printf(" enter_dfu Force board into DFU mode.\n");
|
||||
printf(" factory_reset Perform a factory reset of the board.\n");
|
||||
printf(" info Print information about the connected board.\n");
|
||||
printf(" reboot Perform a reboot/reset of the board.\n");
|
||||
}
|
||||
@@ -1,61 +0,0 @@
|
||||
libusb 1.0 Windows binary snapshot - README
|
||||
|
||||
*********************************************************************
|
||||
* The latest version of this snapshot can always be downloaded at: *
|
||||
* https://sourceforge.net/projects/libusb/files/ *
|
||||
*********************************************************************
|
||||
|
||||
o Visual Studio:
|
||||
- Open existing or create a new project for your application
|
||||
- Copy libusb.h, from the include\libusb-1.0\ directory, into your project and
|
||||
make sure that the location where the file reside appears in the 'Additional
|
||||
Include Directories' section (Configuration Properties -> C/C++ -> General).
|
||||
- Copy the relevant .lib file from MS32\ or MS64\ and add 'libusb-1.0.lib' to
|
||||
your 'Additional Dependencies' (Configuration Properties -> Linker -> Input)
|
||||
Also make sure that the directory where libusb-1.0.lib resides is added to
|
||||
'Additional Library Directories' (Configuration Properties -> Linker
|
||||
-> General)
|
||||
- If you use the static version of the libusb library, make sure that
|
||||
'Runtime Library' is set to 'Multi-threaded DLL (/MD)' (Configuration
|
||||
Properties -> C/C++ -> Code Generation).
|
||||
NB: If your application requires /MT (Multi-threaded/libCMT), you need to
|
||||
recompile a static libusb 1.0 library from source.
|
||||
- Compile and run your application. If you use the DLL version of libusb-1.0,
|
||||
remember that you need to have a copy of the DLL either in the runtime
|
||||
directory or in system32
|
||||
|
||||
o WDK/DDK:
|
||||
- The following is an example of a sources files that you can use to compile
|
||||
a libusb 1.0 based console application. In this sample ..\libusb\ is the
|
||||
directory where you would have copied libusb.h as well as the relevant
|
||||
libusb-1.0.lib
|
||||
|
||||
TARGETNAME=your_app
|
||||
TARGETTYPE=PROGRAM
|
||||
USE_MSVCRT=1
|
||||
UMTYPE=console
|
||||
INCLUDES=..\libusb;$(DDK_INC_PATH)
|
||||
TARGETLIBS=..\libusb\libusb-1.0.lib
|
||||
SOURCES=your_app.c
|
||||
|
||||
- Note that if you plan to use libCMT instead of MSVCRT (USE_LIBCMT=1 instead
|
||||
of USE_MSVCRT=1), you will need to recompile libusb to use libCMT. This can
|
||||
easily be achieved, in the DDK environment, by running 'ddk_build /MT'
|
||||
|
||||
o MinGW/cygwin
|
||||
- Copy libusb.h, from include/libusb-1.0/ to your default include directory,
|
||||
and copy the MinGW32/ or MinGW64/ .a files to your default library directory.
|
||||
Or, if you don't want to use the default locations, make sure that you feed
|
||||
the relevant -I and -L options to the compiler.
|
||||
- Add the '-lusb-1.0' linker option when compiling.
|
||||
|
||||
o Additional information:
|
||||
- The libusb 1.0 API documentation can be accessed at:
|
||||
http://api.libusb.info
|
||||
- For some libusb samples (including source), please have a look in examples/
|
||||
- For additional information on the libusb 1.0 Windows backend please visit:
|
||||
http://windows.libusb.info
|
||||
- The MinGW and MS generated DLLs are fully interchangeable, provided that you
|
||||
use the import libs provided or generate one from the .def also provided.
|
||||
- If you find any issue, please visit http://libusb.info/ and check the
|
||||
Support section
|
||||
Binary file not shown.
Binary file not shown.
File diff suppressed because it is too large.
Load diff
@@ -1,26 +0,0 @@
|
||||
TARGET = bootutil
|
||||
CC = gcc
|
||||
CFLAGS = -g -Wall
|
||||
ifneq ($(OS),Windows_NT) # ncurses support limited to *NIX for now
|
||||
LIBS = -lncurses
|
||||
endif
|
||||
|
||||
.PHONY: default all clean
|
||||
|
||||
default: $(TARGET)
|
||||
all: default
|
||||
|
||||
OBJECTS = $(patsubst %.c, %.o, $(wildcard *.c))
|
||||
HEADERS = $(wildcard *.h)
|
||||
|
||||
%.o: %.c $(HEADERS)
|
||||
$(CC) $(CFLAGS) -c $< -o $@
|
||||
|
||||
.PRECIOUS: $(TARGET) $(OBJECTS)
|
||||
|
||||
$(TARGET): $(OBJECTS)
|
||||
$(CC) $(OBJECTS) -Wall -o $@ $(LIBS)
|
||||
|
||||
clean:
|
||||
-rm -f *.o
|
||||
-rm -f $(TARGET)
|
||||
Binary file not shown.
Binary file not shown.
Binary file not shown.
@@ -1,72 +0,0 @@
|
||||
#include <stdio.h>
|
||||
#include <string.h>
|
||||
#include <errno.h>
|
||||
#include <ctype.h>
|
||||
#include "commands.h"
|
||||
#include "serialport.h"
|
||||
#include "infohelper.h"
|
||||
|
||||
extern int g_bootutil_gui_mode; /* Defined in main.c */
|
||||
|
||||
/*
|
||||
static int
|
||||
commands_stol(char *param_val, long min, long max, long *output, uint8_t b)
|
||||
{
|
||||
char *endptr;
|
||||
long lval;
|
||||
|
||||
if ((b != 10) && (b != 16)) {
|
||||
return EINVAL;
|
||||
}
|
||||
|
||||
lval = strtol(param_val, &endptr, b);
|
||||
if (param_val != '\0' && *endptr == '\0' &&
|
||||
lval >= min && lval <= max) {
|
||||
*output = lval;
|
||||
} else {
|
||||
return EINVAL;
|
||||
}
|
||||
|
||||
return 0;
|
||||
}
|
||||
*/
|
||||
|
||||
static int
|
||||
commands_err_unknown_arg(char *arg_name)
|
||||
{
|
||||
LOGERR("unknown argument \"%s\"\n",
|
||||
arg_name);
|
||||
return EINVAL;
|
||||
}
|
||||
|
||||
int
|
||||
commands_cmd_reset(void)
|
||||
{
|
||||
/* Can't log data with -g option since stdout use kills ncurses */
|
||||
if (g_bootutil_gui_mode == 0) {
|
||||
LOGINFO("attempting to reset (toggling DTR)\n");
|
||||
}
|
||||
|
||||
/* Toggle the DTR line to provoke a reset */
|
||||
serialport_set_dtr(1);
|
||||
serialport_set_dtr(0);
|
||||
|
||||
return 0;
|
||||
}
|
||||
|
||||
int
|
||||
commands_parse(char *argv)
|
||||
{
|
||||
int i = 0;
|
||||
|
||||
while(argv[i]) {
|
||||
argv[i] = tolower(argv[i]);
|
||||
i++;
|
||||
}
|
||||
|
||||
if (strcmp(argv, "reset") == 0) {
|
||||
return commands_cmd_reset();
|
||||
} else {
|
||||
return commands_err_unknown_arg(argv);
|
||||
}
|
||||
}
|
||||
@@ -1,7 +0,0 @@
|
||||
#ifndef __COMMANDS_H__
|
||||
#define __COMMANDS_H__
|
||||
|
||||
int commands_cmd_reset(void);
|
||||
int commands_parse(char *argv);
|
||||
|
||||
#endif
|
||||
@@ -1,334 +0,0 @@
|
||||
#ifndef _WIN32
|
||||
|
||||
#include <string.h>
|
||||
#include <stdlib.h>
|
||||
#include <unistd.h>
|
||||
#include <curses.h>
|
||||
#include "infohelper.h"
|
||||
#include "commands.h"
|
||||
|
||||
enum gui_action {
|
||||
GUI_ACTION_ABOUT = 0,
|
||||
GUI_ACTION_RESET,
|
||||
GUI_ACTION_EXIT,
|
||||
GUI_ACTION_NONE = 0xFF,
|
||||
};
|
||||
|
||||
struct gui_frame_cfg {
|
||||
int x;
|
||||
int y;
|
||||
int w;
|
||||
int h;
|
||||
int titlebar;
|
||||
int colorpair;
|
||||
};
|
||||
|
||||
/* Advanced prototypes for command handler functions */
|
||||
int gui_handler_about(void);
|
||||
int gui_handler_reset(void);
|
||||
|
||||
static const struct {
|
||||
const char *name;
|
||||
const char shortcut;
|
||||
const enum gui_action action;
|
||||
int (*handler)(void);
|
||||
} gui_menu_items[] = {
|
||||
{ "About", '?', GUI_ACTION_ABOUT, gui_handler_about },
|
||||
{ "Reset Device", 'r', GUI_ACTION_RESET, gui_handler_reset },
|
||||
{ "Exit", 'X', GUI_ACTION_EXIT, NULL },
|
||||
{ NULL, '\0', GUI_ACTION_NONE, NULL }
|
||||
};
|
||||
|
||||
static volatile int g_gui_menu_item_count = 0;
|
||||
|
||||
int
|
||||
gui_handler_about(void) {
|
||||
printw("About Adafruit nRF52 bootutil!\n");
|
||||
return 0;
|
||||
}
|
||||
|
||||
int
|
||||
gui_handler_reset(void) {
|
||||
printw("Resetting the nRF52 (toggling DTR)\n");
|
||||
commands_cmd_reset();
|
||||
return 0;
|
||||
}
|
||||
|
||||
static void
|
||||
gui_config(void)
|
||||
{
|
||||
/* Disable line buffering (to avoid waiting for enter key) */
|
||||
raw();
|
||||
/* Enable color functionality */
|
||||
start_color();
|
||||
/* Enable F1, F2, etc. */
|
||||
keypad(stdscr, TRUE);
|
||||
/* Dont echo in getch (avoids garbage output on special keys) */
|
||||
noecho();
|
||||
/* Setup color pairs */
|
||||
init_pair(1, COLOR_CYAN, COLOR_BLACK);
|
||||
init_pair(2, COLOR_BLACK, COLOR_BLACK);
|
||||
init_pair(3, COLOR_WHITE, COLOR_BLUE);
|
||||
/* Hide the cursor by default */
|
||||
curs_set(0);
|
||||
}
|
||||
|
||||
static void
|
||||
gui_draw_frame(WINDOW *win, const struct gui_frame_cfg *cfg)
|
||||
{
|
||||
int i, hpad;
|
||||
|
||||
if ((cfg->x < 0) || (cfg->y < 0)) {
|
||||
return;
|
||||
}
|
||||
|
||||
if ((!cfg->w) || (!cfg->h)) {
|
||||
return;
|
||||
}
|
||||
|
||||
/* Check if we need hpadding for the titlebar */
|
||||
hpad = cfg->titlebar ? 2 : 0;
|
||||
|
||||
/* Set the frame colors */
|
||||
if (cfg->colorpair > 0) {
|
||||
attron(COLOR_PAIR(cfg->colorpair));
|
||||
}
|
||||
|
||||
/* Top bar */
|
||||
wmove(win, cfg->y, cfg->x);
|
||||
addch(ACS_ULCORNER);
|
||||
for (i=0;i<cfg->w;i++) {
|
||||
addch(ACS_HLINE);
|
||||
}
|
||||
addch(ACS_URCORNER);
|
||||
|
||||
/* Title section if requested */
|
||||
if (cfg->titlebar) {
|
||||
wmove(win, cfg->y+1, cfg->x);
|
||||
addch(ACS_VLINE);
|
||||
wmove(win, cfg->y+1, cfg->x+cfg->w+1);
|
||||
addch(ACS_VLINE);
|
||||
wmove(win, cfg->y+2, cfg->x);
|
||||
addch(ACS_LTEE);
|
||||
for (i=0;i<cfg->w;i++) {
|
||||
addch(ACS_HLINE);
|
||||
}
|
||||
addch(ACS_RTEE);
|
||||
}
|
||||
|
||||
/* Middle lines */
|
||||
for (i=0;i<cfg->h;i++) {
|
||||
wmove(win, cfg->y+i+hpad+1, cfg->x);
|
||||
addch(ACS_VLINE);
|
||||
wmove(win, cfg->y+i+hpad+1, cfg->x+cfg->w+1);
|
||||
addch(ACS_VLINE);
|
||||
}
|
||||
|
||||
/* Bottom bar */
|
||||
wmove(win,cfg-> y+cfg->h+hpad+1, cfg->x);
|
||||
addch(ACS_LLCORNER);
|
||||
for (i=0;i<cfg->w;i++) {
|
||||
addch(ACS_HLINE);
|
||||
}
|
||||
addch(ACS_LRCORNER);
|
||||
|
||||
/* Clear the frame colors */
|
||||
if (cfg->colorpair > 0) {
|
||||
attroff(COLOR_PAIR(cfg->colorpair));
|
||||
}
|
||||
|
||||
wrefresh(win);
|
||||
}
|
||||
|
||||
static void
|
||||
gui_menu_print(WINDOW *win, int highlight)
|
||||
{
|
||||
int rows, cols;
|
||||
int x, y, i;
|
||||
|
||||
/* Get the window dimenstions */
|
||||
getmaxyx(stdscr, rows, cols);
|
||||
|
||||
/* Draw some borders */
|
||||
struct gui_frame_cfg cfg = {
|
||||
.x = 0,
|
||||
.y = 0,
|
||||
.w = cols-2,
|
||||
.h = rows-2,
|
||||
.titlebar = false,
|
||||
.colorpair = 0
|
||||
};
|
||||
gui_draw_frame(win, &cfg);
|
||||
|
||||
//box(win, 0, 0);
|
||||
|
||||
/* Add the title */
|
||||
char *title = "Adafruit nRF52 Bootloader Utility";
|
||||
attron(COLOR_PAIR(1));
|
||||
attron(A_BOLD);
|
||||
mvprintw(2, (cols-strlen(title))/2, "%s", title);
|
||||
attroff(A_BOLD);
|
||||
attroff(COLOR_PAIR(1));
|
||||
|
||||
/* Set the menu item start position */
|
||||
y = 4;
|
||||
x = (cols-strlen(title))/2;
|
||||
wmove(win, y, x);
|
||||
|
||||
if (highlight > g_gui_menu_item_count) {
|
||||
highlight = 0;
|
||||
}
|
||||
|
||||
for(i = 0; i < g_gui_menu_item_count; ++i) {
|
||||
/* Print the menu item name */
|
||||
if(highlight == i + 1) {
|
||||
wattron(win, A_REVERSE);
|
||||
mvwprintw(win, y, x, "%s", gui_menu_items[i].name);
|
||||
wattroff(win, A_REVERSE);
|
||||
} else {
|
||||
mvwprintw(win, y, x, "%s", gui_menu_items[i].name);
|
||||
}
|
||||
/* Print the shortcut */
|
||||
if (gui_menu_items[i].shortcut != '\0') {
|
||||
printw(" [");
|
||||
attron(A_BOLD);
|
||||
printw("%c", gui_menu_items[i].shortcut);
|
||||
attroff(A_BOLD);
|
||||
printw("]");
|
||||
}
|
||||
++y;
|
||||
}
|
||||
|
||||
/* Change the cursor to displat any debug output at a safe location*/
|
||||
wmove(win, 5 + g_gui_menu_item_count, x);
|
||||
wrefresh(win);
|
||||
}
|
||||
|
||||
int
|
||||
gui_init(const char *ttyname)
|
||||
{
|
||||
int i;
|
||||
int ch;
|
||||
int selected_menu_item;
|
||||
int execute_menu_item;
|
||||
int rows, cols;
|
||||
WINDOW * mainwin;
|
||||
|
||||
/* Init ncurses window */
|
||||
if ( (mainwin = initscr()) == NULL ) {
|
||||
LOGERR("error initialising ncurses.\n");
|
||||
exit(EXIT_FAILURE);
|
||||
}
|
||||
|
||||
/* Setup the core window properties */
|
||||
gui_config();
|
||||
|
||||
/* Count the total menu items */
|
||||
g_gui_menu_item_count = -1;
|
||||
while (gui_menu_items[++g_gui_menu_item_count].action != GUI_ACTION_NONE) {
|
||||
}
|
||||
|
||||
if (g_gui_menu_item_count < 1) {
|
||||
LOGERR("No menu items defined\n");
|
||||
return EXIT_FAILURE;
|
||||
}
|
||||
|
||||
/* Get the window dimenstions */
|
||||
getmaxyx(stdscr, rows, cols);
|
||||
|
||||
/* Show the TTY/Serial port */
|
||||
attron(COLOR_PAIR(2));
|
||||
attron(A_BOLD);
|
||||
mvprintw(rows-4, (cols-strlen(ttyname))/2, "%s", ttyname);
|
||||
attroff(A_BOLD);
|
||||
attroff(COLOR_PAIR(2));
|
||||
|
||||
/* Help message on navigation */
|
||||
char *dataentry = "Use the arrow or shortcut keys to continue, 'X' to exit";
|
||||
attron(COLOR_PAIR(1));
|
||||
attron(A_BOLD);
|
||||
mvprintw(rows-3, (cols-strlen(dataentry))/2, "%s", dataentry);
|
||||
attroff(A_BOLD);
|
||||
attroff(COLOR_PAIR(1));
|
||||
|
||||
/* Render the menu */
|
||||
selected_menu_item = 1;
|
||||
gui_menu_print(mainwin, selected_menu_item);
|
||||
|
||||
/* Check input until we get an exit request */
|
||||
while(1) {
|
||||
ch = getch();
|
||||
execute_menu_item = -1;
|
||||
switch(ch) {
|
||||
case KEY_F(1):
|
||||
break;
|
||||
case KEY_LEFT:
|
||||
selected_menu_item--;
|
||||
break;
|
||||
case KEY_RIGHT:
|
||||
selected_menu_item++;
|
||||
break;
|
||||
case KEY_UP:
|
||||
selected_menu_item--;
|
||||
break;
|
||||
case KEY_DOWN:
|
||||
selected_menu_item++;
|
||||
break;
|
||||
case 10: /* ENTER */
|
||||
execute_menu_item = selected_menu_item-1;
|
||||
break;
|
||||
case 'Z':
|
||||
goto cleanup;
|
||||
break;
|
||||
default:
|
||||
/* Check for hotkeys */
|
||||
for (i=0;i<g_gui_menu_item_count;i++) {
|
||||
if (ch == gui_menu_items[i].shortcut) {
|
||||
execute_menu_item = i;
|
||||
}
|
||||
}
|
||||
break;
|
||||
}
|
||||
|
||||
/* Check if we should execute an action */
|
||||
if (execute_menu_item != -1) {
|
||||
if (gui_menu_items[execute_menu_item].action != GUI_ACTION_NONE) {
|
||||
if (gui_menu_items[execute_menu_item].handler != NULL) {
|
||||
attron(COLOR_PAIR(2));
|
||||
attron(A_BOLD);
|
||||
gui_menu_items[execute_menu_item].handler();
|
||||
attroff(A_BOLD);
|
||||
attroff(COLOR_PAIR(2));
|
||||
wrefresh(mainwin);
|
||||
}
|
||||
}
|
||||
if (gui_menu_items[execute_menu_item].action == GUI_ACTION_EXIT) {
|
||||
goto cleanup;
|
||||
}
|
||||
}
|
||||
|
||||
/* Check menu boundaries */
|
||||
if (selected_menu_item < 1) {
|
||||
selected_menu_item = 1;
|
||||
}
|
||||
if (selected_menu_item > g_gui_menu_item_count) {
|
||||
selected_menu_item = g_gui_menu_item_count;
|
||||
}
|
||||
|
||||
/* Re-render the menu with the new menu item */
|
||||
gui_menu_print(mainwin, selected_menu_item);
|
||||
|
||||
/* Update the display */
|
||||
refresh();
|
||||
}
|
||||
|
||||
cleanup:
|
||||
/* Clean up after ourselves */
|
||||
delwin(mainwin);
|
||||
endwin();
|
||||
refresh();
|
||||
|
||||
return EXIT_SUCCESS;
|
||||
}
|
||||
|
||||
#endif /* _WIN32 */
|
||||
@@ -1,10 +0,0 @@
|
||||
#ifndef __GUI_H__
|
||||
#define __GUI_H__
|
||||
|
||||
#ifndef _WIN32
|
||||
|
||||
int gui_init(const char *ttyname);
|
||||
|
||||
#endif /* _WIN32 */
|
||||
|
||||
#endif
|
||||
@@ -1,92 +0,0 @@
|
||||
/**********************************************************************************
|
||||
**********************************************************************************
|
||||
***
|
||||
*** infohelper.c
|
||||
*** - implementation of a crude verbosity-controllabe info system
|
||||
***
|
||||
*** Copyright (C) 2014 Christian Klippel <ck@atelier-klippel.de>
|
||||
***
|
||||
*** 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.
|
||||
***
|
||||
*** This program is distributed in the hope that it will be useful,
|
||||
*** but WITHOUT ANY WARRANTY; without even the implied warranty of
|
||||
*** MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the
|
||||
*** GNU General Public License for more details.
|
||||
***
|
||||
*** You should have received a copy of the GNU General Public License along
|
||||
*** with this program; if not, write to the Free Software Foundation, Inc.,
|
||||
*** 51 Franklin Street, Fifth Floor, Boston, MA 02110-1301 USA.
|
||||
***
|
||||
**/
|
||||
|
||||
#include <stdio.h>
|
||||
#include <stdarg.h>
|
||||
#include "infohelper.h"
|
||||
|
||||
static char infolevel = 0;
|
||||
|
||||
void infohelper_set_infolevel(char lvl)
|
||||
{
|
||||
infolevel = lvl;
|
||||
}
|
||||
|
||||
void infohelper_increase_infolevel(void)
|
||||
{
|
||||
if(infolevel < 20)
|
||||
{
|
||||
infolevel++;
|
||||
}
|
||||
}
|
||||
|
||||
void infohelper_set_argverbosity(int num_args, char **arg_ptr)
|
||||
{
|
||||
char *cur_arg;
|
||||
|
||||
while(num_args--)
|
||||
{
|
||||
cur_arg = arg_ptr[num_args];
|
||||
|
||||
if(*cur_arg++ == '-')
|
||||
{
|
||||
if(*cur_arg == 'q')
|
||||
{
|
||||
infolevel = 0;
|
||||
return;
|
||||
}
|
||||
else while(*cur_arg++ == 'v')
|
||||
{
|
||||
infolevel++;
|
||||
}
|
||||
}
|
||||
}
|
||||
}
|
||||
|
||||
void infohelper_output(int loglevel, const char* format, ...)
|
||||
{
|
||||
if (infolevel < loglevel)
|
||||
return;
|
||||
const char* log_level_names[] = {"Error: ", "Warning: ", "", "\t", "\t\t"};
|
||||
const int log_level_names_count = sizeof(log_level_names) / sizeof(const char*);
|
||||
if (loglevel >= log_level_names_count)
|
||||
loglevel = log_level_names_count - 1;
|
||||
|
||||
va_list v;
|
||||
printf("%s", log_level_names[loglevel]);
|
||||
va_start(v, format);
|
||||
vprintf(format, v);
|
||||
va_end(v);
|
||||
printf("\n");
|
||||
}
|
||||
|
||||
void infohelper_output_plain(int loglevel, const char* format, ...)
|
||||
{
|
||||
if (infolevel < loglevel)
|
||||
return;
|
||||
va_list v;
|
||||
va_start(v, format);
|
||||
vprintf(format, v);
|
||||
va_end(v);
|
||||
}
|
||||
@@ -1,60 +0,0 @@
|
||||
/**********************************************************************************
|
||||
**********************************************************************************
|
||||
***
|
||||
*** infohelper.h
|
||||
*** - defines and prototypes for a crude verbositiy-controllabe info output
|
||||
***
|
||||
*** Copyright (C) 2014 Christian Klippel <ck@atelier-klippel.de>
|
||||
***
|
||||
*** 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.
|
||||
***
|
||||
*** This program is distributed in the hope that it will be useful,
|
||||
*** but WITHOUT ANY WARRANTY; without even the implied warranty of
|
||||
*** MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the
|
||||
*** GNU General Public License for more details.
|
||||
***
|
||||
*** You should have received a copy of the GNU General Public License along
|
||||
*** with this program; if not, write to the Free Software Foundation, Inc.,
|
||||
*** 51 Franklin Street, Fifth Floor, Boston, MA 02110-1301 USA.
|
||||
***
|
||||
**/
|
||||
|
||||
#ifndef INFOHELPER_H
|
||||
#define INFOHELPER_H
|
||||
|
||||
|
||||
/*
|
||||
** set verbositiy level
|
||||
** 0 = only error messages
|
||||
** 1 = warnings
|
||||
** 2 = information messages (default)
|
||||
** 3 = debugging info
|
||||
** 4 = extra debugging info
|
||||
*/
|
||||
void infohelper_set_infolevel(char lvl);
|
||||
|
||||
/*
|
||||
** increase verbositylevel by 1
|
||||
*/
|
||||
void infohelper_increase_infolevel(void);
|
||||
|
||||
/*
|
||||
** set verbosity level according to arguments given
|
||||
*/
|
||||
void infohelper_set_argverbosity(int num_args, char **arg_ptr);
|
||||
|
||||
void infohelper_output(int loglevel, const char* format, ...);
|
||||
void infohelper_output_plain(int loglevel, const char* format, ...);
|
||||
|
||||
#define LOGERR(...) infohelper_output(0, __VA_ARGS__)
|
||||
#define LOGWARN(...) infohelper_output(1, __VA_ARGS__)
|
||||
#define LOGINFO(...) infohelper_output(2, __VA_ARGS__)
|
||||
#define LOGDEBUG(...) infohelper_output(3, __VA_ARGS__)
|
||||
#define LOGVERBOSE(...) infohelper_output(4, __VA_ARGS__)
|
||||
|
||||
#define INFO(...) infohelper_output_plain(0, __VA_ARGS__)
|
||||
|
||||
#endif
|
||||
@@ -1,227 +0,0 @@
|
||||
#include <stdio.h>
|
||||
#include <stdlib.h>
|
||||
#include <string.h>
|
||||
#include <errno.h>
|
||||
#include <unistd.h>
|
||||
#include <limits.h>
|
||||
#include "serialport.h"
|
||||
#include "infohelper.h"
|
||||
#include "commands.h"
|
||||
#ifndef _WIN32
|
||||
#include "gui.h"
|
||||
#endif
|
||||
|
||||
#define BOOTUTIL_VER_MAJOR (0U)
|
||||
#define BOOTUTIL_VER_MINOR (0U)
|
||||
#define BOOTUTIL_VER_REVISION (1U)
|
||||
|
||||
volatile int g_bootutil_serport_open = 0;
|
||||
volatile int g_bootutil_gui_mode = 0;
|
||||
|
||||
static int
|
||||
bootutil_err_too_many_instances(char *arg_name)
|
||||
{
|
||||
LOGERR("multiple instances of \"%s\"\n",
|
||||
arg_name);
|
||||
return EINVAL;
|
||||
}
|
||||
|
||||
static int
|
||||
bootutil_err_missing_arg(char *arg_name)
|
||||
{
|
||||
LOGERR("missing argument \"%s\"\n",
|
||||
arg_name);
|
||||
return EINVAL;
|
||||
}
|
||||
|
||||
static int
|
||||
bootutil_err_missing_value(char *arg_name)
|
||||
{
|
||||
LOGERR("missing value for argument \"%s\"\n",
|
||||
arg_name);
|
||||
return EINVAL;
|
||||
}
|
||||
|
||||
static void
|
||||
bootutil_help(int rc)
|
||||
{
|
||||
printf("Bootloader utility for the Adafruit nRF52 board family.\n");
|
||||
printf("Version: %u.%u.%u\n", BOOTUTIL_VER_MAJOR,
|
||||
BOOTUTIL_VER_MINOR,
|
||||
BOOTUTIL_VER_REVISION);
|
||||
printf("\n");
|
||||
#ifdef _WIN32
|
||||
printf("Usage: bootutil.exe -d <TTY.DEVICE> [-c <cmd>] [-ghrv]\n");
|
||||
#else
|
||||
printf("Usage: bootutil -d <TTY.DEVICE> [-c <cmd>] [-hrv]\n");
|
||||
#endif
|
||||
printf("\n");
|
||||
printf(" -d <TTY.DEVICE> : serial/tty port name (mandatory)\n");
|
||||
printf(" -c <cmd> : execute the specified command\n");
|
||||
printf(" reset : perform a system reset (toggle DTR)\n");
|
||||
#ifndef _WIN32
|
||||
printf(" -g : show GUI\n");
|
||||
#endif
|
||||
printf(" -h : show help\n");
|
||||
printf(" -r : perform a system reset (toggle DTR)\n");
|
||||
printf(" -v : verbose output\n");
|
||||
printf("\n");
|
||||
#ifdef _WIN32
|
||||
printf("Ex: $ bootutil.exe -d COM14 -r\n");
|
||||
#else
|
||||
printf("Ex: $ bootutil -d /dev/tty.SLAB_USBtoUART -r\n");
|
||||
#endif
|
||||
|
||||
exit(rc);
|
||||
}
|
||||
|
||||
static int
|
||||
bootutil_serport_open(char *argv)
|
||||
{
|
||||
int serport;
|
||||
|
||||
serport = serialport_open(argv, 115200);
|
||||
if (serport != 0) {
|
||||
g_bootutil_serport_open = 1;
|
||||
}
|
||||
|
||||
return 0;
|
||||
}
|
||||
|
||||
static int
|
||||
bootutil_serport_close(void)
|
||||
{
|
||||
int rc;
|
||||
|
||||
rc = serialport_close();
|
||||
g_bootutil_serport_open = 0;
|
||||
|
||||
return rc;
|
||||
}
|
||||
|
||||
int
|
||||
main(int argc, char **argv)
|
||||
{
|
||||
int ch;
|
||||
int rc = -1;
|
||||
int ttyflag = 0;
|
||||
int rstflag = 0;
|
||||
int cmdflag = 0;
|
||||
int vrbflag = 0;
|
||||
char cmd[256];
|
||||
char tty[PATH_MAX + NAME_MAX];
|
||||
|
||||
memset(cmd, '\0', sizeof(cmd));
|
||||
memset(tty, '\0', sizeof(cmd));
|
||||
|
||||
/* Display help menu on zero params or '?' */
|
||||
if (argc == 1) {
|
||||
bootutil_help(0);
|
||||
}
|
||||
if ((argc == 2) && (strcmp(argv[1], "?") == 0)) {
|
||||
bootutil_help(0);
|
||||
}
|
||||
|
||||
/* Parse input params */
|
||||
while ((ch = getopt(argc, argv, "d:c:ghrv")) != -1) {
|
||||
switch (ch) {
|
||||
case 'd':
|
||||
/* Make sure we have a valid command (isn't another param) */
|
||||
if (optarg[0] == '-') {
|
||||
rc = bootutil_err_missing_value("-d");
|
||||
goto error;
|
||||
}
|
||||
ttyflag = 1;
|
||||
strncpy(tty, optarg, sizeof(tty)-1);
|
||||
break;
|
||||
case 'c':
|
||||
/* Check if we've already received a command */
|
||||
if (cmdflag == 1) {
|
||||
exit(bootutil_err_too_many_instances("-c"));
|
||||
}
|
||||
/* Make sure we have a valid command (isn't another param) */
|
||||
if (optarg[0] == '-') {
|
||||
rc = bootutil_err_missing_value("-c");
|
||||
goto error;
|
||||
}
|
||||
cmdflag = 1;
|
||||
strncpy(cmd, optarg, sizeof(cmd)-1);
|
||||
break;
|
||||
#ifndef _WIN32
|
||||
case 'g':
|
||||
g_bootutil_gui_mode = 1;
|
||||
break;
|
||||
#endif
|
||||
case 'r':
|
||||
rstflag = 1;
|
||||
break;
|
||||
case 'v':
|
||||
vrbflag = 1;
|
||||
break;
|
||||
case 'h':
|
||||
case '?':
|
||||
bootutil_help(0);
|
||||
break;
|
||||
}
|
||||
}
|
||||
|
||||
/* Make sure we have something to do first */
|
||||
if (!rstflag && !cmdflag && !g_bootutil_gui_mode) {
|
||||
LOGERR("no action requested\n");
|
||||
goto error;
|
||||
}
|
||||
|
||||
/* Set logger level to verbose if requested */
|
||||
if (vrbflag == 1) {
|
||||
infohelper_set_infolevel(2);
|
||||
}
|
||||
|
||||
/* Try to open the serial port */
|
||||
if (!ttyflag) {
|
||||
rc = bootutil_err_missing_arg("-d");
|
||||
goto error;
|
||||
} else {
|
||||
bootutil_serport_open(tty);
|
||||
/* Make sure the serial port was actually opened */
|
||||
if (g_bootutil_serport_open != 1) {
|
||||
rc = EINVAL;
|
||||
goto error;
|
||||
}
|
||||
}
|
||||
|
||||
/* Check if a system reset was requested (perform this first) */
|
||||
if (rstflag) {
|
||||
rc = commands_cmd_reset();
|
||||
if (rc != 0) {
|
||||
goto error;
|
||||
}
|
||||
}
|
||||
|
||||
/* Command handler */
|
||||
if (cmdflag) {
|
||||
/* Try to parse the supplied command */
|
||||
rc = commands_parse(cmd);
|
||||
if (rc != 0) {
|
||||
goto error;
|
||||
}
|
||||
}
|
||||
|
||||
#ifndef _WIN32
|
||||
/* GUI handler */
|
||||
if (g_bootutil_gui_mode) {
|
||||
rc = gui_init(tty);
|
||||
if (rc != 0) {
|
||||
goto error;
|
||||
}
|
||||
}
|
||||
#endif
|
||||
|
||||
/* Display the return code of any unhandled errors */
|
||||
if (rc != 0) {
|
||||
LOGERR("rc = 0x%04X (%u): %s\n", rc, rc, strerror(rc));
|
||||
}
|
||||
|
||||
error:
|
||||
bootutil_serport_close();
|
||||
exit(rc);
|
||||
}
|
||||
@@ -1,661 +0,0 @@
|
||||
/**********************************************************************************
|
||||
**********************************************************************************
|
||||
***
|
||||
*** serialport.c
|
||||
*** - low level functions to access the serial port
|
||||
***
|
||||
*** Copyright (C) 2014 Christian Klippel <ck@atelier-klippel.de>
|
||||
***
|
||||
*** 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.
|
||||
***
|
||||
*** This program is distributed in the hope that it will be useful,
|
||||
*** but WITHOUT ANY WARRANTY; without even the implied warranty of
|
||||
*** MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the
|
||||
*** GNU General Public License for more details.
|
||||
***
|
||||
*** You should have received a copy of the GNU General Public License along
|
||||
*** with this program; if not, write to the Free Software Foundation, Inc.,
|
||||
*** 51 Franklin Street, Fifth Floor, Boston, MA 02110-1301 USA.
|
||||
***
|
||||
**/
|
||||
|
||||
#include <stdio.h>
|
||||
#include <stdlib.h>
|
||||
#include <string.h>
|
||||
#include <unistd.h>
|
||||
|
||||
#if defined (_WIN32)
|
||||
#include <Windows.h>
|
||||
#else
|
||||
#include <sys/types.h>
|
||||
#include <sys/stat.h>
|
||||
#include <sys/ioctl.h>
|
||||
#include <sys/time.h>
|
||||
#include <fcntl.h>
|
||||
#include <termios.h>
|
||||
#endif
|
||||
|
||||
#include "serialport.h"
|
||||
#include "infohelper.h"
|
||||
|
||||
#if defined (_WIN32)
|
||||
static HANDLE sPort = NULL;
|
||||
static DCB sDCB;
|
||||
static COMMTIMEOUTS sTIMEOUTS;
|
||||
#else
|
||||
static int serial_port = -1;
|
||||
static struct termios term;
|
||||
static unsigned int timeout;
|
||||
#endif
|
||||
|
||||
|
||||
#ifdef _WIN32
|
||||
|
||||
#ifndef CBR_230400
|
||||
#define CBR_230400 230400
|
||||
#endif
|
||||
#ifndef CBR_460800
|
||||
#define CBR_460800 460800
|
||||
#endif
|
||||
#ifndef CBR_512000
|
||||
#define CBR_512000 512000
|
||||
#endif
|
||||
#ifndef CBR_921600
|
||||
#define CBR_921600 921600
|
||||
#endif
|
||||
|
||||
|
||||
void serialport_setbaudrate(unsigned int baudrate)
|
||||
{
|
||||
DWORD br = 0;
|
||||
switch(baudrate)
|
||||
{
|
||||
case 9600: br = CBR_9600; break;
|
||||
case 14400: br = CBR_14400; break;
|
||||
case 19200: br = CBR_19200; break;
|
||||
case 38400: br = CBR_38400; break;
|
||||
case 56000: br = CBR_56000; break;
|
||||
case 57600: br = CBR_57600; break;
|
||||
case 115200: br = CBR_115200; break;
|
||||
case 128000: br = CBR_128000; break;
|
||||
case 230400: br = CBR_230400; break;
|
||||
case 256000: br = CBR_256000; break;
|
||||
case 512000: br = CBR_512000; break;
|
||||
case 460800: br = CBR_460800; break;
|
||||
case 921600: br = CBR_921600; break;
|
||||
}
|
||||
if (br == 0)
|
||||
{
|
||||
LOGWARN("unsupported baud rate: %d, using 115200", baudrate);
|
||||
br = CBR_115200;
|
||||
}
|
||||
|
||||
memset(&sDCB, 0, sizeof(DCB));
|
||||
BuildCommDCB("baud=9600 parity=N data=8 stop=1",&sDCB);
|
||||
sDCB.DCBlength = sizeof(DCB);
|
||||
sDCB.BaudRate = br;
|
||||
sDCB.fBinary = TRUE;
|
||||
sDCB.fParity = FALSE;
|
||||
// sDCB.fOutxCtsFlow = TRUE;
|
||||
sDCB.fDtrControl = DTR_CONTROL_DISABLE;
|
||||
sDCB.fDsrSensitivity= FALSE;
|
||||
sDCB.fRtsControl = RTS_CONTROL_DISABLE;
|
||||
sDCB.ByteSize = 8;
|
||||
sDCB.StopBits = ONESTOPBIT;
|
||||
sDCB.fAbortOnError = FALSE;
|
||||
sDCB.fOutX = FALSE;
|
||||
sDCB.fInX = FALSE;
|
||||
if (!SetCommState(sPort, &sDCB))
|
||||
{
|
||||
LOGDEBUG("SetCommState call failed");
|
||||
}
|
||||
}
|
||||
|
||||
int serialport_open(const char *device, unsigned int baudrate)
|
||||
{
|
||||
char portName[40];
|
||||
sprintf(portName,"\\\\.\\%s", device);
|
||||
sPort = CreateFile(portName, GENERIC_WRITE|GENERIC_READ, 0, NULL, OPEN_EXISTING, FILE_ATTRIBUTE_NORMAL, NULL);
|
||||
|
||||
if (sPort == INVALID_HANDLE_VALUE)
|
||||
{
|
||||
LOGERR("Failed to open %s", device);
|
||||
return 0;
|
||||
}
|
||||
|
||||
SetupComm(sPort, 256, 256);
|
||||
serialport_setbaudrate(baudrate);
|
||||
serialport_set_timeout(1000);
|
||||
return 1;
|
||||
}
|
||||
|
||||
void serialport_set_timeout(unsigned int timeout)
|
||||
{
|
||||
LOGDEBUG("setting serial port timeouts to %d ms", timeout);
|
||||
sTIMEOUTS.ReadIntervalTimeout = 0;
|
||||
sTIMEOUTS.ReadTotalTimeoutConstant = timeout;
|
||||
sTIMEOUTS.ReadTotalTimeoutMultiplier = 0;
|
||||
sTIMEOUTS.WriteTotalTimeoutConstant = timeout;
|
||||
sTIMEOUTS.WriteTotalTimeoutMultiplier = 0;
|
||||
if (!SetCommTimeouts(sPort,&sTIMEOUTS))
|
||||
{
|
||||
LOGDEBUG("SetCommTimeouts call failed");
|
||||
}
|
||||
SetCommMask(sPort, EV_TXEMPTY);
|
||||
}
|
||||
|
||||
unsigned serialport_get_timeout()
|
||||
{
|
||||
return sTIMEOUTS.ReadTotalTimeoutConstant;
|
||||
}
|
||||
|
||||
unsigned serialport_read(unsigned char* data, unsigned int size)
|
||||
{
|
||||
unsigned long cb;
|
||||
ReadFile(sPort, data, size, &cb, NULL);
|
||||
if (cb != size)
|
||||
{
|
||||
LOGDEBUG("read %d, requested %d", cb, size);
|
||||
}
|
||||
return (unsigned) cb;
|
||||
}
|
||||
|
||||
unsigned serialport_write(const unsigned char* data, unsigned int size)
|
||||
{
|
||||
unsigned long cb;
|
||||
WriteFile(sPort, data, size, &cb, NULL);
|
||||
if (cb != size)
|
||||
{
|
||||
LOGDEBUG("wrote %d, requested %d", cb, size);
|
||||
}
|
||||
return (unsigned) cb;
|
||||
}
|
||||
|
||||
void serialport_flush(void)
|
||||
{
|
||||
unsigned char tmp[512];
|
||||
if(sPort)
|
||||
{
|
||||
LOGDEBUG("flush start");
|
||||
unsigned old_timeout = sTIMEOUTS.ReadTotalTimeoutConstant;
|
||||
serialport_set_timeout(1);
|
||||
ClearCommError(sPort, NULL, NULL);
|
||||
PurgeComm(sPort, PURGE_TXCLEAR|PURGE_RXCLEAR);
|
||||
unsigned long cb;
|
||||
int result;
|
||||
do {
|
||||
result = ReadFile(sPort, tmp, 512, &cb, NULL);
|
||||
LOGVERBOSE("flushed %lu bytes", cb);
|
||||
} while(cb && result == 0);
|
||||
serialport_set_timeout(old_timeout);
|
||||
LOGDEBUG("flush complete");
|
||||
}
|
||||
}
|
||||
|
||||
void serialport_drain(void)
|
||||
{
|
||||
if(sPort)
|
||||
{
|
||||
FlushFileBuffers(sPort);
|
||||
}
|
||||
|
||||
}
|
||||
|
||||
int serialport_close(void)
|
||||
{
|
||||
if(!sPort)
|
||||
return 0;
|
||||
serialport_drain();
|
||||
serialport_flush();
|
||||
CloseHandle(sPort);
|
||||
sPort = NULL;
|
||||
return 1;
|
||||
}
|
||||
|
||||
void serialport_set_dtr(unsigned char val)
|
||||
{
|
||||
if(sPort)
|
||||
{
|
||||
EscapeCommFunction(sPort,((val)?SETDTR:CLRDTR));
|
||||
}
|
||||
}
|
||||
|
||||
void serialport_set_rts(unsigned char val)
|
||||
{
|
||||
if(sPort)
|
||||
{
|
||||
EscapeCommFunction(sPort,((val)?SETRTS:CLRRTS));
|
||||
}
|
||||
}
|
||||
|
||||
void serialport_send_break()
|
||||
{
|
||||
if (sPort)
|
||||
{
|
||||
EscapeCommFunction(sPort, SETBREAK);
|
||||
Sleep(250);
|
||||
EscapeCommFunction(sPort, CLRBREAK);
|
||||
}
|
||||
}
|
||||
|
||||
|
||||
#else
|
||||
|
||||
void serialport_set_baudrate(unsigned int baudrate)
|
||||
{
|
||||
switch(baudrate)
|
||||
{
|
||||
case 2400:
|
||||
cfsetispeed(&term,B2400);
|
||||
cfsetospeed(&term,B2400);
|
||||
break;
|
||||
|
||||
case 4800:
|
||||
cfsetispeed(&term,B4800);
|
||||
cfsetospeed(&term,B4800);
|
||||
break;
|
||||
|
||||
case 9600:
|
||||
cfsetispeed(&term,B9600);
|
||||
cfsetospeed(&term,B9600);
|
||||
break;
|
||||
|
||||
case 19200:
|
||||
cfsetispeed(&term,B19200);
|
||||
cfsetospeed(&term,B19200);
|
||||
break;
|
||||
|
||||
case 38400:
|
||||
cfsetispeed(&term,B38400);
|
||||
cfsetospeed(&term,B38400);
|
||||
break;
|
||||
|
||||
case 57600:
|
||||
cfsetispeed(&term,B57600);
|
||||
cfsetospeed(&term,B57600);
|
||||
break;
|
||||
|
||||
case 115200:
|
||||
cfsetispeed(&term,B115200);
|
||||
cfsetospeed(&term,B115200);
|
||||
break;
|
||||
|
||||
case 230400:
|
||||
cfsetispeed(&term,B230400);
|
||||
cfsetospeed(&term,B230400);
|
||||
break;
|
||||
#ifndef __APPLE__
|
||||
case 460800:
|
||||
cfsetispeed(&term,B460800);
|
||||
cfsetospeed(&term,B460800);
|
||||
break;
|
||||
|
||||
case 921600:
|
||||
cfsetispeed(&term,B921600);
|
||||
cfsetospeed(&term,B921600);
|
||||
break;
|
||||
#endif
|
||||
default:
|
||||
LOGWARN("serialport_set_baudrate: baud rate %d may not work", baudrate);
|
||||
cfsetispeed(&term,baudrate);
|
||||
cfsetospeed(&term,baudrate);
|
||||
break;
|
||||
}
|
||||
}
|
||||
|
||||
void serialport_set_timeout(unsigned int t)
|
||||
{
|
||||
if(t != timeout)
|
||||
{
|
||||
LOGDEBUG("setting timeout %i", t);
|
||||
timeout = t;
|
||||
}
|
||||
}
|
||||
|
||||
unsigned serialport_get_timeout()
|
||||
{
|
||||
return timeout;
|
||||
}
|
||||
|
||||
int serialport_open(const char *device, unsigned int baudrate)
|
||||
{
|
||||
LOGINFO("opening port %s at %d", device, baudrate);
|
||||
int flags = O_RDWR | O_NOCTTY;
|
||||
#ifdef __APPLE__
|
||||
flags |= O_NONBLOCK;
|
||||
#endif
|
||||
serial_port = open(device, flags);
|
||||
|
||||
if(serial_port<0)
|
||||
{
|
||||
LOGERR("cannot access %s\n",device);
|
||||
return 0;
|
||||
}
|
||||
|
||||
#ifdef __APPLE__
|
||||
flags = fcntl(serial_port, F_GETFL, 0);
|
||||
fcntl(serial_port, F_SETFL, flags & (~O_NONBLOCK));
|
||||
#endif
|
||||
|
||||
serialport_set_dtr(0);
|
||||
|
||||
LOGDEBUG("tcgetattr");
|
||||
tcgetattr(serial_port,&term);
|
||||
|
||||
serialport_set_baudrate(baudrate);
|
||||
|
||||
term.c_cflag = (term.c_cflag & ~CSIZE) | CS8;
|
||||
term.c_cflag |= CLOCAL | CREAD;
|
||||
|
||||
term.c_cflag &= ~(PARENB | PARODD);
|
||||
term.c_cflag &= ~CSTOPB;
|
||||
|
||||
term.c_iflag = IGNBRK;
|
||||
|
||||
term.c_iflag &= ~(IXON | IXOFF);
|
||||
|
||||
term.c_lflag = 0;
|
||||
|
||||
term.c_oflag = 0;
|
||||
|
||||
|
||||
term.c_cc[VMIN]=0;
|
||||
term.c_cc[VTIME]=1;
|
||||
timeout = 100;
|
||||
|
||||
|
||||
|
||||
LOGDEBUG("tcsetattr");
|
||||
if (tcsetattr(serial_port, TCSANOW, &term)!=0)
|
||||
{
|
||||
LOGERR("setattr stage 1 failed");
|
||||
return 0;
|
||||
}
|
||||
|
||||
|
||||
if (tcgetattr(serial_port, &term)!=0)
|
||||
{
|
||||
LOGERR("getattr failed");
|
||||
return 0;
|
||||
}
|
||||
|
||||
term.c_cflag &= ~CRTSCTS;
|
||||
|
||||
if (tcsetattr(serial_port, TCSANOW, &term)!=0)
|
||||
{
|
||||
LOGERR("setattr stage 2 failed");
|
||||
return 0;
|
||||
}
|
||||
LOGDEBUG("serial open");
|
||||
return serial_port;
|
||||
}
|
||||
|
||||
unsigned serialport_read(unsigned char* data, unsigned int size)
|
||||
{
|
||||
struct timeval tv0, tv1;
|
||||
gettimeofday(&tv0, NULL);
|
||||
unsigned n = 0;
|
||||
unsigned time_spent = 0;
|
||||
do
|
||||
{
|
||||
unsigned cb = read(serial_port, data + n, size - n);
|
||||
n += cb;
|
||||
gettimeofday(&tv1, NULL);
|
||||
time_spent = (tv1.tv_sec - tv0.tv_sec) * 1000 + tv1.tv_usec / 1000 - tv0.tv_usec / 1000;
|
||||
} while (n < size && time_spent < timeout);
|
||||
return n;
|
||||
}
|
||||
|
||||
unsigned serialport_write(const unsigned char* data, unsigned int size)
|
||||
{
|
||||
return write(serial_port, data, size);
|
||||
}
|
||||
|
||||
void serialport_flush(void)
|
||||
{
|
||||
static unsigned char b;
|
||||
|
||||
if(serial_port)
|
||||
{
|
||||
tcdrain(serial_port);
|
||||
while(read(serial_port, &b, 1) > 0);
|
||||
}
|
||||
}
|
||||
|
||||
void serialport_drain(void)
|
||||
{
|
||||
if(serial_port)
|
||||
{
|
||||
tcdrain(serial_port);
|
||||
}
|
||||
}
|
||||
|
||||
int serialport_close(void)
|
||||
{
|
||||
if(serial_port)
|
||||
{
|
||||
tcdrain(serial_port);
|
||||
tcflush(serial_port, TCIOFLUSH);
|
||||
close(serial_port);
|
||||
return 1;
|
||||
}
|
||||
else
|
||||
{
|
||||
return 0;
|
||||
}
|
||||
}
|
||||
|
||||
void serialport_set_dtr(unsigned char val)
|
||||
{
|
||||
int mcs;
|
||||
|
||||
if(serial_port)
|
||||
{
|
||||
ioctl (serial_port, TIOCMGET, &mcs);
|
||||
|
||||
if(val)
|
||||
{
|
||||
mcs |= TIOCM_DTR;
|
||||
ioctl (serial_port, TIOCMSET, &mcs);
|
||||
}
|
||||
else
|
||||
{
|
||||
mcs &= ~TIOCM_DTR;
|
||||
ioctl (serial_port, TIOCMSET, &mcs);
|
||||
}
|
||||
}
|
||||
}
|
||||
|
||||
void serialport_set_rts(unsigned char val)
|
||||
{
|
||||
int mcs;
|
||||
|
||||
if(serial_port)
|
||||
{
|
||||
ioctl (serial_port, TIOCMGET, &mcs);
|
||||
|
||||
if(val)
|
||||
{
|
||||
mcs |= TIOCM_RTS;
|
||||
ioctl (serial_port, TIOCMSET, &mcs);
|
||||
}
|
||||
else
|
||||
{
|
||||
mcs &= ~TIOCM_RTS;
|
||||
ioctl (serial_port, TIOCMSET, &mcs);
|
||||
}
|
||||
}
|
||||
}
|
||||
|
||||
void serialport_send_break()
|
||||
{
|
||||
tcsendbreak(serial_port, 0);
|
||||
}
|
||||
|
||||
|
||||
|
||||
#endif
|
||||
static unsigned char subst_C0[2] = { 0xDB, 0xDC };
|
||||
static unsigned char subst_DB[2] = { 0xDB, 0xDD };
|
||||
|
||||
#define STATIC_SLIP_BUF_SIZE 4096
|
||||
int serialport_send_slip_static(unsigned char *data, unsigned int size)
|
||||
{
|
||||
unsigned char buf[STATIC_SLIP_BUF_SIZE];
|
||||
unsigned out_pos = 0;
|
||||
for (int i = 0; i < size; ++i)
|
||||
{
|
||||
unsigned char cur = data[i];
|
||||
if (cur == 0xC0)
|
||||
{
|
||||
buf[out_pos++] = subst_C0[0];
|
||||
buf[out_pos++] = subst_C0[1];
|
||||
}
|
||||
else if (cur == 0xDB)
|
||||
{
|
||||
buf[out_pos++] = subst_DB[0];
|
||||
buf[out_pos++] = subst_DB[1];
|
||||
}
|
||||
else
|
||||
buf[out_pos++] = cur;
|
||||
}
|
||||
|
||||
if(serialport_write(buf, out_pos) != out_pos)
|
||||
{
|
||||
LOGERR("failed sending %d bytes", out_pos);
|
||||
return 0;
|
||||
}
|
||||
serialport_drain();
|
||||
return size;
|
||||
}
|
||||
|
||||
int serialport_send_slip(unsigned char *data, unsigned int size)
|
||||
{
|
||||
unsigned int sent;
|
||||
unsigned char cur_byte;
|
||||
|
||||
if (size < STATIC_SLIP_BUF_SIZE / 2)
|
||||
return serialport_send_slip_static(data, size);
|
||||
|
||||
sent = 0;
|
||||
|
||||
while(sent != size)
|
||||
{
|
||||
cur_byte = *data++;
|
||||
if(cur_byte == 0xC0)
|
||||
{
|
||||
if(serialport_write(subst_C0, 2) != 2)
|
||||
{
|
||||
LOGERR("failed substituting 0xC0");
|
||||
return 0;
|
||||
}
|
||||
}
|
||||
else if(cur_byte == 0xDB)
|
||||
{
|
||||
if(serialport_write(subst_DB, 2) != 2)
|
||||
{
|
||||
LOGERR("failed substituting 0xDB");
|
||||
return 0;
|
||||
}
|
||||
}
|
||||
else
|
||||
{
|
||||
if(serialport_write(&cur_byte, 1) != 1)
|
||||
{
|
||||
LOGERR("failed sending byte %i", sent);
|
||||
return 0;
|
||||
}
|
||||
}
|
||||
sent++;
|
||||
}
|
||||
|
||||
serialport_drain();
|
||||
|
||||
return sent;
|
||||
}
|
||||
|
||||
int serialport_receive_slip(unsigned char *data, unsigned int size)
|
||||
{
|
||||
unsigned int received;
|
||||
unsigned char cur_byte;
|
||||
|
||||
received = 0;
|
||||
|
||||
while(received != size)
|
||||
{
|
||||
if(serialport_read(&cur_byte, 1) != 1)
|
||||
{
|
||||
LOGERR("failed reading byte");
|
||||
return 0;
|
||||
}
|
||||
|
||||
if(cur_byte == 0xDB)
|
||||
{
|
||||
if(serialport_read(&cur_byte, 1) != 1)
|
||||
{
|
||||
LOGERR("failed reading byte for unslip");
|
||||
return 0;
|
||||
}
|
||||
|
||||
if(cur_byte == 0xDC)
|
||||
{
|
||||
*data++ = 0xC0;
|
||||
}
|
||||
else if(cur_byte == 0xDD)
|
||||
{
|
||||
*data++ = 0xDB;
|
||||
}
|
||||
else
|
||||
{
|
||||
LOGERR("unslip sequence wrong");
|
||||
return 0;
|
||||
}
|
||||
}
|
||||
else
|
||||
{
|
||||
*data++ = cur_byte;
|
||||
}
|
||||
|
||||
received++;
|
||||
}
|
||||
|
||||
return received;
|
||||
}
|
||||
|
||||
int serialport_send_C0(void)
|
||||
{
|
||||
unsigned char b;
|
||||
|
||||
b = 0xC0;
|
||||
|
||||
if(serialport_write(&b, 1) != 1)
|
||||
{
|
||||
LOGERR("failed sending 0xC0");
|
||||
return 0;
|
||||
}
|
||||
serialport_drain();
|
||||
return 1;
|
||||
}
|
||||
|
||||
int serialport_receive_C0(void)
|
||||
{
|
||||
unsigned char b;
|
||||
|
||||
b = 0x00;
|
||||
|
||||
if(serialport_read(&b, 1) != 1)
|
||||
{
|
||||
return 0;
|
||||
}
|
||||
|
||||
if(b != 0xC0)
|
||||
{
|
||||
LOGDEBUG("serialport_receive_C0: %02X instead of C0", b);
|
||||
return 0;
|
||||
}
|
||||
|
||||
return 1;
|
||||
}
|
||||
@@ -1,46 +0,0 @@
|
||||
/**********************************************************************************
|
||||
**********************************************************************************
|
||||
***
|
||||
*** serialport.h
|
||||
*** - include file for serialport.c
|
||||
***
|
||||
*** Copyright (C) 2014 Christian Klippel <ck@atelier-klippel.de>
|
||||
***
|
||||
*** 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.
|
||||
***
|
||||
*** This program is distributed in the hope that it will be useful,
|
||||
*** but WITHOUT ANY WARRANTY; without even the implied warranty of
|
||||
*** MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the
|
||||
*** GNU General Public License for more details.
|
||||
***
|
||||
*** You should have received a copy of the GNU General Public License along
|
||||
*** with this program; if not, write to the Free Software Foundation, Inc.,
|
||||
*** 51 Franklin Street, Fifth Floor, Boston, MA 02110-1301 USA.
|
||||
***
|
||||
**/
|
||||
|
||||
|
||||
#ifndef SERIALPORT_H
|
||||
#define SERIALPORT_H
|
||||
|
||||
int serialport_open(const char *dev, unsigned int baudrate);
|
||||
int serialport_close(void);
|
||||
void serialport_set_dtr(unsigned char val);
|
||||
void serialport_set_rts(unsigned char val);
|
||||
void serialport_send_break();
|
||||
void serialport_set_timeout(unsigned int timeout);
|
||||
unsigned serialport_get_timeout();
|
||||
void serialport_drain(void);
|
||||
void serialport_flush(void);
|
||||
unsigned serialport_read(unsigned char* data, unsigned int size);
|
||||
unsigned serialport_write(const unsigned char* data, unsigned int size);
|
||||
|
||||
int serialport_send_slip(unsigned char *data, unsigned int size);
|
||||
int serialport_receive_slip(unsigned char *data, unsigned int size);
|
||||
int serialport_send_C0(void);
|
||||
int serialport_receive_C0(void);
|
||||
|
||||
#endif
|
||||
Reference in new issue
Block a user