embedded

Static allocation of opaque data types

送分小仙女□ 提交于 2019-11-26 10:28:03
问题 Very often malloc() is absolutely not allowed when programming for embedded systems. Most of the time I\'m pretty able to deal with this, but one thing irritates me: it keeps me from using so called \'opaque types\' to enable data hiding. Normally I\'d do something like this: // In file module.h typedef struct handle_t handle_t; handle_t *create_handle(); void operation_on_handle(handle_t *handle, int an_argument); void another_operation_on_handle(handle_t *handle, char etcetera); void close

Algorithm to rotate an image 90 degrees in place? (No extra memory)

痞子三分冷 提交于 2019-11-26 09:40:53
问题 In an embedded C app, I have a large image that I\'d like to rotate by 90 degrees. Currently I use the well-known simple algorithm to do this. However, this algorithm requires me to make another copy of the image. I\'d like to avoid allocating memory for a copy, I\'d rather rotate it in-place. Since the image isn\'t square, this is tricky. Does anyone know of a suitable algorithm? Edited to add clarification, because people are asking: I store an image in the usual format: // Images are 16

When is CRC more appropriate to use than MD5/SHA1?

杀马特。学长 韩版系。学妹 提交于 2019-11-26 08:45:00
问题 When is it appropriate to use CRC for error detection versus more modern hashing functions such as MD5 or SHA1? Is the former easier to implement on embedded hardware? 回答1: CRC works fine for detecting random errors in data that might occur, for example, from network interference, line noise, distortion, etc. CRC is computationally much less complex than MD5 or SHA1. Using a hash function like MD5 is probably overkill for random error detection. However, using CRC for any kind of security

Set ALSA master volume from C code

戏子无情 提交于 2019-11-26 08:08:47
问题 I\'ve been looking for a simple C code example to set the master volume of the ALSA mixer but could not find anything simple for this supposedly common operation. I\'m totally unfamiliar with ALSA, so making my own minimal example will take time. I would be happy if anyone could provide one. 回答1: 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;

How much footprint does C++ exception handling add

时间秒杀一切 提交于 2019-11-26 08:03:58
问题 This issue is important especially for embedded development. Exception handling adds some footprint to generated binary output. On the other hand, without exceptions the errors need to be handled some other way, which requires additional code, which eventually also increases binary size. I\'m interested in your experiences, especially: What is average footprint added by your compiler for the exception handling (if you have such measurements)? Is the exception handling really more expensive

Power off an USB device in software on Windows

空扰寡人 提交于 2019-11-26 07:37:07
问题 I would like to power cycle an USB device through software on Windows. I am doing development on a small USB power microcontroller. This chip will revert to native behavior on a power cycle and allow a code download. Since my code will crash the device when things go wrong -- making it ignore all USB commands -- I have to physically unplug the device from the system. I want to do development remotely, and not have to be physically present. So far I have tried using \"devcon\" to disable

How to determine maximum stack usage?

送分小仙女□ 提交于 2019-11-26 06:24:54
问题 What methods are available for determining the optimum stack size for embedded/memory constrained system? If it\'s too big then memory is wasted that could be used elsewhere. However, if it is too small then we get this website\'s namesake... To try to jump start things: Jack Ganssle states in The Art of Designing Embedded Systems that, \"With experience, one learns the standard, scientific way to compute the proper size for a stack: Pick a size at random and hope.\" Can anyone do better than

Unit Testing C Code [closed]

被刻印的时光 ゝ 提交于 2019-11-26 05:42:22
问题 Closed. This question is off-topic. It is not currently accepting answers. Want to improve this question? Update the question so it's on-topic for Stack Overflow. Closed 4 years ago . I worked on an embedded system this summer written in straight C. It was an existing project that the company I work for had taken over. I have become quite accustomed to writing unit tests in Java using JUnit but was at a loss as to the best way to write unit tests for existing code (which needed refactoring)

Looking for an efficient integer square root algorithm for ARM Thumb2

折月煮酒 提交于 2019-11-26 05:21:45
问题 I am looking for a fast, integer only algorithm to find the square root (integer part thereof) of an unsigned integer. The code must have excellent performance on ARM Thumb 2 processors. It could be assembly language or C code. Any hints welcome. 回答1: Integer Square Roots by Jack W. Crenshaw could be useful as another reference. The C Snippets Archive also has an integer square root implementation. This one goes beyond just the integer result, and calculates extra fractional (fixed-point)

Simple serial point-to-point communication protocol

佐手、 提交于 2019-11-26 04:59:47
问题 I need a simple communication protocol between two devices (a PC and a microcontroller). The PC must send some commands and parameters to the micro. The micro must transmit an array of bytes (data from sensor). The data must be noise protected (besides parity checking, I think I need some other data correction method). Is there any standard solution to do this? (I need only an idea, not the complete solution). P.S. Any advice is appreciated. P.P.S Sorry for any grammar mistakes, I hope you