Source-Changes-HG archive

[Date Prev][Date Next][Thread Prev][Thread Next][Date Index][Thread Index][Old Index]

[src/trunk]: src/usr.bin/scmdctl A driver and user land utility for the Spark...



details:   https://anonhg.NetBSD.org/src/rev/027e2c3e89ff
branches:  trunk
changeset: 1027137:027e2c3e89ff
user:      brad <brad%NetBSD.org@localhost>
date:      Tue Dec 07 17:39:53 2021 +0000

description:
A driver and user land utility for the Sparkfun Serial Controlled Motor
Driver module as illustrated here:

https://www.sparkfun.com/products/13911

A SCMD module is a ARM SOC simular to a Arduino in front of a motor
driver chip.  The single SCMD module can control two motors and up to
16 additional modules can be chained together using an internal I2C
bus.  One can interface with the SCMD using tty uart commands, SPI or
I2C.  The driver in this commit adds a kernel driver for the I2C and
SPI interfaces.  The command line utility provides a set of
convenience commands that support most of the functions of the SCMD
and is able to use the tty uart mode, SPI user land or the included
kernel driver in a uniform manor.

The use of the SCMD module is mostly for small robots and the like,
but it can control anything that is controllable by voltage.

diffstat:

 distrib/sets/lists/base/mi         |    3 +-
 distrib/sets/lists/comp/mi         |    3 +-
 distrib/sets/lists/debug/mi        |    3 +-
 distrib/sets/lists/debug/module.mi |    6 +-
 distrib/sets/lists/man/mi          |   14 +-
 distrib/sets/lists/modules/mi      |    6 +-
 etc/MAKEDEV.tmpl                   |   13 +-
 share/man/man4/Makefile            |    4 +-
 share/man/man4/scmd.4              |   87 +++++
 share/man/man4/scmdi2c.4           |   73 ++++
 share/man/man4/scmdspi.4           |   71 ++++
 sys/conf/files                     |    6 +-
 sys/conf/majors                    |    3 +-
 sys/dev/i2c/files.i2c              |    6 +-
 sys/dev/i2c/scmdi2c.c              |  303 +++++++++++++++++
 sys/dev/ic/Makefile                |    5 +-
 sys/dev/ic/scmd.c                  |  627 ++++++++++++++++++++++++++++++++++++
 sys/dev/ic/scmdreg.h               |  236 +++++++++++++
 sys/dev/ic/scmdvar.h               |   44 ++
 sys/dev/spi/files.spi              |    6 +-
 sys/dev/spi/scmdspi.c              |  267 +++++++++++++++
 sys/modules/Makefile               |   12 +-
 sys/modules/scmd/Makefile          |   11 +
 sys/modules/scmd/scmd.ioconf       |    3 +
 sys/modules/scmdi2c/Makefile       |   11 +
 sys/modules/scmdi2c/scmdi2c.ioconf |   16 +
 usr.bin/Makefile                   |    4 +-
 usr.bin/scmdctl/Makefile           |    7 +
 usr.bin/scmdctl/common.c           |  502 ++++++++++++++++++++++++++++
 usr.bin/scmdctl/common.h           |   48 ++
 usr.bin/scmdctl/i2cspi.c           |  132 +++++++
 usr.bin/scmdctl/i2cspi.h           |   28 +
 usr.bin/scmdctl/printscmd.c        |  115 ++++++
 usr.bin/scmdctl/printscmd.h        |   28 +
 usr.bin/scmdctl/responses.h        |   42 ++
 usr.bin/scmdctl/scmdctl.1          |  285 ++++++++++++++++
 usr.bin/scmdctl/scmdctl.c          |  643 +++++++++++++++++++++++++++++++++++++
 usr.bin/scmdctl/scmdctl.h          |   71 ++++
 usr.bin/scmdctl/scmdctlconst.h     |  319 ++++++++++++++++++
 usr.bin/scmdctl/uart.c             |  511 +++++++++++++++++++++++++++++
 usr.bin/scmdctl/uart.h             |   30 +
 41 files changed, 4582 insertions(+), 22 deletions(-)

