Wednesday, 28 April 2010

Monitor Functions in the IAR Compilers for AVR

In AVR chips, game-changing actions like changing the clock prescaler or setting the watchdog are so important that they are afforded a protection mechanism all of their own. Timed write sequences are used to prevent accidental or rogue writes from fundamentally messing with your day.

These require you to perform a sequence of write operations within a defined time period - typically you need to do two writes within four clock cycles.

Care must be taken when performing such a write sequence that no other operations could take place that would violate the required timing. Typical candidates for such mischievous behaviour are interrupt service routines, which have an uncanny knack of firing at the most inconvenient times.

The obvious way to ensure that your timed write sequence is interrupt-safe is to disable interrupts around it, like so:

void do_timed_write_operation( void )
{
__disable_interrupt();
// timed write sequence goes here
__enable interrupt();
}

Unfortunately this contains a nasty little gotcha: if you call this function from code in which interrupts are disabled, they will be enabled on return from the function. This is almost certainly not what is intended, and can lead to late night debugging sessions.

A safer approach is to save the interrupt state on function entry, disable interrupts, do your business, and then put the interrupts back the way you found them:

void do_timed_write_operation_2( void )
{
uint8_t interrupt_state = __save_interrupt();
__disable_interrupt();
// timed write sequence goes here
__restore_interrupt( interrupt_state );
}

This approach is so common and idiomatic that the IAR compilers for AVR support it directly with the __monitor keyword. The following function is equivalent to the previous one:

__monitor void do_timed_write_operation_3( void )
{
// timed write sequence goes here
}

Unfortunately declaring a monitor function involves a code overhead - after all, even though you can't see it explicitly in the C, a quick squint at the list files will show that the interrupts are still being saved, disabled, and restored.

A saving grace here is that most such Big Important Things tend to happen during system initialisation, when interrupts are disabled anyway. In such circumstances you can perform your timed writes au naturel, without any interrupt protection. However you really need to convince yourself that it is safe to do so. It would be a brave man indeed who called the first function above once the system was up and running without spending a very long time looking at possible consequences.

In general I would suggest that all timed write sequences be protected by default. Such protection can be removed if you're convinced that it's safe to do so - and of course if you document this assumption in the comments.


Wednesday, 21 April 2010

File Under Easy Listening

This is an excellent podcast by David Heinemeier Hansson (DHH) on Legacy Software.  It's a recording from a talk at RailsConf Europe, and the podcast (i.e., audio-only) format doesn't really work in the last third of the talk, in which he's refactoring some code on stage.  However, the gist of his argument is completely sound - if you wince in embarrassment/pain/surprise when you look at code you wrote a few years ago, it's nothing to be ashamed of.  The code hasn't got worse - you've got better.  In the interim you've learned new techniques and idioms, and the fact that the earlier you wasn't favoured with your current clear-sighted and visionary approach to writing code shows that you've progressed.

[The corollary of this is that the future you will be embarrassed/pained/surprised by what the current clear-sighted and visionary you is doing today, but what the hey, just appreciate the step change from yesteryear.]

Also highly recommended is this appearance by DHH on Jason Calacanis's This Week In Startups podcast.  Two successful and highly opinionated people with entirely different takes on business, money, and work slug it out.  Who's right?  They both are, of course.  They've figured out what works for them, and good luck to them.  You don't have to agree wholeheartedly with either to enjoy the debate.

Sunday, 28 March 2010

Joel Spolsky and the Death of Blogging

Warning: this article contains meta material.  If you are easily offended by blogging about blogging, please stop reading now.

Still here?  Good, let's crack on then.

I personally am not a fan of metablogs - I read blogs for interest, entertainment, and education, and am not particularly interested in reading the authors' pontifications on the state of their respective navels.  One saving grace for blogs in this respect is that they are less susceptible to the curse of self-reference than tech podcasts.  These seem without exception to descend into an analysis of the microphones, headphones, software, and patch cables being used.  I suspect this is largely a by-product of putting geeks in close proximity to, you know, geeky stuff.  Perhaps blogging is slightly less prone to this phenomenon as it features fewer tools - after all, you just need a text editor.

And so it was with some surprise that I found myself writing this.  What prompted it was the recent announcement by Joel Spolsky that he's going to quit (actually, by the time this goes up it will be 'has quit') blogging.  He made the announcement in an Inc Magazine article, and his blog entry on distributed version control looks like being his last.

