nrf51822_aqi_sensor_test/main.c

119 lines
2.7 KiB
C

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