summaryrefslogtreecommitdiff
path: root/utils/atj2137/adfuload/test_binary/timer_irq/test_timer_irq.c
diff options
context:
space:
mode:
authorMarcin Bukat <marcin.bukat@gmail.com>2014-02-09 22:25:25 +0100
committerMarcin Bukat <marcin.bukat@gmail.com>2014-02-09 22:29:30 +0100
commit75525422883c5e951d1e5fa27c08373b1737301f (patch)
tree429547eb4ef23734d8b9c0a87cac8cddad0b5c55 /utils/atj2137/adfuload/test_binary/timer_irq/test_timer_irq.c
parentbde5394f5a4cc40478f28911cdcde6cec85f1b6d (diff)
downloadrockbox-75525422883c5e951d1e5fa27c08373b1737301f.tar.gz
rockbox-75525422883c5e951d1e5fa27c08373b1737301f.zip
atj213x: Simple test exploring irq handling
This test software setups timer T0 periodic interrupt. In ISR it changes backlight level. The interrupt handler does not support nesting and the whole ISR is run in interrupt context. Exceptions are not handled yet. Change-Id: Idc5d622991c7257b4577448d8be08ddd1c24c745
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.c65
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
4static 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
10static void wdt_feed(void)
11{
12 RTC_WDCTL |= RTC_WDCTL_CLR;
13}
14
15void 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
23int 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 */
56INT_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}