embedded

what is the meaning of this Logical operators combination in C

末鹿安然 提交于 2021-01-29 08:46:41
问题 i know that -> is a pointer |= is OR. what is the logical meaning of such line? TIMER0->ROUTELOC0 |= TIMER_ROUTELOC0_CC0LOC_LOC15 回答1: You're ORing in (setting) a value to a register. Your processor has a TIMER0 with a register ROUTELOC0. It likely has a bit that is "CC0LOC_LOC15" I recommend looking at the data sheet for your processor to figure out what that means specifically. 回答2: |= does not mean OR. | means OR. |= is similar to +=, that is A |= B is the equivalent of A = A | B So to

Best way to convert an ASCII digit to its numeric value

拟墨画扇 提交于 2021-01-29 07:20:32
问题 Lets say I have an ASCII character representing a decimal digit: char digit; // between 0x30 ('0') and 0x39 ('9') inclusive I want to get the numeric value it represents (between 0 and 9 ). I am aware of two possible methods: subtraction: uint8_t value = digit - '0'; bitwise and: uint8_t value = digit & 0x0f; Which one is the most efficient in terms of compiled code size? Execution time? Energy consumption? As the answer may be platform-specific, I am most interested about the kind of

What will be the size of pointer on a 8 bit microcontroller like 8051?

陌路散爱 提交于 2021-01-29 02:47:26
问题 We know that size of the pointer depends on address bus,so what will be the size of pointer on 8 bit microcontroller like 8051? 回答1: The 8051 is not a C friendly processor. It has several address spaces. I used the Keil 8051 compiler extensively and it had several pointer types. An 8 bit pointer to point at the internal memory space or internal indirect space. A 16 bit pointer to point to either external ram or code space. A "smart" 24 bit pointer that could point anywhere. Basically a tag

C - Store global variables in flash?

左心房为你撑大大i 提交于 2021-01-29 02:30:43
问题 As the title may suggest, I'm currently short on SRAM in my program and I can't find a way to reduce my global variables. Is it possible to bring global variables over to flash memory? Since these variables are frequently read and written, would it be bad for the nand flash because they have limited number of read/write cycle? If the flash cannot handle this, would EEPROM be a good alternative? EDIT: Sorry for the ambiguity guys. I'm working with Atmel AVR ATmega32HVB which has: 2K bytes of

Understanding linker script NOLOAD sections in embedded software

耗尽温柔 提交于 2021-01-28 20:01:01
问题 According to the GNU documentation for ld , a NOLOAD section works as following: The `(NOLOAD)' directive will mark a section to not be loaded at run time. The linker will process the section normally, but will mark it so that a program loader will not load it into memory. Now, regarding to the program loader , accordign to wikipedia: Embedded systems typically do not have loaders, and instead, the code executes directly from ROM. In order to load the operating system itself, as part of

C shared memory

夙愿已清 提交于 2021-01-28 19:17:08
问题 I am trying to implement shared memory on embedded device with uClinux. My C source #include <stdio.h> #include <sys/shm.h> #include <sys/stat.h> #include <sys/socket.h> #include <errno.h> //using namespace std; int main() { int segment_id; segment_id = shmget(04, getpagesize(), IPC_CREAT | 0666); printf("Page size - %d\n",getpagesize()); printf("Error in socket - %d\n",errno); } I get an error Page size - 4096 Error in socket - 38 Can anyone help me? Thanks. 回答1: You need to test segment_id

Newer version of GCC throws reinterpret_cast error

痞子三分冷 提交于 2021-01-28 14:09:48
问题 I am developing an embedded project (on STM32). I currently use GCC 4.9.2, but I would like to switch to newer version of my toolchain. Unfortunately my code which succesfully compiles on gcc 4.9.2, throws reinpreted_cast errors on version 6.2.0 or 7.2.0 and I have no idea why. It looks like that newer gcc sees some problems when casting int to pointer and back to int - which I think should be quite normal operation. Error message thrown: 1>STM32L4\CMSIS\stm32l4a6xx.h(1567,30): error :

Issue in interfacing SPI e-ink display with PIC 18F46K22

不羁岁月 提交于 2021-01-28 04:48:30
问题 I am using a PIC 18F46K22 in SPI master mode to communicate with a Waveshare 1.54" ePaper Module. The FOSC frequency is 8Mhz internal and SPI configuration is FOSC/4. So when I check the output on logic-analyzer some output bits are differ from expected. And there is some deviation in SCL. #include <xc.h> #include "config.h" #include <stdbool.h> #include <stddef.h> #include <stdint.h> #include "main.h" //#define _XTAL_FREQ 8000000 #define SPI1_DUMMY_DATA 0x0 #define SPI_RX_IN_PROGRESS 0x0

Testing conditions that exit the test

佐手、 提交于 2021-01-28 03:10:41
问题 I have to test several routines/functions that have several if statements that leads to a terminate() or exit() statement that stops the test execution. I was wondering what's the best/correct approach in testing functions like this? For example, if I had something like the following: void function foo(void) { if(conditionA) { Terminate( //include infinite while loop resulting in timeout); } if(conditionB) { Terminate( //includes infinite white loop resulting in timeout); } } How do I hit

c - casting uint8_t* to uint32_t* behaviour

断了今生、忘了曾经 提交于 2021-01-28 02:09:56
问题 I have read this question: How does casting uint8* to uint32* work? but I am unsure of the answer given. I'm newbie embedded C programmer working on an project that uses GCC and I've been refactoring chunks of code to reduce the memory usage. An example is where I changed the data types of some variables from uint32_t to smaller sized types: uint8_t colour; uint16_t count; uint16_t pixel; func((uint32_t*)&colour); func((uint32_t*)&count); func((uint32_t*)&pixel); Where func(uint32_t* ptr)