Comments related to the PN7150 NFC library

cancel
Showing results for 
Show  only  | Search instead for 
Did you mean: 

Comments related to the PN7150 NFC library

1,641 Views
naga
Contributor III

Hi,

I just managed to adapt the source code example for PN7150 for the EVK-RT1064 board and for the Arduino PN7150 board (source code: evkmimxrt1060_PN7150).

I used the latest versions of MCUxpresso IDE and FreeRTOS.

It was a lot of work but I would like to show you a simple example of the problem solved.

It's about the Sleep () function. This function is wrong and had to be adapted as in the example below:

void Sleep(unsigned int   ms)
{
   // SemaphoreHandle_t xSemaphore = NULL;

   // xSemaphore = xSemaphoreCreateBinary();
   // xSemaphoreTake( xSemaphore, portTICK_PERIOD_MS * ms);
   // vSemaphoreDelete(xSemaphore);

vTaskDelay ((ms * configTICK_RATE_HZ) / 1000);
}

What I do not like about this function is that a multiplication and division operation is required.

I will think of an optimization of it !!

Another simpler example is this:

vTaskDelay (ms / portTICK_PERIOD_MS );

Neculai

0 Kudos
4 Replies

1,244 Views
naga
Contributor III

Hi,

An optimal version of the solution is shown below.

Thus a first modification must be made in the tml.h file as below:

//#define TIMEOUT_INFINITE      0
//#define TIMEOUT_100MS        100
//#define TIMEOUT_1S               1000
//#define TIMEOUT_2S               2000

#define TIMEOUT_INFINITE        0
#define TIMEOUT_100MS           (100 / portTICK_PERIOD_MS)
#define TIMEOUT_1S                  (1000 / portTICK_PERIOD_MS)
#define TIMEOUT_2S                  (2000 / portTICK_PERIOD_MS)

The following modification is also required in the tml.c file:

static Status tml_WaitForRx(uint32_t timeout)
{
//if (xSemaphoreTake(IrqSem, (timeout==0)?(portMAX_DELAY):(portTICK_PERIOD_MS*timeout)) != pdTRUE) return ERROR;
if (xSemaphoreTake(IrqSem, (timeout==0)?(portMAX_DELAY):(timeout)) != pdTRUE) return ERROR;
return SUCCESS;
}

The whole project has been compiled with these changes and it works correctly.

The context is as follows:

- MCUXpresso IDE v11.1.0 (December 2019)
- FreeRTOS Kernel v10.2.1 (2019)
- NXP NCI library for PN7150 v1.5

Best regards,

Neculai

0 Kudos

1,244 Views
naga
Contributor III

Hi,

I found the same mistake in the tml.c file regarding the following function:

static Status tml_WaitForRx(uint32_t timeout)
{
  if (xSemaphoreTake(IrqSem, (timeout==0)?(portMAX_DELAY):(portTICK_PERIOD_MS*timeout)) != pdTRUE) return  ERROR;
  return SUCCESS;
}‍‍‍‍‍

In this function the variable "timeout" does not represent the real time expressed in milliseconds.

The correct variant is:

static Status tml_WaitForRx(uint32_t timeout)
{
  if (xSemaphoreTake(IrqSem, (timeout==0)?(portMAX_DELAY):(timeout/portTICK_PERIOD_MS)) != pdTRUE) return ERROR;
  return SUCCESS;
}

Best regards,

Neculai

ACK Fluid srl

naga@ack.ro

0 Kudos

1,244 Views
naga
Contributor III

Hello,

Below you can find two versions of the Sleep() function.

void Sleep(unsigned int ms)
{
unsigned int delay;

if(ms < (portTICK_PERIOD_MS << 1))     vTaskDelay(1);
else
  {
   delay = ms / portTICK_PERIOD_MS;    // division, time-consuming operation!!
   vTaskDelay(delay);
  }
}

#define TASK_DELAY_10MS     (10 / portTICK_PERIOD_MS)
#define TASK_DELAY_50MS     (50 / portTICK_PERIOD_MS)
#define TASK_DELAY_100MS   (100 / portTICK_PERIOD_MS)
#define TASK_DELAY_500MS   (500 / portTICK_PERIOD_MS)

void Sleep_opt(unsigned int delay)           //  optimized version
{
if(delay)    vTaskDelay(delay);
else          vTaskDelay(1);
}

Example:  Sleep_opt(TASK_DELAY_100MS) ;

Best regards,

Neculai

0 Kudos

1,244 Views
victorjimenez
NXP TechSupport
NXP TechSupport

Hello, Neculai 

This is great, Thanks for sharing it! 

You might find interesting the following community document: https://community.nxp.com/docs/DOC-341843 

Best regards, 

Victor 

0 Kudos