diffs (truncated from 4977 to 300 lines):

diff -r 51bf86267891 -r 027e2c3e89ff distrib/sets/lists/base/mi
--- a/distrib/sets/lists/base/mi        Tue Dec 07 14:31:13 2021 +0000
+++ b/distrib/sets/lists/base/mi        Tue Dec 07 17:39:53 2021 +0000
@@ -1,4 +1,4 @@
-# $NetBSD: mi,v 1.1285 2021/10/22 21:03:01 kre Exp $
+# $NetBSD: mi,v 1.1286 2021/12/07 17:39:53 brad Exp $
 #
 # Note:        Don't delete entries from here - mark them as "obsolete" instead,
 #      unless otherwise stated below.
@@ -811,6 +811,7 @@
 ./usr/bin/rusers                               base-netutil-bin
 ./usr/bin/rwall                                        base-netutil-bin
 ./usr/bin/rwho                                 base-netutil-bin
+./usr/bin/scmdctl                              base-util-bin
 ./usr/bin/scp                                  base-secsh-bin
 ./usr/bin/script                               base-util-bin
 ./usr/bin/sdiff                                        base-util-bin
diff -r 51bf86267891 -r 027e2c3e89ff distrib/sets/lists/comp/mi
--- a/distrib/sets/lists/comp/mi        Tue Dec 07 14:31:13 2021 +0000
+++ b/distrib/sets/lists/comp/mi        Tue Dec 07 17:39:53 2021 +0000
@@ -1,4 +1,4 @@
-#      $NetBSD: mi,v 1.2398 2021/11/15 14:01:50 christos Exp $
+#      $NetBSD: mi,v 1.2399 2021/12/07 17:39:53 brad Exp $
 #
 # Note: don't delete entries from here - mark them as "obsolete" instead.
 ./etc/mtree/set.comp                           comp-sys-root
@@ -637,6 +637,7 @@
 ./usr/include/dev/ic/qemufwcfgio.h             comp-c-include
 ./usr/include/dev/ic/rrunnerreg.h              comp-obsolete           obsolete
 ./usr/include/dev/ic/rrunnervar.h              comp-obsolete           obsolete
+./usr/include/dev/ic/scmdreg.h                 comp-c-include
 ./usr/include/dev/ic/smc83c170reg.h            comp-obsolete           obsolete
 ./usr/include/dev/ic/smc83c170var.h            comp-obsolete           obsolete
 ./usr/include/dev/ic/smc90cx6reg.h             comp-obsolete           obsolete
diff -r 51bf86267891 -r 027e2c3e89ff distrib/sets/lists/debug/mi
--- a/distrib/sets/lists/debug/mi       Tue Dec 07 14:31:13 2021 +0000
+++ b/distrib/sets/lists/debug/mi       Tue Dec 07 17:39:53 2021 +0000
@@ -1,4 +1,4 @@
-# $NetBSD: mi,v 1.368 2021/11/18 15:03:19 thorpej Exp $
+# $NetBSD: mi,v 1.369 2021/12/07 17:39:53 brad Exp $
 ./etc/mtree/set.debug                           comp-sys-root
 ./usr/lib                                      comp-sys-usr            compatdir
 ./usr/lib/i18n/libBIG5_g.a                     comp-c-debuglib         debuglib,compatfile
@@ -787,6 +787,7 @@
 ./usr/libdata/debug/usr/bin/rusers.debug       comp-netutil-debug      debug
 ./usr/libdata/debug/usr/bin/rwall.debug                comp-netutil-debug      debug
 ./usr/libdata/debug/usr/bin/rwho.debug         comp-netutil-debug      debug
+./usr/libdata/debug/usr/bin/scmdctl.debug      comp-util-debug         debug
 ./usr/libdata/debug/usr/bin/scp.debug          comp-secsh-debug        debug
 ./usr/libdata/debug/usr/bin/script.debug       comp-util-debug         debug
 ./usr/libdata/debug/usr/bin/sdiff.debug                comp-util-debug         debug
