Skip to content

Commit

Permalink
adding 1s timer
Browse files Browse the repository at this point in the history
  • Loading branch information
ps2 committed Apr 6, 2017
1 parent fd858a0 commit 147ec8c
Show file tree
Hide file tree
Showing 4 changed files with 39 additions and 19 deletions.
3 changes: 3 additions & 0 deletions Makefile
Original file line number Diff line number Diff line change
Expand Up @@ -92,6 +92,8 @@ remduplicates = $(strip $(if $1,$(firstword $1) $(call remduplicates,$(filter-ou
# source common to all targets

C_SOURCE_FILES += main.c leds.c
C_SOURCE_FILES += $(COMPONENTS)/libraries/timer/app_timer.c

CXX_SOURCE_FILES += logger.cpp
CXX_SOURCE_FILES += $(SIMBLEE_BASE)/libraries/SimbleeBLE/SimbleeBLE.cpp
CXX_SOURCE_FILES += $(SIMBLEE_BASE)/variants/Simblee/variant.cpp
Expand Down Expand Up @@ -156,6 +158,7 @@ INC_PATHS += -I$(COMPONENTS)/softdevice/s110/headers
INC_PATHS += -I$(COMPONENTS)/softdevice/common/softdevice_handler
INC_PATHS += -I$(COMPONENTS)/toolchain/gcc
INC_PATHS += -I$(COMPONENTS)/libraries/util
INC_PATHS += -I$(COMPONENTS)/libraries/timer
INC_PATHS += -I$(COMPONENTS)/ble/common
INC_PATHS += -I$(COMPONENTS)/drivers_nrf/hal
INC_PATHS += -I$(COMPONENTS)/drivers_nrf/spi_slave
Expand Down
2 changes: 1 addition & 1 deletion leds.c
Original file line number Diff line number Diff line change
Expand Up @@ -6,7 +6,7 @@ void init_leds() {
}

void toggle_led(unsigned char led) {
LEDS_INVERT(1 << led);
LEDS_INVERT(1 << (led + LED_START));
}

void led_config(uint8_t led, uint8_t conf)
Expand Down
6 changes: 3 additions & 3 deletions leds.h
Original file line number Diff line number Diff line change
Expand Up @@ -3,9 +3,9 @@

#include "boards.h"

#define LED_BLUE LED_1
#define LED_GREEN LED_2
#define LED_RED LED_3
#define LED_RED 0
#define LED_GREEN 1
#define LED_BLUE 2

#ifdef __cplusplus
extern "C" {
Expand Down
47 changes: 32 additions & 15 deletions main.c
Original file line number Diff line number Diff line change
Expand Up @@ -37,6 +37,7 @@ SOFTWARE, EVEN IF ADVISED OF THE POSSIBILITY OF SUCH DAMAGE.
#include "boards.h"
#include "leds.h"
#include "logger.h"
#include "app_timer.h"
#include <stdbool.h>
#include <stdint.h>
#include <string.h>
Expand All @@ -49,11 +50,24 @@ SOFTWARE, EVEN IF ADVISED OF THE POSSIBILITY OF SUCH DAMAGE.
#define MESH_CLOCK_SRC (NRF_CLOCK_LFCLKSRC_XTAL_75_PPM)


// Timer settings
#define APP_TIMER_ENABLED 1
#define APP_TIMER_PRESCALER 327
#define APP_TIMER_MAX_TIMERS 1
#define APP_TIMER_OP_QUEUE_SIZE 1

static app_timer_id_t timer_ID;


void timeOut(void * p_context)
{
toggle_led(LED_RED);
}

/** @brief General error handler. */
static inline void error_loop(void)
{
logger_print("error");
toggle_led(LED_RED);
__disable_irq();
while (true)
{
Expand Down Expand Up @@ -122,6 +136,18 @@ static void rbc_mesh_event_handler(rbc_mesh_event_t* p_evt)
}
}

void clock_initialization()
{
NRF_CLOCK->LFCLKSRC = (CLOCK_LFCLKSRC_SRC_Xtal << CLOCK_LFCLKSRC_SRC_Pos);
NRF_CLOCK->EVENTS_LFCLKSTARTED = 0;
NRF_CLOCK->TASKS_LFCLKSTART = 1;

while (NRF_CLOCK->EVENTS_LFCLKSTARTED == 0)
{
// Do nothing.
}
}

int main(void)
{
logger_init();
Expand All @@ -136,14 +162,6 @@ int main(void)

init_leds();

#ifdef RBC_MESH_SERIAL

/* only want to enable serial interface, and let external host setup the framework */
mesh_aci_init();
mesh_aci_start();

#else

/* Initialize mesh. */
rbc_mesh_init_params_t init_params;
init_params.access_addr = MESH_ACCESS_ADDR;
Expand All @@ -156,14 +174,13 @@ int main(void)
error_code = rbc_mesh_init(init_params);
APP_ERROR_CHECK(error_code);

/* Enable handle 1 and 2 */
/* Enable handle 1 */
error_code = rbc_mesh_value_enable(1);
APP_ERROR_CHECK(error_code);
error_code = rbc_mesh_value_enable(2);
APP_ERROR_CHECK(error_code);
error_code = rbc_mesh_value_enable(3);
APP_ERROR_CHECK(error_code);
#endif

APP_TIMER_INIT(APP_TIMER_PRESCALER, APP_TIMER_MAX_TIMERS, APP_TIMER_OP_QUEUE_SIZE, false);
app_timer_create(&timer_ID, APP_TIMER_MODE_REPEATED, timeOut);
app_timer_start(timer_ID, 100, NULL);

rbc_mesh_event_t evt;
while (true)
Expand Down

0 comments on commit 147ec8c

Please sign in to comment.