how to store data in non volatile memory [closed] - c

Closed. This question needs to be more focused. It is not currently accepting answers.
Want to improve this question? Update the question so it focuses on one problem only by editing this post.
Closed 8 years ago.
Improve this question
I'm a beginner in the embedded field. I have done a few engineering project using ARM and PIC micro controller. Now I'm facing a problem how to store some details(like name and rate) in the non volatile memory or external memory? Can any one help me to solve this? Fom where I should get examples of this storing? Now am using keil u vision 4 for programming but printf is not working in it? Earlier I'm using keil u vision 3 printf was working on that?

Various controller families have such things as EEPROM, or modifiable Flash. But they are accessed in a completely controller-dependent way.
To use them, you just issue a command (or rather set of commands) to store data X to address Y in this memory area. Later on, you get them back.
How this is done should be obtainable from the manual and/or application notes from the manufacturer of the chip.
Also be aware of the timing. AFAIR, a PIC needs 4 ms to store a single byte, so it might be helpful to set up (or use) a framework which automatically stores data byte for byte and advances upon receipt of an interrupt. So the work is done in the background.

Related

Loading characters from array in mips [closed]

Closed. This question is opinion-based. It is not currently accepting answers.
Want to improve this question? Update the question so it can be answered with facts and citations by editing this post.
Closed 6 years ago.
Improve this question
When you load character from an array in mip does the data still exist at that position in the array ? if not, how can you loop thru the array and get each character within the array ? thanks (:
Though your question seem silly, it is actually a very legitimate question!
Form an outside perspective modern memories have a non-destructive readout.
This means that reading a memory location doesn't destroy the data held there.
So reading from an array won't destroy the item read.
Out of curiosity it is funny to note that internally, depending on the memory technology, reading may be a destructive operation (the common DRAM and the old Magnetic core memory are an example1) and that there exists (and existed) destructive memories.
MIPS could run in a system with destructive readout, that would be tricky however since MIPS is a Von Neumann architecture, instructions are read from the same memory where data are.
So reading an instruction would also destroy it.
Though one can arrange a mixed system where code is run from a non destructive memory and data is in a destructive one, such configuration is so unusual that you can safely assume that it wont never happen.
1 Read-only memory like ROM, PROM and in general non-volatile memories have non destructive reading (so do Flash ROMs). In general memory that stores "charges" have destructive readouts.

Can Endianess of system be changed using c code [closed]

Closed. This question needs to be more focused. It is not currently accepting answers.
Want to improve this question? Update the question so it focuses on one problem only by editing this post.
Closed 6 years ago.
Improve this question
I know that endianess little or big is inherent to the system. Then, how is it possible to change using c code, as I have seen a code, which says it can change the endianess.
Endianess depends on the CPU hardware. So normally you can't do anything about it.
The code you have seen was most likely just tossing bytes around from one endianess to the other. Though some CPUs (for example some PowerPC) do have the possibility to configure endianess by writes to a hardware register.
You can't change the endianness of the system in general (there are bi-endian architectures), this would require you to change the instruction set. You can change the endianness of the data you use though. Take a look at this question to see how.

How locking actually works [closed]

Closed. This question needs to be more focused. It is not currently accepting answers.
Want to improve this question? Update the question so it focuses on one problem only by editing this post.
Closed 8 years ago.
Improve this question
I got one question a very simple one.
while implementing a simple locking mechanism using global variable.I can't find out how to prevent the access of global variable from 2 processes/thread.
My algorithm (take 2 process)
Process p1 check if variable g is set then do not modify the code.
If not set then set it then modify code.
Same for process 2 .
while executing I got fair result but is it correct.
My doubt in some architecture if 2 instructions are not atomic then how to avoid accessing the global variable at a time.
please give me some basic idea.
Use atomic methods to manipulate the global variable.
Atomic operations are 'built-in' to gcc. While they are not generally 'portable', most compilers offer atomic operations.
For GCC, you might implement something like this:
if(__sync_bool_compare_and_swap(&g, g, g+1))
/* Changed by you. */;
else
/* Another process changed it before you could. Perhaps try again. */

Advantages/disadvantages of mapping a whole file vs. blocks when needed [closed]

Closed. This question is opinion-based. It is not currently accepting answers.
Want to improve this question? Update the question so it can be answered with facts and citations by editing this post.
Closed 4 years ago.
Improve this question
What are the advantages/disadvantages of mapping a whole file once vs. mapping large blocks when needed in an algorithm?
Intuitively, I would say it makes most sense just to map the whole file and then let the OS take care of reading/writing to disk when needed instead of making a lot of system calls since the OS is not actually reading the mapped file before accessed. At least on a 64 bit system where the address space isn't an issue.
Some context:
This is for an external priority heap developed during a course on I/O algorithms. Our measurements shows that is slightly better to just map the whole underlying file instead of mapping blocks (nodes in a tree) when needed. However, our professor does not trust our measurements and says that he didn't expect that behaviour. Is there anything we are missing?
We are using mmap with PROT_READ | PROT_WRITE and MAP_SHARED.
Thanks,
Lasse
If you have the VM space, just map the whole file. As others have already said, this allows the OS the maximum flexibility to do read-aheads, or even if it doesn't it will bring in the data as required through page faults which are much more efficient than system calls as they're being made when the system is already in the right kernel context.
Not sure why your professor doesn't expect that behaviour, but would be good to understand his rationale?

A byte has 8-bits. Can it be larger in another system? give an example [closed]

Closed. This question needs to be more focused. It is not currently accepting answers.
Want to improve this question? Update the question so it focuses on one problem only by editing this post.
Closed 8 years ago.
Improve this question
A byte has 8-bits. Can it be larger in another system? Give an example.
Also, how many different types of calls such as writeint,writedec,writestring,writechar are there in assembly language.
Thanks.
Not any more. There was a time, yes, when there were systems without a fundamental 8-bit byte.
System where 1 byte != 8 bit?
how many different types of call such as writeint,writedec,writestring,writechar are there in assembly language
This question makes no sense. Assembly language is just a means of writing code that translates directly to machine instructions. call is just one of these instructions - it jumps to some other section of code, with the intent of returning to the place where the call was made.
The things you're referring to sound more like library routines - in which case there are any number of them, depending on the programming environment.

Resources