Embedded Freaks..

November 17, 2008

Composite Pattern for C (AVR-GCC)

Filed under: avr, programming-tips — Tags: , — kunilkuda @ 5:41 pm

In java, you can have composite pattern easily using interface, like this:

Animal[] animals = new Animal[] { new Elephant(), new Cow(), new Cat() };
for(Animal currAnimal : animals) {
  // Do the stuff here
}

Now, I want to have the same thing for serial RX interrupt in AVR. Something like this:

ISR(USART0_RX_vect) {
  uint8_t data = UDR0;
  for(InterruptHandler currHandler: interruptHandlers) {
    currHandler.handle(data);
  }
}

By that way, I can chain the interrupt handler easily. Of course, mixing C and Java in C-compiler won’t be OK for AVR-GCC. But I found out some way to do the similar thing in C.

(more…)

November 11, 2008

Simple AT Parser for AVR

Filed under: avr — Tags: — kunilkuda @ 10:06 am

After some failure with the direct translation of Java simple AT parser to AVR-GCC, I’ve come out with new design of AT parser, special for AVR.

It’s not complete yet, but I can use it to setup the modem, and send the SMS. I hope I can do more with it soon. Here’s the link of my source code.

November 8, 2008

Bad Example of Interrupt Handling

Filed under: avr, programming-tips — Tags: , — kunilkuda @ 3:39 pm

In life, you need two examples: good one, and bad one. Here’s one of my bad design of interrupt handling.

The purpose of the firmware was to read a line (CR/LF terminated characters) from serial port, then parse it. Actually, I tried to port my simple AT handler from Java into C (AVR-GCC). It works, and as you can see, this program runs okay under x86 PC, but not under AVR with 8Mhz xtal.

Here’s the actual problem:

(more…)

Older Posts »

Blog at WordPress.com.