#include "common.h"
#include "options.h"
+#include "memory.h"
const char *argp_program_version = PACKAGE_VERSION;
const char *argp_program_bug_address = PACKAGE_BUGREPORT;
/* The options we understand. */
static struct argp_option argp_options[] = {
- {"debug", 'd', "level", 0, "Produce debugging output" },
+ {"debug", 'd', "level", 0, "Produce debugging output" },
+ {"iram", 'i', "size", 0, "Set internal ram size" },
+ {"pram", 'p', "size", 0, "Set program memory size" },
+ {"xram", 'x', "size", 0, "Set external ram size (default is 1024)" },
{ 0 }
};
log_level = strtol(arg, &endptr, 0);
if (*endptr != '\0') {
- log_fail_no_exit("Invalid log level");
+ log_err("Invalid log level");
argp_usage(state);
}
if (log_level > LOG_LEVEL_DEBUG) {
- log_fail_no_exit("Invalid log level");
+ log_err("Invalid log level (0 to 3)");
argp_usage(state);
}
- log_set_level(log_level);
+ options.log = log_level;
+}
+
+static void
+decode_memory_size(char *arg, struct argp_state *state, int memid)
+{
+ char *endptr;
+ int *dest;
+
+ if (memid == PGM_MEM_ID)
+ dest = &options.pram_size;
+ else if (memid == INT_MEM_ID)
+ dest = &options.iram_size;
+ else if (memid == EXT_MEM_ID)
+ dest = &options.xram_size;
+ else
+ exit(1); /* Programming error. */
+
+ /*
+ * Sizes versus max memory sizes will be checked when calling
+ * memory_init().
+ */
+ *dest = strtol(arg, &endptr, 0);
+
+ if (*endptr != '\0') {
+ log_err("Invalid memory size");
+ argp_usage(state);
+ }
}
/* Parse a single option. */
case 'd':
decode_debug_option(arg, state);
break;
+ case 'i':
+ decode_memory_size(arg, state, INT_MEM_ID);
+ break;
+ case 'p':
+ decode_memory_size(arg, state, PGM_MEM_ID);
+ break;
+ case 'x':
+ decode_memory_size(arg, state, EXT_MEM_ID);
+ break;
case ARGP_KEY_ARG:
if (state->arg_num >= ARGS_COUNT) {
/* Too many arguments. */
/* Setting default values. */
options.filename = NULL;
+ options.pram_size = PGM_MEM_DEFAULT_SIZE;
+ options.iram_size = INT_MEM_MAX_SIZE;
+ options.xram_size = EXT_MEM_DEFAULT_SIZE;
+ options.log = LOG_LEVEL_ERR;
/* Parse our arguments. */
argp_parse(&argp, argc, argv, 0, 0, NULL);