diff -r 51bf86267891 -r 027e2c3e89ff distrib/sets/lists/debug/module.mi
--- a/distrib/sets/lists/debug/module.mi        Tue Dec 07 14:31:13 2021 +0000
+++ b/distrib/sets/lists/debug/module.mi        Tue Dec 07 17:39:53 2021 +0000
@@ -1,4 +1,4 @@
-# $NetBSD: module.mi,v 1.15 2021/11/06 13:34:40 brad Exp $
+# $NetBSD: module.mi,v 1.16 2021/12/07 17:39:53 brad Exp $
 ./usr/libdata/debug/@MODULEDIR@                                        modules-base-kernel     kmod,debug
 ./usr/libdata/debug/@MODULEDIR@/accf_dataready                 modules-base-kernel     kmod,debug
 ./usr/libdata/debug/@MODULEDIR@/accf_dataready/accf_dataready.kmod.debug       modules-base-kernel     kmod,debug
@@ -318,6 +318,10 @@
 ./usr/libdata/debug/@MODULEDIR@/putter/putter.kmod.debug               modules-base-kernel     kmod,debug
 ./usr/libdata/debug/@MODULEDIR@/raid                           modules-base-kernel     kmod,debug
 ./usr/libdata/debug/@MODULEDIR@/raid/raid.kmod.debug                   modules-base-kernel     kmod,debug
+./usr/libdata/debug/@MODULEDIR@/scmd                           modules-base-kernel     kmod,debug
+./usr/libdata/debug/@MODULEDIR@/scmd/scmd.kmod.debug           modules-base-kernel     kmod,debug
+./usr/libdata/debug/@MODULEDIR@/scmdi2c                                modules-base-kernel     kmod,debug
+./usr/libdata/debug/@MODULEDIR@/scmdi2c/scmdi2c.kmod.debug             modules-base-kernel     kmod,debug
 ./usr/libdata/debug/@MODULEDIR@/scsiverbose                    modules-base-kernel     kmod,debug
 ./usr/libdata/debug/@MODULEDIR@/scsiverbose/scsiverbose.kmod.debug     modules-base-kernel     kmod,debug
 ./usr/libdata/debug/@MODULEDIR@/sdtemp                         modules-base-kernel     kmod,debug
diff -r 51bf86267891 -r 027e2c3e89ff distrib/sets/lists/man/mi
--- a/distrib/sets/lists/man/mi Tue Dec 07 14:31:13 2021 +0000
+++ b/distrib/sets/lists/man/mi Tue Dec 07 17:39:53 2021 +0000
@@ -1,4 +1,4 @@
-# $NetBSD: mi,v 1.1729 2021/11/06 13:34:40 brad Exp $
+# $NetBSD: mi,v 1.1730 2021/12/07 17:39:53 brad Exp $
 #
 # Note: don't delete entries from here - mark them as "obsolete" instead.
 #
@@ -514,6 +514,7 @@
 ./usr/share/man/cat1/rusers.0                  man-netutil-catman      .cat
 ./usr/share/man/cat1/rwall.0                   man-netutil-catman      .cat
 ./usr/share/man/cat1/rwho.0                    man-netutil-catman      .cat
+./usr/share/man/cat1/scmdctl.0                 man-util-catman         .cat
 ./usr/share/man/cat1/scp.0                     man-secsh-catman        .cat
 ./usr/share/man/cat1/screenblank.0             man-sysutil-catman      .cat
 ./usr/share/man/cat1/script.0                  man-util-catman         .cat
@@ -1685,6 +1686,9 @@
 ./usr/share/man/cat4/sc.0                      man-sys-catman          .cat
 ./usr/share/man/cat4/scc.0                     man-obsolete            obsolete
 ./usr/share/man/cat4/schide.0                  man-sys-catman          .cat
+./usr/share/man/cat4/scmd.0                    man-sys-catman          .cat
+./usr/share/man/cat4/scmdi2c.0                 man-sys-catman          .cat
+./usr/share/man/cat4/scmdspi.0                 man-sys-catman          .cat
 ./usr/share/man/cat4/scsi.0                    man-sys-catman          .cat
 ./usr/share/man/cat4/scsibus.0                 man-sys-catman          .cat
 ./usr/share/man/cat4/sctp.0                    man-sys-catman          .cat
