Skip to content

Commit d4faff4

Browse files
committed
Blinky example works with timers, without delays
1 parent c822bb1 commit d4faff4

File tree

3 files changed

+40
-14
lines changed

3 files changed

+40
-14
lines changed

Makefile

Lines changed: 4 additions & 4 deletions
Original file line numberDiff line numberDiff line change
@@ -35,16 +35,16 @@ CFLAGS += -I nordic/
3535
CFLAGS += -I sdk/
3636

3737
// TODO: auto-detect chip revision
38-
CHIP_REVISION = ac
38+
CHIP_REVISION = aa
3939

4040
LINKER_SCRIPT = linker/nrf51-blank-xx$(CHIP_REVISION).ld
4141
LDFLAGS += -T $(LINKER_SCRIPT)
4242
LDFLAGS += -L /usr/lib/gcc/arm-none-eabi/4.8/armv6-m/
4343
LDFLAGS += -L /usr/lib/arm-none-eabi/newlib/armv6-m/
44-
LDFLAGS += --start-group
45-
LDFLAGS += -lgcc
4644
LDFLAGS += -static
4745
LDFLAGS += -nostartfiles -nostdlib
46+
LDFLAGS += --start-group
47+
LDFLAGS += -lgcc
4848

4949

5050
#
@@ -56,7 +56,7 @@ all: demo_uart.elf demo_spi.elf demo_leds.elf demo_rgbstrip.elf demo_timers.elf
5656
demo_uart.elf: sdk/nrf51_startup.o nordic/system_nrf51.o sdk/strings.o sdk/fifo.o sdk/uart.o sdk/delay.o demo_uart.o
5757
$(LD) $(LDFLAGS) $^ -o $@
5858

59-
demo_spi.elf: sdk/nrf51_startup.o nordic/system_nrf51.o sdk/strings.o sdk/fifo.o sdk/uart.o sdk/delay.o libad53x4/ad53x4.o libad53x4/demo_nrf51.o
59+
demo_spi.elf: sdk/nrf51_startup.o nordic/system_nrf51.o sdk/strings.o sdk/fifo.o sdk/uart.o sdk/delay.o libad53x4/ad53x4.o libad53x4/demo_ad53x4.o
6060
$(LD) $(LDFLAGS) $^ -o $@
6161

6262
demo_leds.elf: sdk/nrf51_startup.o nordic/system_nrf51.o sdk/delay.o demo_leds.o

demo_timers.c

Lines changed: 35 additions & 9 deletions
Original file line numberDiff line numberDiff line change
@@ -7,7 +7,7 @@
77
#include "gpio.h"
88
#include "timers.h"
99

10-
#define PIN_LED 20
10+
#define PIN_LED 28
1111
#define my_timer TIMER0
1212

1313
void setup_led()
@@ -19,40 +19,66 @@ void setup_led()
1919
void setup_timer()
2020
{
2121
// reset timer
22-
TIMER_TASK_STOP(my_timer) = 1;
22+
TIMER_TASK_STOP(my_timer) = 1;
2323
TIMER_TASK_CLEAR(my_timer) = 1;
2424

2525
// configure 16MHz crystal frequency as clock source
2626
CLOCK_XTALFREQ = 0xFF;
2727

2828
// start high frequency clock
2929
// (is that necessary?)
30-
CLOCK_HFCLKSTAT = 1;
30+
CLOCK_TASK_HFCLKSTART = 1;
31+
while (!CLOCK_EVENT_HFCLKSTARTED)
32+
asm("nop");
3133

3234
// configure timer frequency
3335
TIMER_PRESCALER(my_timer) = 9;
3436

3537
// configure timer mode
36-
TIMER_MODE(my_timer) = TIMER_MODE_TIMER;
37-
TIMER_BITMODE(my_timer) = TIMER_BITMODE_24BIT;
38+
// TIMER_MODE(my_timer) = TIMER_MODE_TIMER;
39+
// TIMER_BITMODE(my_timer) = TIMER_BITMODE_32BIT;
3840

3941
// configure timer interrupt
40-
TIMER_CC(my_timer)[0] = 0;
41-
TIMER_INTENSET(my_timer) = TIMER_INTERRUPT_UPON_COMPARE(0);
42+
TIMER_CC(my_timer)[0] = 0xffffffff;
43+
TIMER_INTENSET(my_timer) |= TIMER_INTERRUPT_UPON_COMPARE(0);
4244
interrupt_enable(TIMER0_INTERRUPT);
4345

4446
// configure shortcut
47+
/*
4548
TIMER_SHORTCUTS(my_timer) =
4649
TIMER_SHORTCUT_COMPARE_CLEAR(0)
4750
| TIMER_SHORTCUT_COMPARE_STOP(0);
51+
*/
4852
}
4953

54+
bool led_on = false;
55+
uint32_t counter = 0;
56+
5057
void TIMER0_Handler()
5158
{
52-
// XOR with the mask for the chosen LED pin to toggle corresponding bit
53-
GPIO_OUT = GPIO_OUT ^ (1 << PIN_LED);
59+
TIMER_TASK_STOP(my_timer) = 1;
60+
TIMER_TASK_CLEAR(my_timer) = 1;
61+
TIMER_EVENT_COMPARE(my_timer)[0] = 0;
62+
63+
counter++;
64+
if (counter >= 50000)
65+
{
66+
counter = 0;
67+
68+
if (led_on)
69+
{
70+
GPIO_OUT &= ~(1 << PIN_LED);
71+
led_on = false;
72+
}
73+
else
74+
{
75+
GPIO_OUT |= 1 << PIN_LED;
76+
led_on = true;
77+
}
78+
}
5479

5580
// restart timer
81+
// TIMER_CC(my_timer)[0] = 0x10000;
5682
TIMER_TASK_START(my_timer) = 1;
5783
}
5884

libad53x4

Submodule libad53x4 updated 1 file

0 commit comments

Comments
 (0)