Wednesday, September 16, 2009

FIQ and IRQ interrupt

The difference between FIQ and IRQ interrupt system in any microprocessor...Eg:ARM926EJ

Ans1. A method of performing a fast interrupt in a digital data processor having the capability of handling more than one interrupt is provided. When a fast interrupt request is received a flag is set and the program counter and condition code registers are stored on a stack. At the end of the interrupt servicing routine the return from interrupt instructions retrieves the condition code register which contains the status of the digital data processor and checks to see whether the flag has been set or not. If the flag is set it indicates that a fast interrupt was serviced and therefore only the program counter is unstacked.

In other words, an FIQ is just a higher priority interrupt request, that is prioritized by disabling IRQ and other FIQ handlers during request servicing. Therefore, no other interrupts can occur during the processing of the active FIQ interrupt.

Ans 2. An FIQ interrupt is higher priority than an IRQ, it has its own mode (and therefore r13, r14 and spsr) and mask bit (CPSR[6]), which allows it to be taken while an IRQ is being handled - the processor can store enough state to enable the programmer to return to the IRQ handler after handling the FIQ. Further, the extra banked registers and the address of the FIQ vector
allows the programmer to build systems for which the interrupt latency for an FIQ is less than for an IRQ.

In a typical system there will be one FIQ (the highest priority or most critical interrupt) sources and a number of IRQ sources, arbitrated by an interrupt handler.

Please check out my another post in the same blog.

UART port and a serial port in a computer

What is the difference, if any, between a UART port and a serial port in a computer?

UART is the abbreviation of Universal Asynchronous Receiver Transmitter, the name of the chip that enables the computer to communicate via a serial line (eg. RS-232, RS-485, RS-422).

The serial port is the RS-232 interface (internally connected to the UART) of the computer.

Regarding interrupt based communication

We have a simple architecture :

  1. Main chip (arm9 based)
  2. PIC controller

The PIC communicates to ARM via an interrupt based I2C communication protocol for transfer of data. Inside the interrupt we signal a task which reads the data from the I2C layer (bus).

In case the data is limited we usually won't have much problem to read the data and send it to upper layer. In case this data is very huge the interrupt will be tied for a long time.

how to avoid the same? ...or can we a different solution?


Ans 1: Have some kind of 'worker thread', sometimes called a kernel thread, whose job it is to pull data out of the I2C interface and buffer it, hand it off to other parts of your system, etc. Use the interrupt routine only to un-block the kernel thread. That way, if there are other duties the system has to perform, it is not prevented from doing so by the interrupt handler, and you still get your data in from your device in a timely manner.

Ans 2: You shouldn't read a complete packet in one execution of the interrupt routine. Depending on the hardware support you should handle one sample/bit/byte, store data in a buffer and only signal the task when the packet is complete.

Why I couldnt work with the gcc compiler without ‘\n’ in printf?

I have written a printf() statement like below:

printf("hello\n");

this works fine when built using Linux' gcc compiler. However if I write

printf("hello");

the print doesn't appear on the screen. There is some buffering mechanism it seems?


Answer :

Even if buffering isn't a problem, if you don't print the newline your shell's prompt might be clobbering the output.

you are for example using gcc in a unix shell and at the end of your program do printf("hello") it won't print a newline before your shells prompt is displayed. The prompt will be printed on that same line, sometimes overwriting the entire line depending on kind of prompt you have set up.


Sunday, September 6, 2009

C skills : tutor 5: StrStr Library function





char *strstr(char *string1, char *string2);


Description:

The strstr function locates the first occurrence of the string string2 in the string string1 and returns a pointer to the beginning of the first occurrence.

Return Value

The strstr function returns a pointer within string1 that points to a string identical to string2. If no such sub string exists in src a null pointer is returned.



/* user defined strstr */

#include "stdio.h"


char * strstr_ud(char *, char *);

int main()
{

char s1 [] = "This House is Nice";
char s2 [] = "My Car is White";

printf("Returned String 1: %s\n", strstr_ud(s1, "House"));
printf("Returned String 2: %s\n", strstr_ud(s2, "Car"));
return 0;

}

