This is the mail archive of the ecos-devel@sources.redhat.com mailing list for the eCos project.


Index Nav: [Date Index] [Subject Index] [Author Index] [Thread Index]
Message Nav: [Date Prev] [Date Next] [Thread Prev] [Thread Next]
Other format: [Raw text]

Re: Sv: cyg_drv_interrupt_create() troubles


>>>>> "Stephen" == Stephen Mose Aaskov <sma@2m.dk> writes:

    Stephen> Now, maybe this is because it's friday - maybe because
    Stephen> I've gone blind, but...

    Stephen> cyg_interrupt_create() creates a Cyg_Interrupt object
    Stephen> with new(). A parameter is passed to new, this parameter
    Stephen> is the intr parameter that was passed to
    Stephen> cyg_interrupt_create. In my ethernet driver (the NE2000
    Stephen> port) this parameter is given as a pointer to a
    Stephen> cyg_interrupt struct in the driver's private data area.
    Stephen> cyg_interrupt looks to me as a symbolic placeholder and
    Stephen> nothing else.

    Stephen> Q: What is the purpose of this pointer being passed to
    Stephen> new? Normally such a parameter to new would be a typename
    Stephen> of the object to allocate, but in this case it is an
    Stephen> instance of a struct.

    Stephen> Could someone please help me out here?

eCos needs some memory for each interrupt source, for internal
administration purposes. For example it needs to keep track of the
ISR, DSR, and data word for each interrupt vector that is being used.
Suitable data structures could be statically allocated, but that would
require the system to preallocate memory for every interrupt vector.
Typically only a subset of the available interrupt sources will get
used, so preallocating wastes memory. Dynamic allocation would be an
alternative, but then even a minimal system would have to contain a
memory allocator - not a good idea either.

Instead it is left to higher-level code to provide the memory for the
system's per-interrupt data structure, by passing a pointer to a
cyg_interrupt struct.

Regarding the C++ code and its usage of the new operator, the code
looks something like:

    Cyg_Interrupt *t = new(intr) Cyg_Interrupt (...);

More conventional C++ code would look like:

    Cyg_Interrupt *t = new Cyg_Interrupt (...);

That would cause the memory to be dynamically allocated from the heap,
which is not what we want. Instead a special version of the new
operator, placement new, is used. This tells the compiler to use the
memory provided instead of allocating more memory from the heap.

Bart


Index Nav: [Date Index] [Subject Index] [Author Index] [Thread Index]
Message Nav: [Date Prev] [Date Next] [Thread Prev] [Thread Next]