In case your universe hasn't intersected that of Joel's, he runs Fog Creek Software in New York.  They have several products in their portfolio, but I think it's fair to say that their FogBugz bug tracking application is their main calling card.  Joel has also run the Joel on Software blog for some time, and is a well known pundit and commentator on all things software.  More recently he co-founded the Stack Overflow website, a Q and A website for programmers that has very rapidly gained a huge chunk of mindshare.

In his valedictory Inc Magazine article Joel states amongst other things that blogging is just too narrowly focused to be effective advertising for his company.  Which makes perfect sense if you're using it as a source of potential revenue.

In his penultimate Joel on Software article Joel lists some of the subject articles that have been written several kajillion times, by legions of pundits exploiting the whole democratisation of opinion made possible by the explosion of the Internet.  Which makes perfect sense if what you want to do is something truly original, especially in the narrowly-defined genre of geekerature.

All of which made my pause and consider - why am I doing this?  If someone as well known as Joel has had enough, doesn't see the point, and is getting out, why should I bother?  Why expend time and mental effort re-visiting subjects that other people have already addressed, more incisively and profoundly than I can?

Well:

  • I enjoy the act of writing.  I take pleasure in jotting down fleeting ideas or comments, and letting them germinate until they spring forth as fully-fledged articles.  It forces you to articulate and justify vaguely-held opinions and beliefs.  Under the weight of such scrutiny some ideas have self-imploded and got thrown out as blog fodder, but that doesn't diminish the importance of the process one whit.  In fact, if anything it increases it.
  • Joel's been doing this a lot longer than I have.  He's been there, done that, got the T-shirt, and it's time to move on.  Actually, he must have a whole wardrobe full of T-shirts.  For me the world of blogging is still new and shiny and pretty.  I'm enjoying it, so why stop?
  • There's a vague chance that some of my ramblings may be of some use to somebody, somewhere, some when.  Goodness knows I've learnt plenty from other people's blogs, and in some sense it's a little bit of repayment of accumulated karmic debt.
  • The articles act as a reference of techniques and ideas that I can easily find in the future.  If I want to do some fixed point arithmetic, or generate some random numbers, I've got ready-to-go code snippets and links back to original source material.  Of course I haven't actually written all that much yet, but I've already had reason to dip back into the archives a few times.  I've got a stack of blog ideas and sketched-out articles, so this blog will hopefully turn into a useful resource for the future me.
  • It is also of course partly self-aggrandising/self-serving.  The Internet has zeroed the cost of vanity publishing, so I may as well put something out there.  Something I can link to at some point in the future to flesh out my CV a bit.  Something that shows that I haven't spent the last several years just fulfilling a mandate as a corporate drone, but that I also think about and care about what I do.

My apologies for the brief digression into self-analysis.  Relatively normal service will be resumed in due course.

Sunday, 28 February 2010

Backing Up Your Development Environment

Back in the good old bad old days, backing up an embedded project was simple.  You put the source files and makefile on a floppy disk.  And for good measure, you could put a copy of the compiler, assembler, linker, and any other tools on the floppy too.  The complete toolchain needed to recreate the shipped code, neatly wrapped up in its own little time capsule.

And that toolchain is an important detail.  The source code on its own is not enough to recreate a build, you have to factor in the tools too.  The output from a compiler can vary by a surprising amount between versions.

These days things are not so straightforward.  The compiler, assembler, and linker still exist, but they generally lurk behind the comforting facade of a glossy integrated development environment (IDE).  You don't need to figure out the arcane invocations needed to convince the command line tools to do your bidding, you just tick some checkboxes in an options dialog.  And I for one don't have a problem with this, I'm perfectly happy for such details to be sorted out behind the scenes.

However this ease of use can be a double-edged sword.  That sparkly shiny IDE is likely a significant chunk of code, and will be squirreling away information in all sorts of nooks and crannies on your PC - in the registry, in initialisation files, in configuration files, and down in the depths of your Documents and Settings folder.