@@ -3814,6 +3818,7 @@
 ./usr/share/man/html1/rusers.html              man-netutil-htmlman     html
 ./usr/share/man/html1/rwall.html               man-netutil-htmlman     html
 ./usr/share/man/html1/rwho.html                        man-netutil-htmlman     html
+./usr/share/man/html1/scmdctl.html             man-util-htmlman        html
 ./usr/share/man/html1/scp.html                 man-secsh-htmlman       html
 ./usr/share/man/html1/screenblank.html         man-sysutil-htmlman     html
 ./usr/share/man/html1/script.html              man-util-htmlman        html
@@ -4862,6 +4867,9 @@
 ./usr/share/man/html4/sc.html                  man-sys-htmlman         html
 ./usr/share/man/html4/scc.html                 man-obsolete            obsolete
 ./usr/share/man/html4/schide.html              man-sys-htmlman         html
+./usr/share/man/html4/scmd.html                        man-sys-htmlman         html
+./usr/share/man/html4/scmdi2c.html             man-sys-htmlman         html
+./usr/share/man/html4/scmdspi.html             man-sys-htmlman         html
 ./usr/share/man/html4/scsi.html                        man-sys-htmlman         html
 ./usr/share/man/html4/scsibus.html             man-sys-htmlman         html
 ./usr/share/man/html4/sctp.html                        man-sys-htmlman         html
@@ -6770,6 +6778,7 @@
 ./usr/share/man/man1/rusers.1                  man-netutil-man         .man
 ./usr/share/man/man1/rwall.1                   man-netutil-man         .man
 ./usr/share/man/man1/rwho.1                    man-netutil-man         .man
+./usr/share/man/man1/scmdctl.1                 man-util-man            .man
 ./usr/share/man/man1/scp.1                     man-secsh-man           .man
 ./usr/share/man/man1/screenblank.1             man-sysutil-man         .man
 ./usr/share/man/man1/script.1                  man-util-man            .man
@@ -7945,6 +7954,9 @@
 ./usr/share/man/man4/sc.4                      man-sys-man             .man
 ./usr/share/man/man4/scc.4                     man-obsolete            obsolete
 ./usr/share/man/man4/schide.4                  man-sys-man             .man
+./usr/share/man/man4/scmd.4                    man-sys-man             .man
+./usr/share/man/man4/scmdi2c.4                 man-sys-man             .man
+./usr/share/man/man4/scmdspi.4                 man-sys-man             .man
 ./usr/share/man/man4/scsi.4                    man-sys-man             .man
 ./usr/share/man/man4/scsibus.4                 man-sys-man             .man
 ./usr/share/man/man4/sctp.4                    man-sys-man             .man
diff -r 51bf86267891 -r 027e2c3e89ff distrib/sets/lists/modules/mi
--- a/distrib/sets/lists/modules/mi     Tue Dec 07 14:31:13 2021 +0000
+++ b/distrib/sets/lists/modules/mi     Tue Dec 07 17:39:53 2021 +0000
@@ -1,4 +1,4 @@
-# $NetBSD: mi,v 1.149 2021/11/06 13:34:40 brad Exp $
+# $NetBSD: mi,v 1.150 2021/12/07 17:39:53 brad Exp $
 #
 # Note: don't delete entries from here - mark them as "obsolete" instead.
 #
@@ -385,6 +385,10 @@
 ./@MODULEDIR@/scsiverbose/scsiverbose.kmod     modules-base-kernel     kmod
 ./@MODULEDIR@/sdt                              base-obsolete           obsolete
 ./@MODULEDIR@/sdt/sdt.kmod                     base-obsolete           obsolete
