Compare commits

...

2 Commits

Author SHA1 Message Date
imi415 5912e3de77
Enable Softdevice, This application is for xxAC now. 2020-09-17 00:58:48 +08:00
imi415 a6f724b51a
Using Softdevice S130 2020-09-17 00:39:49 +08:00
10 changed files with 219 additions and 125 deletions

View File

@ -6,11 +6,13 @@ SDK_ROOT := $(PWD)/../../nRF_SDK/nRF5_SDK_12.3.0_d7731ad
PROJ_DIR := $(PWD)
$(OUTPUT_DIRECTORY)/nrf51822_xxaa.out: \
LINKER_SCRIPT := nrf51_xxaa_softdevice.ld
LINKER_SCRIPT := nrf51_xxac_softdevice.ld
# 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)

View File

@ -99,7 +99,7 @@
#define configTICK_RATE_HZ 1000
#define configMAX_PRIORITIES ( 3 )
#define configMINIMAL_STACK_SIZE ( 60 )
#define configTOTAL_HEAP_SIZE ( 4096 )
#define configTOTAL_HEAP_SIZE ( 8192 )
#define configMAX_TASK_NAME_LEN ( 4 )
#define configUSE_16_BIT_TICKS 0
#define configIDLE_SHOULD_YIELD 1

8
include/user_config.h Normal file
View File

@ -0,0 +1,8 @@
#ifndef __USER_CONFIG_H
#define __USER_CONFIG_H
#define APP_TIMER_PRESCALER 0 /**< Value of the RTC1 PRESCALER register. */
#define CENTRAL_LINK_COUNT 0 /**< Number of central links used by the application. When changing this number remember to adjust the RAM settings*/
#define PERIPHERAL_LINK_COUNT 1 /**< Number of peripheral links used by the application. When changing this number remember to adjust the RAM settings*/
#endif

6
include/user_functions.h Normal file
View File

@ -0,0 +1,6 @@
#ifndef __USER_FUNCTIONS_H
#define __USER_FUNCTIONS_H
uint32_t ble_new_event_handler(void);
#endif

12
include/user_tasks.h Normal file
View File

@ -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
View File

@ -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);
}

28
nrf51_xxaa_softdevice.ld Normal file
View File

@ -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 = 0x20001fe8, LENGTH = 0x2018 /* 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"

46
src/main.c Normal file
View File

@ -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);
}
}

24
src/user_functions.c Normal file
View File

@ -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);
}

89
src/user_tasks.c Normal file
View File

@ -0,0 +1,89 @@
#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_config.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", 128, 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);
ble_enable_params_t ble_enable_params;
uint32_t err_code = softdevice_enable_get_default_config(CENTRAL_LINK_COUNT, PERIPHERAL_LINK_COUNT, &ble_enable_params);
APP_ERROR_CHECK(err_code);
CHECK_RAM_START_ADDR(CENTRAL_LINK_COUNT, PERIPHERAL_LINK_COUNT);
err_code = softdevice_enable(&ble_enable_params);
APP_ERROR_CHECK(err_code);
NRF_LOG_INFO("Softdevice enabled, 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);
}
}