]> hackdaworld.org Git - my-code/arm.git/commitdiff
some interrupt/pwm testing
authorhackbard <hackbard@hackdaworld.org>
Mon, 24 Sep 2007 19:48:48 +0000 (21:48 +0200)
committerhackbard <hackbard@hackdaworld.org>
Mon, 24 Sep 2007 19:48:48 +0000 (21:48 +0200)
betty/Makefile
betty/betty.c
betty/betty.h
betty/interrupts.c
betty/interrupts.h
betty/system.c

index 4d2a1aa44450803513cd65d6596c7ff0a146d1bd..a76cf327378c3677204f345b1253169755fe6c6e 100644 (file)
@@ -20,7 +20,7 @@ CROSS_TARGET = fwbc.hex fwflash.hex betty.hex
 
 # betty deps
 BETTY_DEPS = system.o uart.o buttons.o spi.o display.o flash.o functions.o
-BETTY_DEPS += interrupts.o #pffs.o
+BETTY_DEPS += interrupts.o pwm.o #pffs.o
 
 # all projects
 all: $(HOST_TARGET) $(CROSS_TARGET)
index bac66143a21d14c53f875da34132b7375c49e396..3b29d2e2207c5a2e2659ea68771c6384a5f0889f 100644 (file)
@@ -17,6 +17,7 @@ const char d1_txt[]="betty";
 const char d2_txt[]="- alphablend -";
 u8 contrast;
 t_button button;
+int sample_count;
 
 /*
  * functions
@@ -37,6 +38,16 @@ void display_string_page(u8 x,u8 p,u8 *s,u8 f,u8 o,u8 sp) {
        }
 }
 
+void __attribute__ ((interrupt("IRQ"))) set_sample(void) {
+
+       uart0_send_byte('S');
+       pwm_update_match(PWM_CHAN2,PWM_SINGLE_EDGE,sinus[sample_count++],0);
+       if(sample_count==0xff)
+               sample_count=0;
+       interrupt_ack();
+       interrupt_tc_ir_set(INTERRUPT_TC0,INTERRUPT_M0);
+}
+
 void __attribute__ ((interrupt("IRQ"))) input_event(void) {
 
        u8 noret,tries;
@@ -135,6 +146,9 @@ int main() {
 
        /* variables */
 
+       /* init */
+       sample_count=0;
+
        /* system init */
        pll_init();
        pin_init();
@@ -166,12 +180,29 @@ int main() {
 
        /* interrupt init */
        interrupt_init();
+
+       // ext interrupt
        interrupt_ext_ir_config(INTERRUPT_EXT3,INTERRUPT_EXT_NOWAKE,
                                INTERRUPT_EXT_MODE_EDGE,
                                INTERRUPT_EXT_POLAR_LOW);
        interrupt_ext_ir_set(INTERRUPT_EXT3);
        interrupt_enable(INTERRUPT_EINT3,INTERRUPT_MODE_VIRQ,
-                        0,(u32)input_event);
+                        0,(u32)&input_event);
+
+       // timer interrupt
+       interrupt_tc_config(INTERRUPT_TC0,INTERRUPT_TC_MODE_T,0,0);
+       interrupt_tc_match_config(INTERRUPT_TC0,INTERRUPT_M0,120,
+                                 INTERRUPT_TC_MATCH_IR|INTERRUPT_TC_MATCH_RESET);
+       interrupt_tc_ir_set(INTERRUPT_TC0,INTERRUPT_M0);
+       interrupt_enable(INTERRUPT_PWM,INTERRUPT_MODE_VIRQ,1,(u32)&set_sample);
+
+       /* pwm init */
+       pwm_set_rate_and_prescaler(0xff,0);
+       pwm_config(PWM_CHAN2,PWM_SINGLE_EDGE,0,0);
+       pwm_match_ctrl_config(PWM_CHAN2,0);
+       interrupt_pwm_ir_set(PWM_CHAN2);
+       pwm_enable;
+       
 
        /*
         * start it ...
index 07d063a01d512962796842f2696f0d18755db5db..e292a804cd05cc8a38469835ad1f97752635dd8b 100644 (file)
 #include "flash.h"
 #include "pffs.h"
 #include "interrupts.h"
+#include "pwm.h"
 
 // font/logo
 #include "default_font.h"
 #include "default_logo.h"
 
+// sinus
+#include "sinus.h"
+
 /*
  * defines
  */
