Created
December 22, 2012 20:49
-
-
Save RickKimball/4361000 to your computer and use it in GitHub Desktop.
Energia - Timer based blink
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
$ diff linux/work/hardware/lm4f/cores/lm4f/startup_gcc.c ../hardware/lm4f/cores/lm4f/startup_gcc.c | |
71d70 | |
< __attribute__((weak)) extern void Timer0IntHandler(void) {} | |
123c122 | |
< Timer0IntHandler, // Timer 0 subtimer A | |
--- | |
> IntDefaultHandler, // Timer 0 subtimer A | |
$ |
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
/* | |
* timer_blink - C API | |
*/ | |
#include "Energia.h" | |
#include "inc/hw_ints.h" | |
#include "driverlib/interrupt.h" | |
#include "driverlib/sysctl.h" | |
#include "driverlib/timer.h" | |
#include "timer_blink.h" | |
void initTimer(unsigned Hz) | |
{ | |
//GPIOPinTypeGPIOOutput(GPIO_PORTF_BASE, GPIO_PIN_1|GPIO_PIN_2|GPIO_PIN_3); | |
SysCtlPeripheralEnable(SYSCTL_PERIPH_TIMER0); | |
TimerConfigure(TIMER0_BASE, TIMER_CFG_32_BIT_PER); | |
unsigned long ulPeriod = (SysCtlClockGet() / Hz) / 2; | |
TimerLoadSet(TIMER0_BASE, TIMER_A, ulPeriod -1); | |
IntEnable(INT_TIMER0A); | |
TimerIntEnable(TIMER0_BASE, TIMER_TIMA_TIMEOUT); | |
TimerEnable(TIMER0_BASE, TIMER_A); | |
} | |
void Timer0IntHandler() | |
{ | |
// Clear the timer interrupt | |
TimerIntClear(TIMER0_BASE, TIMER_TIMA_TIMEOUT); | |
// Read the current state of the GPIO pin and | |
// write back the opposite state | |
if(GPIOPinRead(GPIO_PORTF_BASE, GPIO_PIN_2)) { | |
GPIOPinWrite(GPIO_PORTF_BASE, GPIO_PIN_1|GPIO_PIN_2|GPIO_PIN_3, 0); | |
} | |
else { | |
GPIOPinWrite(GPIO_PORTF_BASE, GPIO_PIN_2, 4); | |
} | |
} |
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
#ifdef __cplusplus | |
extern "C" { | |
#endif | |
void initTimer(unsigned); | |
void Timer0IntHandler(void); | |
#ifdef __cplusplus | |
} | |
#endif |
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
/** | |
* LM4F120 - timer based blink | |
*/ | |
#include "timer_blink.h" | |
static const unsigned Hz=3; | |
void setup() | |
{ | |
pinMode(BLUE_LED,OUTPUT); | |
initTimer(Hz); | |
} | |
void loop() | |
{ | |
} |
Sign up for free
to join this conversation on GitHub.
Already have an account?
Sign in to comment