For code that targets an embedded device or some severely resource-constrained environment.

learn more… | top users | synonyms

31
votes
5answers
2k views

Running Lights - Embedded “Hello World”

I'm getting my feet wet in embedded development, and like all those before me, my first task was to make an LED blink. I went a bit further than that and made a "runner" that lights up each led from 0 ...
16
votes
1answer
318 views

Spell Corrector in C

I recently stumbled across this article on how to write a spelling corrector, and figured I'd try to have a go at it in C (mainly because the link at the end of the page for the C code is broken). ...
16
votes
2answers
294 views

Fast 32x32 bit multiply on ARM M0

I have a time-critical calculation running on an ARM Cortex-M0. This is the fastest 32x32 bit -> 64 bit multiplication that I can come up with. The following C compiles almost 1-1 to assembly ...
14
votes
1answer
133 views

Embedded FizzBuzz

Recently, I have started to enter the realms of embedded systems programming. And, as my first major project, I thought I'd do the obvious: FizzBuzz. However, this is a little different: this is a ...
12
votes
1answer
201 views

Compile-time data structure generator

In response to another recent question I mentioned that one mechanism to avoid runtime overhead for creating a data structure was to create it at compile time and use it directly. Since there was ...
11
votes
2answers
12k views

Convert between date/time and time-stamp without using standard library routines

