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