summaryrefslogtreecommitdiff
diff options
context:
space:
mode:
authorLeo C2014-11-21 13:49:19 +0100
committerLeo C2014-11-21 13:49:19 +0100
commit05994bd90cb36f10ff72c6a70d7cecc61b67fb2f (patch)
treee3f56ddcf2255a77db11566dfbf52bdac4fb356c
parentfc454c83abd628f03eb39800b269d25c54f9591a (diff)
downloadz180-stamp-05994bd90cb36f10ff72c6a70d7cecc61b67fb2f.zip
Rename pin.. to gpio..
-rw-r--r--avr/Tupfile17
-rw-r--r--avr/cmd_gpio.c (renamed from avr/cmd_pin.c)33
-rw-r--r--avr/command_tbl.c45
-rw-r--r--avr/gpio.c (renamed from avr/pin.c)75
-rw-r--r--include/gpio.h17
-rw-r--r--include/pin.h17
6 files changed, 99 insertions, 105 deletions
diff --git a/avr/Tupfile b/avr/Tupfile
index acb4aa5..a50b3b9 100644
--- a/avr/Tupfile
+++ b/avr/Tupfile
@@ -3,10 +3,12 @@ include_rules
PROG = stamp-monitor
SRC = main.c
SRC += cli.c cli_readline.c command.c command_tbl.c
-SRC += cmd_help.c cmd_date.c cmd_mem.c cmd_boot.c cmd_pin.c cmd_misc.c
+SRC += cmd_help.c cmd_date.c cmd_mem.c cmd_boot.c cmd_gpio.c cmd_misc.c
+SRC += cmd_sd.c
SRC += env.c xmalloc.c date.c con-utils.c print-utils.c getopt-min.c
-SRC += timer.c serial.c i2c.c pcf8583.c
-SRC += background.c z180-serv.c z80-if.c pin.c
+SRC += timer.c serial.c i2c.c pcf8583.c mmc.c
+SRC += background.c z180-serv.c z80-if.c gpio.c
+SRC += $(TOP)/fatfs/src/ff.c
SRC_Z = ../z180/hdrom.c
@@ -22,7 +24,7 @@ INCLUDES += -I$(TOP)/include
###############################################################################
-TOOLCHAINDIR =
+TOOLCHAINDIR =
TOOLCHAIN = avr
CC = $(TOOLCHAIN)-gcc
@@ -45,8 +47,8 @@ CFLAGS = -g -Os
CFLAGS += -mmcu=$(MCU_TARGET)
CFLAGS += -std=gnu99
CFLAGS += -Wall -Wextra
-CFLAGS += -Wredundant-decls
-CFLAGS += -mrelax
+CFLAGS += -Wredundant-decls
+CFLAGS += -mrelax
CFLAGS += -fno-common
CFLAGS += -ffunction-sections
CFLAGS += -fdata-sections
@@ -74,7 +76,7 @@ LDFLAGS += -Wl,--cref
!LINK = |> ^ LINK %o^ $(LD) $(CFLAGS) $(LDFLAGS) -Wl,-Map=%O.map %f $(LDLIBS) -o %o |> | %O.map
!OBJCOPY= |> ^ OBJCOPY %o^ $(OBJCOPY) -Oihex %f %o |>
!OBJDUMP= |> ^ OBJDUMP %o^ $(OBJDUMP) -h -S %f > %o |> %O.lss
-!SIZE = |> ^ SIZE^ $(SIZE) %f |>
+!SIZE = |> ^ SIZE^ $(SIZE) %f |>
: foreach $(SRC) | ../z180/hdrom.h |> !cc |> {objs}
: $(SRC_Z) |> !cc -D'const=const __flash' |> {objs}
@@ -83,4 +85,3 @@ LDFLAGS += -Wl,--cref
: $(PROG).elf |> !OBJCOPY |> %B.hex
: $(PROG).elf |> !OBJDUMP |> %B.lss
: $(PROG).elf |> !SIZE |>
-
diff --git a/avr/cmd_pin.c b/avr/cmd_gpio.c
index 83a55f7..84723d2 100644
--- a/avr/cmd_pin.c
+++ b/avr/cmd_gpio.c
@@ -7,13 +7,13 @@
#include "print-utils.h"
#include "getopt-min.h"
#include "env.h"
-#include "pin.h"
+#include "gpio.h"
//#include "debug.h"
-static const int namestr = PIN_MAX;
-static char *pin_names[PIN_MAX+1];
+static const int namestr = GPIO_MAX;
+static char *pin_names[GPIO_MAX+1];
static uint_least8_t pin_names_width;
static void pinnames_get(void)
@@ -33,7 +33,7 @@ static void pinnames_get(void)
pin_names[namestr] = strdup(lp);
ptr = strtok_P(pin_names[namestr], delim1);
while (ptr != NULL) {
- if (((i = strtoul(ptr, &lp, 10)) < PIN_MAX) &&
+ if (((i = strtoul(ptr, &lp, 10)) < GPIO_MAX) &&
lp != ptr &&
(ptr = strtok_P(NULL, delim2)) != NULL ) {
pin_names[i] = ptr;
@@ -41,7 +41,7 @@ static void pinnames_get(void)
}
}
- for (i = 0; i < PIN_MAX; i++)
+ for (i = 0; i < GPIO_MAX; i++)
if (strlen(pin_names[i]) > pin_names_width)
pin_names_width = strlen(pin_names[i]);
}
@@ -76,12 +76,12 @@ static int print_pin(int pin, int multi)
const FLASH char *levelp;
long div;
- pinconf = pin_config_get(pin);
+ pinconf = gpio_config_get(pin);
if (pinconf == OUTPUT_TIMER) {
- div = pin_clockdiv_get(pin);
+ div = gpio_clockdiv_get(pin);
levelp = pinlevel_str[2];
} else
- levelp = pinlevel_str[pin_read(pin)];
+ levelp = pinlevel_str[gpio_read(pin)];
if (multi) {
printf_P(PSTR("%3d "), pin);
@@ -115,7 +115,7 @@ static int_fast8_t pinarg_insert(int pin, uint_fast8_t count, uint_fast8_t pinar
{
uint_fast8_t pos;
- if (pin < 0 || pin >= PIN_MAX)
+ if (pin < 0 || pin >= GPIO_MAX)
return -1;
for (pos = 0; pos < count; pos++) {
@@ -168,10 +168,10 @@ static uint_fast8_t pinarg_get(char * arg, uint_fast8_t pinarg[])
}
-command_ret_t do_pin(cmd_tbl_t *cmdtp, int flag, int argc, char *const argv[])
+command_ret_t do_gpio(cmd_tbl_t *cmdtp, int flag, int argc, char *const argv[])
{
char printheader = 1;
- uint_fast8_t pinarg[PIN_MAX];
+ uint_fast8_t pinarg[GPIO_MAX];
uint_fast8_t pinargc;
(void) cmdtp; (void) flag;
@@ -197,7 +197,7 @@ command_ret_t do_pin(cmd_tbl_t *cmdtp, int flag, int argc, char *const argv[])
if (argc == 0) {
/* print cofig of all pins */
- for (pinargc = 0; pinargc < PIN_MAX; pinargc++)
+ for (pinargc = 0; pinargc < GPIO_MAX; pinargc++)
pinarg[pinargc] = pinargc;
} else {
/* get first arg */
@@ -240,7 +240,7 @@ command_ret_t do_pin(cmd_tbl_t *cmdtp, int flag, int argc, char *const argv[])
while (argc > 0) {
char *endp;
- pinmode_t mode = NONE;
+ gpiomode_t mode = NONE;
int level = 0;
unsigned long value = 0;
uint8_t hz_flag = 0;
@@ -301,14 +301,14 @@ command_ret_t do_pin(cmd_tbl_t *cmdtp, int flag, int argc, char *const argv[])
for (uint_fast8_t i = 0; i < pinargc; i++) {
switch (mode) {
case OUTPUT:
- pin_write(pinarg[i], level);
+ gpio_write(pinarg[i], level);
/* fall thru */
case INPUT:
case INPUT_PULLUP:
- pin_config(pinarg[i], mode);
+ gpio_config(pinarg[i], mode);
break;
case OUTPUT_TIMER:
- if (pin_clockdiv_set(pinarg[i], value) < 0) {
+ if (gpio_clockdiv_set(pinarg[i], value) < 0) {
printf_P(PSTR("Setting pin %d to %lu failed.\n"),
pinarg[i], value);
}
@@ -325,4 +325,3 @@ command_ret_t do_pin(cmd_tbl_t *cmdtp, int flag, int argc, char *const argv[])
return CMD_RET_SUCCESS;
}
-
diff --git a/avr/command_tbl.c b/avr/command_tbl.c
index 336c608..97110fd 100644
--- a/avr/command_tbl.c
+++ b/avr/command_tbl.c
@@ -20,7 +20,14 @@ extern command_ret_t do_dump_mem(cmd_tbl_t *, int, int, char * const []);
extern command_ret_t do_eep_cp(cmd_tbl_t *, int, int, char * const []);
extern command_ret_t do_busreq_pulse(cmd_tbl_t *, int, int, char * const []);
extern command_ret_t do_date(cmd_tbl_t *, int, int, char * const []);
-extern command_ret_t do_pin(cmd_tbl_t *, int, int, char * const []);
+extern command_ret_t do_gpio(cmd_tbl_t *, int, int, char * const []);
+extern command_ret_t do_sd(cmd_tbl_t *, int, int, char * const []);
+
+#ifdef CONFIG_SYS_LONGHELP
+const FLASH char sd_help_text[] =
+ "bla \t- do bla\n"
+ ;
+#endif /* CONFIG_SYS_LONGHELP */
cmd_tbl_t cmd_tbl[] = {
@@ -134,31 +141,8 @@ CMD_TBL_ITEM(
""
),
-#if 0
-CMD_TBL_ITEM(
- clock, 2, 0, do_clock,
- "Set or get CPU frequency",
- "\n"
- " - print frequency or state of clock pin\n"
- "clock value[K|M]\n"
- " - set frequency of clock pin to value\n"
- "clock [high|low]\n"
- " - set clock pin level high or low"
-),
CMD_TBL_ITEM(
- clk2, 3, 0, do_clock2,
- "Set or get clk2 frequency",
- "\n"
- " - print frequency or state of clk2 pin\n"
- "clk2 [-d] value[K|M]\n"
- " - set frequency of clk2 pin to value\n"
- "clk2 [high|low]\n"
- " - set clk2 pin level high or low"
-),
-#endif
-
-CMD_TBL_ITEM(
- pin, CONFIG_SYS_MAXARGS, 0, do_pin,
+ pin, CONFIG_SYS_MAXARGS, 1, do_gpio,
"Set or query pin state",
"[-s] [<pins>]\n"
" - print cofiguration and state or frequency of pins\n"
@@ -257,6 +241,17 @@ CMD_TBL_ITEM(
" - print detailed usage of 'command'"
),
+/* TODO: make macro CMD_TBL_ITEM work with this */
+ {FSTR("sd"), CONFIG_SYS_MAXARGS, 1, do_sd,
+ FSTR("SD/MMC card handling commands"),
+#ifdef CONFIG_SYS_LONGHELP
+ sd_help_text,
+#endif /* CONFIG_SYS_LONGHELP */
+#ifdef CONFIG_AUTO_COMPLETE
+ 0,
+#endif
+},
+
/* This does not use the CMD_TBL_ITEM macro as ? can't be used in symbol names */
{FSTR("?"), CONFIG_SYS_MAXARGS, 1, do_help,
FSTR("alias for 'help'"),
diff --git a/avr/pin.c b/avr/gpio.c
index 6e88aa5..3c47247 100644
--- a/avr/pin.c
+++ b/avr/gpio.c
@@ -2,7 +2,7 @@
#include <util/atomic.h>
#include <limits.h>
#include "debug.h"
-#include "pin.h"
+#include "gpio.h"
/*
@@ -32,7 +32,7 @@ pre Timer0 Timer1 Timer2
5 1024 x4 1024 x4 128 x2
6 256 x2
7 1024 x4
---------------------------------------------------
+--------------------------------------------------
*/
@@ -42,10 +42,10 @@ pre Timer0 Timer1 Timer2
#define PWMNEG 0b11
-const FLASH uint8_t prescale_factors_01[] =
+const FLASH uint8_t prescale_factors_01[] =
{ 8, 8, 4, 4, 0 };
-const FLASH uint8_t prescale_factors_2[] =
+const FLASH uint8_t prescale_factors_2[] =
{ 8, 4, 2, 2, 2, 4, 0 };
typedef volatile struct {
@@ -69,7 +69,7 @@ struct pindef_s {
};
-const FLASH struct pindef_s pinlist[PIN_MAX] = {
+const FLASH struct pindef_s pinlist[GPIO_MAX] = {
{ (port_t *) &PING, _BV(5), TIMER0 | CHANB },
{ (port_t *) &PING, _BV(4), NO_TIMER },
{ (port_t *) &PINB, _BV(4), TIMER2 | CHANA },
@@ -82,11 +82,11 @@ const FLASH struct pindef_s pinlist[PIN_MAX] = {
{ (port_t *) &PING, _BV(0), NO_TIMER },
{ (port_t *) &PINE, _BV(7), NO_TIMER },
};
-
-void pin_timer_off(uint8_t timertype)
+
+void gpio_timer_off(uint8_t timertype)
{
uint8_t chan_mask;
-
+
if (timertype & CHANA)
chan_mask = 0xc0;
else
@@ -117,7 +117,7 @@ void pin_timer_off(uint8_t timertype)
}
}
-int pin_config(int pin, pinmode_t mode)
+int gpio_config(int pin, gpiomode_t mode)
{
if ((unsigned) pin >= ARRAY_SIZE(pinlist)) {
/* Invalid pin number */
@@ -126,24 +126,24 @@ int pin_config(int pin, pinmode_t mode)
port_t *p = pinlist[pin].adr;
uint8_t bit = pinlist[pin].mask;
-
+
switch (mode) {
case INPUT:
- pin_timer_off(pinlist[pin].timer);
+ gpio_timer_off(pinlist[pin].timer);
ATOMIC_BLOCK(ATOMIC_FORCEON) {
p->ddr &= ~bit;
p->pout &= ~bit;
}
break;
case INPUT_PULLUP:
- pin_timer_off(pinlist[pin].timer);
+ gpio_timer_off(pinlist[pin].timer);
ATOMIC_BLOCK(ATOMIC_FORCEON) {
p->ddr &= ~bit;
p->pout |= bit;
}
break;
case OUTPUT:
- pin_timer_off(pinlist[pin].timer);
+ gpio_timer_off(pinlist[pin].timer);
case OUTPUT_TIMER:
ATOMIC_BLOCK(ATOMIC_FORCEON) {
p->ddr |= bit;
@@ -157,11 +157,11 @@ int pin_config(int pin, pinmode_t mode)
return 0;
}
-void pin_write(int pin, uint8_t val)
+void gpio_write(int pin, uint8_t val)
{
port_t *p = pinlist[pin].adr;
uint8_t bit = pinlist[pin].mask;
-
+
ATOMIC_BLOCK(ATOMIC_FORCEON) {
if (val)
p->pout |= bit;
@@ -170,20 +170,20 @@ void pin_write(int pin, uint8_t val)
}
}
-int pin_read(int pin)
+int gpio_read(int pin)
{
port_t *p = pinlist[pin].adr;
uint8_t bit = pinlist[pin].mask;
-
+
return (p->pin & bit) != 0;
}
-pinmode_t pin_config_get(int pin)
+gpiomode_t gpio_config_get(int pin)
{
uint8_t timertype = pinlist[pin].timer;
if (timertype & TIMER) {
-
+
uint8_t chan_mask;
if (timertype & CHANA)
chan_mask = 0xc0;
@@ -205,26 +205,26 @@ pinmode_t pin_config_get(int pin)
break;
}
}
-
+
port_t *p = pinlist[pin].adr;
uint8_t bit = pinlist[pin].mask;
if (p->ddr & bit)
return OUTPUT;
-
+
if (p->pout & bit)
return INPUT_PULLUP;
-
+
return INPUT;
}
-
+
/*
* return -1: pin has no timer output
* 0: pin is not configured for timer output
* > 0: divider
*/
-
-long pin_clockdiv_get(int pin)
+
+long gpio_clockdiv_get(int pin)
{
long divider;
uint8_t prescale;
@@ -234,9 +234,9 @@ long pin_clockdiv_get(int pin)
if ((timertype & TIMER) == 0)
return -1;
- if (pin_config_get(pin) != OUTPUT_TIMER)
+ if (gpio_config_get(pin) != OUTPUT_TIMER)
return 0;
-
+
switch (timertype & TIMER) {
case TIMER0:
prescale = TCCR0B;
@@ -257,19 +257,19 @@ long pin_clockdiv_get(int pin)
prescale = (prescale & 0x07) - 1;
divider += 1;
- pstab = (timertype & TIMER) == TIMER2 ?
+ pstab = (timertype & TIMER) == TIMER2 ?
prescale_factors_2 : prescale_factors_01;
-
+
while (prescale--)
divider *= pstab[prescale];
-
+
if ((timertype & (CHANA|T_16BIT)) == CHANA)
divider *= 2;
-
+
return divider;
}
-int pin_clockdiv_set(int pin, unsigned long divider)
+int gpio_clockdiv_set(int pin, unsigned long divider)
{
unsigned long ltop;
uint16_t top;
@@ -282,18 +282,18 @@ int pin_clockdiv_set(int pin, unsigned long divider)
if (divider < 2)
return -1;
-
+
ltop = divider;
if ((timertype & (CHANA|T_16BIT)) == CHANA)
ltop /= 2;
-
+
if (ltop > 1024 * ((timertype & T_16BIT) ? (1L<<16) : (1L<<8)))
return -1;
prescale = 1;
- pstab = (timertype & TIMER) == TIMER2 ?
+ pstab = (timertype & TIMER) == TIMER2 ?
prescale_factors_2 : prescale_factors_01;
-
+
// debug("** clockdiv_set: pin: %d, ltop: %lu, prescale: %d\n",
// pin, ltop, prescale);
@@ -365,8 +365,7 @@ int pin_clockdiv_set(int pin, unsigned long divider)
PING |= _BV(0); /* Debug */
- pin_config(pin, OUTPUT_TIMER);
+ gpio_config(pin, OUTPUT_TIMER);
return 0;
}
-
diff --git a/include/gpio.h b/include/gpio.h
new file mode 100644
index 0000000..ac48045
--- /dev/null
+++ b/include/gpio.h
@@ -0,0 +1,17 @@
+#ifndef GPIO_H
+#define GPIO_H
+
+/* Number of user configurable I/O pins */
+#define GPIO_MAX 11
+
+typedef enum {NONE, INPUT, INPUT_PULLUP, OUTPUT, OUTPUT_TIMER} gpiomode_t;
+
+int gpio_config(int pin, gpiomode_t mode);
+gpiomode_t gpio_config_get(int pin);
+int gpio_read(int pin);
+void gpio_write(int pin, uint8_t val);
+int gpio_clockdiv_set(int pin, unsigned long divider);
+long gpio_clockdiv_get(int pin);
+
+#endif /* GPIO_H */
+
diff --git a/include/pin.h b/include/pin.h
deleted file mode 100644
index 5b37587..0000000
--- a/include/pin.h
+++ /dev/null
@@ -1,17 +0,0 @@
-#ifndef PIN_H
-#define PIN_H
-
-/* Number of user configurable I/O pins */
-#define PIN_MAX 11
-
-typedef enum {NONE, INPUT, INPUT_PULLUP, OUTPUT, OUTPUT_TIMER} pinmode_t;
-
-int pin_config(int pin, pinmode_t mode);
-pinmode_t pin_config_get(int pin);
-int pin_read(int pin);
-void pin_write(int pin, uint8_t val);
-int pin_clockdiv_set(int pin, unsigned long divider);
-long pin_clockdiv_get(int pin);
-
-#endif /* PIN_H */
-