summaryrefslogtreecommitdiff
path: root/boards/ek-lm4f120xl/stellaris-vga/main.c
blob: 81554c7089bd56650a3d54810b8777cce3aeb429 (plain)
1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
22
23
24
25
26
27
28
29
30
31
32
33
34
35
36
37
38
39
40
41
42
43
44
45
46
47
48
49
50
51
52
53
54
55
56
57
58
59
60
61
62
63
64
65
66
67
68
69
70
71
72
73
74
75
76
77
#include "inc/hw_ints.h"
#include "inc/hw_memmap.h"
#include "inc/hw_types.h"
#include "driverlib/debug.h"
#include "driverlib/fpu.h"
#include "driverlib/gpio.h"
#include "driverlib/interrupt.h"
#include "driverlib/pin_map.h"
#include "driverlib/rom.h"
#include "driverlib/sysctl.h"
#include "driverlib/timer.h"
#include "utils/uartstdio.h"

void Timer0IntHandlerC()
{
  TimerIntClear(TIMER0_BASE, TIMER_TIMA_TIMEOUT);
  // TIMER0_BASE 0x40030000
  // TIMER_TIMA_TIMEOUT 0x00000001
  // TIMER_O_ICR 0x00000024

  // update this reg 0x40030024 = 0x00000001

  __asm__("nop");
}

void main()
{
  /* run at 40 mhz */
  SysCtlClockSet(SYSCTL_SYSDIV_5 |
                 SYSCTL_USE_PLL |
                 SYSCTL_OSC_MAIN |
                 SYSCTL_XTAL_16MHZ);
  
  /* enable led */
  SysCtlPeripheralEnable(SYSCTL_PERIPH_GPIOF);
  GPIOPinTypeGPIOOutput(GPIO_PORTF_BASE, GPIO_PIN_1);
  GPIOPinTypeGPIOOutput(GPIO_PORTF_BASE, GPIO_PIN_2);
  GPIOPinTypeGPIOOutput(GPIO_PORTF_BASE, GPIO_PIN_3);
  
  /* enable vga rgb ping */
  SysCtlPeripheralEnable(SYSCTL_PERIPH_GPIOE);
  GPIOPinTypeGPIOOutput(GPIO_PORTE_BASE, GPIO_PIN_1);   // r
  GPIOPinTypeGPIOOutput(GPIO_PORTE_BASE, GPIO_PIN_2);   // g
  GPIOPinTypeGPIOOutput(GPIO_PORTE_BASE, GPIO_PIN_3);   // b
  GPIOPinTypeGPIOOutput(GPIO_PORTE_BASE, GPIO_PIN_4);   // i
  
  /* enable vga sync pins */
  SysCtlPeripheralEnable(SYSCTL_PERIPH_GPIOB);
  GPIOPinTypeGPIOOutput(GPIO_PORTB_BASE, GPIO_PIN_0);   // vsync
  GPIOPinTypeGPIOOutput(GPIO_PORTB_BASE, GPIO_PIN_1);   // hsync
  
  /* enable & configure timer + interrupt */
  SysCtlPeripheralEnable(SYSCTL_PERIPH_TIMER0);
  IntMasterEnable();
  TimerConfigure(TIMER0_BASE, TIMER_CFG_PERIODIC);
  TimerLoadSet(TIMER0_BASE,
               TIMER_A,
               1056);     /* 26.4us (1056 cycles @ 40 mhz) */
  IntEnable(INT_TIMER0A);
  TimerIntEnable(TIMER0_BASE, TIMER_TIMA_TIMEOUT);
  TimerEnable(TIMER0_BASE, TIMER_A);

  
  while (1)
  {
    /* blink led */
    int i = 0xffff;

    
while(i--);
    GPIOPinWrite(GPIO_PORTF_BASE, GPIO_PIN_1 | GPIO_PIN_2 | GPIO_PIN_3, 0xff);
    SysCtlDelay(SysCtlClockGet() / 100);
while(i--);
    GPIOPinWrite(GPIO_PORTF_BASE, GPIO_PIN_1 | GPIO_PIN_2 | GPIO_PIN_3, 0);
    SysCtlDelay(SysCtlClockGet() / 100);
  }
}