From c3e4c9a25c2910d2d66d52215b3406b13d5b23d5 Mon Sep 17 00:00:00 2001 From: Yuval Adam Date: Sun, 29 Jun 2014 12:34:32 +0300 Subject: Add more board models --- boards/dk-tm4c129x/timers/timers.c | 216 +++++++++++++++++++++++++++++++++++++ 1 file changed, 216 insertions(+) create mode 100644 boards/dk-tm4c129x/timers/timers.c (limited to 'boards/dk-tm4c129x/timers/timers.c') diff --git a/boards/dk-tm4c129x/timers/timers.c b/boards/dk-tm4c129x/timers/timers.c new file mode 100644 index 0000000..72ec92f --- /dev/null +++ b/boards/dk-tm4c129x/timers/timers.c @@ -0,0 +1,216 @@ +//***************************************************************************** +// +// timers.c - Timers example. +// +// Copyright (c) 2013-2014 Texas Instruments Incorporated. All rights reserved. +// Software License Agreement +// +// Texas Instruments (TI) is supplying this software for use solely and +// exclusively on TI's microcontroller products. The software is owned by +// TI and/or its suppliers, and is protected under applicable copyright +// laws. You may not combine this software with "viral" open-source +// software in order to form a larger program. +// +// THIS SOFTWARE IS PROVIDED "AS IS" AND WITH ALL FAULTS. +// NO WARRANTIES, WHETHER EXPRESS, IMPLIED OR STATUTORY, INCLUDING, BUT +// NOT LIMITED TO, IMPLIED WARRANTIES OF MERCHANTABILITY AND FITNESS FOR +// A PARTICULAR PURPOSE APPLY TO THIS SOFTWARE. TI SHALL NOT, UNDER ANY +// CIRCUMSTANCES, BE LIABLE FOR SPECIAL, INCIDENTAL, OR CONSEQUENTIAL +// DAMAGES, FOR ANY REASON WHATSOEVER. +// +// This is part of revision 2.1.0.12573 of the DK-TM4C129X Firmware Package. +// +//***************************************************************************** + +#include +#include +#include "inc/hw_ints.h" +#include "inc/hw_memmap.h" +#include "inc/hw_types.h" +#include "driverlib/interrupt.h" +#include "driverlib/rom.h" +#include "driverlib/rom_map.h" +#include "driverlib/sysctl.h" +#include "driverlib/timer.h" +#include "grlib/grlib.h" +#include "drivers/frame.h" +#include "drivers/kentec320x240x16_ssd2119.h" +#include "drivers/pinout.h" + +//***************************************************************************** +// +//! \addtogroup example_list +//!

Timer (timers)

+//! +//! This example application demonstrates the use of the timers to generate +//! periodic interrupts. One timer is set up to interrupt once per second and +//! the other to interrupt twice per second; each interrupt handler will toggle +//! its own indicator on the display. +// +//***************************************************************************** + +//***************************************************************************** +// +// Flags that contain the current value of the interrupt indicator as displayed +// on the display. +// +//***************************************************************************** +uint32_t g_ui32Flags; + +//***************************************************************************** +// +// Graphics context used to show text on the display. +// +//***************************************************************************** +tContext g_sContext; + +//***************************************************************************** +// +// The error routine that is called if the driver library encounters an error. +// +//***************************************************************************** +#ifdef DEBUG +void +__error__(char *pcFilename, uint32_t ui32Line) +{ +} +#endif + +//***************************************************************************** +// +// The interrupt handler for the first timer interrupt. +// +//***************************************************************************** +void +Timer0IntHandler(void) +{ + // + // Clear the timer interrupt. + // + ROM_TimerIntClear(TIMER0_BASE, TIMER_TIMA_TIMEOUT); + + // + // Toggle the flag for the first timer. + // + HWREGBITW(&g_ui32Flags, 0) ^= 1; + + // + // Update the interrupt status on the display. + // + ROM_IntMasterDisable(); + GrStringDraw(&g_sContext, (HWREGBITW(&g_ui32Flags, 0) ? "1" : "0"), -1, + 195, 108, 1); + ROM_IntMasterEnable(); +} + +//***************************************************************************** +// +// The interrupt handler for the second timer interrupt. +// +//***************************************************************************** +void +Timer1IntHandler(void) +{ + // + // Clear the timer interrupt. + // + ROM_TimerIntClear(TIMER1_BASE, TIMER_TIMA_TIMEOUT); + + // + // Toggle the flag for the second timer. + // + HWREGBITW(&g_ui32Flags, 1) ^= 1; + + // + // Update the interrupt status on the display. + // + ROM_IntMasterDisable(); + GrStringDraw(&g_sContext, (HWREGBITW(&g_ui32Flags, 1) ? "1" : "0"), -1, + 195, 128, 1); + ROM_IntMasterEnable(); +} + +//***************************************************************************** +// +// This example application demonstrates the use of the timers to generate +// periodic interrupts. +// +//***************************************************************************** +int +main(void) +{ + uint32_t ui32SysClock; + + // + // Run from the PLL at 120 MHz. + // + ui32SysClock = MAP_SysCtlClockFreqSet((SYSCTL_XTAL_25MHZ | + SYSCTL_OSC_MAIN | SYSCTL_USE_PLL | + SYSCTL_CFG_VCO_480), 120000000); + + // + // Configure the device pins. + // + PinoutSet(); + + // + // Initialize the display driver. + // + Kentec320x240x16_SSD2119Init(ui32SysClock); + + // + // Initialize the graphics context. + // + GrContextInit(&g_sContext, &g_sKentec320x240x16_SSD2119); + + // + // Draw the application frame. + // + FrameDraw(&g_sContext, "timers"); + + // + // Initialize timer status display. + // + GrStringDraw(&g_sContext, "Timer 0:", -1, 100, 108, 0); + GrStringDraw(&g_sContext, "Timer 1:", -1, 100, 128, 0); + + // + // Enable the peripherals used by this example. + // + ROM_SysCtlPeripheralEnable(SYSCTL_PERIPH_TIMER0); + ROM_SysCtlPeripheralEnable(SYSCTL_PERIPH_TIMER1); + + // + // Enable processor interrupts. + // + ROM_IntMasterEnable(); + + // + // Configure the two 32-bit periodic timers. + // + ROM_TimerConfigure(TIMER0_BASE, TIMER_CFG_PERIODIC); + ROM_TimerConfigure(TIMER1_BASE, TIMER_CFG_PERIODIC); + ROM_TimerLoadSet(TIMER0_BASE, TIMER_A, ui32SysClock); + ROM_TimerLoadSet(TIMER1_BASE, TIMER_A, ui32SysClock / 2); + + // + // Setup the interrupts for the timer timeouts. + // + ROM_IntEnable(INT_TIMER0A); + ROM_IntEnable(INT_TIMER1A); + ROM_TimerIntEnable(TIMER0_BASE, TIMER_TIMA_TIMEOUT); + ROM_TimerIntEnable(TIMER1_BASE, TIMER_TIMA_TIMEOUT); + + // + // Enable the timers. + // + ROM_TimerEnable(TIMER0_BASE, TIMER_A); + ROM_TimerEnable(TIMER1_BASE, TIMER_A); + + // + // Loop forever while the timers run. + // + while(1) + { + } +} -- cgit v1.3.1