From: hackbard Date: Mon, 24 Sep 2007 19:48:48 +0000 (+0200) Subject: some interrupt/pwm testing X-Git-Url: https://hackdaworld.org/cgi-bin/gitweb.cgi?a=commitdiff_plain;h=9f1a71389dff6cddd11c4b9975a0d1b91806ee2d;p=my-code%2Farm.git some interrupt/pwm testing --- diff --git a/betty/Makefile b/betty/Makefile index 4d2a1aa..a76cf32 100644 --- a/betty/Makefile +++ b/betty/Makefile @@ -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) diff --git a/betty/betty.c b/betty/betty.c index bac6614..3b29d2e 100644 --- a/betty/betty.c +++ b/betty/betty.c @@ -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 ... diff --git a/betty/betty.h b/betty/betty.h index 07d063a..e292a80 100644 --- a/betty/betty.h +++ b/betty/betty.h @@ -28,11 +28,15 @@ #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 */ diff --git a/betty/interrupts.c b/betty/interrupts.c index df99354..ed33c15 100644 --- a/betty/interrupts.c +++ b/betty/interrupts.c @@ -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; } /* diff --git a/betty/interrupts.h b/betty/interrupts.h index 21d7413..0d8266c 100644 --- a/betty/interrupts.h +++ b/betty/interrupts.h @@ -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); diff --git a/betty/system.c b/betty/system.c index ef18b57..7554373 100644 --- a/betty/system.c +++ b/betty/system.c @@ -64,10 +64,11 @@ void pin_init(void) { * pinsel 0 * * uart0: tx, rx + * p0.7: pwm2 * */ - PINSEL0=0x00000005; + PINSEL0=0x00008005; /* * pinsel 1