embedded

C How to calculate a percentage(perthousands) without floating point precision

为君一笑 提交于 2019-12-07 05:15:36
问题 How do you calculate a percentage from 2 int values into a int value that represents a percentage(perthousands for more accuracy)? Background/purpose: using a processor that doesn't have a FPU, floating point computations take 100's of times longer. int x = 25; int y = 75; int resultPercentage; // desire is 250 which would mean 25.0 percent resultPercentage = (x/(x+y))*1000; // used 1000 instead of 100 for accuracy printf("Result= "); printf(resultPercentage); output: Result= 0 When really

Open-source solutions for creating a cyclical logfile?

我是研究僧i 提交于 2019-12-07 05:04:07
问题 if (!wheel) { wheel = new Wheel(); } // or some such My google goggles aren't working too well today. I figured this one must have been coded a gazillion times already and was looking for some FOSS code, but couldn't find any. Before I reinvent the spherical axle-surrounding device, can anyone point me at a URL? I am coding in C for an embedded system (Atmel UC3), but that shouldn't make any difference, just explain why I need a cyclical logfile (because of limited storage). I want to log

What is zalloc in embedded programming?

眉间皱痕 提交于 2019-12-07 04:38:46
问题 I am looking into programming the ESP8266 serial-wifi chip. In its SDK examples it makes extensive use of a function called os_zalloc where I would expect malloc . Occasionally though, os_malloc is used as well. So they do not appear to be identical in function. Unfortunately there is no documentation. Can anybody make an educated guess from the following header file? #ifndef __MEM_H__ #define __MEM_H__ //void *pvPortMalloc( size_t xWantedSize ); //void vPortFree( void *pv ); //void

Using printf with two UARTs

天涯浪子 提交于 2019-12-07 04:26:47
问题 I have implemented fputc and fgetc in retarget.c to successfully use printf via UART0 on a Cortex-M3. However, I want a second uart channel for additional debug information. How can I integrate this as nicely as I can UART0 using printf? For example, using fprintf to a custom target and checking in fputc which target to send the character to.. E.g. for normal output fprintf(UART0,".."); and for debug output fprintf(UART1,".."); But I cannot see if fopen is called for stdout so I am struggling

How is the CSR signature constructed?

|▌冷眼眸甩不掉的悲伤 提交于 2019-12-07 03:58:29
I am trying to generate a CSR (Certificate Signing Request) in an embedded device. I have implemented some OpenSSL functions in one embedded device. Unfortunately I only have a few functions available. So far I've been able to generate an RSA private key and now I need to generate the CSR. My library does NOT have any of the functions such as X509_REQ_new() , X509_REQ_get_subject_name() etc. Therefore I'm building the CSR by means of creating a DER file directly. The CSR in DER format is decoded as follows: ASN1 Sequence Version Subject(s) name(s) Type of encryption Modulus & Exponent (from my

How to test reliability of my own (small) embedded operating system?

与世无争的帅哥 提交于 2019-12-07 03:38:50
问题 I've written a small operating system for embedded project running on small to medium target. I added some automated unit test with a high test code coverage (>95%), but the scope is only the static part. I got some code metrics as complexity and readability. I'm testing my code with a rule checker with MiSRA support, and of course fixed all warnings. I'm testing the code with a static analyzer and again fixed all warnings. What can I do now to test - and improve - the reliability of my OS ?

Declaring a pointer to const or a const pointer to const as a formal parameter

被刻印的时光 ゝ 提交于 2019-12-07 03:22:47
问题 I was recently making some adjustments to code wherein I had to change a formal parameter in a function. Originally, the parameter was similar to the following (note, the structure was typedef'd earlier): static MySpecialStructure my_special_structure; static unsigned char char_being_passed; // Passed to function elsewhere. static MySpecialStructure * p_my_special_structure; // Passed to function elsewhere. int myFunction (MySpecialStructure * p_structure, unsigned char useful_char) { ... }

Building a two-part firmware image using GCC toolchain

依然范特西╮ 提交于 2019-12-07 03:08:00
问题 I have some firmware built with GCC that runs on an ARM Cortex M0 based microcontroller. The build currently generates a single binary image that can be written into the program memory of the microcontroller. For reasons to do with field update, I need to split this image into two parts that can be updated separately. I'll call these Core and App . Core : contains the interrupt vector table, main() routine, and various drivers and library routines. It will be located in the first half of the

CPU usage measurment on arm bare metal system

空扰寡人 提交于 2019-12-07 03:06:29
问题 I am working on a ARM cortex M4 evaluation board, its a bare metal application without any operating system running on it. Now I want to measure CPU usage of a given process/algorithm , what would be the best way to do so? Should i implement an operating system to measure the CPU usage that have the functionality for such demand? 回答1: The question almost answers itself. What is your bare metal application doing when it is not in that process/algorithm? Measure one or the other or both. If you

Portable way to serialize float as 32-bit integer

a 夏天 提交于 2019-12-07 02:49:30
问题 I have been struggling with finding a portable way to serialize 32-bit float variables in C and C++ to be sent to and from microcontrollers. I want the format to be well-defined enough so that serialization/de-serialization can be done from other languages as well without too much effort. Related questions are: Portability of binary serialization of double/float type in C++ Serialize double and float with C c++ portable conversion of long to double I know that in most cases a typecast union