From: Robin Krens Date: Wed, 28 Aug 2019 09:43:16 +0000 (+0800) Subject: simple timer with led test X-Git-Url: https://robinkrens.nl/gitweb/?a=commitdiff_plain;h=1e24a69aae66280bec2c706212d1dd2938d23c8c;p=cortex-from-scratch simple timer with led test --- diff --git a/drivers/tsensor.c b/drivers/tsensor.c index d1ebcd4..04fb383 100644 --- a/drivers/tsensor.c +++ b/drivers/tsensor.c @@ -23,7 +23,7 @@ #include -#define PRESCALER 36000 // 1 Mhz +#define PRESCALER 8000 // 1 kHz int *ccr1, *ccr2, *ccr1b, *ccr2b; bool s1, s2; @@ -107,6 +107,23 @@ void * cnt_complete_handler() { tsensor_input(0xFFFF); } +int cnt; + +void * bare_handler() { + cnt += 1; + printf("Count event %d\n", cnt); + int switchled = cnt % 2; + if (switchled) { + printf("setting low\n"); + rclrbit(GPIOB_ODR, 6); // low + } + else { + printf("setting high\n"); + rsetbit(GPIOB_ODR, 6); // high + } + rclrbit(TIM4_SR1, 0); +} + void tsensor_simple(uint16_t preload) { @@ -120,10 +137,10 @@ void tsensor_simple(uint16_t preload) { rwrite(TIM4_ARR, preload); rsetbit(TIM4_EGR, 0); - ivt_set_gate(46, cnt_complete_handler, 0); + ivt_set_gate(46, bare_handler, 0); rsetbit(NVIC_ISER0, 30); // interupt 41 - 32 - rsetbit(GPIOB_BSRR, 22); // + rsetbit(GPIOB_ODR, 6); // rsetbit(TIM4_DIER, 0); rsetbit(TIM4_CR1, 0); @@ -131,11 +148,14 @@ void tsensor_simple(uint16_t preload) { void run() { + cnt = 0; rsetbit(RCC_APB2ENR, 3); // GPIOB enable - rwrite(GPIOB_CRL, 0x47444444); // open drain general + rwrite(GPIOB_CRL, 0x42444444); // open drain general for sensor? rsetbit(GPIOB_BSRR, 22); // high - tsensor_simple(2000); + + tsensor_simple(4000); // 2 second? + // tsensor_output(580, 520); // reset(); // tsensor_simple(580); diff --git a/include/sys/mmap.h b/include/sys/mmap.h index 9aae914..a473c70 100644 --- a/include/sys/mmap.h +++ b/include/sys/mmap.h @@ -71,6 +71,7 @@ #define GPIOA_ODR MEM_ADDR(0x4001080C) #define GPIOB_CRL MEM_ADDR(0x40010C00) // low register (!) for I2C1 #define GPIOB_BSRR MEM_ADDR(0x40010C10) +#define GPIOB_ODR MEM_ADDR(0x40010C0C) #define GPIOC_CRL MEM_ADDR(0x40011000) // led #define GPIOC_CRH MEM_ADDR(0x40011004) #define GPIOC_ODR MEM_ADDR(0x4001100C) diff --git a/main.c b/main.c index 221d7d6..fd762e4 100644 --- a/main.c +++ b/main.c @@ -62,7 +62,10 @@ void main() */ /* LED Segment Driver */ - tm1637_init(); + //tm1637_init(); + + /* TEMP SENSOR */ + run(); /* Start up terminal */ terminal(); diff --git a/rtc.c b/rtc.c index f169a85..7765046 100644 --- a/rtc.c +++ b/rtc.c @@ -34,7 +34,7 @@ void * rtc_handler() { // Real time clock output on a LED display - int cntvalue = *RTC_CNTL; + /* int cntvalue = *RTC_CNTL; if (cntvalue < 9999) { unsigned char dn[10] = {0xFC, 0x60, 0xDA, 0xF2, 0x66, 0xB6, 0xBE, 0xE0, 0xFE, 0xF6}; @@ -55,12 +55,12 @@ void * rtc_handler() { } set_display(true, 0); - } + } */ // Simple LED blink - //uint32_t curr = *RTC_CNTL; - //int even = *RTC_CNTL % 2; - //(!even) ? led_off() : led_on(); + uint32_t curr = *RTC_CNTL; + int even = *RTC_CNTL % 2; + (!even) ? led_off() : led_on(); rclrbit(RTC_CRL, 0); /* clear interrupt flag */ }