embedded

Lookup table vs switch in C embedded software

|▌冷眼眸甩不掉的悲伤 提交于 2019-11-27 20:24:16
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: Switch static void func1(){} static void func2(){} void fsm(int state) { switch(state) { case FUNC1: func1

Strategy for feeding a watchdog in a multitask environment

旧巷老猫 提交于 2019-11-27 20:20:28
问题 Having moved some embedded code to FreeRTOS, I'm left with an interesting dilemma about the watchdog. The watchdog timer is a must for our application. Using FreeRTOS has been a huge boon for us too. When the application was more single-tasked, it fed the watchdog at timely points in its logic flow so that we could make sure the task was making logical progress in a timely fashion. With multiple tasks though, that's not easy. One task could be bound up for some reason, not making progress,

Embedded C++ : to use exceptions or not?

倾然丶 夕夏残阳落幕 提交于 2019-11-27 19:55:50
问题 I realize this may be subjective, so will ask a concrete question, but first, background: I have always been an embedded software engineer, but usually at Layer 3 or 2 of the OSI stack. I am not really a hardware guy. I have generally always done telecoms products, usually hand/cell-phones, which generally means something like an ARM 7 processor. Now I find myself in a more generic embedded world, in a small start-up, where I might move to "not so powerful" processors (there's the subjective

How to flush Input Buffer of an UDP Socket in C?

假如想象 提交于 2019-11-27 19:12:01
问题 How to flush Input Buffer (if such thing exists at all) of an UDP Socket in C ? I'm working on an embedded Linux environment and using C to create some native application. There are several of these embedded machines on the same network, and when an event occurs on one of them (lets call it the WHISTLE-BLOWER), WHISTLE-BLOWER should send a network message to the network broadcast address, so that all machines on the network (including the WHISTLE-BLOWER) knows about the event and executes

How to prevent system hang before watchdog timer task kicks in

南楼画角 提交于 2019-11-27 18:55:00
问题 We are using an ARM AM1808 based Embedded System with an rtos and a File System. We are using C language. We have a watchdog timer implemented inside the Application code. So, whenever something goes wrong in the Application code, the watchdog timer takes care of the system. However, we are experiencing an issue where the system hangs before the watchdog timer task starts. The system hangs because the File System code is badly coded with so many number of while loops. And sometimes due to a

Process for reducing the size of an executable

醉酒当歌 提交于 2019-11-27 18:52:29
I'm producing a hex file to run on an ARM processor which I want to keep below 32K. It's currently a lot larger than that and I wondered if someone might have some advice on what's the best approach to slim it down? Here's what I've done so far So I've run 'size' on it to determine how big the hex file is. Then 'size' again to see how big each of the object files are that link to create the hex files. It seems the majority of the size comes from external libraries. Then I used 'readelf' to see which functions take up the most memory. I searched through the code to see if I could eliminate

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

六月ゝ 毕业季﹏ 提交于 2019-11-27 18:01:44
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 code. Tools Platform ----------- ------------ ______Visual C++ _____ WIN32 / /_______MBED (ARM)______

Why would a region of memory be marked non-cached?

喜欢而已 提交于 2019-11-27 17:58:27
问题 In an embedded application, we have a table describing the various address ranges that are valid on out target board. This table is used to setup the MMU. The RAM address range is marked as cacheable, but other regions are marked at not cacheable. Why is that? 回答1: If a memory region is accessed by both hardware and software simultaneously (EX: hardware configuration register or scatter-gather list for DMA), this region must be defined as non-cached. For actual DMA, the memory buffer can be

Stack Size Estimation

落花浮王杯 提交于 2019-11-27 17:51:37
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 pthread_create() or the like). Often, these stack sizes are hard-coded to values that are known to be

Testing Code for Embedded Application

倾然丶 夕夏残阳落幕 提交于 2019-11-27 17:36:15
问题 Background: I am developing a largish project using at Atmel AVR atmega2560. This project contains a lot of hardware based functions (7 SPI devices, 2 I2C, 2 RS485 MODBUS ports, lots of Analogue and Digital I/O). I have developed "drivers" for all of these devices which provide the main application loop with an interface to access the required data. Question: The project I am developing will eventually have to meet SIL standards. I would like to be able to test the code and provide a good