add simple shell comomand parsr
This commit is contained in:
parent
e7e5cfd126
commit
7f0a9f9285
@ -26,6 +26,7 @@
|
|||||||
#include "info.h"
|
#include "info.h"
|
||||||
#include "uart.h"
|
#include "uart.h"
|
||||||
#include "sram.h"
|
#include "sram.h"
|
||||||
|
#include "dump.h"
|
||||||
|
|
||||||
|
|
||||||
extern FILE uart_stdout;
|
extern FILE uart_stdout;
|
||||||
|
|||||||
@ -20,12 +20,19 @@
|
|||||||
#include <stdint.h>
|
#include <stdint.h>
|
||||||
#include <string.h>
|
#include <string.h>
|
||||||
#include <avr/io.h>
|
#include <avr/io.h>
|
||||||
|
#include <stdlib.h>
|
||||||
#include <avr/interrupt.h>
|
#include <avr/interrupt.h>
|
||||||
|
#include <util/delay.h>
|
||||||
|
#include <avr/pgmspace.h>
|
||||||
|
#include <avr/eeprom.h>
|
||||||
|
|
||||||
|
|
||||||
#include "pwm.h"
|
#include "pwm.h"
|
||||||
#include "debug.h"
|
#include "debug.h"
|
||||||
#include "info.h"
|
#include "info.h"
|
||||||
#include "sram.h"
|
#include "sram.h"
|
||||||
|
#include "util.h"
|
||||||
|
#include "uart.h"
|
||||||
|
|
||||||
#define RECEIVE_BUF_LEN 40
|
#define RECEIVE_BUF_LEN 40
|
||||||
|
|
||||||
@ -33,12 +40,11 @@
|
|||||||
volatile uint8_t recv_counter = 0;
|
volatile uint8_t recv_counter = 0;
|
||||||
volatile uint8_t cr = 0;
|
volatile uint8_t cr = 0;
|
||||||
|
|
||||||
|
uint8_t *token_ptr;
|
||||||
|
|
||||||
static char *token_ptr;
|
uint8_t *get_token(void)
|
||||||
|
|
||||||
static char *get_token(void)
|
|
||||||
{
|
{
|
||||||
char *p = token_ptr;
|
uint8_t *p = token_ptr;
|
||||||
while (*p == ' ')
|
while (*p == ' ')
|
||||||
p++;
|
p++;
|
||||||
if (*p == '\0')
|
if (*p == '\0')
|
||||||
@ -54,81 +60,76 @@
|
|||||||
return p;
|
return p;
|
||||||
}
|
}
|
||||||
|
|
||||||
static int get_dec(int *decval)
|
uint8_t get_dec(uint32_t *decval)
|
||||||
{
|
{
|
||||||
const char *t;
|
const uint8_t *t;
|
||||||
t = get_token();
|
t = get_token();
|
||||||
if (t != NULL) {
|
if (t != NULL) {
|
||||||
int x = Util_sscandec(t);
|
int x = util_sscandec(t);
|
||||||
if (x < 0)
|
if (x < 0)
|
||||||
return FALSE;
|
return 0;
|
||||||
*decval = x;
|
*decval = x;
|
||||||
return TRUE;
|
return 1;
|
||||||
}
|
}
|
||||||
return FALSE;
|
return 0;
|
||||||
}
|
}
|
||||||
|
|
||||||
static int parse_hex(const char *s, UWORD *hexval)
|
uint8_t parse_hex(const uint8_t *s, uint32_t *hexval)
|
||||||
{
|
{
|
||||||
int x = Util_sscanhex(s);
|
uint32_t x = util_sscanhex(s);
|
||||||
#ifdef MONITOR_HINTS
|
if (x > 0xffffff)
|
||||||
int y = find_label_value(s);
|
return 0;
|
||||||
if (y >= 0) {
|
*hexval = (uint32_t) x;
|
||||||
if (x < 0 || x > 0xffff || x == y) {
|
return 1;
|
||||||
*hexval = (UWORD) y;
|
|
||||||
return TRUE;
|
|
||||||
}
|
|
||||||
/* s can be a hex number or a label name */
|
|
||||||
printf("%s is ambiguous. Use 0%X or %X instead.\n", s, x, y);
|
|
||||||
return FALSE;
|
|
||||||
}
|
|
||||||
#endif
|
|
||||||
if (x < 0 || x > 0xffff)
|
|
||||||
return FALSE;
|
|
||||||
*hexval = (UWORD) x;
|
|
||||||
return TRUE;
|
|
||||||
}
|
}
|
||||||
|
|
||||||
static int get_hex(UWORD *hexval)
|
uint8_t get_hex(uint32_t *hexval)
|
||||||
{
|
{
|
||||||
const char *t;
|
const uint8_t *t;
|
||||||
t = get_token();
|
t = get_token();
|
||||||
if (t != NULL)
|
if (t != NULL)
|
||||||
return parse_hex(t, hexval);
|
return parse_hex(t, hexval);
|
||||||
return FALSE;
|
return 0;
|
||||||
}
|
}
|
||||||
|
|
||||||
static int get_hex2(UWORD *hexval1, UWORD *hexval2)
|
uint8_t get_hex_arg2(uint32_t *hexval1, uint32_t *hexval2)
|
||||||
{
|
{
|
||||||
return get_hex(hexval1) && get_hex(hexval2);
|
return get_hex(hexval1) && get_hex(hexval2);
|
||||||
}
|
}
|
||||||
|
|
||||||
static int get_hex3(UWORD *hexval1, UWORD *hexval2, UWORD *hexval3)
|
uint8_t get_hex_arg3(uint32_t *hexval1, uint32_t *hexval2, uint32_t *hexval3)
|
||||||
{
|
{
|
||||||
return get_hex(hexval1) && get_hex(hexval2) && get_hex(hexval3);
|
return get_hex(hexval1) && get_hex(hexval2) && get_hex(hexval3);
|
||||||
}
|
}
|
||||||
|
|
||||||
static void get_uword(UWORD *val)
|
static uint8_t get_int32(uint32_t *val)
|
||||||
{
|
{
|
||||||
if (!get_hex(val))
|
if (!get_hex(val)){
|
||||||
printf("Invalid argument!\n");
|
printf("Invalid argument!\n");
|
||||||
|
return 0;
|
||||||
|
} else {
|
||||||
|
return 1;
|
||||||
|
}
|
||||||
}
|
}
|
||||||
|
|
||||||
static void get_ubyte(UBYTE *val)
|
static uint8_t get_int8(uint8_t *val)
|
||||||
{
|
{
|
||||||
UWORD uword;
|
uint32_t ret;
|
||||||
if (!get_hex(&uword) || uword > 0xff)
|
if (!get_hex(&ret) ||ret > 0xff){
|
||||||
printf("Invalid argument!\n");
|
printf("Invalid argument!\n");
|
||||||
else
|
return 0;
|
||||||
*val = (UBYTE) uword;
|
}else{
|
||||||
|
*val = (uint8_t)ret;
|
||||||
|
return 1;
|
||||||
|
}
|
||||||
}
|
}
|
||||||
|
|
||||||
static int get_bool(void)
|
static int get_bool(void)
|
||||||
{
|
{
|
||||||
const char *t;
|
const uint8_t *t;
|
||||||
t = get_token();
|
t = get_token();
|
||||||
if (t != NULL) {
|
if (t != NULL) {
|
||||||
int result = Util_sscanbool(t);
|
int result = util_sscanbool(t);
|
||||||
if (result >= 0)
|
if (result >= 0)
|
||||||
return result;
|
return result;
|
||||||
}
|
}
|
||||||
@ -170,3 +171,32 @@ ISR(USART0_RX_vect) // Interrupt for UART Byte received
|
|||||||
}
|
}
|
||||||
UCSR0B |= (1<<RXCIE0);// Interrupts enable for RxD
|
UCSR0B |= (1<<RXCIE0);// Interrupts enable for RxD
|
||||||
}
|
}
|
||||||
|
|
||||||
|
|
||||||
|
void shellrun(void)
|
||||||
|
{
|
||||||
|
uint8_t command_buf[RECEIVE_BUF_LEN];
|
||||||
|
uint8_t *t;
|
||||||
|
uint32_t arg1;
|
||||||
|
uint32_t arg2;
|
||||||
|
uint32_t arg3;
|
||||||
|
|
||||||
|
if (!cr)
|
||||||
|
return;
|
||||||
|
cr=0;
|
||||||
|
strcpy((char*)command_buf, (char*)recv_buf);
|
||||||
|
|
||||||
|
token_ptr = command_buf;
|
||||||
|
t = get_token();
|
||||||
|
if (t == NULL)
|
||||||
|
return;
|
||||||
|
|
||||||
|
util_strupper(t);
|
||||||
|
|
||||||
|
if (strcmp((char*)t, "DUMP") == 0) {
|
||||||
|
if (get_hex_arg2(&arg1,&arg2))
|
||||||
|
dump_memory(arg1,arg2);
|
||||||
|
else
|
||||||
|
printf("ERROR: arg parsing\n");
|
||||||
|
}
|
||||||
|
}
|
||||||
@ -3,7 +3,7 @@
|
|||||||
<plist version="1.0">
|
<plist version="1.0">
|
||||||
<dict>
|
<dict>
|
||||||
<key>currentDocument</key>
|
<key>currentDocument</key>
|
||||||
<string>avr/usbload/util.c</string>
|
<string>avr/usbload/shell.c</string>
|
||||||
<key>documents</key>
|
<key>documents</key>
|
||||||
<array>
|
<array>
|
||||||
<dict>
|
<dict>
|
||||||
@ -21,19 +21,109 @@
|
|||||||
<integer>271</integer>
|
<integer>271</integer>
|
||||||
<key>metaData</key>
|
<key>metaData</key>
|
||||||
<dict>
|
<dict>
|
||||||
|
<key>avr/usbload/crc.c</key>
|
||||||
|
<dict>
|
||||||
|
<key>caret</key>
|
||||||
|
<dict>
|
||||||
|
<key>column</key>
|
||||||
|
<integer>0</integer>
|
||||||
|
<key>line</key>
|
||||||
|
<integer>59</integer>
|
||||||
|
</dict>
|
||||||
|
<key>firstVisibleColumn</key>
|
||||||
|
<integer>0</integer>
|
||||||
|
<key>firstVisibleLine</key>
|
||||||
|
<integer>15</integer>
|
||||||
|
</dict>
|
||||||
|
<key>avr/usbload/debug.c</key>
|
||||||
|
<dict>
|
||||||
|
<key>caret</key>
|
||||||
|
<dict>
|
||||||
|
<key>column</key>
|
||||||
|
<integer>0</integer>
|
||||||
|
<key>line</key>
|
||||||
|
<integer>26</integer>
|
||||||
|
</dict>
|
||||||
|
<key>columnSelection</key>
|
||||||
|
<false/>
|
||||||
|
<key>firstVisibleColumn</key>
|
||||||
|
<integer>0</integer>
|
||||||
|
<key>firstVisibleLine</key>
|
||||||
|
<integer>0</integer>
|
||||||
|
<key>selectFrom</key>
|
||||||
|
<dict>
|
||||||
|
<key>column</key>
|
||||||
|
<integer>0</integer>
|
||||||
|
<key>line</key>
|
||||||
|
<integer>25</integer>
|
||||||
|
</dict>
|
||||||
|
<key>selectTo</key>
|
||||||
|
<dict>
|
||||||
|
<key>column</key>
|
||||||
|
<integer>0</integer>
|
||||||
|
<key>line</key>
|
||||||
|
<integer>26</integer>
|
||||||
|
</dict>
|
||||||
|
</dict>
|
||||||
|
<key>avr/usbload/dump.c</key>
|
||||||
|
<dict>
|
||||||
|
<key>caret</key>
|
||||||
|
<dict>
|
||||||
|
<key>column</key>
|
||||||
|
<integer>12</integer>
|
||||||
|
<key>line</key>
|
||||||
|
<integer>67</integer>
|
||||||
|
</dict>
|
||||||
|
<key>columnSelection</key>
|
||||||
|
<false/>
|
||||||
|
<key>firstVisibleColumn</key>
|
||||||
|
<integer>0</integer>
|
||||||
|
<key>firstVisibleLine</key>
|
||||||
|
<integer>35</integer>
|
||||||
|
<key>selectFrom</key>
|
||||||
|
<dict>
|
||||||
|
<key>column</key>
|
||||||
|
<integer>5</integer>
|
||||||
|
<key>line</key>
|
||||||
|
<integer>67</integer>
|
||||||
|
</dict>
|
||||||
|
<key>selectTo</key>
|
||||||
|
<dict>
|
||||||
|
<key>column</key>
|
||||||
|
<integer>16</integer>
|
||||||
|
<key>line</key>
|
||||||
|
<integer>67</integer>
|
||||||
|
</dict>
|
||||||
|
</dict>
|
||||||
<key>avr/usbload/main.c</key>
|
<key>avr/usbload/main.c</key>
|
||||||
<dict>
|
<dict>
|
||||||
<key>caret</key>
|
<key>caret</key>
|
||||||
<dict>
|
<dict>
|
||||||
<key>column</key>
|
<key>column</key>
|
||||||
<integer>42</integer>
|
<integer>0</integer>
|
||||||
<key>line</key>
|
<key>line</key>
|
||||||
<integer>252</integer>
|
<integer>28</integer>
|
||||||
</dict>
|
</dict>
|
||||||
|
<key>columnSelection</key>
|
||||||
|
<false/>
|
||||||
<key>firstVisibleColumn</key>
|
<key>firstVisibleColumn</key>
|
||||||
<integer>0</integer>
|
<integer>0</integer>
|
||||||
<key>firstVisibleLine</key>
|
<key>firstVisibleLine</key>
|
||||||
<integer>247</integer>
|
<integer>0</integer>
|
||||||
|
<key>selectFrom</key>
|
||||||
|
<dict>
|
||||||
|
<key>column</key>
|
||||||
|
<integer>0</integer>
|
||||||
|
<key>line</key>
|
||||||
|
<integer>22</integer>
|
||||||
|
</dict>
|
||||||
|
<key>selectTo</key>
|
||||||
|
<dict>
|
||||||
|
<key>column</key>
|
||||||
|
<integer>0</integer>
|
||||||
|
<key>line</key>
|
||||||
|
<integer>28</integer>
|
||||||
|
</dict>
|
||||||
</dict>
|
</dict>
|
||||||
<key>avr/usbload/rle.h</key>
|
<key>avr/usbload/rle.h</key>
|
||||||
<dict>
|
<dict>
|
||||||
@ -65,35 +155,33 @@
|
|||||||
<integer>0</integer>
|
<integer>0</integer>
|
||||||
</dict>
|
</dict>
|
||||||
</dict>
|
</dict>
|
||||||
|
<key>avr/usbload/shared_memory.h</key>
|
||||||
|
<dict>
|
||||||
|
<key>caret</key>
|
||||||
|
<dict>
|
||||||
|
<key>column</key>
|
||||||
|
<integer>45</integer>
|
||||||
|
<key>line</key>
|
||||||
|
<integer>24</integer>
|
||||||
|
</dict>
|
||||||
|
<key>firstVisibleColumn</key>
|
||||||
|
<integer>0</integer>
|
||||||
|
<key>firstVisibleLine</key>
|
||||||
|
<integer>0</integer>
|
||||||
|
</dict>
|
||||||
<key>avr/usbload/shell.c</key>
|
<key>avr/usbload/shell.c</key>
|
||||||
<dict>
|
<dict>
|
||||||
<key>caret</key>
|
<key>caret</key>
|
||||||
<dict>
|
<dict>
|
||||||
<key>column</key>
|
<key>column</key>
|
||||||
<integer>0</integer>
|
<integer>41</integer>
|
||||||
<key>line</key>
|
<key>line</key>
|
||||||
<integer>74</integer>
|
<integer>177</integer>
|
||||||
</dict>
|
</dict>
|
||||||
<key>columnSelection</key>
|
|
||||||
<false/>
|
|
||||||
<key>firstVisibleColumn</key>
|
<key>firstVisibleColumn</key>
|
||||||
<integer>0</integer>
|
<integer>0</integer>
|
||||||
<key>firstVisibleLine</key>
|
<key>firstVisibleLine</key>
|
||||||
<integer>80</integer>
|
<integer>154</integer>
|
||||||
<key>selectFrom</key>
|
|
||||||
<dict>
|
|
||||||
<key>column</key>
|
|
||||||
<integer>0</integer>
|
|
||||||
<key>line</key>
|
|
||||||
<integer>73</integer>
|
|
||||||
</dict>
|
|
||||||
<key>selectTo</key>
|
|
||||||
<dict>
|
|
||||||
<key>column</key>
|
|
||||||
<integer>0</integer>
|
|
||||||
<key>line</key>
|
|
||||||
<integer>74</integer>
|
|
||||||
</dict>
|
|
||||||
</dict>
|
</dict>
|
||||||
<key>avr/usbload/shell.h</key>
|
<key>avr/usbload/shell.h</key>
|
||||||
<dict>
|
<dict>
|
||||||
@ -102,28 +190,12 @@
|
|||||||
<key>column</key>
|
<key>column</key>
|
||||||
<integer>0</integer>
|
<integer>0</integer>
|
||||||
<key>line</key>
|
<key>line</key>
|
||||||
<integer>0</integer>
|
<integer>23</integer>
|
||||||
</dict>
|
</dict>
|
||||||
<key>columnSelection</key>
|
|
||||||
<false/>
|
|
||||||
<key>firstVisibleColumn</key>
|
<key>firstVisibleColumn</key>
|
||||||
<integer>0</integer>
|
<integer>0</integer>
|
||||||
<key>firstVisibleLine</key>
|
<key>firstVisibleLine</key>
|
||||||
<integer>0</integer>
|
<integer>0</integer>
|
||||||
<key>selectFrom</key>
|
|
||||||
<dict>
|
|
||||||
<key>column</key>
|
|
||||||
<integer>0</integer>
|
|
||||||
<key>line</key>
|
|
||||||
<integer>19</integer>
|
|
||||||
</dict>
|
|
||||||
<key>selectTo</key>
|
|
||||||
<dict>
|
|
||||||
<key>column</key>
|
|
||||||
<integer>0</integer>
|
|
||||||
<key>line</key>
|
|
||||||
<integer>0</integer>
|
|
||||||
</dict>
|
|
||||||
</dict>
|
</dict>
|
||||||
<key>avr/usbload/sram.c</key>
|
<key>avr/usbload/sram.c</key>
|
||||||
<dict>
|
<dict>
|
||||||
@ -188,14 +260,14 @@
|
|||||||
<key>caret</key>
|
<key>caret</key>
|
||||||
<dict>
|
<dict>
|
||||||
<key>column</key>
|
<key>column</key>
|
||||||
<integer>15</integer>
|
<integer>1</integer>
|
||||||
<key>line</key>
|
<key>line</key>
|
||||||
<integer>46</integer>
|
<integer>25</integer>
|
||||||
</dict>
|
</dict>
|
||||||
<key>firstVisibleColumn</key>
|
<key>firstVisibleColumn</key>
|
||||||
<integer>0</integer>
|
<integer>0</integer>
|
||||||
<key>firstVisibleLine</key>
|
<key>firstVisibleLine</key>
|
||||||
<integer>14</integer>
|
<integer>0</integer>
|
||||||
</dict>
|
</dict>
|
||||||
<key>avr/usbload/util.h</key>
|
<key>avr/usbload/util.h</key>
|
||||||
<dict>
|
<dict>
|
||||||
@ -261,12 +333,16 @@
|
|||||||
<string>avr/usbload/sram.c</string>
|
<string>avr/usbload/sram.c</string>
|
||||||
<string>avr/usbload/main.c</string>
|
<string>avr/usbload/main.c</string>
|
||||||
<string>avr/usbload/shell.c</string>
|
<string>avr/usbload/shell.c</string>
|
||||||
|
<string>avr/usbload/crc.c</string>
|
||||||
|
<string>avr/usbload/dump.c</string>
|
||||||
|
<string>avr/usbload/debug.c</string>
|
||||||
<string>avr/usbload/uart.c</string>
|
<string>avr/usbload/uart.c</string>
|
||||||
<string>avr/usbload/util.c</string>
|
<string>avr/usbload/util.c</string>
|
||||||
<string>avr/usbload/util.h</string>
|
<string>avr/usbload/util.h</string>
|
||||||
<string>avr/usbload/usb_bulk.h</string>
|
<string>avr/usbload/usb_bulk.h</string>
|
||||||
<string>avr/usbload/rle.h</string>
|
<string>avr/usbload/rle.h</string>
|
||||||
<string>avr/usbload/shell.h</string>
|
<string>avr/usbload/shell.h</string>
|
||||||
|
<string>avr/usbload/shared_memory.h</string>
|
||||||
</array>
|
</array>
|
||||||
<key>showFileHierarchyDrawer</key>
|
<key>showFileHierarchyDrawer</key>
|
||||||
<false/>
|
<false/>
|
||||||
|
|||||||
Loading…
x
Reference in New Issue
Block a user