+./@MODULEDIR@/scmd                             modules-base-kernel     kmod
+./@MODULEDIR@/scmd/scmd.kmod                   modules-base-kernel     kmod
+./@MODULEDIR@/scmdi2c                          modules-base-kernel     kmod
+./@MODULEDIR@/scmdi2c/scmdi2c.kmod             modules-base-kernel     kmod
 ./@MODULEDIR@/sdtemp                           modules-base-kernel     kmod
 ./@MODULEDIR@/sdtemp/sdtemp.kmod               modules-base-kernel     kmod
 ./@MODULEDIR@/secmodel_bsd44                   modules-base-kernel     kmod
diff -r 51bf86267891 -r 027e2c3e89ff etc/MAKEDEV.tmpl
--- a/etc/MAKEDEV.tmpl  Tue Dec 07 14:31:13 2021 +0000
+++ b/etc/MAKEDEV.tmpl  Tue Dec 07 17:39:53 2021 +0000
@@ -1,5 +1,5 @@
 #!/bin/sh -
-#      $NetBSD: MAKEDEV.tmpl,v 1.227 2021/11/06 13:34:40 brad Exp $
+#      $NetBSD: MAKEDEV.tmpl,v 1.228 2021/12/07 17:39:53 brad Exp $
 #
 # Copyright (c) 2003,2007,2008 The NetBSD Foundation, Inc.
 # All rights reserved.
@@ -267,6 +267,7 @@
 #      radio*  radio devices
 #      random  Random number generator
 #      rtc*    RealTimeClock
+#      scmd*   Sparkfun Serial Controlled Motor Driver
 #      scsibus* SCSI busses
 #      se*     SCSI Ethernet
 #      ses*    SES/SAF-TE SCSI Devices
@@ -847,6 +848,7 @@
        makedev ipmi0
        makedev qemufwcfg
        makedev sht3xtemp0
+       makedev scmd0
        makedev local # do this last
        ;;
 
@@ -919,6 +921,10 @@
        makedev sht3xtemp0
        ;;
 
+scmd)
+       makedev scmd0
+       ;;
+
 usbs)
        makedev usb usb0 usb1 usb2 usb3 usb4 usb5 usb6 usb7
        makedev usb8 usb9 usb10 usb11 usb12 usb13 usb14 usb15
@@ -2261,6 +2267,11 @@
        mkdev sht3xtemp$unit c %sht3xtemp_chr% $unit 664
        ;;
 
+scmd[0-9]*)
+       unit=${i#scmd}
+       mkdev scmd$unit c %scmd_chr% $unit 666
+       ;;
+
 midevend)
 %MI_DEVICES_END%
 local)
diff -r 51bf86267891 -r 027e2c3e89ff share/man/man4/Makefile
--- a/share/man/man4/Makefile   Tue Dec 07 14:31:13 2021 +0000
+++ b/share/man/man4/Makefile   Tue Dec 07 17:39:53 2021 +0000
@@ -1,4 +1,4 @@
-#      $NetBSD: Makefile,v 1.719 2021/11/06 13:34:39 brad Exp $
+#      $NetBSD: Makefile,v 1.720 2021/12/07 17:39:54 brad Exp $
 #      @(#)Makefile    8.1 (Berkeley) 6/18/93
 
 MAN=   aac.4 ac97.4 acardide.4 aceride.4 acphy.4 \
@@ -55,7 +55,7 @@
        raid.4 ral.4 ray.4 rcons.4 rdcphy.4 re.4 rge.4 rgephy.4 rlphy.4 \
        rnd.4 route.4 rs5c372rtc.4 rtk.4 rtsx.4 rtw.4 rtwn.4 rum.4 run.4 \
        s390rtc.4 satalink.4 sbus.4 schide.4 \
-       scsi.4 sctp.4 sd.4 se.4 seeprom.4 sem.4 \
+       scmd.4 scmdi2c.4 scmdspi.4 scsi.4 sctp.4 sd.4 se.4 seeprom.4 sem.4 \
        ses.4 sf.4 sfb.4 sgp40mox.4 sgsmix.4 shb.4 shmif.4 shpcic.4 sht3xtemp.4 \
        sht4xtemp.4 si70xxtemp.4 siisata.4 siop.4 sip.4 siside.4 sk.4 sl.4 \
        slide.4 sm.4 smscphy.4 smsh.4 sn.4 sony.4 spc.4 speaker.4 spif.4 sqphy.4 \
