Monday Nov 05, 2007

A programmer's ABCs

Several years ago, before blogging, I cons'd up a programmer's ABC for Stephen Hahn's first child, Benjamin.  I'd forgotten about this until Stephen mentioned last week and mailed me a link to the image; I'd lost the original.  It's a little SPARC-centric, but so was I at the time:


A Programmer's ABC

A is for algorithm, patented or not.

B is for break, to jump out of this rot.

C is for continue, to jump to the top of one's loops.

D is for default, the case that handles the oops.

E is for else, the predicate's inversion.

F is for for, of the loops the most popular version.

G is for goto, a jump oft considered dubious.

H is for hardware, for profits salubrious.

I is for if, a conditional statement.

J is for jmpl, an indirect jump causing performance abatement.

K is for thousands in powers of two.

L is for long, whose size recently grew.

M is for membar, whose use can confound.

N is for NOP, which in delay slots often is found.

O is for operator, whose overloading is oft unsupportable.

P is for pragma, with usage unportable.

Q is for quadword, the largest of all.

R is for return, when we make the stack not so tall.

S is for switch, a computed goto for which we all yearn.

T is for trap, from which we may never return.

U is for unsigned, to avoid two's complement extension.

V is for volatile, whose presence incites apprehension.

W is for WSTATE register, for window traps most topical.

X is for XOR, bitwise not logical.

Y is for Y register, deprecated for years.

Z is for zero, whose dereferencing everyone fears.

Friday Jun 01, 2007

Friday afternoon SPARKFUN

Mike Pogue mentioned he was considering using a USB-connected PIC controller to drive some stepper motors from a PC.  He'd ordered out a USB Bit Wacker , which plugs right into a USB port and looks like a serial port to the host OS, and gives you 14 ports that can either be digital in, out or analog in.  The host sends simple ASCII commands down, and the Bit Whacker sends back status/port data. Cool!  Earlier this afternoon, he brought it in and we plugged it into my Tyan whitebox running Nevada 64a using a mini-USB cable.  I was running a tail -f on /var/adm/messages, and saw:

Jun  1 15:29:34 cyber usba: [ID 912658] USB 2.0 device (usb4d8,a) operating at full speed (USB 1.x) on USB 1.10 root hub: communications@1, usb_mid6 at bus address 3
Jun  1 15:29:34 cyber usba: [ID 349649]       Microchip Technology Inc. CDC RS-232 Emulation Demo
Jun  1 15:29:34 cyber genunix: [ID 936769] usb_mid6 is /pci@0,0/pci1022,7460@6/pci1022,7464@0/communications@1
Jun  1 15:29:34 cyber genunix: [ID 408114] /pci@0,0/pci1022,7460@6/pci1022,7464@0/communications@1 (usb_mid6) online
Jun  1 15:29:34 cyber usba: [ID 349649] usba: no driver found for interface 1 (nodename: 'data') of Microchip Technology Inc. CDC RS-232 Emulation Demo
Jun  1 15:29:34 cyber usba: [ID 912658] USB 2.0 interface (usbif4d8,a.config1.0) operating at full speed (USB 1.x) on USB 1.10 root hub: modem@0, usbsacm3 at bus address 3
Jun  1 15:29:34 cyber usba: [ID 349649]       Microchip Technology Inc. CDC RS-232 Emulation Demo
Jun  1 15:29:34 cyber genunix: [ID 936769] usbsacm3 is /pci@0,0/pci1022,7460@6/pci1022,7464@0/communications@1/modem@0
Jun  1 15:29:34 cyber genunix: [ID 408114] /pci@0,0/pci1022,7460@6/pci1022,7464@0/communications@1/modem@0 (usbsacm3) online

Well, that looked promising!  Sure enough,

 % ls -l /dev/term
 total 6
 lrwxrwxrwx   1 root     root          78 Jun  1 15:29 0 ->
 lrwxrwxrwx   1 root     root          29 Dec 21 14:43 a -> ../../devices/isa/asy@1,3f8:a
 lrwxrwxrwx   1 root     root          29 Dec 21 14:43 b -> ../../devices/isa/asy@1,2f8:b

Ok.  I added a quick entry to /etc/remote:

# tip sparkfun
UBW FW D Version 1.4.1

At this point I used various commands to read the inputs/buttons, flash the LED, etc.  If needed, one can also write and download alternate firmware directly to the on-board PIC18F2455; there's a built-in bootloader that cannot be flashed over, so a PIC programmer is never needed.  This unit seems ideally suited to wiring up coffee makers, sprinkler systems, etc, so they can be connected to a host computer.  Looks like I could write some firmware to directly drive servo motors using the Bit Whacker to count encoder  pulses and close the velocity loop; the host computer would read say 100Hz update of position and update the desired velocity of the motor... and w/o any firmware work at all, it seems directly applicable to our next Burning Man project, which will have an OpenSolaris computer controlling things for the first time on the playa AFAIK... more about that later.

Here's a picture of the device:

Bit Whacker next to a quarter

(The picture was taken w/ my Razr 3i and uploaded using Solaris as well.... )




Wednesday Jan 17, 2007

