nobody wrote on Tuesday, April 04, 2006:
I was given a HD44780 LCD module a few months ago and took interest in writing a driver for it when I was kicking the tires on FreeRTOS. Below is my approach, it’s the first driver I’ve written and I was seeking comments. (I should say that I’m using FreeRTOS in pre-emptive mode with several tasks running. At this point everything is an exercise in programming, just to learn the basics.)
I first wrote a few core routines to manage the control and data lines out of an ATMega32. I employed a lot of macros to do the device/OS specific code (like PORT output, delays, critical sections, etc.) in case I wanted to use this on another platform. All the device/OS macros are kept in a lcd_port.h file. Since the LCD control signals are time sensitive, I protected each LCD command in a critical block. This way the driver is ensured that it can complete the current LCD command.
The next step was writting routines like lcd_char, lcd_string, etc. Since these are likely to change from application to application, I placed them in another .C file. In addition, since the eventual code will possibly be running in a pre-emptive OS, I placed mutex code in each LCD routine. In short, each LCD routine grabs the mutex while it’s running, and gives it up when it’s done, ensuring sequential text output. At this point, I have a collection of routines that I can easily use to display text on the LCD as well as a somewhat easy-to-port lower level driver.
The final step is integrating this into FreeRTOS. As an RTOS newbie, I’m a little unsure of how to continue. I’m assuming the mutex and critical sections place this application in the soft-realtime space. My tenative next step is to create an LCD-output task in FreeRTOS that handles output. This way the other tasks can fire off a message and continue working if needed. (I’m thinking that this approach would also minimize priority inversions.)
This is getting a little long winded, so I’ll wrap it up here. As a newbie, is my approach sound? Any suggestions or glaring issues?