Categories
Emacs

Handy emacs printing trick

emacs -nw myfile.c -e “ps-print-buffer” -e “save-buffers-kill-terminal”

By extension, you can keep stacking -e’s with interactive functions that take no arguments for as many commands as you want. I would imagine there is a way to pass arguments to the functions you list, but I haven’t found that yet. Also, it might be nice to be able to do something like -e “(+ 5 9)”, but I haven’t found the proper way to do that either.

Categories
Family

David in hat

David has a new hat to wear to his grandparents.

Categories
Cooking Reviews

A new thermometer

I don’t know where I got the idea from, but I’ve long thought that knowing how hot a pan is would be tremendously handy. And of course, the obvious way to measure surface temperature is with an infrared thermometer. So, I went and got a Ryobi IR001 Non-contact Infrared Thermometer (with Laser) from Amazon (see http://amzn.com/B001O7H61Y).

So far, it is particularly handy for seeing how close to boiling water is (212°F) and when a pan is hot enough to saute (350-400°F).

My only complaint is that it tops out at about 600 °F, and sometimes higher would be nice.

Also, I really wish that I would remember to keep notes on temperatures for frying eggs, pancakes, and what exactly is high, medium, and medium high?

Categories
Programming

Small revisit of C++ message passing (in a threaded program)

The post C/C++ Message Passing from June ’08 is one or the more popular ones, if Google Analytics is to be believed. Not only that, but every one who arrived there by Google search was looking for C++, not C.

Upon re-reading it, it occurs to me that it would be a good candidate for being a lock free structure.  With C++0x, this should be pretty simple to do, using the new atomic template.  For straight C though, I would have to use compiler specific extensions (or inline assembly), so there may be little reason not to make a C++ specific version of the code that is lock free.

I’ve also thought of trying to use C++0x to construct a purely functional data structure library.  In that case, C++0x would be chosen because of the new shared_ptr addition.  I might have to have a post soon exploring that idea a bit further.

So far, I’ve converted this to be a C++ class and to use templates instead of void*s. Otherwise, it still behaves the same and still uses pthread locking directly. Additional versions will be forthcoming. Here is the recent work.

Hopefully it will be of use to some of the searchers. Keep an eye out for future revisions.

Categories
System Administration

Oops

All the pictures in old entries are missing, and it seems that it is because a pictures folder was removed.  Now looking for a backup.  And this time perhaps I should let WordPress keep track of them instead of making my own image folder.

And now it should be fixed, so please let me know if you still see problems.

Categories
Family

Izzy Sitting in a Window, Looking Blue

Categories
Family

David again.

Categories
Programming

Circular buffers as C Macros

I was recently reviewing some FIFO based serial TX/RX circular buffer code that I thought was buggy in the FIFO part.  Since the FIFO was entwined with the ISRs, it was hard to test in isolation.  I looked around at some other FIFO implementations for PIC and AVR, and all of them did the same thing, including duplicated all of the FIFO code for every serial port implemented.   It seemed to me that it would be better to have the two activities separated to provide better re-usability and test-ability.

Back when I was working on PCI audio drivers, I thought the same thing.  Everyone wrote their sample FIFOs directly into the ISR functions in the driver.  Back then, I seperated my FIFO out into a separate reusable module that could be tested thoroughly from user land.  I grabbed that to use on my current project, but it depended on malloc and free, something notably missing on a lot of 8 bit micro controllers.  Also, it would result in extra function call overhead, which is not good in ISRs on PICs (very limited hardware call stack).

Anyway, after debugging the FIFO in my ISRs, I decided to extract it all out into a file of just that code. Then I transformed those functions into macros to do away with the function call overhead.

Here is draft 1, if it is of any use to anyone, and even if it isn’t I certainly wouldn’t mind review/commentary.

I could wrap the globals into a struct, but then I still would need a
custom struct for each instance to change the size of the array at run
time, unless I required a global struct, and MAKE_FIFO inserted a
pointer to a global array…

I’m not sure, which might be better.

Also, if you were to need 32bit elements instead of 8 bit elements, just change the type in MAKE_FIFO.

/**
* @file
* @author Joshua Boyd
* @version 1.0
*
* @description DESCRIPTION
*
* Macros for statically allocated, circular buffer, character FIFOs.
*
* NOTE: change the types in MAKE_FIFO to support types other than
* chars. Should just work for any primitive type, and only
* a little more work for structs.
*
* The basic usage is to MAKE_FIFO your fifo, giving it a name and size
* then GET, PUT, etc, the fifo of that name.
*
*/

/**
* Make a new FIFO.
*
* @param prefix - the name of the fifo, eg. 485_tx, or 232_rx.
* @param size - number of elements in the fifo.
*/
#define MAKE_FIFO(prefix, size) \
char prefix ##_buffer[size];\
long prefix ##_next_in = 0;\
long prefix ##_next_out = 0;\
long prefix ##_ovfl=0;

/**
* Get and remove an element from the FIFO.
*
* Value here works a little like a reference in C++.
*
* @param name of the fifo
* @param Location for the returned element.
*/
#define GET(prefix, value) { \
value=prefix ##_buffer[prefix ##_next_out]; \
prefix ##_next_out = (prefix ##_next_out+1) % sizeof(prefix ##_buffer);}

/**
* Get an element from the FIFO without removing it.
*
* Value here works a little like a reference in C++.
*
* @param name of the fifo
* @param Location for the returned element.
*/
#define PEEK(prefix, value) { \
value=prefix ##_buffer[prefix ##_next_out];}

/**
* Remove an element from the FIFO without getting it.
*
* @param name of the fifo
*/
#define REMOVE(prefix) { \
prefix ##_next_out = (prefix ##_next_out+1) % sizeof(prefix ##_buffer);}

/**
* Return the index of the next input location.
*
* NOTICE: This is the only macro meant for internal use, and not the
* application programmer.
*/
#define NEXT_IN(prefix) ((prefix ##_next_in + 1) % sizeof( prefix ##_buffer ))

/**
* Put an element into the FIFO.
*
* @param name of the fifo
* @param Value of the new element.
*/
#define PUT(prefix, value) { int8 t; \
prefix ##_buffer[ prefix ##_next_in ] = value; \
t = prefix ##_next_in; \
prefix ##_next_in = ( prefix ##_next_in + 1) % sizeof( prefix ##_buffer ); \
if(prefix ##_next_in == prefix ##_next_out) { \
prefix ##_next_in = t; \
prefix ##_ovfl = 1; }}

/**
*
* Set the points back to as if it were empty.
* Doesn't erase the data, but only a GET or PEEK will
* return garbage after this has been called.
*
* @param Name of the FIFO
*/
#define FLUSH(prefix) prefix ##_next_in = prefix ##_next_out = 0

/**
* Is the FIFO empty? True/False
*
* @param FIFO name
* @return T/F
*/
#define IS_EMPTY(prefix) (prefix ##_next_in == prefix ##_next_out)

/**
* Is there any data? True/False.
* Basically the opposite of IS_EMPTY
*
* @param Name of the FIFO
* @return TRUE/FALSE
*/
#define IS_NOT_EMPTY(prefix) (prefix ##_next_in != prefix ##_next_out)

/**
* Is there any data? True/False.
* Basically the opposite of IS_EMPTY
* The same as IS_NOT_EMPTY
*
* @param Name of the FIFO
* @return TRUE/FALSE
*/
#define KBHIT IS_NOT_EMPTY

/**
*
* Is the FIFO full? True/False
*
* @param FIFO name
* @return TRUE/FALSE
*/
#define IS_FULL(prefix) (NEXT_IN(prefix) == prefix ##_next_out)

/**
* Is there free space?
* This is basically the opposite of IS_FULL
*
* @param FIFO name
* @return TRUE/FALSE
*/
#define IS_NOT_FULL(prefix) (prefix ##_next_in>prefix ##_next_out?prefix ##_next_in-prefix ##_next_out:(prefix ##_next_in+sizeof(prefix ##_buffer) - prefix ##_next_out))

/**
* Is there free space?
* THis is the same as IS_NOT_FULL.
* This is basically the opposite of IS_FULL
*
* @param FIFO name
* @return TRUE/FALSE
*/
#define AVAIL IS_NOT_FULL

Categories
System Administration

Using rxvt with [Open]Solaris.

After years of hard coding TERM to xterm or vt100 in .bashrc to get around rxvt incompatibility, I finally found this:

sudo cp /usr/gnu/lib/terminfo/r/rxvt /usr/share/lib/terminfo/r/rxvt

I suppose I really should use pfexec instead of sudo, but mastering that is a job for another month.

Categories
Reviews

XO Update: F11 based image

This past weekend I updated to the new XO-1 firmware image following the directions at this website.  The process was simple and painless. I believe this was the first significant update since Sugar was spun off from the OLPC project, and I had long given up hope of seeing any significant updates for the XO-1.

I can’t say that this adds any dramatic features.  They do offer a Switch to GNOME option now, which may be useful sometime, but I don’t think I want to run Gimp or Gnumeric on this machine all that much.

What it does offer is a lot less hassle. First up, the machine seems to boot faster. That is nice. I prefer not to reboot though, so pardon me for not being thrilled.

Second, they now offer an “Advanced Power Management” option, that helps the battery life a good deal. Alas, it still doesn’t seem to want to happily sleep for days on end like Deb’s MacBook will, and it doesn’t even want to sleep as long as my Toshiba laptop, but still it is a lot better than no sleep mode. They now seem to have a sleep mode where the display is active, but the CPU sleeps after some time of inactivity. You can tell that it has done this because when you later hit a kit, the screen will jump and there will be about a second pause before the key stroke shows up. Way cool, but still I want it to manage power well enough to never have to power down then back up. I guess a hibernate mode is out of the question though.

Potentially an even bigger deal is that now it does a much better job of remembering my wireless settings. Before I’d have to re-choose after every reboot, and sometimes even between reboots, and I always had to re-enter the password, frequently even after it had just been sitting unused for awhile. Now, I haven’t had to re-choose the network once, and I haven’t had to re-enter the wireless password either.

Application wise, I don’t see any improvement in the web browser, the Activity (what they call a program) I use most. I do see a change in all activities where when you exit the activity you are now asked to make a journal entry. I don’t like this at all.

To be honest, I haven’t really looked at the education activities since the update since I mostly use this as a kitchen recipe machine (thus why the picture shows the XO-1 between my toaster and salt and pepper). I figure that when he is a bit older, I’ll give this to David.

Since I never actually wrote a review of this machine, allow me to insert here that the display is really great (but obviously a bit small). Also, I found that the keyboard is nearly unusable. I can use the keyboard on similarly sized 9″ netbooks (albeit more slowly than a regular keyboard), but on this membrane keyboard I end up resorting to two finger typing most of the time. Obviously this isn’t designed for me, but it does sap some of the motivation out of my hopes of actually working some on this machine (although I have still taken it around to use as a terminal).

One thing I’d really love to see in the future would be a webkit based browser. I think that it would be a much better fit for this low memory machine than the Gecko engine that is currently used. Another thing I really want is an email program. They take the view that kids don’t need email or can use webmail, but I’d like to see a decent email sugar activity. Another nice one could be a calendar and address book activity. These probably aren’t important for most places, but I think that for American Sugar users (presumably running on non-OLPC hardware) this would be handy. Better still would be social networking support for these programs as well as twitter and facebook clients. If such features were to be added, there probably should also be some system for parents to set limits on how various pieces are used.

I keep wanting to find time to setup a Sugar environment and actually work on writing some activities. A twitter client, while frivolous, may be an excellent first activity. BTW, I’m @jdboyd. I need to add a sidebar link at some point.