Tuesday, March 22, 2016

Core Dump : part 1


Well ...if u spend significant time on learning one language and slowly slowly or quickly depending on how much you are interested in that language ..you will try to see its different facets of that language.

So since I mostly work on C, I use to see lot of segmentation fault happening when writing program related to pointers or stackoverflow.  In all these cases COREDUMPS are generated, which tells memory wise what went wrong.

Now , mostly I don't use to see this, but go back to program and try to figure out what went wrong.

This works if your program is 1-2 files only and simple. Else its very hard to know why crash happened.

So i started to read about how to check core-dump in gcc.

Below is what i learned.

1) Is core dump getting generated ? 

Even though your gcc will say core dump is generated, but you will see it is not present. It happens because your SHELL doesn't have permission to generated coredump by default.

hence you have to run below command.

> ulimit -c unlimited.

NOTE : ulimit is shell property, so when you start running your program you have to run above cmd first. So any program then run on that will generate core dump.

2) Checking Core Dump#

1) Run below cmd :  
gdb <executable> <core-file> or gdb <executable> -c <core-file>

Example I have c file name crash.c and core dump generated name is core, so i will run

> gdb ./crash core

This will give some information on my screen.

My .c program was

#include<stdio.h> #include<stdlib.h> int main() { int p[0]; int b=10; p[0];//=(int*) malloc(sizeof(int)*1); printf("b %d\n",b); printf("%p %p %p",&b,&p[0],&p[1]); p[1]=20; printf("b %d\n",b); free(p); // This is point where crash should occur //p=&b; }


Output of running cmd which mentioned below is

Core was generated by `./crash'. Program terminated with signal SIGABRT, Aborted. #0 0xb76df424 in __kernel_vsyscall ()


So as you can see with above message, you cannot do any shit with your program. Hence you have to use gdb next command -- bt . It stands for backtrace and prints the stack of program.

when i run bt below thing I got

(gdb) bt

#0  0xb76df424 in __kernel_vsyscall ()
#1  0xb7548827 in __GI_raise (sig=sig@entry=6)
    at ../nptl/sysdeps/unix/sysv/linux/raise.c:56
#2  0xb754bc53 in __GI_abort () at abort.c:89
#3  0xb7583993 in __libc_message (do_abort=do_abort@entry=1, 
    fmt=fmt@entry=0xb7680a5c "*** Error in `%s': %s: 0x%s ***\n")
    at ../sysdeps/posix/libc_fatal.c:175
#4  0xb758de7a in malloc_printerr (action=<optimized out>, 
    str=0xb767c56d "free(): invalid pointer", ptr=0xbf7fc108)
    at malloc.c:4996
#5  0xb758eaed in _int_free (av=0xb76c5420 <main_arena>, 
    p=<optimized out>, have_lock=0) at malloc.c:3840
#6  0x080484c1 in main ()

As you can see, something makes a bit sense now.
Since stack is LIFO, the first line ( from last) tells as what was function entered in which we had crash, it was MAIN().

now, when we called free, it defination would hav been in malloc.c , since it is pointed next.

Line 4 is telling as 'free() : invalid pointer' so we can see our pointer there and can see that it is not correct.

Voila our program is debugged. In next tute , we will see more better code.

Sunday, March 20, 2016

UART : Arduino : Serial Port


I got a new Arduino Uno .........:):):)

So first thing I started is to get the BLINK program which comes as part of examples to run.

Now as thing stand, whenever u tend to do things by urself u will run into lot of questions.

So I am not sure how I came to read about UART, but I did and below are things as per my understanding.




UART is software component which tells how to transmit data.

Ex : Mostly UART uses 10 bit frame structure, which can send 8 bit of data.
       or 11 bit , where 1 bit is parity bit.

2 extra bit are STARTING BIT , which is marked by LOW VOLTAGE and
                       STOP BIT , marked by HIGH VOLTAGE.

We will have BAUD RATE, which tells no of bits can be send per second. Most common is 9600.

So we can send 960 frames ( 10-bit frame) each second. or 960 octects of data in 1 second using UART with baud rate of 9600.

BAUD RATE is property of BAUD GENERATOR, which is an oscillator, with a particular frequency.

Formula  of baud rate :

Frequency / (16*(spbrg+1))   // spbrg here is register value of baud rate generator register. 

Basically depending on the BAUD RATE we need, we set spbrg for a particular frequency. 

there is one function I get from net, which will be in the library of microcontroller u are buying. 

OpenUSART(para1,para2,para3,para4,para5,para6)

here para6 is value of spbrg.  and para4 tell 8 bit data transmission.  REST can be get from internet

We also have to assign MICROCONTROLLER one port as INPUT and one as OUTPUT.

So now we know FRAME structure and how to set spbrg programmatically. Doing this we can tell microcontroller to send / receive data using UART.

Good Link : https://www.youtube.com/watch?v=py3HpisbJEY



Now coming to 2nd part . This will be brief

UART was the software part. The hardware/PHY part which converts signals and send them across can be RS-232 or TTL.

Most microcontrollers with UART uses TTL (Transistor-transistor Logic) level UART.
he TTL level UART is commonly used in the communications between microcontrollers and ICs. Only 2 wires are required for the full duplex communications.It is the simplest form of UART. Both logic 1 and 0 are represented by 5V and 0V respectively.



RS-232 (Recommended Standard 232) is a standard for serial binary data signals connecting between a Data Terminal Equipment (DTE) and a Data Communication Equipment (DCE).


GOOD LINK:
 http://tutorial.cytron.com.my/2012/02/16/uart-universal-asynchronous-receiver-and-transmitter/





Tuesday, February 16, 2016

RIL + Modem

Why to I write ?   Mayb sometime to look back and see what I was doing at a particular age.


My love with technology is like loving a girl who who adore ...are crazy about ...but can't marry since ....irrespective of all the things she is good at ...you didn't fall in love with her on first sight....

Same way even though I love technology...but aftertime I simply feel what is the use of learning all this.

But you never know...in that hope ...I keep on writing and loving :P


So there was I issue which i was checking and learnt something.

In android phones : There will be a application processor and baseband processor.

The application processor will run operating system Android and Baseband will run RTOS.

Now when we make call/sms/data ...what happens is

In android there first LAYER which comes in Android Framework which is kind of libraries and lot of other stuff. When you make application for Android you keep on calling these library functions.

Now after Android Framework, your request goes to RIL-J , radio interface layer-Java. It will have two process :

RILSender    and RILreceiver :

Now here Android kind of ends. Then we will have RIL-Daemon which will have Vendor RIL code.

Since every vendor have thier own way of communicating with baseband.

So  RIL-J will post request to RIL-D.

RIL-D will further communicate with Baseband processor.


Taking an example of vendor who uses AT cmd to communicate between AP and baseband.


Process -wise


RIL-J runs two different process ; Reciever and Sender
RIL-D has to check 
At Modem also there will be two different process, one for handling the REQUEST and one for handling the RESPONSE/INDICATION.

More Questions like :

Does RILJ stores any request or simply keeps on pumping them?
 Does RILD process commands one by one ?
There is socket between RILJ and RILD , so they will be two different task. Can in case of socket we can pump data continously to other side.

Between RILD and AT-CMD there will be shared memory.