nutinit.c File Reference

Go to the source code of this file.

Defines

#define NUT_THREAD_MAINSTACK   1024
#define NUT_THREAD_IDLESTACK   1024
#define MAX_IRQ_SLOTS   3
#define PSEUDO_RAM_SIZE   999999
 Nut/OS Initialization.

Functions

void NutAppMain (void *arg)
int NutRegisterIrqHandler (uint8_t irq, void(*handler)(void *), void *arg)
 Register an interrupt handler.
void NutUnixIrqEventPostAsync (uint8_t irq, HANDLE *queue)
 Register NutEventPostAsync for next NutThreadYield.
void NutUnixThreadYieldHook (void)
 Handle interrupt triggered NutEventPostAsync Check list of events to post and call NutEventPostAsync on them.
void NutUnixRaiseInterrupt (int)
void * NutInterruptEmulation (void *unused_arg)
 Send emulated interrupt signal to Nut threads.
void NutIdle (void *arg)
 Emulated idle thread.
void NutThreadInit (void)
NUTFILENUT_freopen (CONST char *name, CONST char *mode, NUTFILE *stream)
int main (int argc, char *argv[])

Variables

int interrupts_pending [MAX_IRQ_SLOTS]
sigset_t irq_signal
uint16_t int_disabled
int irq_current = 0
int irq_slot = 0
int irq_sent = 0
pthread_mutex_t pending_mutex
pthread_cond_t pending_cv
pthread_mutex_t irq_mutex
pthread_cond_t irq_cv
IRQ_HANDLER irq_handlers [IRQ_MAX]
HANDLEirq_eventqueues [IRQ_MAX]
uint32_t nut_ticks
 Emulate a Nut hardware interrupt on Unix.
uint8_t PSEUDO_RAM [PSEUDO_RAM_SIZE]
NUTFILE__iob []


Define Documentation

#define NUT_THREAD_MAINSTACK   1024

Definition at line 65 of file nutinit.c.

#define NUT_THREAD_IDLESTACK   1024

Definition at line 69 of file nutinit.c.

#define MAX_IRQ_SLOTS   3

Definition at line 73 of file nutinit.c.

Referenced by NutUnixRaiseInterrupt().


Function Documentation

void NutAppMain ( void *  arg  ) 

int NutRegisterIrqHandler ( uint8_t  irq,
void(*)(void *)  handler,
void *  arg 
)

Register an interrupt handler.

This function is typically called by device drivers.

Parameters:
irq Interrupt number to be associated with this handler.
handler This routine will be called by Nut/OS, when the specified interrupt occurs.
arg Argument to be passed to the interrupt handler.
Returns:
0 on success, -1 otherwise.

Definition at line 119 of file nutinit.c.

References IRQ_HANDLER::ir_arg, IRQ_HANDLER::ir_handler, IRQ_MAX, NutEnterCritical, and NutExitCritical.

void NutUnixIrqEventPostAsync ( uint8_t  irq,
HANDLE queue 
)

Register NutEventPostAsync for next NutThreadYield.

Store responsible IRQ and queue to signal in list

Parameters:
irq responsible IRQ
queue to signal
this is added to allow an non-nut thread to post events without introducing a race-condition

Definition at line 147 of file nutinit.c.

References IRQ_MAX.

void NutUnixThreadYieldHook ( void   ) 

Handle interrupt triggered NutEventPostAsync Check list of events to post and call NutEventPostAsync on them.

this is added to allow an non-nut thread to post events without introducing a race-condition

Definition at line 162 of file nutinit.c.

References IRQ_MAX, and NutEventPostFromIrq.

Referenced by NutThreadYield().

void NutUnixRaiseInterrupt ( int  irq  ) 

void* NutInterruptEmulation ( void *  unused_arg  ) 

Send emulated interrupt signal to Nut threads.

Hardware devices, such as timer, usart, etc., raise interrupts to get serviced by NutOS. This function does the same for devices on Unix emulation.

Parameters:
irq IRQ raised
The Nut thread is interrupted using the SIGUSR1 signal. The corresponding signal handler dispatches to the respective interrupt handler. All IRQs are multiplexed through the same signal handler.

Signalling the interrupt is done in a separate thread so that the "calling/interrupting" thread can go back to emulate the hardware. Otherwise, in case of disabled interrupts, it would be hanging and waiting for interrupts to be re-enabled.

This thread here does nothing but signal interrupts and can safely hang it they are disabled (by NutEnterCritical, for example).

Definition at line 295 of file nutinit.c.


Variable Documentation

int interrupts_pending[MAX_IRQ_SLOTS]

Definition at line 76 of file nutinit.c.

sigset_t irq_signal

Definition at line 79 of file nutinit.c.

uint16_t int_disabled

Definition at line 82 of file nutinit.c.

int irq_current = 0

Definition at line 85 of file nutinit.c.

int irq_slot = 0

Definition at line 86 of file nutinit.c.

int irq_sent = 0

Definition at line 87 of file nutinit.c.

pthread_mutex_t pending_mutex

Definition at line 93 of file nutinit.c.

pthread_cond_t pending_cv

Definition at line 94 of file nutinit.c.

pthread_mutex_t irq_mutex

Definition at line 97 of file nutinit.c.

pthread_cond_t irq_cv

Definition at line 98 of file nutinit.c.

IRQ_HANDLER irq_handlers[IRQ_MAX]

Definition at line 101 of file nutinit.c.

HANDLE* irq_eventqueues[IRQ_MAX]

Definition at line 104 of file nutinit.c.


© 2000-2007 by egnite Software GmbH - visit http://www.ethernut.de/