blob: 4b62ea76e8252694645af039114b2d026da2d6ec [file] [log] [blame]
rjw1f884582022-01-06 17:20:42 +08001/*
2 * Copyright (c) 2012 Travis Geiselbrecht
3 *
4 * Permission is hereby granted, free of charge, to any person obtaining
5 * a copy of this software and associated documentation files
6 * (the "Software"), to deal in the Software without restriction,
7 * including without limitation the rights to use, copy, modify, merge,
8 * publish, distribute, sublicense, and/or sell copies of the Software,
9 * and to permit persons to whom the Software is furnished to do so,
10 * subject to the following conditions:
11 *
12 * The above copyright notice and this permission notice shall be
13 * included in all copies or substantial portions of the Software.
14 *
15 * THE SOFTWARE IS PROVIDED "AS IS", WITHOUT WARRANTY OF ANY KIND,
16 * EXPRESS OR IMPLIED, INCLUDING BUT NOT LIMITED TO THE WARRANTIES OF
17 * MERCHANTABILITY, FITNESS FOR A PARTICULAR PURPOSE AND NONINFRINGEMENT.
18 * IN NO EVENT SHALL THE AUTHORS OR COPYRIGHT HOLDERS BE LIABLE FOR ANY
19 * CLAIM, DAMAGES OR OTHER LIABILITY, WHETHER IN AN ACTION OF CONTRACT,
20 * TORT OR OTHERWISE, ARISING FROM, OUT OF OR IN CONNECTION WITH THE
21 * SOFTWARE OR THE USE OR OTHER DEALINGS IN THE SOFTWARE.
22 */
23#include <err.h>
24#include <debug.h>
25#include <target.h>
26#include <compiler.h>
27#include <dev/gpio.h>
28#include <kernel/timer.h>
29#include <platform/gpio.h>
30#include <platform/nrf51.h>
31#include <target/gpioconfig.h>
32
33
34static timer_t blinktimer;
35static bool heartbeat = false;
36
37void target_early_init(void)
38{
39 NRF_CLOCK->XTALFREQ = CLOCK_XTALFREQ_XTALFREQ_16MHz;
40
41 /* configure the usart1 pins */
42 gpio_config(GPIO_LED1, GPIO_OUTPUT);
43 gpio_config(GPIO_LED2, GPIO_OUTPUT);
44 gpio_config(GPIO_LED3, GPIO_OUTPUT);
45
46 gpio_set(GPIO_LED1,1);
47 gpio_set(GPIO_LED2,1);
48 gpio_set(GPIO_LED3,1);
49
50 gpio_config(UART0_RTS_PIN, GPIO_OUTPUT);
51 gpio_set(UART0_RTS_PIN,0); //placate flow control requirements of pca10000
52
53 nrf51_debug_early_init();
54}
55
56static enum handler_return blinker(timer_t * timer, lk_time_t now, void * args){
57
58 if (heartbeat) {
59 heartbeat = false;
60 gpio_set(GPIO_LED1,1); //turn off led
61 timer_set_oneshot(timer,950, blinker, NULL);
62 } else {
63 heartbeat = true;
64 gpio_set(GPIO_LED1,0);
65 timer_set_oneshot(timer,50, blinker, NULL);
66 }
67 return INT_RESCHEDULE;
68}
69
70
71
72
73void target_init(void)
74{
75 nrf51_debug_init();
76 dprintf(SPEW,"Target: PCA10000 DK...\n");
77 timer_initialize(&blinktimer);
78 timer_set_oneshot(&blinktimer, 1000, blinker, NULL);
79}