diff -r 51bf86267891 -r 027e2c3e89ff share/man/man4/scmd.4
--- /dev/null   Thu Jan 01 00:00:00 1970 +0000
+++ b/share/man/man4/scmd.4     Tue Dec 07 17:39:53 2021 +0000
@@ -0,0 +1,87 @@
+.\" $NetBSD: scmd.4,v 1.1 2021/12/07 17:39:54 brad Exp $
+.\"
+.\" Copyright (c) 2021 Brad Spencer <brad%anduin.eldar.org@localhost>
+.\"
+.\" Permission to use, copy, modify, and distribute this software for any
+.\" purpose with or without fee is hereby granted, provided that the above
+.\" copyright notice and this permission notice appear in all copies.
+.\"
+.\" THE SOFTWARE IS PROVIDED "AS IS" AND THE AUTHOR DISCLAIMS ALL WARRANTIES
+.\" WITH REGARD TO THIS SOFTWARE INCLUDING ALL IMPLIED WARRANTIES OF
+.\" MERCHANTABILITY AND FITNESS. IN NO EVENT SHALL THE AUTHOR BE LIABLE FOR
+.\" ANY SPECIAL, DIRECT, INDIRECT, OR CONSEQUENTIAL DAMAGES OR ANY DAMAGES
+.\" WHATSOEVER RESULTING FROM LOSS OF USE, DATA OR PROFITS, WHETHER IN AN
+.\" ACTION OF CONTRACT, NEGLIGENCE OR OTHER TORTIOUS ACTION, ARISING OUT OF
+.\" OR IN CONNECTION WITH THE USE OR PERFORMANCE OF THIS SOFTWARE.
+.\"
+.Dd December 1, 2021
+.Dt SCMD 4
+.Os
+.Sh NAME
+.Nm scmd
+.Nd Common driver for the Sparkfun Serial Controlled Motor Driver
+.Sh SYNOPSIS
+.Cd "scmd* at iic? ..."
+.Cd "scmd* at spi? ..."
+.Sh DESCRIPTION
+The
+.Nm
+driver provides the common framework to the Sparkfun SCMD board.
+The SCMD board is a Cypress core ARM SOC in front of a DRV8835 motor driver chip.
+There are a number of ways to talk to the board and
+.Xr scmdi2c 4
+and
+.Xr scmdspi 4
+should be consulted for the I2C and SPI frontend drivers.
+The board is fully documented in the datasheet for at Sparkfun.
+.Pp
+The board provides a register address space of 126 registers which control the various
+behaviors of the motors attached to the board.
+Each SCMD board can handle two motors,
+and up to 16 SCMD boards may be chained together allowing for 34 motors to be controlled
+from a single master instance.
+The secondary boards are accessed by set of view port registers
+from the main board.  The
+.Xr scmd 4
+driver and its assoicated frontends flatten the main SCMD board and all chained boards into
+a linear register space that can be opened, seeked, read from and written to like any other
+file or device without having to worry about the view port.
+.Pp
+A command line utility
+.Xr scmdctl 1
+is provided that allows convient command line commands for most of the functions provided by the
+SCMD board.
+.Sh SYSCTL VARIABLES
+The following
+.Xr sysctl 3
+variables are provided:
+.Bl -tag -width indent
+.It Li hw.scmd0.debug
+If the driver is compiled with
+.Dv SCMD_DEBUG ,
+this node will appear and can be used to set the debugging level.
+.El
+.Sh FILES
+.Bl -tag -width /dev/rcaXXXXX -compact
+.It Pa /dev/scmd Ns Ar u
+character device allowing access to the register space of a main
+.Ar u ,
+SCMD device
+.Sh SEE ALSO
+.Xr iic 4 ,
+.Xr spi 4 ,
+.Xr scmdi2c 4 ,
+.Xr scmdspi 4 ,
+.Xr scmdctl 1 ,



Home | Main Index | Thread Index | Old Index