collab/PineapplePad
git clone https://git.julia.blue/collab/PineapplePad
7d01d63
master
1// Timer1.c 2// Runs on LM4F120/TM4C123 3// Use TIMER1 in 32-bit periodic mode to request interrupts at a periodic rate 4// Daniel Valvano 5// Last Modified: 3/6/2015 6// You can use this timer only if you learn how it works 7 8/* This example accompanies the book 9"Embedded Systems: Real Time Interfacing to Arm Cortex M Microcontrollers", 10ISBN: 978-1463590154, Jonathan Valvano, copyright (c) 2013 11Program 7.5, example 7.6 12 13Copyright 2013 by Jonathan W. Valvano, valvano@mail.utexas.edu 14You may use, edit, run or distribute this file 15as long as the above copyright notice remains 16THIS SOFTWARE IS PROVIDED "AS IS". NO WARRANTIES, WHETHER EXPRESS, IMPLIED 17OR STATUTORY, INCLUDING, BUT NOT LIMITED TO, IMPLIED WARRANTIES OF 18MERCHANTABILITY AND FITNESS FOR A PARTICULAR PURPOSE APPLY TO THIS SOFTWARE. 19VALVANO SHALL NOT, IN ANY CIRCUMSTANCES, BE LIABLE FOR SPECIAL, INCIDENTAL, 20OR CONSEQUENTIAL DAMAGES, FOR ANY REASON WHATSOEVER. 21For more information about my classes, my research, and my books, see 22http://users.ece.utexas.edu/~valvano/ 23*/ 24#include <stdint.h> 25#include "../inc/Timer1.h" 26#include "../inc/tm4c123gh6pm.h" 27 28void (* PeriodicTask1 )(void );// user function 29extern "C" void TIMER1A_Handler (void ); 30 31// ***************** TIMER1_Init **************** 32// Activate TIMER1 interrupts to run user task periodically 33// Inputs: task is a pointer to a user function 34// period in units (1/clockfreq) 35// Outputs: none 36void Timer1_Init (void (* task )(void ),uint32_t period ){ 37SYSCTL_RCGCTIMER_R |=0x02 ;// 0) activate TIMER1 38PeriodicTask1 = task ;// user function 39TIMER1_CTL_R = 0x00000000 ;// 1) disable TIMER1A during setup 40TIMER1_CFG_R = 0x00000000 ;// 2) configure for 32-bit mode 41TIMER1_TAMR_R = 0x00000002 ;// 3) configure for periodic mode, default down-count settings 42TIMER1_TAILR_R = period - 1 ;// 4) reload value 43TIMER1_TAPR_R = 0 ;// 5) bus clock resolution 44TIMER1_ICR_R = 0x00000001 ;// 6) clear TIMER1A timeout flag 45TIMER1_IMR_R = 0x00000001 ;// 7) arm timeout interrupt 46NVIC_PRI5_R = (NVIC_PRI5_R & NVIC_PRI5_INT21_M )|NVIC_PRI5_INT21_M ;// 8) priority 7 47// interrupts enabled in the main program after all devices initialized 48// vector number 37, interrupt number 21 49NVIC_EN0_R = 1 <<21 ;// 9) enable IRQ 21 in NVIC 50TIMER1_CTL_R = 0x00000001 ;// 10) enable TIMER1A 51} 52extern "C" void TIMER1A_Handler (void ); 53void TIMER1A_Handler (void ){ 54TIMER1_ICR_R = TIMER_ICR_TATOCINT ;// acknowledge TIMER1A timeout 55 (* PeriodicTask1 )();// execute user task 56}