You cannot select more than 25 topics Topics must start with a letter or number, can include dashes ('-') and can be up to 35 characters long.
rail/plugin/rail_util_init/sl_rail_util_init.c.jinja

182 lines
8.3 KiB
Django/Jinja

/***************************************************************************//**
* @file
* @brief
*******************************************************************************
* # License
* <b>Copyright 2020 Silicon Laboratories Inc. www.silabs.com</b>
*******************************************************************************
*
* SPDX-License-Identifier: Zlib
*
* The licensor of this software is Silicon Laboratories Inc.
*
* This software is provided 'as-is', without any express or implied
* warranty. In no event will the authors be held liable for any damages
* arising from the use of this software.
*
* Permission is granted to anyone to use this software for any purpose,
* including commercial applications, and to alter it and redistribute it
* freely, subject to the following restrictions:
*
* 1. The origin of this software must not be misrepresented; you must not
* claim that you wrote the original software. If you use this software
* in a product, an acknowledgment in the product documentation would be
* appreciated but is not required.
* 2. Altered source versions must be plainly marked as such, and must not be
* misrepresented as being the original software.
* 3. This notice may not be removed or altered from any source distribution.
*
******************************************************************************/
#include "rail.h"
#include "rail_ble.h" // for RAIL_BLE_State_t
#include "sli_rail_util_callbacks.h" // for internal-only callback signatures
#include "sl_rail_util_init.h"
#include "sl_rail_util_protocol.h"
#include "sl_flex_assert.h"
#if 0U \
{%- for inst in rail_util_init_instance %}
|| SL_RAIL_UTIL_INIT_RADIO_CONFIG_SUPPORT_{{ inst | upper }}_ENABLE \
{%- endfor %}
|| 0U
#include "rail_config.h"
#endif
{%- for inst in rail_util_init_instance %}
// Instance: {{ inst | lower }}
static RAIL_Handle_t sl_rail_handle_{{ inst | lower }} = RAIL_EFR32_HANDLE;
#if SL_RAIL_UTIL_INIT_BLE_SUPPORT_{{ inst | upper }}_ENABLE
static RAIL_BLE_State_t sl_rail_ble_state_{{ inst | lower }}; // needed for BLE (ignored by others)
#endif // SL_RAIL_UTIL_INIT_BLE_SUPPORT_{{ inst | upper }}_ENABLE
#if SL_RAIL_UTIL_INIT_SCHEDULER_SUPPORT_{{ inst | upper }}_ENABLE
static RAILSched_Config_t sl_rail_sched_config_{{ inst | lower }};
#endif // SL_RAIL_UTIL_INIT_SCHEDULER_SUPPORT_{{ inst | upper }}_ENABLE
static RAIL_Config_t sl_rail_config_{{ inst | lower }} = {
.eventsCallback = &sli_rail_util_on_event,
#if SL_RAIL_UTIL_INIT_BLE_SUPPORT_{{ inst | upper }}_ENABLE
.protocol = &sl_rail_ble_state_{{ inst | lower }},
#endif // SL_RAIL_UTIL_INIT_BLE_SUPPORT_{{ inst | upper }}_ENABLE
#if SL_RAIL_UTIL_INIT_SCHEDULER_SUPPORT_{{ inst | upper }}_ENABLE
.scheduler = &sl_rail_sched_config_{{ inst | lower }},
#endif // SL_RAIL_UTIL_INIT_SCHEDULER_SUPPORT_{{ inst | upper }}_ENABLE
};
static void sl_rail_util_init_{{ inst | lower }}(void)
{
#if SL_RAIL_UTIL_INIT_{{ inst | upper }}_ENABLE
RAIL_Status_t status;
sl_rail_handle_{{ inst | lower }} = RAIL_Init(&sl_rail_config_{{ inst | lower }},
#if SL_RAIL_UTIL_INIT_INIT_COMPLETE_CALLBACK_{{ inst | upper }}_ENABLE
&sli_rail_util_on_rf_ready
#else
NULL
#endif // SL_RAIL_UTIL_INIT_INIT_COMPLETE_CALLBACK_{{ inst | upper }}_ENABLE
);
APP_ASSERT((NULL != sl_rail_handle_{{ inst | lower }}),
"RAIL_Init failed, return value: NULL");
#if SL_RAIL_UTIL_INIT_DATA_FORMATS_{{ inst | upper }}_ENABLE
RAIL_DataConfig_t data_config = {
.txSource = SL_RAIL_UTIL_INIT_DATA_FORMAT_{{ inst | upper }}_TX_SOURCE,
.rxSource = SL_RAIL_UTIL_INIT_DATA_FORMAT_{{ inst | upper }}_RX_SOURCE,
.txMethod = SL_RAIL_UTIL_INIT_DATA_FORMAT_{{ inst | upper }}_TX_MODE,
.rxMethod = SL_RAIL_UTIL_INIT_DATA_FORMAT_{{ inst | upper }}_RX_MODE,
};
status = RAIL_ConfigData(sl_rail_handle_{{ inst | lower }}, &data_config);
APP_ASSERT((RAIL_STATUS_NO_ERROR == status),
"RAIL_ConfigData failed, return value: %d",
status);
#endif // SL_RAIL_UTIL_INIT_DATA_FORMATS_{{ inst | upper }}_ENABLE
#if SL_RAIL_UTIL_INIT_PROTOCOLS_{{ inst | upper }}_ENABLE
const RAIL_ChannelConfig_t *channel_config = NULL;
if (SL_RAIL_UTIL_INIT_PROTOCOL_{{ inst | upper }}_DEFAULT
== SL_RAIL_UTIL_PROTOCOL_PROPRIETARY) {
#if SL_RAIL_UTIL_INIT_RADIO_CONFIG_SUPPORT_{{ inst | upper }}_ENABLE
channel_config = channelConfigs[SL_RAIL_UTIL_INIT_PROTOCOL_PROPRIETARY_{{ inst | upper }}_INDEX];
#else // !SL_RAIL_UTIL_INIT_RADIO_CONFIG_SUPPORT_{{ inst | upper }}_ENABLE
APP_ASSERT(false,
"SL_RAIL_UTIL_INIT_RADIO_CONFIG_SUPPORT_{{ inst | upper }}_ENABLE must be true when (SL_RAIL_UTIL_INIT_PROTOCOL_{{ inst | upper }}_DEFAULT == SL_RAIL_UTIL_PROTOCOL_PROPRIETARY)");
#endif // SL_RAIL_UTIL_INIT_RADIO_CONFIG_SUPPORT_{{ inst | upper }}_ENABLE
}
(void) RAIL_ConfigChannels(sl_rail_handle_{{ inst | lower }},
channel_config,
&sli_rail_util_on_channel_config_change);
status = sl_rail_util_protocol_config(sl_rail_handle_{{ inst | lower }},
SL_RAIL_UTIL_INIT_PROTOCOL_{{ inst | upper }}_DEFAULT);
APP_ASSERT((RAIL_STATUS_NO_ERROR == status),
"sl_rail_util_protocol_config failed, return value: %d",
status);
#endif // SL_RAIL_UTIL_INIT_PROTOCOLS_{{ inst | upper }}_ENABLE
#if SL_RAIL_UTIL_INIT_CALIBRATIONS_{{ inst | upper }}_ENABLE
status = RAIL_ConfigCal(sl_rail_handle_{{ inst | lower }},
0U
| (SL_RAIL_UTIL_INIT_CALIBRATION_TEMPERATURE_NOTIFY_{{ inst | upper }}_ENABLE
? RAIL_CAL_TEMP : 0U)
| (SL_RAIL_UTIL_INIT_CALIBRATION_ONETIME_NOTIFY_{{ inst | upper }}_ENABLE
? RAIL_CAL_ONETIME : 0U));
APP_ASSERT((RAIL_STATUS_NO_ERROR == status),
"RAIL_ConfigCal failed, return value: %d",
status);
#endif // SL_RAIL_UTIL_INIT_CALIBRATIONS_{{ inst | upper }}_ENABLE
#if SL_RAIL_UTIL_INIT_EVENTS_{{ inst | upper }}_ENABLE
status = RAIL_ConfigEvents(sl_rail_handle_{{ inst | lower }},
RAIL_EVENTS_ALL,
SL_RAIL_UTIL_INIT_EVENT_{{ inst | upper }}_MASK);
APP_ASSERT((RAIL_STATUS_NO_ERROR == status),
"RAIL_ConfigEvents failed, return value: %d",
status);
#endif // SL_RAIL_UTIL_INIT_EVENTS_{{ inst | upper }}_ENABLE
#if SL_RAIL_UTIL_INIT_TRANSITIONS_{{ inst | upper }}_ENABLE
RAIL_StateTransitions_t tx_transitions = {
.success = SL_RAIL_UTIL_INIT_TRANSITION_{{ inst | upper }}_TX_SUCCESS,
.error = SL_RAIL_UTIL_INIT_TRANSITION_{{ inst | upper }}_TX_ERROR
};
RAIL_StateTransitions_t rx_transitions = {
.success = SL_RAIL_UTIL_INIT_TRANSITION_{{ inst | upper }}_RX_SUCCESS,
.error = SL_RAIL_UTIL_INIT_TRANSITION_{{ inst | upper }}_RX_ERROR
};
status = RAIL_SetTxTransitions(sl_rail_handle_{{ inst | lower }},
&tx_transitions);
APP_ASSERT((RAIL_STATUS_NO_ERROR == status),
"RAIL_SetTxTransitions failed, return value: %d",
status);
status = RAIL_SetRxTransitions(sl_rail_handle_{{ inst | lower }},
&rx_transitions);
APP_ASSERT((RAIL_STATUS_NO_ERROR == status),
"RAIL_SetRxTransitions failed, return value: %d",
status);
#endif // SL_RAIL_UTIL_INIT_TRANSITIONS_{{ inst | upper }}_ENABLE
#else // !SL_RAIL_UTIL_INIT_{{ inst | upper }}_ENABLE
// Eliminate compiler warnings.
(void) sl_rail_handle_{{ inst | lower }};
(void) sl_rail_config_{{ inst | lower }};
#endif // SL_RAIL_UTIL_INIT_{{ inst | upper }}_ENABLE
}
{%- endfor %}
RAIL_Handle_t sl_rail_util_get_handle(sl_rail_util_handle_type_t handle)
{
RAIL_Handle_t *sl_rail_handle_array[] = {
{%- for inst in rail_util_init_instance %}
&sl_rail_handle_{{ inst | lower }},
{%- endfor %}
};
return *sl_rail_handle_array[handle];
}
void sl_rail_util_init(void)
{
{%- for inst in rail_util_init_instance %}
sl_rail_util_init_{{ inst | lower }}();
{%- endfor %}
}
#if !SL_RAIL_LIB_MULTIPROTOCOL_SUPPORT && ((0{%- for inst in rail_util_init_instance %} + 1{%- endfor %}) > 1)
#error "sl_rail_util_init.c: If you are going to use more than one rail_util_init instance, you must use the Multiprotocol RAIL library."
#endif