char * strstr_ud(char * str1, char * str2)
{

char *temp1=NULL;
char *temp2=NULL;

temp2 = str2;
while(*str1++ != '\0')
{

if(*str2 == *str1)
{
temp1 = str1;

while(*str2 != '\0')
{
if(*str2 != *temp1)
{
flag = 1;
}
else
{
flag = 0;
}
str2++;temp1++;
}

if(flag == 0)
{
return str1;
}
else
{
str2 = temp2;
}

}

}

return NULL;

}


Output
House is Nice
Car is White

Friday, September 4, 2009

C skills : tutor 4: Reversal of Linklist using Recursion

#include"stdio.h"

typedef struct node
{
int data;
struct node *next;

} NODE;

NODE * reverse( NODE *);
void print_list(NODE *);
NODE *insert_node(NODE *);

main()
{
NODE * front = NULL;
char ch;


printf("\nEnter 1:insert,2:print,3:reverse,4:exit\n");
while(1)
{


scanf("%c",&ch);


switch(ch)
{

case '1':front=insert_node(front);
printf("\n====Node is inserted===\n");
printf("\nEnter 1:insert,2:print,3:reverse,4:exit\n");
break;

case '2':print_list(front);
printf("\nEnter 1:insert,2:print,3:reverse,4:exit\n");
break;

case '3':front = reverse(front);
printf("\n====Node is reversed===\n");
printf("\nEnter 1:insert,2:print,3:reverse,4:exit\n");
break;
case '4':free(front);
return(0);


};

}

}


NODE * insert_node(NODE * ptr)
{

NODE * newnode ;
int newnode_data;
NODE *temp=ptr;
NODE *front=NULL;


/* INSERT FROM FRONT*/
if(ptr == NULL)
{
ptr = (NODE *)malloc(sizeof(NODE *));
printf("\n=====Enter the data for the first newnode ======\n");
scanf("%d",&newnode_data);
ptr->data = newnode_data;
ptr->next = NULL;
front = ptr;
}
else
{
newnode = (NODE *)malloc(sizeof(NODE *));
printf("\n=====Enter the data for the newnode ======\n");
scanf("%d",&newnode_data);
newnode->data = newnode_data;
newnode->next = ptr;
front = newnode;
}
return front;

}

void print_list(NODE *ptr)
{

NODE *temp_ptr=ptr;
int count=0;

if(temp_ptr == NULL)
{
printf("\nNo list to print \n");
return;
}

while(temp_ptr != NULL)
{

printf("\nnode [%d] : data [%d]\n",count,temp_ptr->data);
temp_ptr=temp_ptr->next;
count++;
}



return;
}


NODE * reverse( NODE * root )
{
NODE * ret_val;

if ( root == NULL || root->next == NULL )
return root;

ret_val = reverse(root->next);

(root -> next)->next = root;
root->next = NULL;

return ret_val;
}

C Skills : Tutor -3 : String Copy

/*string cpy */

#include "stdio.h"

char *stringcpy(char *str_des,const char *str_src);

int main()
{

char str_des[40];
char str_src[20];

printf("\nEnter the first string\n");
scanf("%s",str_des);

printf("\nEnter the second string\n");
scanf("%s",str_src);

stringcpy(str_des,str_src);
printf("\nstring copy is done:The first string is : %s \n", str_des);

return(0);

}

char *stringcpy(char *str_des,const char *str_src)
{
char *temp= str_des;
while(*temp!='\0')temp++;
while(*str_src != '\0')*temp++ = *str_src++;
*temp = '\0';
return str_des;

}

C Skills : Tutor -2 : Pointer declaration

What's wrong with this declaration?

char * t1,t2;


Answer : t1 is a pointer to char and t2 is a char .

if we want both t1 and t2 as pointer to char, below is the declaration for the same:

char *t1,*t2;


P.S : The tutorial only covers few important tricks of the language , This is only for people who have some basic knowledge of the language.

C Skills : Tutor-1 :HelloWorld

C is just Sea , the more I learn, the more I forget ....This is the reason , I thought of writing all about C and try to accumulate all that I know and share with all using the blog....Well!!...My Blog turned technical huh!!!...


This is a simple program in C ..

Say "Hello to the world....."

#include"stdio.h"

int main()
{
printf("hello world ! \n");
return 0;
}

stdio.h is called a header file .......Beginners..come on search in google wats there inside the header file.

Question: What happens when I execute the same code in unix after changing the printf like
printf("hello world !"); ?????



P.S : The tutorial only covers few important tricks of the language , This is only for people who have some basic knowledge of the language.