embedded

C++ frontend only compiler (convert C++ to C)

 ̄綄美尐妖づ 提交于 2019-11-26 22:37:34
问题 I'm currently managing some C++ code that runs on multiple platforms from a single source tree (Win32, Linux, Verifone CC terminals, MBED and even the Nintendo GBA/DS). However I need to build an app targetted at an embedded platform for which there is no C++ compiler (C only). I remmber that many of the early C++ compilers were only front-ends stitting on existing C compilers (Glockenspiel for example used MSC). Are there any such 'frontend' C++ compilers in use today that will generate C

C++, can I statically initialize a std::map at compile time?

﹥>﹥吖頭↗ 提交于 2019-11-26 22:17:27
问题 If I code this std::map<int, char> example = { (1, 'a'), (2, 'b'), (3, 'c') }; then g++ says to me deducing from brace-enclosed initializer list requires #include <initializer_list> in C++98 ‘example’ must be initialized by constructor, not by ‘{...}’ and that annoys me slightly because the constructor is run-time and can, theoretically fail. Sure, if it does, it will fail quickly and ought to do so consistently, so that I ought to quickly locate & correct the problem. But, still, I am

Set ALSA master volume from C code

≡放荡痞女 提交于 2019-11-26 22:06:21
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. 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(

How much footprint does C++ exception handling add

浪尽此生 提交于 2019-11-26 21:53:33
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 (many say that), in terms of binary output size, than other error handling strategies? What error handling

STM32 SPI Slow Compute

风格不统一 提交于 2019-11-26 21:41:09
问题 I'm using a STM32F4 and its SPI to talk to a 74HC595 like in this tutorial. Difference is for starters I'm using the non-DMA version for simplicity. I used STMCubeMX to configure SPI and GPIO Issue is: I'm not getting the latch PIN, that I set to PA8 to toggle during transmission fast enough. The code I'm using: spiTxBuf[0] = 0b00000010; HAL_GPIO_WritePin(GPIOA, GPIO_PIN_8, GPIO_PIN_RESET); HAL_SPI_Transmit(&hspi1, spiTxBuf, 1, HAL_MAX_DELAY); // while(HAL_SPI_GetState(&hspi1) != HAL_SPI

How to improve fixed point square-root for small values

隐身守侯 提交于 2019-11-26 21:20:03
问题 I am using Anthony Williams' fixed point library described in the Dr Dobb's article " Optimizing Math-Intensive Applications with Fixed-Point Arithmetic " to calculate the distance between two geographical points using the Rhumb Line method. This works well enough when the distance between the points is significant (greater than a few kilometers), but is very poor at smaller distances. The worst case being when the two points are equal or near equal, the result is a distance of 194 meters,

What is the fastest way to rotate the bits in an 8x8 block on bits?

僤鯓⒐⒋嵵緔 提交于 2019-11-26 20:43:32
问题 I'm not sure the exact term for what I'm trying to do. I have an 8x8 block of bits stored in 8 bytes , each byte stores one row. When I'm finished, I'd like each byte to store one column. For example, when I'm finished: Byte0out = Byte0inBit0 + Byte1inBit0 + Byte2inBit0 + Byte3inBit0 + ... Byte1out = Byte0inBit1 + Byte1inBit1 + Byte2inBit1 + Byte3inBit1 + ... What is the easiest way to do this in C which performs well? 回答1: This code is cribbed directly from "Hacker's Delight" - Figure 7-2

Lookup table vs switch in C embedded software

£可爱£侵袭症+ 提交于 2019-11-26 20:23:43
问题 In another thread, I was told that a switch may be better than a lookup table in terms of speed and compactness. So I'd like to understand the differences between this: Lookup table static void func1(){} static void func2(){} typedef enum { FUNC1, FUNC2, FUNC_COUNT } state_e; typedef void (*func_t)(void); const func_t lookUpTable[FUNC_COUNT] = { [FUNC1] = &func1, [FUNC2] = &func2 }; void fsm(state_e state) { if (state < FUNC_COUNT) lookUpTable[state](); else ;// Error handling } and this:

Stack Size Estimation

自古美人都是妖i 提交于 2019-11-26 19:15:36
问题 In multi-threaded embedded software (written in C or C++), a thread must be given enough stack space in order to allow it to complete its operations without overflowing. Correct sizing of the stack is critical in some real-time embedded environments, because (at least in some systems I've worked with), the operating system will NOT detect this for you. Usually, the stack size for a new thread (other than the main thread) is designated at the time that thread is created (i.e. in an argument to

Driving Beaglebone GPIO through /dev/mem

假装没事ソ 提交于 2019-11-26 18:55:55
问题 I'm trying to write a C program for blinking a LED on the Beaglebone. I know I can use the sysfs way...but I'd like to see if it is possible to get the same result mapping the physical address space with /dev/mem. I have a header file, beaglebone_gpio.h wit the following contents: #ifndef _BEAGLEBONE_GPIO_H_ #define _BEAGLEBONE_GPIO_H_ #define GPIO1_START_ADDR 0x4804C000 #define GPIO1_END_ADDR 0x4804DFFF #define GPIO1_SIZE (GPIO1_END_ADDR - GPIO1_START_ADDR) #define GPIO_OE 0x134 #define GPIO