Add in some vendor patch releases and user modifications, and suddenly keeping a snapshot of the state of your tools starts getting tricky.  Not only do you need to know that the code was built with v1.2.3.4 of the Acme Super Awesome IDE, but also that at that point you'd applied three vendor patches, and hand-modified a chip configuration file that you'd found a bug in.  You'd reported it to Acme MegaCorp technical support, but there hadn't been a bug fix release yet. 

Now what do you do?

My current solution is to store a simple text file called 'build instructions.txt' or similar with each project.  It lists the IDE version, any applied patches, and any funnies such as the aforementioned modified chip configuration file.  This approach is not exactly high tech or complicated, but works fine. 

I can't help thinking that there must be a better way though - this is still a bit handraulic and error-prone.  I suggested to our IT guy that we could create a virtual machine (VM) image containing a bare bones XP install, plus the IDE, plus any 'non-standard' files (patches and the like).  That way we could simply specify which VM image to use with the source and project files hauled out of version control.  But that made him go a bit green and start shaking.  He was mumbling about licensing issues with that many Windows images. 

So - if anybody knows of a better way of doing this, do please let me know in the comments.

Sunday, 14 February 2010

Zero Tolerance

This week I picked up some code from a colleague for review.  To me, part and parcel of the review process is rebuilding the code - I want to check that I get the same hex (i.e., output) file as has been checked in to our version control system for release.  And sure enough, this time I did. 

But I also got 16 warning messages.  The compiler spat out a variety of messages, including warnings of integer truncation, and what looked like notes the developer had written to himself - "This could be done faster with pointers" and the like.

What did this mean?  Was I using a different compiler version than the  developer?  Was my version smarter about flagging potential coding errors?  It seemed unlikely, as I got the same hex file.  This almost certainly indicated that we were using the same compiler.  Also, there was the matter or all those notes-to-self.  Those were clearly there for a reason.  How did he know it would be faster with pointers?  Presumably he'd coded that up to test it, as otherwise he couldn't know that it would be faster?  If he had, and it was, why hadn't he used it?

I spent a while scratching my head over this before going to see the developer.  "Oh yeah, I had a look at those, the real warnings are all fine.  Nothing to worry about.  And the others are just reminders to myself.".  And the comments about pointers and the like?  "It's always faster to do that code with pointers, I just didn't have the time.  That's just a reminder in case I look at this again."

Well, that was fine for him, as he'd written the code.  But at some point somebody else was going to look at it.  Maybe a customer would report a bug, and a colleague would be assigned to fixing it.  Maybe we'd want to add some new features.  Maybe we'd want to use this code as the basis for another product with similar functionality.  Or maybe, as in this case, a reviewer would pick up the code. 

In all of these scenarios, Joe Bloggs engineer would pick up some allegedly working code, hit build, be faced with a screenful of warnings, and freeze like a rabbit trapped in headlights.  Hampered as he would be by a lack of omnipotence, he wouldn't know that all the warnings are benign, and that a colleague knows a better way to write his own code.

The warnings might indicate real problems.  They might be the compiler being picky.  But our hypothetical engineer is going to have to assume that each is a land mine requiring individual attention and possible defusing.  All of which could have been avoided if the original developer had simply added some casts or whatever else was needed to placate the compiler.

The only acceptable number of warnings in a build is zero.  Anything else is going to waste people's time.  Any cost saving to the developer in not dealing with the issues as they crop up will be more than offset by the time wasted by a colleague (or possibly themselves) further down the line.

Possibly more importantly, a developer is fooling themselves if they think they can live with a raft of warning messages.

If you have 16 warnings every time you build, you are much less likely to notice the silent arrival of a seventeenth, this one a genuine harbinger of doom.  If however your build has always been clean, and is suddenly polluted by a warning - well, you'll see that.

This is indicative of a professional attitude to development, as well as saving time in the long run.  If all warnings are examined and addressed as they surface, the ongoing code quality and workmanship are high.  If attending to such items is left as a last-minute operation before release, or even worse pencilled in for the often mythical post-release clean-up, then it will either (a) be a huge job, or (b) not get done.

The same comments apply to writing code that is MISRA-compliant, or that gets a clean bill of health from Lint.  It's always faster and easier to do this as you go, rather than banging a keyboard for several days and then trying to impose some semblance of quality as an afterthought.

