Using Softdevice S130
This commit is contained in:
parent
5e8181aa2b
commit
a6f724b51a
8
Makefile
8
Makefile
|
@ -10,7 +10,9 @@ $(OUTPUT_DIRECTORY)/nrf51822_xxaa.out: \
|
|||
|
||||
# Source files common to all targets
|
||||
SRC_FILES += \
|
||||
$(PROJ_DIR)/main.c \
|
||||
$(PROJ_DIR)/src/main.c \
|
||||
$(PROJ_DIR)/src/user_functions.c \
|
||||
$(PROJ_DIR)/src/user_tasks.c \
|
||||
$(SDK_ROOT)/components/toolchain/gcc/gcc_startup_nrf51.S \
|
||||
$(SDK_ROOT)/components/toolchain/system_nrf51.c \
|
||||
$(SDK_ROOT)/components/boards/boards.c \
|
||||
|
@ -40,6 +42,7 @@ SRC_FILES += \
|
|||
INC_FOLDERS += \
|
||||
$(PROJ_DIR) \
|
||||
$(PROJ_DIR)/config \
|
||||
$(PROJ_DIR)/include \
|
||||
$(SDK_ROOT)/components \
|
||||
$(SDK_ROOT)/components/boards \
|
||||
$(SDK_ROOT)/components/ble/common \
|
||||
|
@ -97,7 +100,6 @@ CFLAGS += -DSOFTDEVICE_PRESENT
|
|||
CFLAGS += -DS130
|
||||
CFLAGS += -DBLE_STACK_SUPPORT_REQD
|
||||
CFLAGS += -DNRF_SD_BLE_API_VERSION=2
|
||||
CFLAGS += -D__STACK_SIZE=2048
|
||||
|
||||
# C++ flags common to all targets
|
||||
CXXFLAGS += \
|
||||
|
@ -112,8 +114,6 @@ ASMFLAGS += -DSOFTDEVICE_PRESENT
|
|||
ASMFLAGS += -DS130
|
||||
ASMFLAGS += -DBLE_STACK_SUPPORT_REQD
|
||||
ASMFLAGS += -DNRF_SD_BLE_API_VERSION=2
|
||||
ASMFLAGS += -D__STACK_SIZE=2048
|
||||
|
||||
|
||||
# Linker flags
|
||||
LDFLAGS += -mthumb -mabi=aapcs -L $(TEMPLATE_PATH) -T$(LINKER_SCRIPT)
|
||||
|
|
|
@ -0,0 +1,6 @@
|
|||
#ifndef __USER_CONFIG_H
|
||||
#define __USER_CONFIG_H
|
||||
|
||||
#define APP_TIMER_PRESCALER 0 /**< Value of the RTC1 PRESCALER register. */
|
||||
|
||||
#endif
|
|
@ -0,0 +1,6 @@
|
|||
#ifndef __USER_FUNCTIONS_H
|
||||
#define __USER_FUNCTIONS_H
|
||||
|
||||
uint32_t ble_new_event_handler(void);
|
||||
|
||||
#endif
|
|
@ -0,0 +1,12 @@
|
|||
#ifndef __USER_TASKS_H
|
||||
#define __USER_TASKS_H
|
||||
|
||||
extern SemaphoreHandle_t xSemaphoreBLEEventReadyHandle;
|
||||
|
||||
extern TaskHandle_t xTaskBLEHandle;
|
||||
extern TaskHandle_t xTaskBlinkLEDHandle;
|
||||
extern TaskHandle_t xTaskLoggerHandle;
|
||||
|
||||
void init_tasks(void);
|
||||
|
||||
#endif
|
119
main.c
119
main.c
|
@ -1,119 +0,0 @@
|
|||
#include <stdbool.h>
|
||||
#include <stdint.h>
|
||||
#include <stdio.h>
|
||||
|
||||
#include "bsp.h"
|
||||
|
||||
#include "nordic_common.h"
|
||||
#include "nrf.h"
|
||||
#include "ble.h"
|
||||
#include "ble_hci.h"
|
||||
#include "ble_srv_common.h"
|
||||
#include "ble_advdata.h"
|
||||
#include "ble_advertising.h"
|
||||
#include "ble_bas.h"
|
||||
#include "ble_hrs.h"
|
||||
#include "ble_dis.h"
|
||||
#include "ble_conn_params.h"
|
||||
|
||||
#include "boards.h"
|
||||
#include "sensorsim.h"
|
||||
|
||||
#include "sdk_errors.h"
|
||||
#include "app_error.h"
|
||||
#include "app_timer.h"
|
||||
#include "softdevice_handler.h"
|
||||
|
||||
#include "peer_manager.h"
|
||||
#include "bsp.h"
|
||||
#include "bsp_btn_ble.h"
|
||||
#include "fds.h"
|
||||
#include "fstorage.h"
|
||||
#include "ble_conn_state.h"
|
||||
|
||||
#include "nrf_drv_clock.h"
|
||||
|
||||
#define NRF_LOG_MODULE_NAME "APP"
|
||||
|
||||
#include "nrf_log.h"
|
||||
#include "nrf_log_ctrl.h"
|
||||
|
||||
#include "FreeRTOS.h"
|
||||
#include "task.h"
|
||||
#include "timers.h"
|
||||
#include "semphr.h"
|
||||
|
||||
#define APP_TIMER_PRESCALER 0
|
||||
#define APP_TIMER_OP_QUEUE_SIZE 4
|
||||
|
||||
/* Task Definitions */
|
||||
|
||||
TaskHandle_t xTaskBlinkLEDHandle = NULL;
|
||||
void vTaskBlinkLED(void *pvParameters);
|
||||
|
||||
TaskHandle_t xTaskLoggerHandle = NULL;
|
||||
void vTaskLogger(void *pvParameters);
|
||||
|
||||
/* Timers */
|
||||
|
||||
TimerHandle_t xTimerBlinkAnotherLEDHandle = NULL;
|
||||
void xTimerBlinkAnotherLEDCallback(TimerHandle_t xTimer);
|
||||
|
||||
int main(void) {
|
||||
ret_code_t err_code;
|
||||
|
||||
err_code = nrf_drv_clock_init();
|
||||
APP_ERROR_CHECK(err_code);
|
||||
|
||||
bsp_board_leds_init();
|
||||
bsp_board_leds_off();
|
||||
|
||||
err_code = NRF_LOG_INIT(xTaskGetTickCount);
|
||||
APP_ERROR_CHECK(err_code);
|
||||
|
||||
SCB->SCR |= SCB_SCR_SLEEPDEEP_Msk;
|
||||
|
||||
if(pdPASS != xTaskCreate(vTaskBlinkLED, "TASKLED0", 128, NULL, 2, &xTaskBlinkLEDHandle)) {
|
||||
APP_ERROR_HANDLER(NRF_ERROR_NO_MEM);
|
||||
}
|
||||
|
||||
if(pdPASS != xTaskCreate(vTaskLogger, "TASKLOG0", 256, NULL, 1, &xTaskLoggerHandle));
|
||||
|
||||
xTimerBlinkAnotherLEDHandle = xTimerCreate("TIMERLED1", pdMS_TO_TICKS(200), pdTRUE, NULL, xTimerBlinkAnotherLEDCallback);
|
||||
UNUSED_VARIABLE(xTimerStart(xTimerBlinkAnotherLEDHandle, 0));
|
||||
|
||||
vTaskStartScheduler();
|
||||
|
||||
for(;;) {
|
||||
APP_ERROR_HANDLER(NRF_ERROR_FORBIDDEN);
|
||||
}
|
||||
}
|
||||
|
||||
void vTaskBlinkLED(void *pvParameters) {
|
||||
UNUSED_VARIABLE(pvParameters);
|
||||
|
||||
for(;;) {
|
||||
bsp_board_led_invert(BSP_BOARD_LED_0);
|
||||
NRF_LOG_INFO("Toggle LED0...\r\n");
|
||||
vTaskDelay(1000);
|
||||
}
|
||||
}
|
||||
|
||||
void xTimerBlinkAnotherLEDCallback(TimerHandle_t xTimer) {
|
||||
UNUSED_VARIABLE(xTimer);
|
||||
NRF_LOG_DEBUG("FreeRTOS timer FIRED!\r\n");
|
||||
bsp_board_led_invert(BSP_BOARD_LED_1);
|
||||
}
|
||||
|
||||
void vTaskLogger(void *pvParameters) {
|
||||
UNUSED_VARIABLE(pvParameters);
|
||||
|
||||
for(;;) {
|
||||
NRF_LOG_FLUSH();
|
||||
vTaskSuspend(NULL);
|
||||
}
|
||||
}
|
||||
|
||||
void vApplicationIdleHook(void) {
|
||||
vTaskResume(xTaskLoggerHandle);
|
||||
}
|
|
@ -0,0 +1,28 @@
|
|||
/* Linker script to configure memory regions. */
|
||||
|
||||
SEARCH_DIR(.)
|
||||
GROUP(-lgcc -lc -lnosys)
|
||||
|
||||
MEMORY
|
||||
{
|
||||
FLASH (rx) : ORIGIN = 0x1b000, LENGTH = 0x25000 /* --- */
|
||||
RAM (rwx) : ORIGIN = 0x200013c8, LENGTH = 0x2c38 /* Nordic S130 SDS v2 */
|
||||
}
|
||||
|
||||
SECTIONS
|
||||
{
|
||||
.fs_data :
|
||||
{
|
||||
PROVIDE(__start_fs_data = .);
|
||||
KEEP(*(.fs_data))
|
||||
PROVIDE(__stop_fs_data = .);
|
||||
} > RAM
|
||||
.pwr_mgmt_data :
|
||||
{
|
||||
PROVIDE(__start_pwr_mgmt_data = .);
|
||||
KEEP(*(.pwr_mgmt_data))
|
||||
PROVIDE(__stop_pwr_mgmt_data = .);
|
||||
} > RAM
|
||||
} INSERT AFTER .data;
|
||||
|
||||
INCLUDE "nrf5x_common.ld"
|
|
@ -0,0 +1,46 @@
|
|||
#include <stdbool.h>
|
||||
#include <stdint.h>
|
||||
#include <stdio.h>
|
||||
|
||||
#include "nrf_drv_clock.h"
|
||||
|
||||
#include "bsp.h"
|
||||
|
||||
#define NRF_LOG_MODULE_NAME "MAIN"
|
||||
|
||||
#include "nrf_log.h"
|
||||
#include "nrf_log_ctrl.h"
|
||||
|
||||
#include "FreeRTOS.h"
|
||||
#include "task.h"
|
||||
#include "timers.h"
|
||||
#include "semphr.h"
|
||||
|
||||
#include "user_functions.h"
|
||||
|
||||
#include "user_tasks.h"
|
||||
|
||||
int main(void) {
|
||||
ret_code_t err_code;
|
||||
|
||||
err_code = nrf_drv_clock_init();
|
||||
APP_ERROR_CHECK(err_code);
|
||||
|
||||
bsp_board_leds_init();
|
||||
bsp_board_leds_off();
|
||||
|
||||
err_code = NRF_LOG_INIT(xTaskGetTickCount);
|
||||
APP_ERROR_CHECK(err_code);
|
||||
|
||||
NRF_LOG_INFO("Initializing platform\r\n");
|
||||
|
||||
SCB->SCR |= SCB_SCR_SLEEPDEEP_Msk;
|
||||
|
||||
init_tasks();
|
||||
|
||||
vTaskStartScheduler();
|
||||
|
||||
for(;;) {
|
||||
APP_ERROR_HANDLER(NRF_ERROR_FORBIDDEN);
|
||||
}
|
||||
}
|
|
@ -0,0 +1,24 @@
|
|||
#define NRF_LOG_MODULE_NAME "FUNCTION"
|
||||
|
||||
#include "nrf_log.h"
|
||||
#include "nrf_log_ctrl.h"
|
||||
|
||||
#include "FreeRTOS.h"
|
||||
#include "task.h"
|
||||
#include "semphr.h"
|
||||
#include "timers.h"
|
||||
|
||||
#include "user_config.h"
|
||||
#include "user_tasks.h"
|
||||
#include "user_functions.h"
|
||||
|
||||
uint32_t ble_new_event_handler(void) {
|
||||
BaseType_t yield_req = pdFALSE;
|
||||
UNUSED_VARIABLE(xSemaphoreGiveFromISR(xSemaphoreBLEEventReadyHandle, &yield_req));
|
||||
portYIELD_FROM_ISR(yield_req);
|
||||
return NRF_SUCCESS;
|
||||
}
|
||||
|
||||
void vApplicationIdleHook(void) {
|
||||
vTaskResume(xTaskLoggerHandle);
|
||||
}
|
|
@ -0,0 +1,80 @@
|
|||
#include "bsp.h"
|
||||
|
||||
#define NRF_LOG_MODULE_NAME "TASK"
|
||||
|
||||
#include "nrf_log.h"
|
||||
#include "nrf_log_ctrl.h"
|
||||
|
||||
|
||||
#include "FreeRTOS.h"
|
||||
#include "task.h"
|
||||
#include "semphr.h"
|
||||
|
||||
#include "user_functions.h"
|
||||
#include "user_tasks.h"
|
||||
|
||||
SemaphoreHandle_t xSemaphoreBLEEventReadyHandle = NULL;
|
||||
|
||||
void vTaskBlinkLED(void *pvParameters);
|
||||
void vTaskBLE(void *pvParameters);
|
||||
void vTaskLogger(void *pvParameters);
|
||||
|
||||
void init_tasks(void) {
|
||||
|
||||
xSemaphoreBLEEventReadyHandle = xSemaphoreCreateBinary();
|
||||
if(NULL == xSemaphoreBLEEventReadyHandle) {
|
||||
APP_ERROR_HANDLER(NRF_ERROR_NO_MEM);
|
||||
}
|
||||
|
||||
if(pdPASS != xTaskCreate(vTaskLogger, "TASKLOG0", 256, NULL, 1, &xTaskLoggerHandle)) {
|
||||
APP_ERROR_HANDLER(NRF_ERROR_NO_MEM);
|
||||
}
|
||||
|
||||
if(pdPASS != xTaskCreate(vTaskBlinkLED, "TASKBLINK0", 64, NULL, 2, &xTaskBlinkLEDHandle)) {
|
||||
APP_ERROR_HANDLER(NRF_ERROR_NO_MEM);
|
||||
}
|
||||
if(pdPASS != xTaskCreate(vTaskBLE, "TASKBLE0", 256, NULL, 2, &xTaskBLEHandle)) {
|
||||
APP_ERROR_HANDLER(NRF_ERROR_NO_MEM);
|
||||
}
|
||||
}
|
||||
|
||||
TaskHandle_t xTaskBlinkLEDHandle = NULL;
|
||||
void vTaskBlinkLED(void *pvParameters) {
|
||||
UNUSED_PARAMETER(pvParameters);
|
||||
|
||||
for(;;) {
|
||||
bsp_board_led_invert(BSP_BOARD_LED_0);
|
||||
NRF_LOG_INFO("Toggle LED 0\r\n");
|
||||
vTaskDelay(pdMS_TO_TICKS(1000));
|
||||
}
|
||||
}
|
||||
|
||||
TaskHandle_t xTaskBLEHandle = NULL;
|
||||
void vTaskBLE(void *pvParameters) {
|
||||
|
||||
NRF_LOG_INFO("Created BLE task, initialize softdevice handler\r\n");
|
||||
|
||||
nrf_clock_lf_cfg_t clock_lf_cfg = NRF_CLOCK_LFCLKSRC;
|
||||
SOFTDEVICE_HANDLER_INIT(&clock_lf_cfg, ble_new_event_handler);
|
||||
|
||||
NRF_LOG_INFO("Softdevice handler created, waiting for events\r\n");
|
||||
|
||||
for(;;) {
|
||||
while(pdFALSE == xSemaphoreTake(xSemaphoreBLEEventReadyHandle, portMAX_DELAY)) {
|
||||
//
|
||||
}
|
||||
NRF_LOG_INFO("BLE event occured!\r\n");
|
||||
intern_softdevice_events_execute();
|
||||
}
|
||||
}
|
||||
|
||||
/* System tasks below */
|
||||
TaskHandle_t xTaskLoggerHandle = NULL;
|
||||
void vTaskLogger(void *pvParameters) {
|
||||
UNUSED_VARIABLE(pvParameters);
|
||||
|
||||
for(;;) {
|
||||
NRF_LOG_FLUSH();
|
||||
vTaskSuspend(NULL);
|
||||
}
|
||||
}
|
Loading…
Reference in New Issue