From mboxrd@z Thu Jan 1 00:00:00 1970 From: Wolfram Kattanek To: Carlos Eduardo dos Reis Rodrigues Sobrinho Cc: eCos Discuss Subject: Re: [ECOS] Build eCos and Handle/Interrupts problems Date: Thu, 01 Mar 2001 02:38:00 -0000 Message-id: <983443086.3a9e268e1013c@imp.imms.de> References: <00d501c0a158$d9137960$35bd12d4@netc.pt> <3A9CB01C.E0075686@redhat.com> <003a01c0a234$f53898a0$24bd12d4@netc.pt> X-SW-Source: 2001-03/msg00006.html Carlos Eduardo dos Reis Rodrigues Sobrinho : > > > I also have some questions about interrupts and handles like how can I > make > > > a program with two threads, one that printf the cosine of a number and > the > > > other one (don't know if i need another one or if one thread is enough) > that > > > is only active when the push button of the AEB is pressed for > example.The > > > one near the reset button. > > > > You mean the interrupt button? That only delivers an interrupt. Even if > you > > configure it to be level triggered (rather than edge triggered) it would > > mean getting far too many interrupts while the button is depressed. > > > > If my understanding is wrong, then find out what interrupt the button is > > associated with, and write an application using the kernel C API that > > attaches an ISR and DSR to that interrupt. In the DSR, suspend the thread > > whatever way you like depending on what its doing (and whether it needs to > > finish it whenever the button is released). > > Sorry to being so anoying but could you or anyone give me and example of > using and interrupt to call a thread > Thanks Here's code snippet which probably will help you: #include #include #include volatile int i=0; /* this is the ISR for ext 0 interrupts */ cyg_uint32 int_0_isr(cyg_vector_t vector, cyg_addrword_t data) { /* ISRs must acknowledge the interrupt, or they might be invoked again */ cyg_interrupt_acknowledge(vector); return CYG_ISR_CALL_DSR; } /* this is the DSR for ext 0 interrupts */ void int_0_dsr(cyg_vector_t vector, cyg_ucount32 count, cyg_addrword_t data) { /* put your code here; for details of ISRs and DSRs see eCos documentation */ /* the following serves only as an example: */ i += count; } int main( int argc, char *argv[] ) { cyg_handle_t int_0_ISR_H; cyg_interrupt intr; int oldi = 0; cyg_interrupt_create(CYGNUM_HAL_INTERRUPT_EXT0, 0, 0, &int_0_isr, &int_0_dsr, &int_0_ISR_H, &intr); cyg_interrupt_attach(int_0_ISR_H); for (;;) { if (i != oldi) { printf("Now received %d interrupts\n", i); oldi = i; } } return 0; } Wolfram -- Wolfram 'L.A.' Kattanek Institut fuer Mikroelektronik- und Email: LA@imms.de Mechatronik-Systeme (IMMS) gGmbH Tel: +49 3677 / 6783-55 Langewiesener Str. 22 Fax: +49 3677 / 6783-38 98693 Ilmenau / Germany ------------------------------------------------- This mail sent through IMP: imp.imms.de