The Jim Patchell AVR Page
created September 30, 2001
updated January 29, 2008


    Feburary 16, 2008

    ETHERNUT

        Recently I purchased an Ethernut 2.1 board for here at home as well as a couple for use at work.

        These boards seem to be a nice way to make a web based embedded application.  The source code for the library is completely open source.  And you do get the entire thing.  This is nice, because several times I have refered to the source code when the documentation was unclear as to how a function operated.

    The NUT/OS is a cooperative multitasking system.  This means that a thread will execute until it returns control back to the operating system.  The one advantage that this has is that resourse sharing is a lot easier.  I was a little skeptical of the NUT/OS at first, but after actually using it, I have to say I was quite impressed with it.  It does seem to work as advertised.

    It took a few tries to get a succesful compile with WinAVR, but as soon as I got it to compile (all of the problems were just setup...I did not need to modify any source) the examples ran just fine, and then I began to modify them as a way of exploring how ethernut actually works.

    The NUT/OS is very sophisticated as compared to something like say uCOS.  uCOS is preemptive, but it doesn't have the sophisticated goodies that NUT/OS does.  For instance, the IO subsystem seems to be integrated very nicely into the OS.

    I can highly recomend this product.

    http://www.ethernut.de
   
       

July 18, 2007

    AVR RTOS

    I have no idea if this is bullet proof or not.  But hey, it is free, how can you complain.

    This is a very simple RTOS.  Sorry, right now, there are no docs.  And not all of the files in the zip really have anything to do with it....yet.

    Right now, you can create tasks, and there are counting semaphore objects.  Which is really all you need for a basic implementation of an RTOS.

    I am surprised at how good it actually works.  I am not sure how it compares with say FreeRTOS, since I have never used it.

extern void CreateTask(TCB *t, void (*task)(void *),char *stack, int stacksize,int priority,char *name,void *arg);
extern void IrqSwap(void);
extern void InitTask(void);
extern void Yeild(void);
extern ECB *NewSemaphore(int InitCount,int Mode,char *name);
extern void CreateSemaphore(ECB *e,int InitCount,int Mode,char *n);
extern int PendSemaphore(ECB *e, int Timeout);    //wait for semaphore availiable
extern int PostSemaphore(ECB *e, int Value);    //signal semaphore availiable
extern void TimerTicker(void);
extern int TimeDelay(int mSec);
extern void Enable(char sr);
extern char Disable(void);
extern void StartOS(void);
extern void DoSwap(void);
extern void ExitInterrupt(void);

    Rtos for ATmegas        Updated January 29, 2008

    January 24, 2008

        There is a BUG in this RTOS.  I am still not sure where, but I think I know where it might be.  Here is the problem.

    It seems that a semaphore that is posted in an interrupt routine seems to cause a TASK CONTROL BLOCK to somehow get lost.  I suspect that it is in the IRQ entry that the problem is located.  When an interrupt occures, all of the 32 registers get pushed on the stack.  In avr-gcc, registers r0 and r1 are supposed to be set to zero.  However, they do on occasion get used temporarily to do things.  So, they could, sometimes, have different values in them.   Other C code gets executed durring the interrupt.  It may be that having a strange value in either r0 or r1 could cause a problem.  I don't know.  I changed the code a little so that right after r1 and r0 is pushed, they are cleared....oppss...forgot to clear r0....well, we shall see how what I did does over night.

    January 25, 2008

        Well, I do believe I have fixed that one bug.  It seems that I was right.  This is a good lesson...read the documentation...and take it seriously ;^).....

        So, you may download the latest version above...I have updated it.

        You are free to do with this as you please...but, you are not allowed to come whining to me if something doesn't work right.

        My next project....get the VGA all up and running and write a windowing library to take advantage of the rtos.

    January 29, 2008

        Well, I found another bug in the RTOS...this one was much more minor.  It was in the TimerTicker function.  When a semaphore times out, it is posted so that the task that was waiting on the semaphore can decide what to do next about the resource that has not become availiable.  However, I was not incrementing the EventCount object member.  This caused wierd  behavior, so I added this line of code.

        The new version of the RTOS is now posted above.

        I have it running on a test setup using an ATmega2561 on an STK500/501 setup.  The STK500/501 is connected up to a Xilinx Spartan 3 Starter Board that is running a VGA display and also a hardware timer.  This was a kind of fun project.

        Next up...Midi -> CV converter using the RTOS...I hope.
   

July 14, 2007
   
    I can't believe it has been about 6 yearrs since I first started using the AVR....alot of water has flowed under the AVR bridge since then.

    1. I originally used the Image Craft C compiler.  It is a good compiler, but I think I have now found a much better choice.  And that is WinAVR.

    Pros:
        1. It is FREE
        2. Works in conjuction with AVR Studio
        3. In theory, it can do C++
    Cons:
        1. Support is spotty
        2. Still has a few sharp edges
        3. Documentation is sometimes difficult to find.

    However, overall, it is the best compiler package, in my opinion, for the AVR.  If you need a software developement system, I can highly recomend AVR Studio (Atmel),  WinAVR, and JTAGICE Mk II (Atmel).  The JTAGICE is the only thing you will have to pay for.  It is quite pricecy, but well, not everything in life is free.

    And also, there are many free packages that work with WinAVR, like FRERTOS.

    2.  I also originally used the AT90S8515 for most of my projects.  However, it, and it's successor, the ATMega8515 do not have a JTAG interface, which makes using it a bit of a problem when it comes to debugging firmware.  I am now starting to use the ATMega128 and ATMega2561.  More than enough programming space, plus 4K and 8K of ram respecfully.


    I am also working on porting my RTOS over to the the AVR running under WinAVR.  Right now, the only problem I am having is trying to figure out how to deal with interrupts.  This is not as easy as it would seem.  But, I am working on it.


Sept 30, 2001

    I only just started to really work with the AVR only a couple of weeks ago (from the created date you see above).  The ulitmate application for the AVR in my projects is for a MIDI interface for my synthesizer projects.  Some of the things I am writing may, however, be of some use to others, so, I am willing to share what I have learned.

    As of the create date, all code on this web page was created with the Image Craft ICC compiler.

    The code is run on an STK200 unless otherwise noted.



Example 1
    Interrupt Driven Uart Transmit routine.

    This is the first interrupt code I wrote for the AVR.  It is very simple.  It sends a stream of ascii data out of the serial port.  It does this by writting the data into a buffer, which is then emptied by a transmit interrupt routine.

    The data is transmitted at 9600 baud if the processor is using a 4 MHz clock (which is what is on the STK200 eval board).

     Source Code For Simple transmit interrupt routine



Example 2
    Interrupt Driven Uart Transmit and Recieve Routines

    This is the second interrupt code I wrote for the AVR.  It is the same as example 1, with the addition of the recieve routines.

    The data is transmitted and recieved at 9600 baud if the processor is using a 4 MHz clock.

     Source Code for Simple Transmit and Recieve interrupts