Wirepas SDK
basic_interrupt/app.c
/* Copyright 2017 Wirepas Ltd. All Rights Reserved.
*
* See file LICENSE.txt for full license details.
*
*/
/*
* \file app.c
* \brief This application gives an example for a basic interrupt
* service. When it receives data on EP 12, it starts the
* internal temperature measure of the chip and send the
* result to a sink on EP 13
*/
#include "api.h"
#include <stdlib.h>
#include <string.h>
#include "shared_data.h"
#include "app_scheduler.h"
#include "mcu.h"
#define EXECUTION_TIME_US 500
#define GET_TEMPERATURE_EP 12
#define SEND_TEMPERATURE_EP 13
static uint32_t m_temperature = 0;
uint32_t send_temperature(void)
{
app_lib_data_to_send_t data_to_send = {
.bytes = (const uint8_t *) &m_temperature,
.num_bytes = sizeof(m_temperature),
.dest_address = APP_ADDR_ANYSINK,
.src_endpoint = SEND_TEMPERATURE_EP,
.dest_endpoint = SEND_TEMPERATURE_EP,
};
Shared_Data_sendData(&data_to_send, NULL);
}
static void temp_interrupt_handler(void)
{
NRF_TEMP->INTENCLR = 1;
if (NRF_TEMP->EVENTS_DATARDY != 0)
{
m_temperature = NRF_TEMP->TEMP;
}
else
{
m_temperature = 0;
}
// Add a task to send the temperature outside of interrup context
EXECUTION_TIME_US);
}
static app_lib_data_receive_res_e unicastDataReceivedCb(
const shared_data_item_t * item,
const app_lib_data_received_t * data )
{
m_temperature = 0;
NRF_TEMP->TASKS_START = 1;
NRF_TEMP->INTENSET = 1;
}
static shared_data_item_t unicast_packets_filter =
{
.cb = unicastDataReceivedCb,
.filter = {
/* Filtering by destination endpoint. */
.src_endpoint = -1,
.dest_endpoint = GET_TEMPERATURE_EP,
.multicast_cb = NULL
}
};
void App_init(const app_global_functions_t * functions)
{
// Basic configuration of the node with a unique node address
{
// Could not configure the node
// It should not happen except if one of the config value is invalid
return;
}
// Enable interrupt
lib_system->enableAppIrq(true, TEMP_IRQn, APP_LIB_SYSTEM_IRQ_PRIO_LO, temp_interrupt_handler);
// Register for unicast messages
Shared_Data_addDataReceivedCb(&unicast_packets_filter);
// Start the stack
lib_state->startStack();
}
Shared_Data_addDataReceivedCb
app_res_e Shared_Data_addDataReceivedCb(shared_data_item_t *item)
Add a new packet received item to the list. If the item is already in the list it is only updated.
node_configuration.h
APP_LIB_DATA_RECEIVE_RES_HANDLED
@ APP_LIB_DATA_RECEIVE_RES_HANDLED
Definition: wms_data.h:192
App_Scheduler_addTask_execTime
app_scheduler_res_e App_Scheduler_addTask_execTime(task_cb_f cb, uint32_t delay_ms, uint32_t exec_time_us)
Add a task.
APP_RES_OK
@ APP_RES_OK
Definition: wms_app.h:204
app_lib_data_receive_res_e
app_lib_data_receive_res_e
Return value of data reception callback.
Definition: wms_data.h:188
APP_LIB_SYSTEM_IRQ_PRIO_LO
#define APP_LIB_SYSTEM_IRQ_PRIO_LO
Definition: wms_system.h:55
app_scheduler.h
app_lib_data_to_send_t
A struct for lib_data->sendData().
Definition: wms_data.h:331
app_global_functions_t
List of global functions, passed to App_entrypoint()
Definition: wms_app.h:157
APP_LIB_DATA_QOS_HIGH
@ APP_LIB_DATA_QOS_HIGH
Definition: wms_data.h:91
configureNodeFromBuildParameters
__STATIC_INLINE app_res_e configureNodeFromBuildParameters()
Wrapper on top of configureNode to get parameters from build system and hardcoded values from chip (f...
Definition: node_configuration.h:233
app_lib_data_received_t
Struct passed to data reception callback functions.
Definition: wms_data.h:283
APP_ADDR_ANYSINK
@ APP_ADDR_ANYSINK
Definition: wms_app.h:236
shared_data.h
Shared_Data_sendData
app_lib_data_send_res_e Shared_Data_sendData(app_lib_data_to_send_t *data, app_lib_data_data_sent_cb_f sent_cb)
Send data. The packet to send is represented as a app_lib_data_to_send_t struct.
SHARED_DATA_NET_MODE_UNICAST
@ SHARED_DATA_NET_MODE_UNICAST
Definition: shared_data.h:42
app_lib_data_to_send_t::bytes
const uint8_t * bytes
Definition: wms_data.h:334
APP_SCHEDULER_SCHEDULE_ASAP
#define APP_SCHEDULER_SCHEDULE_ASAP
Value to return from task or as initial time to be executed ASAP.
Definition: app_scheduler.h:42
APP_LIB_SYSTEM_STOP_PERIODIC
#define APP_LIB_SYSTEM_STOP_PERIODIC
Constant to stop periodic callback.
Definition: wms_system.h:46
api.h