I am trying to implement two simple convertors: date/time to time-stamp and vice-versa, without any dependencies on time library routines (such as localtime, ...
11
votes
1answer
266 views

Where it all begins: Khronos

This is the main.c file for Khronos, a personal project of mine. This is basically where the whole program is setup, run and then quit. I'll post the short ...
10
votes
3answers
584 views

Parsing comma-separated floats and semicolon-delimited commands

I wrote a cstring parser. It has to work with a relatively wide amount of arguments (usually 3 or 4, but maybe in future with a different amount), which are ...
10
votes
2answers
243 views

Embedded C# bitpacked arrays to low-level STM32F4 driver for GE G35 RGB LED Christmas tree light

I'm going to be opensourcing some code I'm working on. I don't need help with the code, I just want to make sure my code is readable and my comments make sense. I have a knack for the esoteric. ...
8
votes
3answers
1k views

Hierarchical k-ary tree in C without relying on RAM

I created a k-ary tree in C to be used as an easy and efficient way to organize "UML-like" data in embedded devices. The left node is at the lower logical level (a child) while the right node is at ...
8
votes
1answer
219 views

Embedded conditional code compaction

I'm porting some AVR code from PROGMEM/PGM_P to __flash, and I want to reduce the amount of ...
7
votes
4answers
202 views

Writing an interface for networking in an embedded system

I'm writing a driver in C for a WiFi module attached to a PIC18 microcontroller. I want to implement some functions that I'm familiar with in computer application level programming like Window's API ...
7
votes
3answers
455 views

Optimizing a loop in C for a microcontroller

I am trying to draw a Checkerboard pattern on a LCD using a GUI library called emWin. I have actually managed to draw it using the following code. But having this many loops in the program body for a ...
7
votes
2answers
188 views

Manage multiple file writes in C

I have a very simple C program that continuously reads from a temperature sensor and displays the temperature on two 7-segment LEDs. Reading is simple, but to display the LEDs I need to write to 14 ...
7
votes
3answers
135 views

Shell Script Image Replication

I have a shell script which is being used on an embedded human machine interface (HMI). This script is used to copy a few files from a USB stick to a different place on the device, but with multiple ...
7
votes
1answer
86 views

A Class that is used to run a 5x5x5 RGB Cube

So I had a hardware project of a 5x5x5 RGB cube which is driven by a 22118400Hz 8Bit AVR. (1284p for those who like hardware) So basically what the class does is set bits in a huge array of 8bit ...
7
votes
1answer
83 views

Adding support to Busybox vi for reading file from stdin

I am writing a patch for Busybox's implementation of vi, the classical command line code editor and predecessor of vim. It can ...
6
votes
2answers
321 views

Very basic shell on microcontroller in C

Objective: A lightweight shell that runs on a microcontroller (MSP430) and parses incoming data into a command and additional parameters. Requirements: Support of quoting in ...
6
votes
2answers
238 views

Selecting an algorithm and key for Java Card encryption

I was playing around with Java Card and I try to do one of the examples. P1 is what it has to do (e.g. decrypt, encrypt, etc) and P2 is to select which key to use in P1. Here is what the code looks ...
6
votes
1answer
172 views

MicroC task switching

My background for this review is a university course in embedded systems using MicroC and this question. Now my program appears to run ok, but I'd like to know what you think can be improved or if the ...
6
votes
1answer
295 views

Simple dishwasher C++ code

I have a project in embedded systems and I have to write the code in C, and make it simple. This is my first time, and it's only a simulation of how it should work. ...
5
votes
2answers
79 views

Microgrid device driver controlling GSM modem, LCD, keypad, and relays

Now I am working with an MCU (TI Tiva TM4C) that operates a GSM modem, LCD display, keypad, voltage inputs, and four relays for microgrid control/operation. To date I have written about 2000 lines ...
5
votes
1answer
97 views

Better way to write this branch with an exceptional retry in an embedded C environment?

A while back I wrote the following code (target is embedded C code on an 8 bit atmel device): ...
4
votes
2answers
1k views

Bash CGI Upload File

I'm using the following Bash CGI to upload a file: ...
4
votes
3answers
171 views

State machine implementation

I have written a simple state machine. Comments and feedback are welcome. ...
4
votes
3answers
672 views

Basic Encoding Rules (BER) class for embedded system

I'm implementing a communications protocol in an embedded system and the protocol uses a subset of the ASN.1 BER (Basic Encoding Rules). In a nutshell, this class simply represents a TLV triplet ...
4
votes
1answer
549 views

Websocket-based server for Raspberry Pi

I am trying to build a websocket server to run on the Raspberry Pi. The websocket server has to push periodic realtime update to a browser. Here is a sample code that I am planning to use. The example ...
4
votes
1answer
71 views

Processing text messages from a GSM module

I have a Tiva TM4C ARM processor connected to a GSM modem (SIM900). When the GSM modem receives a new text message it sends a UART string to the MCU, where an interrupt routine increments a new ...
4
votes
1answer
60 views

Using record variant for register mapping in Ada

It is OK to model a double usage register with a record variant: ...
3
votes
1answer
37 views

PWM wave generation

This code takes a integer x of range [0,127] as input, returns an array of four 32-bit integers, with x bits set. I'm trying to ...
3
votes
1answer
145 views

Detecting the duration of a button press in a microcontroller project

I'm a C++ newbie and so far have written my code mostly in an not OO way. Since this is getting confusing I'd like to start creating libraries for some of the functionalities that I've implemented. ...
3
votes
2answers
59 views

Function that strips trailing '0's from a float

I'm writing an embedded application in C, and at one point I need to convert a float into an ASCII representation of that float, so I can send the ASCII over a serial port. The protocol the serial ...
3
votes
1answer
444 views

Small, embedded full-stack web server

I did this project last year, under some interesting constraints: it's a thin webserver which lives in a Raspberry Pi, which is networked to an embedded system in an industrial sign which is running a ...
3
votes
0answers
44 views

A version of the Pebble Big Time watch face that also displays the date

I'm seeking style pointers, bugs, memory leaks, incorrect usage etc. ...
3
votes
0answers
119 views

Mifare AES-128 symmetric key diversification

I have implemented a symmetric (AES 128-bit) key diversification algorithm for Java following the NXP Notes. It works as expected but am not the best Java programmer around, I guess I have done quite ...
3
votes
0answers
220 views

Defining a char device driver protocol over uart at kernel level

My aim is to write a blocking char driver that return to the user space a complete protocol message from the kernel uart driver. Protocol description I'm fighting with a very bad protocol, called ...
2
votes
2answers
100 views

Checking battery voltage with ADC and interrupts - which way is best? [closed]

Here are some stripped down versions of the two different programs I am deciding between. In version one, my state machine is called within the interrupt: ...
2
votes
1answer
1k views

Nios 2 interrupt handler

This is homework for which we have prepared Nios 2 assembly: ...
2
votes
1answer
187 views

Very basic shell on microcontroller in C - follow-up

This is a follow-up of: Very basic shell on microcontroller in C A few days back I've asked for a review on a simple shell parser in c. Based on the answers, I've restructured my code to use a ...
2
votes
1answer
615 views

Driving 7-segment displays

I made a little JavaScript app here that let people generate bitmap for generating characters. Currently it generate code of a dictionary. But I want to also generate a example that let them play like ...
1
vote
1answer
166 views

Blinking LED code at a particular frequency [closed]

I wrote a function for interacting with my PIC16F1788. The code sends pulses out the RC4 port at a specific frequency, to make ...
1
vote
0answers
29 views

Automatic resource allocation for the purpose of resource-dependent task scheduling

Here is what I'm trying to accomplish: Suppose you are trying to control an embedded system with several external hardware resources/components/devices. Naturally, you are concerned with the issue of ...
0
votes
1answer
450 views

C for Nios-2 IRQ handling

Related: Please review assembly for Nios 2 interrupts ...
0
votes
1answer
85 views

Two over-complicated UART interrupt handlers for SIM900 GSM module [closed]

UARTIntHandler0 interfaces to the USB UART for debugging. UARTIntHandler1 interfaces to the SIM900 GSM module. The purpose of ...
0
votes
1answer
32 views

Moving between two angles in a set amount of time [closed]

I need to slowly change from one angle to another angle over a certain amount of time, using the shortest path between them. I have a function that accepts four parameters — the start and end angles ...
-2
votes
1answer
74 views

Singleton as static instance

In my project I need to have one class as singleton which must be globally accessible: board.h: ...