summaryrefslogtreecommitdiff
path: root/firmware/target/arm/imx31/gigabeat-s/kernel-imx31.c
diff options
context:
space:
mode:
Diffstat (limited to 'firmware/target/arm/imx31/gigabeat-s/kernel-imx31.c')
-rw-r--r--firmware/target/arm/imx31/gigabeat-s/kernel-imx31.c55
1 files changed, 45 insertions, 10 deletions
diff --git a/firmware/target/arm/imx31/gigabeat-s/kernel-imx31.c b/firmware/target/arm/imx31/gigabeat-s/kernel-imx31.c
index 9df90a2344..7f882405a5 100644
--- a/firmware/target/arm/imx31/gigabeat-s/kernel-imx31.c
+++ b/firmware/target/arm/imx31/gigabeat-s/kernel-imx31.c
@@ -1,25 +1,60 @@
1#include "config.h"
2#include "system.h"
3#include "avic-imx31.h"
1#include "kernel.h" 4#include "kernel.h"
2#include "thread.h" 5#include "thread.h"
3
4#include <stdio.h> 6#include <stdio.h>
5#include "lcd.h"
6 7
7extern void (*tick_funcs[MAX_NUM_TICK_TASKS])(void); 8extern void (*tick_funcs[MAX_NUM_TICK_TASKS])(void);
8 9
9void timer4(void) { 10#ifndef BOOTLOADER
10 int i; 11static __attribute__((interrupt("IRQ"))) void EPIT1_HANDLER(void)
12{
13 int i;
14
15 EPITSR1 = 1; /* Clear the pending status */
16
11 /* Run through the list of tick tasks */ 17 /* Run through the list of tick tasks */
12 for(i = 0; i < MAX_NUM_TICK_TASKS; i++) 18 for(i = 0;i < MAX_NUM_TICK_TASKS;i++)
13 { 19 {
14 if(tick_funcs[i]) 20 if(tick_funcs[i])
15 {
16 tick_funcs[i](); 21 tick_funcs[i]();
17 }
18 } 22 }
19 23
20 current_tick++; 24 current_tick++;
21
22 /* following needs to be fixed. */
23 /*wake_up_thread();*/
24} 25}
26#endif
27
28void tick_start(unsigned int interval_in_ms)
29{
30 EPITCR1 &= ~(1 << 0); /* Disable the counter */
31 EPITCR1 |= (1 << 16); /* Reset */
25 32
33 CLKCTL_CGR0 |= (0x3 << 6); /* Clock ON */
34 CLKCTL_WIMR0 &= ~(1 << 23); /* Clear wakeup mask */
35
36 /* NOTE: This isn't really accurate yet but it's close enough to work
37 * with for the moment */
38
39 /* CLKSRC=32KHz, EPIT Output Disconnected, Enabled
40 * prescale 1/32, Reload from modulus register, Compare interrupt enabled,
41 * Count from load value */
42 EPITCR1 = (0x3 << 24) | (1 << 19) | (32 << 4) |
43 (1 << 3) | (1 << 2) | (1 << 1);
44 EPITSR1 = 1; /* Clear any pending interrupt */
45#ifndef BOOTLOADER
46 EPITLR1 = interval_in_ms;
47 EPITCMPR1 = 0; /* Event when counter reaches 0 */
48 avic_enable_int(EPIT1, IRQ, EPIT1_HANDLER);
49#else
50 (void)interval_in_ms;
51#endif
52
53 EPITCR1 |= (1 << 0); /* Enable the counter */
54
55 /* Why does only this trigger the counter? Remove when we find out. */
56 asm volatile (
57 "mcr p15, 0, %0, c7, c0, 4 \n"
58 : : "r" (0)
59 );
60}