index df99354c84c4cebb60bca5c0d15f8363e61db589..ed33c154094862c52404d8d5555dd26388e59fd8 100644 (file)
@@ -180,14 +180,14 @@ void interrupt_tc_match_config(u8 tcnum,u8 mnum,u32 val,u8 mode) {
 
        if(tcnum==0) {
                T0MCR=(T0MCR&0x0fff)|(mode<<(3*mnum));
-               mrddr=&T0MR0
+               mraddr=(u32 *)&T0MR0;
        }
        else {
                T1MCR=(T1MCR&0x0fff)|(mode<<(3*mnum));
-               mrddr=&T1MR0
+               mraddr=(u32 *)&T1MR0;
        }
 
-       mraddr[mnum]=val;
+       *((volatile u32 *)(mraddr+mnum))=val;
 }
 
 void interrupt_tc_capt_config(u8 tcnum,u8 cnum,u8 mode) {
@@ -220,29 +220,9 @@ void interrupt_tc_ir_set(u8 tcnum,u8 tcmc) {
 }
 
 // pwm interrupts
-void interrupt_pwm_set_rate(u32 rate) {
-
-       PWMMR0=rate;
-}
-
-void interrupt_pwm_match_config(u8 mnum,u8 op,u8 mode,u32 val1,u32 val2) {
-
-       u32 *addr=&PWMR0;
-
-       *((volatile u32 *)(addr+mnum))=mval;
-       PWMMCR=(PWMMCR&0x1fffff)|(mode<<(op*3));
-}
-
-void interrupt_pwm_enable(u8 mode,u32 ps_val) {
-
-       PWMPR=ps_val;
-       PWMTCR=0x0b;
-}
-
 void interrupt_pwm_ir_set(u8 pwm_channel) {
 
        PWMIR=(pwm_channel&0x0f)|((pwm_channel&0x70)<<4);
-       PWMTCR=0x09;
 }
 
 /*
index 21d741338e9fbec7ea104de163801954a77b36a9..0d8266c1a4828dbb53a6d8f6c0d5ba06f08d5855 100644 (file)
@@ -77,6 +77,9 @@
 #define INTERRUPT_C2                   0x40
 #define INTERRUPT_C3                   0x80
 
+#define INTERRUPT_TC0                  0
+#define INTERRUPT_TC1                  1
+
 #define INTERRUPT_SET                  0x00
 #define INTERRUPT_USED                 0x01
 #define INTERRUPT_PRIORITY_USED                0x02
@@ -111,6 +114,8 @@ void interrupt_tc_match_config(u8 tcnum,u8 mnum,u32 val,u8 mode);
 void interrupt_tc_capt_config(u8 tcnum,u8 cnum,u8 mode);
 void interrupt_tc_ir_set(u8 tcnum,u8 tcmc);
 
+void interrupt_pwm_ir_set(u8 pwm_channel);
+
 void interrupt_handler_reset(void);
 void interrupt_handler_undef_instruction(void);
 void interrupt_handler_soft_ir(void);
index ef18b57926472842fb8ec180ccd64d305925798e..755437358528a8ec953b3b08b50ab29bba5c5f04 100644 (file)
@@ -64,10 +64,11 @@ void pin_init(void) {
         * pinsel 0
         *
         * uart0: tx, rx
+        * p0.7: pwm2
         *
         */
 
-       PINSEL0=0x00000005;
+       PINSEL0=0x00008005;
 
        /*
         * pinsel 1