diff options
Diffstat (limited to 'utils/atj2137/adfuload/test_binary/timer_irq/test_timer_irq.c')
-rw-r--r-- | utils/atj2137/adfuload/test_binary/timer_irq/test_timer_irq.c | 65 |
1 files changed, 65 insertions, 0 deletions
diff --git a/utils/atj2137/adfuload/test_binary/timer_irq/test_timer_irq.c b/utils/atj2137/adfuload/test_binary/timer_irq/test_timer_irq.c new file mode 100644 index 0000000000..4583a69d8d --- /dev/null +++ b/utils/atj2137/adfuload/test_binary/timer_irq/test_timer_irq.c | |||
@@ -0,0 +1,65 @@ | |||
1 | #include "mips.h" | ||
2 | #include "atj213x.h" | ||
3 | |||
4 | static void backlight_set(int level) | ||
5 | { | ||
6 | /* set duty cycle in 1/32 units */ | ||
7 | PMU_CHG = ((PMU_CHG & ~PMU_CHG_PDOUT_MASK) | PMU_CHG_PDUT(level)); | ||
8 | } | ||
9 | |||
10 | static void wdt_feed(void) | ||
11 | { | ||
12 | RTC_WDCTL |= RTC_WDCTL_CLR; | ||
13 | } | ||
14 | |||
15 | void set_sw_interrupt0(void) | ||
16 | { | ||
17 | unsigned int val; | ||
18 | asm volatile("mfc0 %0,$13" : "=r" (val)); | ||
19 | val |= 0x100; | ||
20 | asm volatile("mtc0 %0,$13" : "+r" (val)); | ||
21 | } | ||
22 | |||
23 | int main(void) | ||
24 | { | ||
25 | /* backlight clock enable, select backlight clock as 32kHz */ | ||
26 | CMU_FMCLK = (CMU_FMCLK & ~(CMU_FMCLK_BCLK_MASK)) | CMU_FMCLK_BCKE | CMU_FMCLK_BCLK_32K; | ||
27 | |||
28 | /* baclight enable */ | ||
29 | PMU_CTL |= PMU_CTL_BL_EN; | ||
30 | |||
31 | /* pwm output, phase high, some initial duty cycle set as 24/32 */ | ||
32 | PMU_CHG = ((PMU_CHG & ~PMU_CHG_PDOUT_MASK)| PMU_CHG_PBLS_PWM | PMU_CHG_PPHS_HIGH | PMU_CHG_PDUT(24)); | ||
33 | |||
34 | /* ADEC_N63.BIN seems to setup P_CLK as 7.5MHz which is timer clk */ | ||
35 | RTC_T0 = (7500000*10/32); /* with this we should see transition every ~0.3125s and 'black' every ~10s */ | ||
36 | RTC_T0CTL = (1<<5) | (1<<2) | (1<<1) | (1<<0); /* timer enable, timer reload, timer irq, clear irq pending bit */ | ||
37 | |||
38 | /* Configure T0 interrupt as IP6. IP6 is unmasked in crt0.S */ | ||
39 | INTC_CFG0 = 0; | ||
40 | INTC_CFG1 = 0; | ||
41 | INTC_CFG2 = (1<<10); | ||
42 | |||
43 | /* unmask T0 source in INTC */ | ||
44 | INTC_MSK |= (1<<10); | ||
45 | |||
46 | while(1) | ||
47 | { | ||
48 | /* otherwise wdt will trigger reset */ | ||
49 | wdt_feed(); | ||
50 | } | ||
51 | |||
52 | return 0; | ||
53 | } | ||
54 | |||
55 | /* Timer T0 interrupt service routine */ | ||
56 | INT_T0() | ||
57 | { | ||
58 | static int j = 0; | ||
59 | |||
60 | /* clear pending bit in timer module */ | ||
61 | RTC_T0CTL |= 1; | ||
62 | |||
63 | /* change backligh */ | ||
64 | backlight_set(++j); | ||
65 | } | ||