From mboxrd@z Thu Jan 1 00:00:00 1970 Return-Path: Received: (qmail 5435 invoked by alias); 19 Feb 2013 08:34:04 -0000 Received: (qmail 5337 invoked by uid 22791); 19 Feb 2013 08:34:02 -0000 X-SWARE-Spam-Status: No, hits=2.9 required=5.0 tests=AWL,BAYES_00,BOTNET,KHOP_SPAMHAUS_DROP,KHOP_THREADED,RP_MATCHES_RCVD,SPF_HELO_PASS X-Spam-Check-By: sourceware.org Received: from ip2.televic.com (HELO ip2.televic.com) (81.82.194.222) by sourceware.org (qpsmtpd/0.43rc1) with ESMTP; Tue, 19 Feb 2013 08:33:52 +0000 Received: from SRV-VS06.TELEVIC.COM ([10.0.0.46]) by SRV-VS06.TELEVIC.COM ([10.0.0.46]) with mapi; Tue, 19 Feb 2013 09:33:50 +0100 From: =?iso-8859-1?Q?Lambrecht_J=FCrgen?= To: Michael Jones CC: "ecos-devel@ecos.sourceware.org" , ecos Date: Tue, 19 Feb 2013 08:34:00 -0000 Subject: Re: Problem setting up an ISR for a K60 PORT Message-ID: <512338ED.6000705@televic.com> References: In-Reply-To: user-agent: Mozilla/5.0 (X11; Linux i686; rv:11.0) Gecko/20120329 Thunderbird/11.0.1 Content-Type: text/plain; charset="iso-8859-1" Content-Transfer-Encoding: quoted-printable MIME-Version: 1.0 X-IsSubscribed: yes Mailing-List: contact ecos-devel-help@ecos.sourceware.org; run by ezmlm Precedence: bulk List-Id: List-Subscribe: List-Post: List-Help: , Sender: ecos-devel-owner@ecos.sourceware.org X-SW-Source: 2013-02/txt/msg00002.txt.bz2 Hi Michael, first of all, I think your message should be sent to ecos-discuss=20 instead (so I put it in cc). I put some comments below - it is a long time ago I coded ISR/DSR, so I=20 just looked to some working code of ours to compare. On 02/19/2013 01:12 AM, Michael Jones wrote: > I am struggling to setup an ISR/DSR for a PORT on the K60. My goal is to = get an ISR/DSR when Pin 19 of PORTA transitions from high to low. This is p= in PTA19 of the device. > > My non-working code and complete code below. > > What the code tries to do is setup PORTA PIN19 as input. Then take the PC= R register and set the interrupt to work off a falling edge. > > Then create the ISR/DSR. > > When I toggle the pin, nothing happens. > > FYI the hardware works with MQX, so I know the hardware is ok. I use it t= he same way under MQX where I get an ISR from a negative edge. And I have p= ut a scope on it to make sure there is an edge. So I am quite sure the prob= lem is the code. > > This code was generated by trying to understand the Kinetis code, but thi= ngs were not clear to me. Some macros use __pin to mean different things. S= o this is my best guess. > > Does anyone know how to do this? > > PORT SETUP CODE > =3D=3D=3D=3D=3D=3D=3D=3D=3D=3D=3D=3D=3D=3D=3D=3D > > cyghwr_hal_kinetis_port_t *port_p; > > CYGHWR_HAL_KINETIS_GPIO_PIN_DDR_IN(ALERT_PORT, ALERT_PIN); > > // Get address for PORTA > port_p =3D Ports[0]; > > // 0xA means interrupt on falling edge. > // Read modify write PCR > port_p->pcr[ALERT_PIN] =3D > (port_p->pcr[ALERT_PIN]& 0xFFF0FFFF) | > (0xA<< 16); > > // Create an ISR/DSR for PORTA. > // Assuming the priority is what the DSR will run at. > // No data passed. > cyg_interrupt_create( > CYGNUM_HAL_INTERRUPT_PORTA, // Vector > 3, // Priority > (cyg_addrword_t)0, // Data > alert_isr, // ISR > alert_dsr, // DSR > &alert_handle, // Handle > &alert_interrupt); // INTR > cyg_thread_suspend(cyg_thread_self()); After our 'interrupt_create', we also have those calls (we use IRQ2=20 instead of your PORTA): cyg_interrupt_attach(t_intrhandle); cyg_interrupt_configure(CYGNUM_HAL_INTERRUPT_IRQ2, TLV_FALSE, TLV_FALSE); cyg_interrupt_acknowledge(CYGNUM_HAL_INTERRUPT_IRQ2); cyg_interrupt_unmask(CYGNUM_HAL_INTERRUPT_IRQ2); Why do you call 'cyg_thread_suspend...' ? I do not see code that creates=20 a thread. And when I create a thread, I do cyg_thread_create(...);=20 cyg_thread_resume(..);. Why do you need a thread when your code is run by interrupts? > } > > ALL CODE > =3D=3D=3D=3D=3D=3D=3D=3D=3D > > #ifndef ALERT_H_ > #define ALERT_H_ > > #include > #include > #include > #include > > #define ALERT_PORT A > #define ALERT_PIN 19 > > extern void start_alert(cyg_addrword_t data); > > #endif > > #include "alert.h" > > cyg_handle_t alert_handle; > cyg_interrupt alert_interrupt; > > cyghwr_hal_kinetis_port_t * const Ports[] =3D { > CYGHWR_HAL_KINETIS_PORTA_P, CYGHWR_HAL_KINETIS_PORTB_P, > CYGHWR_HAL_KINETIS_PORTC_P, CYGHWR_HAL_KINETIS_PORTD_P, > CYGHWR_HAL_KINETIS_PORTE_P > }; > > cyg_uint32 alert_isr( cyg_vector_t vector, > cyg_addrword_t data > ) > { > return CYG_ISR_HANDLED | CYG_ISR_CALL_DSR; No need for: cyg_interrupt_mask(CYGNUM_HAL_INTERRUPT_IRQ2); cyg_interrupt_acknowledge(CYGNUM_HAL_INTERRUPT_IRQ2); ? > } > > void alert_dsr( cyg_vector_t vector, > cyg_ucount32 count, > cyg_addrword_t data > ) > { I guess you still need to add code here. No need for this at the end: cyg_interrupt_unmask(CYGNUM_HAL_INTERRUPT_IRQ2); ? I hope this helps. Kind regards, J=FCrgen > } > > void pmbus_alert_callback(void) > { > > > } > > void start_alert(cyg_addrword_t data) > { > cyghwr_hal_kinetis_port_t *port_p; > > CYGHWR_HAL_KINETIS_GPIO_PIN_DDR_IN(ALERT_PORT, ALERT_PIN); > > // Get address for PORTA > port_p =3D Ports[0]; > > // 0xA means interrupt on falling edge. > // Read modify write PCR > port_p->pcr[ALERT_PIN] =3D > (port_p->pcr[ALERT_PIN]& 0xFFF0FFFF) | > (0xA<< 16); > > // Create an ISR/DSR for PORTA. > // Assuming the priority is what the DSR will run at. > // No data passed. > cyg_interrupt_create( > CYGNUM_HAL_INTERRUPT_PORTA, // Vector > 3, // Priority > (cyg_addrword_t)0, // Data > alert_isr, // ISR > alert_dsr, // DSR > &alert_handle, // Handle > &alert_interrupt); // INTR > cyg_thread_suspend(cyg_thread_self()); > } > > --=20 J=FCrgen Lambrecht R&D Associate Tel: +32 (0)51 303045 Fax: +32 (0)51 310670 http://www.televic-rail.com Televic Rail NV - Leo Bekaertlaan 1 - 8870 Izegem - Belgium Company number 0825.539.581 - RPR Kortrijk