SOMRT1061 PinIrq Application
Overview
This application demonstrates how to use pin interrupt functionality on the SOMRT1061 platform. It implements a real-time edge detection system that monitors pin state changes and provides visual feedback through an LED indicator.
Location
examples/PlatformSpecific/SOMRT1061/PinIrq
Supported Platforms
Application Description
The PinIrq application showcases interrupt-driven GPIO monitoring using NetBurner's RTOS capabilities. The program:
- Monitors pin 30 for edge transitions (both rising and falling edges)
- Uses a semaphore-based notification system to handle interrupts safely
- Provides real-time feedback through pin 78 (LED output)
- Tracks and reports the total number of detected transitions
- Demonstrates proper interrupt handling in an RTOS environment
Key Features
Hardware Configuration
- Input Pin: Pin 30 (configured as input with interrupt capability)
- Output Pin: Pin 78 (LED indicator)
- Edge Detection: Both rising and falling edges
Software Architecture
- Interrupt Service Routine: Minimal ISR that posts to a semaphore
- Task-based Processing: Dedicated task handles the actual pin change logic
- Thread-safe Communication: Uses OS semaphores for inter-task communication
- Real-time Monitoring: Continuous status reporting every second
How It Works
- Initialization: The application configures pin 30 as input and pin 78 as output
- Interrupt Setup: Registers an interrupt handler for pin 30 that triggers on both edges
- Event Handling: When a pin transition occurs:
- The interrupt handler (
NotifyFunc
) posts to a semaphore
- The
PinChangeTask
wakes up and processes the event
- The transition counter is incremented
- The LED state is updated to follow the input pin state
- Status Reporting: Main loop continuously prints the current transition count and pin state
Code Structure
Main Components
- NotifyFunc(): Interrupt service routine that signals pin changes
- PinChangeTask(): Task that handles pin change processing
- UserMain(): Main application loop with status reporting
- Semaphore (NotifySem): Synchronization primitive for interrupt handling
Global Variables
- Transitions: Counter tracking total number of edge detections
- irq_pin_num: Pin number for interrupt monitoring (pin 30)
Usage
- Connect a switch or signal source to pin 30
- Connect an LED to pin 78 to observe the output
- Compile and upload the application to the SOMRT1061
- Monitor the serial output to see transition counts and pin states
- Toggle the input on pin 30 to observe the LED response and counter updates
Expected Output
The application will continuously output status information in the format:
Running SOMRT1061 PinIrq
{We have detected X edges pin is currently: Y
Where X is the total transition count and Y is the current pin state (0 or 1).
Technical Notes
- The interrupt handler is kept minimal to avoid issues in interrupt context
- All significant processing is performed in task context for safety
- The LED output inverts the input state, providing clear visual feedback
- System diagnostics are enabled for debugging purposes
Dependencies
- NetBurner RTOS
- Pin interrupt functionality
- Standard NetBurner GPIO libraries