We are what we repeatedly do.  Excellence, then, is not an act, but a habit.  (I didn't say that, Aristotle did.  And according to Wikipedia, it's actually a misattribution.  But as misattributions go, it's got to be one of the best.)

Sunday, 7 February 2010

Generating Random Numbers using LFSRs

On a recent project I needed a simple random number generator. It didn't need to be anything fancy, nothing mathematically pure or statistically valid, just a quick'n'dirty little generator that would spit out numbers that looked random to the casual eye.

In a previous incarnation I worked for a mobile radio consultancy. One of the things I came across in that particular life was the concept of Pseudo Random Binary Sequences (PRBSs).

These are sequences of 0s and 1s that are generated deterministically, yet are random enough for many practical purposes. They are used extensively in communications to spread the bandwidth occupied by a signal. This makes the signal more immune to jamming, as the signal is smeared across a bigger chunk of spectrum than would otherwise be the case. It is also more difficult to intercept, since any receiver must know and be synchronised to the spreading sequence at the transmitter. A more subtle usage is that multiple signals can be spread across the same spectrum by multiple PRBSs, yet be teased apart at multiple receivers by correlation with the correct individual spreading sequences.

PRBSs are typically generated using Linear Feedback Shift Registers (LFSRs). These are cheap and easy to build in hardware, and easy to code in software.

At any time, a function of the LFSR contents is generated as the output bit value. This is fed back into the shift register as the next input. The output bit sequence is essentially random, as is the sequence of states formed by the LFSR contents.

The 'function of the LFSR contents' mentioned above is called a generator polynomial. It determines which LFSR cells are combined and fed back to form the LFSR input for the next state.

For instance, the Wikipedia article on LFSRs lists the following generator polynomial for an 8-bit PRBS:

x^8 + x^6 + x^5 + x^4 + 1

We now need to know how to convert this into code.

As we are generating an 8-bit polynomial, we start off with the 8-bit unsigned value 0x00u as our feedback function. If a power of x, say m, is used in the polynomial, assign a 1 to polynomial bit (m-1). The +1 in the polynomial corresponds to the output bit, and does not appear in the feedback settings. Here we have an 8-bit generator polynomial with bits 7, 5, 4, and 3 set, giving a value of 0xB8u.

Given this, and also using the example code in the Wikipedia article, we can now write a function that returns the next value in a pseudo-random 8-bit sequence.

#define LFSR_8_INITIAL_VALUE 0x01u
#define LFSR_8_POLYNOMIAL 0xB8u

uint8_t next_lfsr_8( void )
{
/* seed LFSR */
static uint8_t lfsr = LFSR_8_INITIAL_VALUE;

/* get LFSR LSB */
uint8_t lsb = (uint8_t)( lfsr & 0x01u );

/* shift LFSR contents */
lfsr = (uint8_t)( lfsr >> 1u );

/* toggle feedback taps if we output a 1 */
if( 1 == lsb )
{
lfsr ^= LFSR_8_POLYNOMIAL;
}

return lfsr;
}

An n-bit PRBS is said to be maximal length if the number of distinct output values it generates is 2^n - 1. That is, a maximal length 8-bit PRBS consists of 255 values. Our generator polynomial is indeed maximal length, and so the values returned will start to repeat after 255 calls.

In the above code I have set the initial value of the LFSR to 0x01u. The LFSR will generate a fixed sequence of output values, and the initial value merely determines where in the sequence the reported values will start.

Note that because the feedback taps uses the XOR operator, the LFSR will get stuck in the all-zeros state if it ever gets there. Care must be taken that an LFSR is not initialised with this value.

The corresponding 16-bit function is as follows.

#define LFSR_16_INITIAL_VALUE 0x0001u
#define LFSR_16_POLYNOMIAL 0xB400u
uint16_t next_lfsr_16( void )
{
/* seed LFSR */
static uint16_t lfsr = LFSR_16_INITIAL_VALUE;

/* get LFSR LSB */
uint8_t lsb = (uint8_t)( lfsr & 0x0001u );

/* shift LFSR contents */
lfsr = (uint16_t)( lfsr >> 1u );

/* toggle feedback taps if we output a 1 */
if( 1 == lsb )
{
lfsr ^= LFSR_16_POLYNOMIAL;
}

return lfsr;
}
Using the above approach, you can generate PRBSs of arbitrary length, given tables of generator polynomials (your search engine of choice will unearth plenty).

Sunday, 20 December 2009

What's In Your Toolbox?

This article started out as a simple list of the tools and applications on my work PC.  This was to be both an audit of the current state of the union on my PC, and a checklist for myself for when my PC gets upgraded or dies (note that there is no 'if' in the preceding statement).  I was interested in not just the full-blown applications that appear in the Start menu, but also the little scripts, batch files, and utilities that tend to accrete on our PCs, the small-but-useful stuff that doesn't get much mind share.

The main reason stuff is on my PC is to help me develop, maintain, or review code, but some other bits and pieces have snuck on too, for instance applications that help me write documentation, or prepare a presentation.  I try to keep my PC fluff-free, and any application that doesn't cut the mustard is ruthlessly excised.  If it's listed here, I use it, and find it useful.

Programmers are notoriously obsessive about their choice of tools, and love agonising over them in minute detail.  Just type 'best text editor' into Stack Overflow and watch your screen melt.  I suspect engineers are comparatively pragmatic, but there's no harm in taking a lead from our non-soldering brethren.

This list does not by any means constitute the best of breed.  It's just bits and pieces I've accumulated in my travels.  Sometimes I stumble upon gems through books, blogs, or magazines, sometimes I go looking for a particular functionality I'm sure somebody must have built, and sometimes people recommend programs.  Whatever.  If you see something here that looks interesting, but would like to see some alternatives, Scott Hanselman maintains an awesomely huge tools über-list, and I highly recommend that you at least skim it.

One tip: learn to use your tools.  RTFM, and learn the keyboard shortcuts.  I've found over the years that many of the tools I've been using are more powerful than I realised, but you need to delve to find this out.  And using keyboard shortcuts is a no-brainer - even if they only save a couple of seconds over the equivalent operation with a mouse, the compound interest on this saving over the course of a year is enormous.  [Related pet peeve - I find it almost physically painful to watch somebody doing something like copying and pasting text between two documents using the mouse.  They carefully highlight the text of interest, then go to Edit|Copy, then press the toolbar icon for the destination document, carefully place the cursor at the appropriate point, and then select Edit|Paste.  And in my head I'm shouting "Double click!  Ctrl-C!  Alt-tab!  Ctrl-V!".  But maybe that's just me.]

Don't be afraid to splash your own cash.  Even if the department budget won't stretch to buying everybody a decent text editor, spending a few quid of your own hard-earned on decent tools is well worth the investment.  I've a friend who's a car mechanic, and has spent thousands of pounds on stocking a decent toolbox over the years - I don't see why supposedly professional engineers should shy away from investing in their own careers in like manner.  That said, many of the tools listed below are free.

Rules for inclusion: I'm interested in applications that may be of interest to the engineer on the Clapham omnibus, and so haven't listed project-specific tools like compilers and vendor IDEs.  If you need such tools, you'll have them.  I've also skipped over staples like Microsoft Office - such applications are likely to be on the default engineer PC install.  Again, if you need them, you'll have them.  Tools are listed in alphabetical order.  And lastly, these are all Windows applications, because that's where I live.  Some may have ports to other platforms, and there are almost certainly functional equivalents for Linux, OS X, etc.

7-zip: Everybody needs a compression tool.  This one is free, and handles all of the formats I've thrown at it over the years (including things like *nix tarballs).  It can also generate password-encrypted zip files, which is neat for sending confidential documents or source code to offsite contacts.

Absolute Uninstaller: The clue's in the name - this uninstalls programs.  But this free program lists installed programs much more quickly than control panel, removes programs more completely, and can export a list of all installed programs.  In truth this is my main use for this program - generating a weekly list of all installed programs as a snapshot for future reference.

Agent Ransack: This is just insanely useful.  It's a free search program allowing you to recursively search folders for files containing specified text.  Both the filenames and the search text can be regular expressions.  When installed, "Agent Ransack..." appears on the right-click context menu in Windows Explorer, allowing you to specify the root folder for your search.  I have this up and running pretty much all the time I'm developing or examining code.

Beyond Compare: Again, everybody needs a file differencing program.  This one lets you compare files or folders in text or binary mode.  Text comparisons can ignore whitespace-only differences, or 'trivial' changes such as source code comments.  Changes between two files or folders can be copied across in either direction.  Folders can be synchronised, FTP is supported, and there's a whole bunch of options I haven't even looked at.  Heeding my own advice above, I really need to revisit this and RTFM.  Again, the tool integrates with Windows Explorer, appearing on the right-click menu to let you choose the 'from' and 'to' files/folders for a comparison.

Bug Shooting: Before I installed this free screenshot utility, I wouldn't have believed how much I would use it.  It can be run by clicking on its icon in the system tray, or by pressing one of the hot key combinations.  It can capture either the whole screen, or just a specified section, and can do so immediately or after a timed interval.  Once captured, you can crop the image, highlight an area, write text on the image, and so on.  It was originally developed for posting screenshots to bug tracking systems, but I use it for writing documentation, FAQs on our in-house wiki, and a bunch of other stuff that wouldn't have occurred to me before I'd installed it.

CCCC: This one is fairly hard-core geeky.  It's an open source application based, I believe, on a doctoral thesis, that analyses C/C++ source code and spits out various metrics including line of code, line of comments, and McCabe complexity metric.  I use these as a general basis for comparison of bodies of source code - is this application inherently more complicated than this other one?  It also highlights complexity hotspots worth investigating in a bit more detail.

CCleaner: This free program removes unused files to free up space by clearing your recycle bin, Windows temporary and log files, browsing history, and so on.  It also contains a registry cleaner for removing unused and old entries.

Clean Sources Plus: This is a neat little freebie utility from Jeff Atwood.  It gives you a right-click menu item in Windows Explorer (yes, I'm a sucker for these) that lets you delete a user-specified set of files and folders in and under the clicked-on folder.  So, for instance, you can remove all object files in your development folder before checking your code into version control.  It also gives you the option to zip the folder - very handy when you want to upload or email some code.

Clipname: Another freebie that rapidly became indispensable.  Right-click on one or more files or folders, and you get the option to save their names to the clipboard for copying into other applications.  You can save just their names, or their full paths including all folder information, and can do so in the URL-encoded format needed for hyperlinks.  Very, very helpful.

CmdHere Powertoy: This time the freebie is from Microsoft itself.  Right-click on a folder (are you spotting a common theme here?) to get the option to open a command window pointing at the selected folder.  Very useful when you want to jump in and check the output from a batch file, or quickly run a program with particular command line options.

DebugView: The first but by no means the last appearance for the Sysinternals tools on this list.  This program captures debug output locally, or across a TCP/IP network.  In my case I've only ever used it to capture OutputDebugString() calls in my PC code, but apparently it also supports kernel mode debugging.

Editplus: a decent text editor is absolutely essential.  When developing you almost certainly spend a huge chunk of your working day in a text editor, and so should be using a tool that helps you as much as possible.  For me, the minimum requirements of a text editor include language-specific syntax highlighting, the ability to record and play back keystroke macros, and regular expression searching.  Failure to provide any of these results in me immediately losing interest.  For historical reasons my weapon of choice here is Editplus, which is small, cheap, and powerful.  BTW, one of my standard interview questions is to ask the candidate what their favourite editor is.  I'm not really interested in their answer, so much as in if they have one.  If not, they're not thinking about what they're doing.

EverNote: I realise that I'm only using a tiny percentage of the functionality of this application.  I basically use it as a journal/logbook, writing up notes as I work, and pasting in code snippets, scope shots, and photos as appropriate.  These are all then available for searching when, in six months, I want to quickly find all my notes on a given project.

Fences: This one is still in the stage I like to call "trying-it-out-to-see-if-I-like-it-and-or-find-it-useful".  It lets you create areas (that it calls 'fences') on your desktop, in which you can drop files or shortcuts.  I personally try to keep my desktop empty, and use a hotkey application launcher to start up most of my programs, but this has potential.  I've been using it to create project fences containing links to the datasheet for the chip I'm working with, the project demo software, and so on.  Fences feels stable and would certainly be worth looking at if you tend to use your desktop as a holding area.

Foxit Reader: Smaller, faster, and leaner than Adobe Reader.

Google Desktop Search: This brings the power of the mighty Google to your desktop.  Once installed it starts indexing all of the files on your PC.  I've got it running in the system tray, and by typing in, for instance, the name of a project I've worked on, it will find all files containing that name.  And that includes not just text files, but also Word, Excel, PDFs, emails, etc.

Janitor Script: I have a folder on my PC where I put all downloads, email attachments, and things I only want to deal with on a temporary basis.  This little script runs every lunch time and deletes everything older than a week from the folder.  Neat.

Keepass: Keep all your passwords in a single database with a single password to remember.  I use this for not only all of the web sites demanding I have a password to identify myself, but also for the passwords I've assigned to users on some of our internal tools.

Launchy: This is just mind-bogglingly, consciousness-expandingly useful.  It's a hotkey application launcher that has totally removed my need to use the Start menu, shortcuts, or just about any other method of running a program or opening a commonly accessed file.  I press ALT-space, type in the first few characters of the application I'm interested in, it auto-suggests the most likely candidate based on my previous invocations, and I hit enter to run the program or open the file.  Or, in many cases, I can supply further information.  For instance, to search for a book on Amazon, I type in 'am' to get Launchy to suggest 'Amazon', then hit tab, followed by the name of the book I'm interested in.  It then launches my browser and displays the Amazon search results.  I can also create emails, add items to my web-based to-do list, and append text to files on my PC.  If you haven't tried a hotkey launcher, give them a go, they'll change your life.

PDFCreator: Install this freebie to have a PDF output option appear in your print menu.  This lets you create PDFs straight from any Windows application that lets you print.  Neat.

Paint.NET: Free and increasingly-powerful image and photo editing software.  I tend to use it for really simple things like annotating photos, but there are a wealth of features in there.

PC-Lint: If you're writing C or C++, and don't have this, or a functional equivalent, go buy it.  Now.  Seriously.  This static analysis tool remorselessly examines all of your code, and pedantically flags every potential violation of the rules of the language.  You can also configure it to perform MISRA compliance checking, so consider it as two-for-the-price-of-one.  It's remarkably flexible (for which read 'difficult to configure to get it going'), but well worth the effort.  Hook it in to your development system so that it runs every time you build your application, and you'll never look back. 

Portmon: YASG (Yet Another Sysinternals Gem).  I stumbled across this when debugging a serial port application I'd written.  It lets you capture all reads and writes to/from specified serial and parallel ports.  Absolutely essential if you're playing with such items.  Also useful if you want to figure out the interface protocol for a bit of third-party kit.  There used to be similar applications for file activity (filemon) and registry activity (regmon), but these have now been superseded by a process monitor (procmon).

Process Explorer: YASG (see above).  Task Manager on steroids.  See unbelievably detailed information on what's going on in your PC.  I've no idea what a lot of the displayed data is, but what I have been able to do with this in the past is use it to check for memory leaks in my PC code.  Select a program, right click to select 'Properties...', and switch to the 'Performance Graph' tab to see the application memory usage - if it continually ramps up, you've got a problem.

RegexBuddy: OK, this is pretty geeky too, but in a good way.  I bought this following Jeff Atwood's enthusiastic endorsement, and find that it excels in its (admittedly rather narrow) sphere of application.  As previously mentioned, one of my main uses for script languages is searching for data in log files.  Well, with RegexBuddy, I can copy some of a log file into a 'test' window and try out regular expressions that are evaluated on the fly, highlighting matches as I type.  When I'm happy with my expression I can copy and paste it into a fully-fledged script and I'm good to go.  Similarly, I can copy sections of code into the test window, and develop regular expression searches to be pasted into the aforementioned Agent Ransack.

Source Code Spell Checker: As I’ve mentioned before, I have a fairly dogmatic approach to spelling and grammar in source code.  I run this tool on all of my own code, and on code I'm reviewing, and fix or flag all transgressions.  Cheap, and does what it says on the tin.

Source Navigator: This is an open source code analysis tool.  It can generate function call trees, variable cross reference tables, class hierarchies, etc.  Extremely handy in getting you up and running on a glob of code you haven't seen before.

SyncToy: Another freebie from Redmond.  This one lets you synchronise folders, which is very useful when, for instance, keeping a snapshot of your source code on a USB stick or network drive.

TreeSize: Right-click a folder to see a graphical representation of the size of it and all folders under it.  Great when trying to track down what's eating all of the space on your hard drive/USB stick.

ZoomIt: YASG (see above).  Lets you zoom in and scroll around on your PC screen, highlight areas, and scribble notes on it.  Invaluable during presentations or training sessions.