Port the radio_test sample to the Coprocessor sample to test the radio_test function error
How do I merge the two examples
I was hoping you could help me out
many thanks
Port the radio_test sample to the Coprocessor sample to test the radio_test function error
How do I merge the two examples
I was hoping you could help me out
many thanks
Hi
I don't see what the issue here is. What are you expecting to receive on the RX side here? I think having such a large timeslot might cause issues on the Thread side if there are time critical tasks to take care of, but if it's only to be a thread node for example I think it should be fine.
Best regards,
Simon
Hi
I want the RX port to always print F0,I configured the enum transmit_pattern pattern = TRANSMIT_PATTERN_11110000 in the radio_tx function.
Today, I solved this problem with the following code, causing the OpenThread test to fail.Using the Wpantund tool to test OpenThread, I think this has something to do with timeslot taking up time all the time. Is there any suggestion for modification.
#include <kernel.h>
#include <console/console.h>
#include <string.h>
#include <sys/printk.h>
#include <zephyr/types.h>
#include <irq.h>
#include <mpsl_timeslot.h>
#include <mpsl.h>
#include <hal/nrf_timer.h>
#include <shell/shell_uart.h>
#include <drivers/uart.h>
#include <init.h>
#define TIMESLOT_REQUEST_DISTANCE_US (1000000)
#define TIMESLOT_LENGTH_US (20000)
#define TIMER_EXPIRY_US (TIMESLOT_LENGTH_US - 50)
#define MPSL_THREAD_PRIO CONFIG_MPSL_THREAD_COOP_PRIO
#define STACKSIZE CONFIG_MAIN_STACK_SIZE
#define THREAD_PRIORITY K_LOWEST_APPLICATION_THREAD_PRIO
extern void radio_tx(void);
static uint32_t extension_count;
/* MPSL API calls that can be requested for the non-preemptible thread */
enum mpsl_timeslot_call {
OPEN_SESSION,
MAKE_REQUEST,
CLOSE_SESSION,
};
/* Timeslot requests */
static mpsl_timeslot_request_t timeslot_request_earliest = {
.request_type = MPSL_TIMESLOT_REQ_TYPE_EARLIEST,
//.params.earliest.hfclk = MPSL_TIMESLOT_HFCLK_CFG_NO_GUARANTEE,
.params.normal.hfclk = MPSL_TIMESLOT_HFCLK_CFG_XTAL_GUARANTEED,
//.params.earliest.priority = MPSL_TIMESLOT_PRIORITY_NORMAL,
.params.normal.priority = MPSL_TIMESLOT_PRIORITY_HIGH,
.params.earliest.length_us = TIMESLOT_LENGTH_US,
.params.earliest.timeout_us = 1000000
};
static mpsl_timeslot_request_t timeslot_request_normal = {
.request_type = MPSL_TIMESLOT_REQ_TYPE_NORMAL,
//.params.normal.hfclk = MPSL_TIMESLOT_HFCLK_CFG_NO_GUARANTEE,
.params.normal.hfclk = MPSL_TIMESLOT_HFCLK_CFG_XTAL_GUARANTEED,
//.params.normal.priority = MPSL_TIMESLOT_PRIORITY_NORMAL,
.params.normal.priority = MPSL_TIMESLOT_PRIORITY_HIGH,
.params.normal.distance_us = TIMESLOT_REQUEST_DISTANCE_US,
.params.normal.length_us = TIMESLOT_LENGTH_US
};
static mpsl_timeslot_signal_return_param_t signal_callback_return_param;
/* Message queue for printing the signal type from timeslot callback */
//K_MSGQ_DEFINE(callback_msgq, sizeof(uint32_t), 100, 4);
/* Message queue for requesting MPSL API calls to non-preemptible thread */
K_MSGQ_DEFINE(mpsl_api_msgq, sizeof(enum mpsl_timeslot_call), 10, 4);
static void error(void)
{
printk("ERROR!\n");
while (true) {
/* Spin for ever */
k_sleep(K_MSEC(1000));
}
}
static mpsl_timeslot_signal_return_param_t *mpsl_timeslot_callback(
mpsl_timeslot_session_id_t session_id,
uint32_t signal_type)
{
//printk("sig=%d\n",signal_type);
(void) session_id; /* unused parameter */
mpsl_timeslot_signal_return_param_t *p_ret_val = NULL;
switch (signal_type) {
case MPSL_TIMESLOT_SIGNAL_START:
/* No return action */
printk("START11\n");
// if(tx_flag==1)
// {
//printk("start radio_tx\n");
radio_tx();//Fixed parameter Radio tx function
// }
//NRF_RADIO->POWER = (RADIO_POWER_POWER_Enabled << RADIO_POWER_POWER_Pos);
//NVIC_EnableIRQ(RADIO_IRQn);
signal_callback_return_param.callback_action =
MPSL_TIMESLOT_SIGNAL_ACTION_NONE;
p_ret_val = &signal_callback_return_param;
/* Setup timer to trigger an interrupt (and thus the TIMER0
* signal) before timeslot end.
*/
nrf_timer_cc_set(NRF_TIMER0, NRF_TIMER_CC_CHANNEL0,
TIMER_EXPIRY_US);
nrf_timer_int_enable(NRF_TIMER0, NRF_TIMER_INT_COMPARE0_MASK);
break;
case MPSL_TIMESLOT_SIGNAL_RADIO:
break;
case MPSL_TIMESLOT_SIGNAL_TIMER0:
/* Clear event */
/* Request new timeslot when callback returns */
if (extension_count)
{
extension_count--;
signal_callback_return_param.params.extend.length_us = TIMESLOT_LENGTH_US;
signal_callback_return_param.callback_action = MPSL_TIMESLOT_SIGNAL_ACTION_EXTEND; //End the current timeslot and request a new one
}
else
{
signal_callback_return_param.callback_action = MPSL_TIMESLOT_SIGNAL_ACTION_END; //End the current timeslot and request a new one
}
p_ret_val = &signal_callback_return_param;
break;
case MPSL_TIMESLOT_SIGNAL_EXTEND_FAILED:
signal_callback_return_param.params.request.p_next = ×lot_request_earliest;
signal_callback_return_param.callback_action = MPSL_TIMESLOT_SIGNAL_ACTION_EXTEND;
p_ret_val = &signal_callback_return_param;
break;
break;
case MPSL_TIMESLOT_SIGNAL_EXTEND_SUCCEEDED:
NRF_TIMER0->EVENTS_COMPARE[0]=0;
NRF_TIMER0->TASKS_CLEAR = 1;
//signal_callback_return_param.params.request.p_next = ×lot_request_normal;
signal_callback_return_param.callback_action = MPSL_TIMESLOT_SIGNAL_ACTION_EXTEND;
p_ret_val = &signal_callback_return_param;
break;
case MPSL_TIMESLOT_SIGNAL_SESSION_IDLE:
break;
case MPSL_TIMESLOT_SIGNAL_SESSION_CLOSED:
break;
default:
printk("unexpected signal: %u", signal_type);
//error();
break;
}
return p_ret_val;
}
void mpsl_timeslot_demo(void)
{
int err;
enum mpsl_timeslot_call api_call;
extension_count = 1000;
api_call = OPEN_SESSION;
err = k_msgq_put(&mpsl_api_msgq, &api_call, K_FOREVER);
if (err) {
error();
}
api_call = MAKE_REQUEST;
err = k_msgq_put(&mpsl_api_msgq, &api_call, K_FOREVER);
if (err) {
printk("198error\n");
error();
}
}
/* To ensure thread safe operation, call all MPSL APIs from a non-preemptible
* thread.
*/
static void mpsl_nonpreemptible_thread(void)
{
int err;
enum mpsl_timeslot_call api_call = 0;
/* Initialize to invalid session id */
mpsl_timeslot_session_id_t session_id = 0xFFu;
while (1) {
if (k_msgq_get(&mpsl_api_msgq, &api_call, K_FOREVER) == 0) {
switch (api_call) {
case OPEN_SESSION:
err = mpsl_timeslot_session_open(
mpsl_timeslot_callback,
&session_id);
if (err) {
error();
}
break;
case MAKE_REQUEST:
err = mpsl_timeslot_request(
session_id,
×lot_request_earliest);
if (err) {
printk("237error\n");
error();
}
break;
case CLOSE_SESSION:
err = mpsl_timeslot_session_close(session_id);
if (err) {
error();
}
break;
default:
error();
break;
}
}
}
}
K_THREAD_DEFINE(mpsl_nonpreemptible_thread_id, STACKSIZE,
mpsl_nonpreemptible_thread, NULL, NULL, NULL,
K_PRIO_COOP(MPSL_THREAD_PRIO), 0, 0);
Best regards,
Ethan.Shi
Hi Ethan
I need some more information on what exactly is failing in your OpenThread test, as it's hard to tell what's causing this error by just looking at your main file. I would suggest making the timeslots smaller however, to see if that helps at all.
Best regards,
Simon
Hi
I'm sorry,The previous description might have been confusing.Ignore the previous code.
I am currently working on merging the radio_test sample with the Coprocessor sample,I think timeslot can accomplish this task. I want to be free from the influence of OpenThread when conducting radio test.
I plan to extend timeslot to realize radio test normally. The delay process always receives the signal MPSL_TIMESLOT_SIGNAL_SESSION_IDLE and will not continue to delay. Is there any example of extending timeslot? The other examples I refer to are too old.
Best regards,
Ethan
Hi
I'm sorry,The previous description might have been confusing.Ignore the previous code.
I am currently working on merging the radio_test sample with the Coprocessor sample,I think timeslot can accomplish this task. I want to be free from the influence of OpenThread when conducting radio test.
I plan to extend timeslot to realize radio test normally. The delay process always receives the signal MPSL_TIMESLOT_SIGNAL_SESSION_IDLE and will not continue to delay. Is there any example of extending timeslot? The other examples I refer to are too old.
Best regards,
Ethan