[En-Nut-Discussion] Writting a new UART device

Avex avexwu at yahoo.com.tw
Fri Oct 18 05:01:44 CEST 2002


Hi Harald Kipp ,

I am writting a 4-port driver using st16c554 chip on ethernut 
platform. I refer to uartavr.c & uarts.c and wrote a program
following the format like these 2 files.  However, I found, I 
can't open 4 ports at the same time. To describe it clearly, I
couldn't open more than 2 ports concurrently. 2 ports is the 
limitation which I can open at the same time.To open the 
ports of uart one by one , the operation is correct. However,
 if I open it more than 2, it means opening 3 ports concurrently, 
it went wrong. 

I trace it and I found the problem is at 
NutHeapAllocClear(sizeof(IFSTREAM));  , shown as follow.

int UartStInit(NUTDEVICE *dev)
{
    volatile IFSTREAM *ifs;
    volatile UARTSTDCB *dcb;
    volatile u_char lcr_byte  = 0;
     volatile u_char fifo_byte = 0;
     volatile u_char *base;    // reference: dev\eth0rtl.c

    // Check for valid device.
    if (dev->dev_type != IFTYP_STREAM)
        return -1;

//  #define COMA 0x8000 , int0
//  #define COMB 0x8008 , int1
//  #define COMC 0x8010 , int2
//  #define COMD 0x8018 , int3
    base = (u_char *)(dev->dev_base); // reference: dev\eth0rtl.c

    // Initialize interface control block.
    if (dev->dev_icb == 0)  
        // Problem : If  I alloc more then 2 times, the data which ports send out will
        // not be correct 
        dev->dev_icb = NutHeapAllocClear(sizeof(IFSTREAM));    <-- this line, The Problems

    ifs = dev->dev_icb;
    ifs->if_input  = UartStInput;
    ifs->if_output = UartStOutput;
    ifs->if_flush  = UartStFlush;
    // Initialize driver control block.
.................................................................

    return 0;
}

The problem is if I used heapalloc more then 2 times, 
the operation of extern uarts I wrote
will not correct. I still have about 22K memory in my 
device (Using HeapAvailiable to get the value).

And, I knew you should know the problem. It's due to 
you used two different ways in uartavr.c
and uartspi. One it a 'static ifstream' and the other is a 
'dynamic ifstream' as above. The methods 
of memory allocation between they two are different.
Hope you can help me,Thanks in advanced,

Sincerely,


Avex

 



-----------------------------------------------------------------
< ╗C╓яЁё Yahoo!╘_╪╞ >  www.yahoo.com.tw



More information about the En-Nut-Discussion mailing list