Netduino home hardware projects downloads community

Jump to content


The Netduino forums have been replaced by new forums at community.wildernesslabs.co. This site has been preserved for archival purposes only and the ability to make new accounts or posts has been turned off.
Photo

Creating an FIQ-accelerated pin


  • Please log in to reply
3 replies to this topic

#1 monewwq1

monewwq1

    Advanced Member

  • Members
  • PipPipPip
  • 104 posts

Posted 28 September 2011 - 02:15 PM

I've been advised that I can create a "super-interrupt" pin on the Netduino by hacking the firmware. Please see quote from Chris Walker below:

...make that pin an FIQ-accelerated pin...and then use an FIQ handler in your code to count the number of pulses. Then you can easily create a "startcount" and "StopAndGetCount" managed code method to capture the values. FIQs will activate in less than one microsecond, will supercede the .NET MF runtime and...as long as they're quick...will not interfere with your code. We're using them for software PWM in an future update of the firmware, for instance.


Chris et. al,

How do I start with getting this set up? I downloaded the .Net MF Porting Kit and the Netduino Plus firmware, and I've copied the Netduino firmware into the Porting Kit directory. Now I need to know how to modify the firmware to get this operational.

#2 Stefan W.

Stefan W.

    Advanced Member

  • Members
  • PipPipPip
  • 153 posts

Posted 28 September 2011 - 03:46 PM

If it's a Plus you are using and really need the plus features, be prepared to buy a compiler that produces small enough code to fit everything on the chip (RVDS, i heard it's about 6000$).
There are some good posts on compiling the firmware on this forums already, e.g. this post - I'd recommend compiling the vanilla firmware first and deploying it to make sure your toolchain works before changing something in the firmware.
The datasheet for the SAM7X512 has lots of information on the internals of the chip.
I believe that no discovery of fact, however trivial, can be wholly useless to the race, and that no trumpeting of falsehood, however virtuous in intent, can be anything but vicious.
-- H.L. Mencken, "What I Believe"

#3 Chris Walker

Chris Walker

    Secret Labs Staff

  • Moderators
  • 7767 posts
  • LocationNew York, NY

Posted 28 September 2011 - 04:05 PM

Hi Nick,

This is a VERY advanced topic. I'd be happy to provide some starter pointers, but you're probably going to want a nice compiler and a few weeks to digest how the ARM processors work in assembly and C...

For instance, in "C:\MicroFrameworkPK\Application\common\assemblycode\ARM\RVD_S\BooterVectorTable.s" you might want to re-enable FIQs by removing the IF...END IF in the following code:
FIQ_Handler
;    IF :DEF: FIQ_SAMPLING_PROFILER    
    ldr     pc, FIQ_SubHandler_Trampoline    
    
FIQ_SubHandler_Trampoline    
    DCD     FIQ_SubHandler
;    ENDIF
And in "C:\MicroFrameworkPK_v4_2\DeviceCode\cores\arm\AssemblyCode\arm\RVD_S\VectorsHandlers.s" you might do the same... Setting the PSR_ values to 0x9# instead of 0xD# will enable the FIQ interrupt
PSR_MODE_USER       EQU     0x90
; vs.
; PSR_MODE_USER       EQU     0xD0
And in "C:\MicroFrameworkPK_v4_2\DeviceCode\cores\arm\AssemblyCode\arm\RVD_S\VectorsTrampolines.s" you'll enable the FIQ handler (via vector trampolines).

You'd also need to actually enable the FIQs at the processor level. One way to do this is to hack the SmartPtr_arm.cpp file and change the BIC operation in SmartPtr_IRQ::Restore() to:
BIC     Cp, Cp, #0xC0
; instead of
; BIC     Cp, Cp, #0x80
Although there are a lot of ways to handle the situation... There are also a few other places that you'd need to enable the FIQ code.

After all that, you'll write your C/C++ code to handle the actual interrupts, set the interrupt (timer or hardware) which you want to have FIQ priority, etc.

Needless to say, a fairly advanced topic :) If you really, really want to go this path...I'd recommend picking up a few ARM books to dig into it...

BTW, in a future firmware update we plan on enabling software PWM for the Netduino. If we use FIQ for this, you'll be able to simply modify our FIQ code hooks and repurpose them for your own application.

Chris

#4 CW2

CW2

    Advanced Member

  • Members
  • PipPipPip
  • 1592 posts
  • LocationCzech Republic

Posted 28 September 2011 - 07:48 PM

I've been using a PIC32 to count a 1Hz to 1MHz frequency from a TAOS light-to-frequency sensor
...
I've been advised that I can create a "super-interrupt" pin on the Netduino by hacking the firmware.
...
How do I start with getting this set up?

IMHO you'd just need to port the frequency counter functionality from PIC32 to Netduino (SAM7X), forget about FIQ for now (*). I assume you've used hardware timer/counter module, which is also present in Netuino microcontroller, so the basic steps could be

  • Setup the toolchain. As Stefan W. has already pointed out, you'd need either ARM RVDS or Keil MDK (both ~$6000, ARM has time-limited trial) to compile Netduino Plus firmware that fits into the flash. You can use GCC during development, but most features has to be removed, you'd probably need to use Netduino firmware.
  • Get familiar with hardware differences - i.e. size of timer registers, operational modes, clock sources etc. I don't know which PIC32 you use (or why 32 ;-), device datasheets should contain all the necessary information.
  • Examine .NET Micro Framework code (e.g. search for register names or constants), as I've mentioned in that light measurement thread, Timer 0 is used for slow clock, you'd probably need to use Timer 2 (if you choose to utilize its capture mode) or Timer 1 (if you want just generic timer), so you basically need to implement the ISR and initialize the timer driver.
  • After you get the code working, i.e. your ISR is called properly, you can implement the managed wrapper - at the time you get there, you will not need any further advice...
(*) FIQ is just an interrupt (albeit a special one), you may not even need it - there is already mechanism to handle interrupt priorities and any 'normal' interrupt can be redirected to FIQ later on. It will be much easier to say fine tune working frequency counter than start development by troubleshooting board after messing up the vector table.

Note: There is no firmware debugging possible on regular Netduino boards, which makes development/troubleshooting challenging and time consuming (to say the least). If you have JTAG debugger, you may need to break out the necessary microcontroller pins (if you have a steady hand), or use/design a board that has them already accessible.




0 user(s) are reading this topic

0 members, 0 guests, 0 anonymous users

home    hardware    projects    downloads    community    where to buy    contact Copyright © 2016 Wilderness Labs Inc.  |  Legal   |   CC BY-SA
This webpage is licensed under a Creative Commons Attribution-ShareAlike License.