[En-Nut-Discussion] External interrupts on Ethernut 3

Henrik Maier hmnews at proconx.com
Mon Mar 30 15:42:28 CEST 2009


Hi Petri,

In the mean time I have sent my MCP2515 driver code to Ole after I saw your
posts. My code is BSD licensed and can be used as a basis for a Nut/OS
MCP2515 driver. I always wanted to implement a Nut/OS driver myself but
never had time and the requirement to do this as I am using the driver on an
ATmega168 which has not enough memory resources for Nut/OS.

If you would like the code as well, send me a private message by using the
contact page at http://www.proconx.com.

Regards

Henrik
 
> -----Original Message-----
> From: en-nut-discussion-bounces at egnite.de [mailto:en-nut-discussion-
> bounces at egnite.de] On Behalf Of Petri Hyötylä
> Sent: Monday, 30 March 2009 9:54 PM
> To: Ethernut User Chat (English)
> Subject: Re: [En-Nut-Discussion] External interrupts on Ethernut 3
> 
> Hello again
> 
> On Fri, Mar 27, 2009 at 6:56 PM, Ole Reinhardt <ole.reinhardt at embedded-
> it.de
> > wrote:
> 
> > If you want you may send me some code example and I'd take a look on
> it.
> > Btw: I'd be happy if you would contribute your code, as I'll need the
> > MCP2515 in an upcomming project as well...
> >
> 
> Here's the interrupt related code in its current form. The interrupt is
> re-enabled in the threads handling the actual reception.
> As far as the contributing goes, I'm not my own boss but I'm for the
> idea of
> publishing the code. Getting acceptance from the appropriate people may
> take
> a while but there are also slight hurdles in using this code in other
> projects. Currently the code also depends on some helper functions and
> macros that we are using but that should not take long to replace the
> prints
> with standard ones and  the final version will probably use very few
> prints
> anyway because the speed is very important in our case. Furthermore,
> the
> driver currently does not adhere to the device model of the Nut/OS but
> it
> does use the CANFRAME as defined in the can_dev.h.
> 
> static void CAN_Interrupt(void *arg)
> {
>     #ifdef ETHERNUT2
>     sbi(PORTF,0);
>     #endif
> 
>     NutIrqDisable(&CAN_SIGNAL);
>     NutEventPostFromIrq(&can_rx_queue);
> 
>     #ifdef ETHERNUT2
>     cbi(PORTF,0);
>     #endif
> }
> 
> void CAN_Init(unsigned int filter_mode, unsigned long filter_id,
> unsigned
> long filter_mask)
> {
>     ...
> 
>     //Enabled interrupts: ERRIF, RX1IF, RX0IF
>     CAN_ByteWrite(CANINTE,0x23);
> 
>     //Register the interrupt to Nut/OS
>     NutRegisterIrqHandler(&CAN_SIGNAL, CAN_Interrupt, NULL);
> 
>     // Set Interrupt mode to low level sensitive
>     NutIrqSetMode(&CAN_SIGNAL, NUT_IRQMODE_LOWLEVEL);
>     //NutIrqSetMode(&CAN_SIGNAL, NUT_IRQMODE_FALLINGEDGE);
> 
>     // Disable just in case
>     NutIrqDisable(&CAN_SIGNAL);
> 
>     //Set NORMAL mode
>     CAN_RequestMode(REQOP_NORMAL);
> 
>     //Verify device entered Normal mode
>     if (OPMODE_NORMAL != CAN_GetMode())
>         CAN_RequestMode(REQOP_NORMAL);
> 
>     // If the second attempt fails, notify the user
>     if (OPMODE_NORMAL != CAN_GetMode()){
>         SLFATAL("MCP2515: Failed to set operation mode");
>         SLFATAL("MCP2515: CAN Controller unusable");
>     }else{
>         SLINFO("CAN controller mode normal");
>     }
> 
>     /* Start the threads */
>     NutThreadCreate ("CAN_Rx",CAN_Rx,NULL,1024);
>     NutThreadCreate ("CAN_Process",CAN_Process,NULL,1024);
> 
>     NutIrqEnable(&CAN_SIGNAL);
> }
> _______________________________________________
> http://lists.egnite.de/mailman/listinfo/en-nut-discussion




More information about the En-Nut-Discussion mailing list