]> hackdaworld.org Git - my-code/arm.git/commitdiff
basic interrupt approach succeded, buttons (extint) working perfectly from
authorhackbard <hackbard@staubsauger.localdomain>
Thu, 20 Sep 2007 23:39:41 +0000 (01:39 +0200)
committerhackbard <hackbard@staubsauger.localdomain>
Thu, 20 Sep 2007 23:39:41 +0000 (01:39 +0200)
flash AND ram :)

betty/betty.c
betty/interrupts.c
betty/interrupts.h

index 0bd6d0a6ca6b40492fab913d269f10b6a1d6683a..bac66143a21d14c53f875da34132b7375c49e396 100644 (file)
@@ -37,9 +37,11 @@ void display_string_page(u8 x,u8 p,u8 *s,u8 f,u8 o,u8 sp) {
        }
 }
 
-void input_event(void) {
+void __attribute__ ((interrupt("IRQ"))) input_event(void) {
 
-       /* button test! */
+       u8 noret,tries;
+
+       /* button scan */
        if(button_get_event(&button)) {
                switch(button.key[0]) {
                        case BUTTON_POWER:
@@ -109,6 +111,20 @@ void input_event(void) {
                                break;
                }
        }
+
+       /* resume the interrupt at button release */
+       noret=1;
+       while(noret) {
+               tries=0xff;
+               noret=1;
+               while(tries--) {
+                       noret=IOPIN0&(1<<30)?0:1;
+                       if(noret)
+                               break;
+               }
+       }
+       interrupt_ack();
+       interrupt_ext_ir_set(INTERRUPT_EXT3);
 }
 
 /*
@@ -139,7 +155,7 @@ int main() {
        /* button init */
        button.mode=BUTTON_INT;
        button_init(&button);
-       button_set_retries(&button,0);
+       button_set_retries(&button,30);
 
        /* flash init */
        flash_init();
@@ -153,7 +169,9 @@ int main() {
        interrupt_ext_ir_config(INTERRUPT_EXT3,INTERRUPT_EXT_NOWAKE,
                                INTERRUPT_EXT_MODE_EDGE,
                                INTERRUPT_EXT_POLAR_LOW);
-       interrupt_enable(INTERRUPT_EINT3,INTERRUPT_MODE_VIRQ,0,(u32)input_event);
+       interrupt_ext_ir_set(INTERRUPT_EXT3);
+       interrupt_enable(INTERRUPT_EINT3,INTERRUPT_MODE_VIRQ,
+                        0,(u32)input_event);
 
        /*
         * start it ...
@@ -167,6 +185,8 @@ int main() {
 
        
        while(1) {
+               pause(0xffffff);
+               uart0_send_string((char *)announce);
        }
 
        return 0;
index db2061dd433f66c0a378bfe4c76e4672b9f081d7..e344f054149066fd6724e3ea061056ecb147ce73 100644 (file)
@@ -95,6 +95,26 @@ int interrupt_enable(u8 src_number,u8 mode,u8 priority,u32 callback_addr) {
        return INTERRUPT_SET;
 }
 
+int interrupt_change_callback(u8 src_number,u32 callback) {
+
+       int i;
+       u32 *addr,*cntl;
+
+       cntl=(u32 *)&VICVectCntl0;
+       addr=(u32 *)&VICVectAddr0;
+
+       i=0;
+       while(i<INTERRUPT_MAX_VIC) {
+               if((*cntl&0x1f)==src_number) {
+                       *(addr+i)=callback;
+                       return INTERRUPT_CALLBACK_CHANGED;
+               }
+               i++;
+       }
+
+       return INTERRUPT_SRC_NOT_USED;
+}
+
 void interrupt_ext_ir_config(u8 eint,u8 wakeup,u8 mode,u8 polarity) {
 
        if(eint>3)
@@ -105,7 +125,19 @@ void interrupt_ext_ir_config(u8 eint,u8 wakeup,u8 mode,u8 polarity) {
 
        EXTMODE=(EXTMODE&0xf)|(mode<<eint);
        EXTPOLAR=(EXTPOLAR&0xf)|(polarity<<eint);
-       EXTINT=(EXTINT&0xf)|(1<<eint);
+}
+
+void interrupt_ext_ir_set(u8 eint) {
+
+       if(eint>3)
+               return;
+
+       EXTINT=(1<<eint);
+}
+
+void interrupt_ack(void) {
+
+       VICVectAddr=0;
 }
 
 /*
index 194dd9adc2ad02d2bbd81faccfbe5f057a916434..cfb7591aa425bdeb7ad400f1573fcaca20be54b5 100644 (file)
@@ -53,6 +53,8 @@
 #define INTERRUPT_SET                  0x00
 #define INTERRUPT_USED                 0x01
 #define INTERRUPT_PRIORITY_USED                0x02
+#define INTERRUPT_CALLBACK_CHANGED     0x03
+#define INTERRUPT_SRC_NOT_USED         0x04
 
 /* type definitions */
 
@@ -69,7 +71,10 @@ void interrupt_soft_clear(u8 src_number);
 void interrupt_clear(u8 src_number);
 void interrupt_soft_enable(u8 src_number);
 int interrupt_enable(u8 src_number,u8 mode,u8 priority,u32 callback_addr);
+int interrupt_change_callback(u8 src_number,u32 callback_addr);
 void interrupt_ext_ir_config(u8 eint,u8 wakeup,u8 mode,u8 polarity);
+void interrupt_ext_ir_set(u8 eint);
+void interrupt_ack(void);
 
 void interrupt_handler_reset(void);
 void interrupt_handler_undef_instruction(void);