New home server

Building a new household server....

Like a lot of families these days, our household IT infrastructure has had to adapt as we all became more and more fond of computers for work, school and recreation.  With digital photograpy, ripping hundreds of CDs, describing our various activities and travels on web pages,  two teenagers and the heavy use of email, and the need to provide stable storage for homework and digital art, we've been playing catchup for a while.  This led us directly to designing and building a new server to handle storage of all the digital media, web-serving and email.  At the same time, I was tired of the whine from the surplus X1 rack-mount server I had stuffed in the closet, and decided to merge my home desktop and server together to reduce power consumption.  With some thinking we arrived at the following hardware design:

  • Tyan 2865 motherboard - 4 SATA ports that worked w/ Solaris in compatibility mode, sound and an on-board nvidia gigabit ethernet chip, both supported by Solaris as these were the motherboards in the original Ultra 20s.
  • 2 x 2.6 GHZ AMD CPU; this was rather more CPU than I originally planned, but sometimes things turn up...
  • 1 GB ECC RAM, later upgraded to 2 GB.
  • 4 x 500 GB Seagate drives for redundant data storage, plus a leftover 40GB IDE drive for root and a DVD-RW drive for movies and burning DVDs.
  • NVIdia 6600 GT video card - available for a reasonable price and with good 3D graphics for playing with those video game ports to Solaris.  With the bundled NVidia OpenGL drivers in 55, the cool screen savers work out of the box, too!
  • 450 W Antec power supply
  • inexpensive second NIC for our external interface; I happened to have an $7 Gb Airlink card which uses the Realtek part; this works out of the box as well.
  • A small case - I used an Antec Lanboy as they're small and light.  In retrospect, a larger case such as an Antec P180 would have been a better choice.  I do like the disk cooling on this design, though - the 120 MM (blue, heh) fan keeps the drive temps very moderate.
Well, this went together pretty easily (especially since I had my son do all the work...).  The software selection and configuration was actually considerably more effort than picking the hardware components and building the system.  We're now running:
  • Solaris Nevada build 55
  • the bundled Bind 9 for handling internal, DMZ and external views of our various domains.
  • the bundled Apache 2.2 handles our various web pages and our 3 virtual domains.
  • the bundled dhcp server handles DHCP service.  I configured this with dhcpmgr; since all the other machines in the house use DHCP there's little admin work to do anywhere else.  This is a real boon during the kid's LAN parties; things just work.
  • The bundled Samba server provides NAS for the various Microsoft and Mac clients in the house.  With the latest OS-X builds, NFS works well enough to use; we may switch.  I use swat to configure Samba.
  • Printing is provided by the stock lp and ipp-listeners aided by Samba for the kid's microsoft game platforms.  I configured this with printmgr.  We print to an HP1200 that has worked flawlessly for years w/ just a couple of toner changes.
  • the bundled IPFilter provides carefully controlled port filtering on both the external and internal network interfaces.
  • Dovecot (compiled from source) provides IMAP service for both our LAN and (with SSL) over the Internet.  This service is under SMF control so it starts automatically when the machine boots. I chose Dovecot since it also cooperates with Postfix to handle SMTP authentication.
  • Postfix (compiled from source + Berkeley DBM libraries).  This provides SMTP service with TLS and AUTH needed to control relaying by family members using external connections.  The anti-SPAM features are also excellent and pretty easy to setup given the numerous how-to guides available on the web.  With Postfix I feel actually in control; I always had to rely on John Beck to customize my sendmail configuration.
  • The unbundled SUNcry{r} encryption packages were needed to get the bundled OpenSSL libraries working correctly w/ TLS and Thunderbird. Darren Moffat promises to have the high grade support bundled into OpenSolaris soon.

So far things are working very well.  The 4x500 GB drives are in a RAID-Z configuration with ZFS; we can sustain 120 MB/sec or so reading or writing to the 20 odd filesystems configured on the single pool.  Samba works pretty well; we managed to feed 10 different files to 10 different clients at nearly 100Mb/sec apiece during one of the kids' Lan parties.  Dovecot in particular seems very fast on top of ZFS, and other than a glitch with my forgetting to set the maximum user mailbox size Postfix has been trouble free.  I use this machine as my desktop as well in the evenings.

What are we still thinking about changing? Well:

  • My son wants a Ventrilo audio server for his Guild Wars games.  Another manifest, some more testing.
  • I may add greylisting to our SPAM prevention techniques; this will require a bit more configuration work. We reject perhaps 700 SPAM emails per day for our small number of email users; we each still get a handleful each day.
  • I'm going to add a Slim Devices Squeezebox to our stereo system; we outgrew the 200 CD changer some time ago.  That's another server to run, but we get access to the 65+ GB of music anywhere in the house.
  • I'm thinking about adding a separate Ethernet interface to plug in the wireless router  This will let me experiment with more secure ways to configure wireless services.
  • When ZFS root and boot is supported , I'll configure another pair of drives for a mirrored root pool using a SI3114 card. Right now we just back up the small root partition to our ZFS pool.

An engineer's viewpoint on Solaris...


« July 2016