C: Volatile Arrays in C

Yes, volatile is required, and the right declaration is: volatile unsigned char *my_data; This declares my_data to be a pointer to volatile unsigned char. To make the pointer itself volatile, you’d need this instead: unsigned char *volatile my_data; And of course, both the pointer and the pointed-to data may be volatile: volatile unsigned char *volatile … Read more

Stack Size Estimation

Runtime-Evaluation An online method is to paint the complete stack with a certain value, like 0xAAAA (or 0xAA, whatever your width is). Then you can check how large the stack has maximally grown in the past by checking how much of the painting is left untouched. Have a look at this link for an explanation … Read more

Power off an USB device in software on Windows

Some USB hubs have the ability to turn power off to its downstream devices. “Is it possible to power up ports on a USB hub from Ubuntu?” https://askubuntu.com/questions/149242/is-it-possible-to-power-up-ports-on-a-usb-hub-from-ubuntu Which points to some c source for hub-ctrl.c See: http://www.gniibe.org/development/ac-power-control-by-USB-hub/index I tested this on Ubuntu with a Dream-Cheeky USB LED unit, and it did seem to turn … Read more

Pimpl idiom without using dynamic memory allocation

Warning: the code here only showcases the storage aspect, it is a skeleton, no dynamic aspect (construction, copy, move, destruction) has been taken into account. I would suggest an approach using the C++0x new class aligned_storage, which is precisely meant for having raw storage. // header class Foo { public: private: struct Impl; Impl& impl() … Read more

Set ALSA master volume from C code

The following works for me. The parameter volume is to be given in the range [0, 100]. Beware, there is no error handling! void SetAlsaMasterVolume(long volume) { long min, max; snd_mixer_t *handle; snd_mixer_selem_id_t *sid; const char *card = “default”; const char *selem_name = “Master”; snd_mixer_open(&handle, 0); snd_mixer_attach(handle, card); snd_mixer_selem_register(handle, NULL, NULL); snd_mixer_load(handle); snd_mixer_selem_id_alloca(&sid); snd_mixer_selem_id_set_index(sid, 0); … Read more

Differences Between ARM Assembly and x86 Assembly [closed]

Main differences: ARM is a RISC style architecture – instructions have a regular size (32-bit for standard ARM and 16-bits for Thumb mode, though Thumb has some instructions that chew up 2 instruction ‘slots’) up through at least ARM v5 architecture (I’m not sure what v6 does), the interrupt model on ARM is vastly different … Read more

Unit testing device drivers

In the old days, that was how we tested and debugged device drivers. The very best way to debug such a system was for engineers to use the embedded system as a development system and—once adequate system maturity was reached— take away the original cross-development system! For your situation, several approaches come to mind: Add … Read more