]> cloudbase.mooo.com Git - z180-stamp.git/commitdiff
Rename pin.. to gpio..
authorLeo C <erbl259-lmu@yahoo.de>
Fri, 21 Nov 2014 12:49:19 +0000 (13:49 +0100)
committerLeo C <erbl259-lmu@yahoo.de>
Fri, 21 Nov 2014 12:49:19 +0000 (13:49 +0100)
avr/Tupfile
avr/cmd_gpio.c [moved from avr/cmd_pin.c with 90% similarity]
avr/command_tbl.c
avr/gpio.c [moved from avr/pin.c with 88% similarity]
include/gpio.h [new file with mode: 0644]
include/pin.h [deleted file]

index acb4aa54efca61dda0ee015afa1d2b8212da628a..a50b3b9b4726ddd84114c86c3fa13a8615dc79eb 100644 (file)
@@ -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 |>
-
similarity index 90%
rename from avr/cmd_pin.c
rename to avr/cmd_gpio.c
index 83a55f7eeddb1e69f78c7c4215f9173e5999a05e..84723d2372453f2d14e9f0913284cc4b03bf6f58 100644 (file)
@@ -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;
 }
-
index 336c608b326c72a530a99e824ecaa4b52ce63a24..97110fd4f4649f6f651734a4524cb8cae026114b 100644 (file)
@@ -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'"),
similarity index 88%
rename from avr/pin.c
rename to avr/gpio.c
index 6e88aa576c561f280aecc82a57be5f44070e4502..3c47247ef64baf90ff66b18e198713cec3c97cf6 100644 (file)
--- a/avr/pin.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 (file)
index 0000000..ac48045
--- /dev/null
@@ -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 (file)
index 5b37587..0000000
+++ /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 */
-