Stack Exchange Network

Stack Exchange network consists of 175 Q&A communities including Stack Overflow, the largest, most trusted online community for developers to learn, share their knowledge, and build their careers.

Visit Stack Exchange

Questions tagged [embedded]

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

17
votes
4answers
1k views

Sensor logger for Raspberry Pi in a stratospheric probe

I'm writing a Python Script for a Raspberry Pi to measure different sensors. We are planning to send the Pi with that Script running to the stratosphere, so the power usage for the Pi is limited. I ...
0
votes
0answers
62 views

Function to check if received message matches any of the expected messages

I have a message coming in and I need to match it against the expected messages. The program will eventually do something as a result of receiving those messages. I am not very experienced at ...
3
votes
2answers
127 views

Circular Queue in C for an embedded project

I wrote a simple circular queue. (in order to store characters because of the fact, that I am using UART through the DMA and sometimes my printf's override each other) I am looking for some review, ...
4
votes
1answer
26 views

Compare two strings in extended memory - classic 8052

I'm looking for a simpler code that isn't resource hungry that can compare two strings stored in different locations in the extended memory of a classic 8052 (namely the AT89S52 microcontroller) to ...
6
votes
4answers
192 views

Efficiently swapping the first and last five bits in an unsigned 16-bit integer in C

I'm programming on an 8-bit Z80 embedded system, and encountered a problem. The program needs to render some pixels to the screen. The color is stored as RGB565 format as a 16-bit unsigned integer, ...
1
vote
0answers
94 views

C++ embedded application to control a light with a timer

I enhanced the my daughter's bed light to IoT. Specifically I can turn the light on/off remotely and there is a timer & alarm function. All of this is implemented with a Particle Photon. This ...
2
votes
1answer
118 views

Printing 64-bit decimal numbers in freestanding environment

I need to print signed 64-bit numbers in decimal form. Program runs in freestanding environment (no C library available, libgcc may be unavailable too, or may not work correctly). So I can't use ...
11
votes
1answer
145 views

A Structured FizzBuzz

Warning Wall of text, little bit of code. This question is about as much as introducing the language as it is about whether or not I still know how to write the language. Introduction Programmable ...
6
votes
1answer
831 views

Multiple-producer, single-consumer lock-free circular queue

I'm working on a firmware on a bare-metal ARM single core processor (Cortex M4), with no RTOS. I need to add a multiple-producer, single-consumer, lockless fixed-size circular (ring) buffer to the ...
4
votes
1answer
195 views

Averaging accumulator template with overflow detection/prevention

This is a class/template I just wrote for my embedded project (IAR EW ARM - Cortex/ARM7TDMI - Atmel SAM7, SAM4, SAMG). I am gathering data from CAN BUS (FMS), e.g. Engine Revolutions (Per Minute), ...
2
votes
2answers
420 views

Simple dispatcher for an embedded system

This code is something that I have used for about 3-4 simple embedded systems projects. The idea is something like this: This is non-OS based implementation, everything is done in an outer infinite ...
3
votes
0answers
255 views

C++ object pool using C memory pool as base

I started out with this question on Stack Overflow. I have since then gotten an official answer from the mbed developers that the MemoryPool that I was asking about only issued raw C malloc/free type ...
12
votes
4answers
708 views

Function for approximating a sine signal

I want to approximate a sine signal with a parabola, which is given by the function: $$f(x) = 0.4053 \cdot x \cdot (3.1415 - x) \space\text{for}\space 0 \le x \le 3.1415$$ In a first approach, I ...
8
votes
2answers
1k views

SPI Connection Class on embedded Linux

I'm currently developing on a embedded Linux chip with a couple of spi devices attached. I wrapped the code to do SPI transfers in a C++ class. A Class represents a single SPI Connection to a single ...
1
vote
0answers
18 views

Real-time timekeeping logic for ATmega16A

As part of a clock I'm building based on an ATmega16A, I wrote some assembly code to handle setting up the timer for a 32.768kHz crystal and handle second/minute/hour/day updates. Here are the ...
3
votes
1answer
41 views

Two bidirectional Software UARTs with AT89S52 microcontroller

I have learned one way to read from a serial port via software UART is via timer interrupts. I have made an implementation of receiving data from one serial port below. I haven't tested it yet because ...
4
votes
1answer
235 views

8051 RFID reader for Atmel microcontroller

I am currently using an AT89S52 microcontroller for a major project that involves a use of an RFID reader that outputs data in a serial format (9600 baud, no parity, 8 data bits, 1 stop bit). The ...
3
votes
0answers
684 views

Tuple-like container for packed data

I'm writing some code which needs to be compatible accross a Cortex-M based embedded device and x86 / x86_64 based PCs. I needed a solution for sending binary data between the Cortex-M and the ...
4
votes
1answer
196 views

Simple SystemVerilog AXI controller

I have more long term project I'm using to learn FPGA/HDL and this is first sub-sub-sub component of it used for testing ;) I'm targeting Zynq device. I'd like to create a component which create an ...
5
votes
3answers
2k views

Elegant Circular Buffer

I would like to design an elegant yet efficient circular buffer of integers. I have designed a FIFO type circular buffer in C++(11)- starting with the class header (declaration) as follow: [...
6
votes
1answer
200 views

Sending instructions to an LCD display controlled by HD44780

My current embedded project uses a 16x2 LCD controlled by the HD44780 standard controller. My PIC18 speaks to the LCD via the Adafruit LCD serial backpack (schematic link). I chose the SPI interface. ...
1
vote
2answers
505 views

Dual state button algorithm in C

I wrote code for determining the push button state whether it is long pressed or not. This function is called by timer interrupt routine every 1ms. But it seems really dumb. How can I make it shorter ...
9
votes
1answer
1k views

Simple callback wrapper for an embedded C++ app

I'm writing a callback wrapper class for an embedded application in C++11. The basic idea of the class is to be able to use it as a replacement instead of C-style callback functions, with the added ...
6
votes
2answers
759 views

Generic enum to text lookup in C

Can my code from this question be improved? I am thiking of validating inputs, portability issues, etc Please note that we must declare our strings at compile time. We code embedded systems and are ...
3
votes
0answers
165 views

Daemonizing shell scripts - MqSH

This is an mqtt driven, interactive, and asynchronous remote shell daemon written in bash. I call it "MqSH" or simply "mq". It works with bash, the busybox ash shell, and perhaps other Bourne-like ...
2
votes
1answer
115 views

GNU Makefile for google benchmark

I've decided to write a common Makefile for Google benchmark library. You could say I could have taken generated Makefile, but it's not appropriate solution (or maybe I'm wrong?). ...
7
votes
1answer
175 views

Lightweight LED library

One of the projects that have been on my to-do list since years involves controlling a number of Inter-Integrated Circuit (\$I^2C\$) peripherals. Lately I've been turning everything into it's own ...
2
votes
0answers
222 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 ...
4
votes
2answers
76 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
573 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. ...
0
votes
1answer
251 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 ...
2
votes
2answers
118 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: ...
12
votes
1answer
292 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 ...
22
votes
4answers
4k 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 ...
5
votes
1answer
405 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 ...
6
votes
3answers
160 views

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

I have an MCU (TI Tiva TM4C) that operates a GSM modem, LCD display, keypad, ADC inputs, and four relays for microgrid control/operation. To date I have about 2000 lines of code, mostly for ...
3
votes
0answers
71 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. ...
8
votes
1answer
395 views

Class that is used to run a 5x5x5 RGB cube

I had a hardware project for a 5x5x5 RGB cube which is driven by a 22118400Hz 8-bit AVR (1284p for those who like hardware). Basically, the class sets the bits in a huge array of 8-bit values (...
3
votes
1answer
43 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 ...
-2
votes
1answer
487 views

Singleton as static instance

In my project I need to have one class as singleton which must be globally accessible: board.h: ...
5
votes
3answers
4k views

State machine implementation

I have written a simple state machine. Comments and feedback are welcome. ...
3
votes
0answers
531 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 ...
14
votes
1answer
327 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 ...
14
votes
1answer
912 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 ...
37
votes
5answers
3k 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 ...
7
votes
1answer
165 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 ...
3
votes
0answers
841 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 ...
19
votes
1answer
691 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). ...
7
votes
2answers
208 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 ...
0
votes
1answer
474 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 ...