What does Zigbit WSNDemo BSP_Handler Do?

Go To Last Post
6 posts / 0 new
Author
Message
#1
  • 1
  • 2
  • 3
  • 4
  • 5
Total votes: 0

I read the example code of WSNDemo and get confused, Does anyone can help?

/**************************************************************************//**
  \brief Sensors data request.

  \param[in] sensorsGot - on sensors reading finished callback.

  \return None.
******************************************************************************/
void appGetSensorData(void (*sensorsGot)(void))
{
  callback = sensorsGot;
  assert(BC_SUCCESS == BSP_ReadTemperatureData(temperatureDataReady), BSPRESDSENSORDATAASSERT_0);
}

/**************************************************************************//**
  \brief Temperature reading done callback.

  \param[in] result - successful temperature reading flag.
  \param[in] temperature - result of temperature reading, if result is true.

  \return None.
******************************************************************************/
static void temperatureDataReady(bool result, int16_t temperature)
{
  if (result)
    appNwkInfo.boardInfo.meshbean.temperature = CPU_TO_LE32(temperature);
  else
    appNwkInfo.boardInfo.meshbean.temperature = CPU_TO_LE32(0);

  assert(BC_SUCCESS == BSP_ReadLightData(lightDataReady), BSPRESDSENSORDATAASSERT_1);
}

already put the sensor measurement data to message buffer, so what does BSP_Handler do?

for example

/**************************************************************************//**
\brief BSP task handler.
\ call bsplm73Handler in zigbit, should be  bspTemperatureSensorHandler
******************************************************************************/
void bspTemperatureSensorHandler(void)
//void bspLm73Handler(void)
{
  HAL_CloseI2cPacket(&desc); // free
  lm73State = IDLE;
  lm73Control.lm73Callback(lm73Control.lm73Result, lm73Control.lm73Data);
}

Thanks :D

Last Edited: Fri. Oct 16, 2015 - 01:46 PM
  • 1
  • 2
  • 3
  • 4
  • 5
Total votes: 0

BSP_TaskHandler() is what makes those BSP_ReadTemperatureData() and others work. First code snippet does not do actual measurement, BSP does.

NOTE: I no longer actively read this forum. Please ask your question on www.eevblog.com/forum if you want my answer.

  • 1
  • 2
  • 3
  • 4
  • 5
Total votes: 0

Thank you very much Alex,

in

void bspLm73Handler(void)
{
  HAL_CloseI2cPacket(&desc); // free
  lm73State = IDLE;
  lm73Control.lm73Callback(lm73Control.lm73Result, lm73Control.lm73Data);
}

function

  lm73Control.lm73Callback(lm73Control.lm73Result,lm73Control.lm73Data);

is

static void temperatureDataReady(bool result, int16_t temperature)

am I right?

  • 1
  • 2
  • 3
  • 4
  • 5
Total votes: 0

Correct.

NOTE: I no longer actively read this forum. Please ask your question on www.eevblog.com/forum if you want my answer.

  • 1
  • 2
  • 3
  • 4
  • 5
Total votes: 0

Thank you Alex,
the other question, in lm73.c


/**************************************************************************//**
\brief  Reads data from lm73 sensor.

\param[in]
    f - callback method.
\param[in]
    result - the result of the requested operation.
             true - operation finished successfully, false - some error has
             occured.
\param[in]
    data - sensor data.

\return
  BC_FAIL - the previous request was not completed,
            the address of callback is 0, i2c interface is busy,
            there is error on i2c interface. \n
  BC_SUCCESS - other case.
******************************************************************************/
result_t readLm73Data(void (*f)(bool result, int16_t data))
{
  if (IDLE != lm73State)
    return BC_FAIL;

  if (!f)
    return BC_FAIL;

  if (-1 == HAL_OpenI2cPacket(&desc))
    return BC_FAIL;
  lm73State = DATA;
  lm73Control.lm73Callback = f;                                                    //callback point to temperatureDataReady()

  if (-1 == HAL_ReadI2cPacket(&desc))
  {
    lm73State = IDLE;
    HAL_CloseI2cPacket(&desc);
    return BC_FAIL;
  }

  return BC_SUCCESS;
}

if read sensor smoothly, this function should return BC_SUCCESS,
BC_SUCCESS defined in Types.h


#define BC_SUCCESS false
#define BC_FAIL    true

that means this function return false.

in this way the callback function

/**************************************************************************//**
\brief  The notice on that the packet has been read.

\param[in]
  result - the result of operation
******************************************************************************/
static void lm73I2cPacketReadDone(bool result)
{
  int16_t i;

  lm73Control.lm73Result = result; // stores the result of operation
  if (false == lm73Control.lm73Result)
  { // there were some errors on the i2c interface
    lm73Control.lm73Data = 0;
    bspPostTask(BSP_TEMPERATURE);
    return;
  }

  if (DATA == lm73State)
  {
    i = (uint8_t)lm73Control.lm73Data;
    i <<= 8;
    i |= ((lm73Control.lm73Data >> 8) & 0x00FF);
    lm73Control.lm73Data = (i >> 7);
    bspPostTask(BSP_TEMPERATURE);
  }
}

lm73Control.data should always be 0 if I2C read correctly.

where is not correct in my thinking?

  • 1
  • 2
  • 3
  • 4
  • 5
Total votes: 0

It is quite possible that when this code was updates condition " if (false ==" was missed. This code was not tested in years, boards with this sensor have been out of production since 2008.

You don't really need all this complicated mess of callbacks. Just read the sensor directly from your application and forget this BSP even exist.

NOTE: I no longer actively read this forum. Please ask your question on www.eevblog.com/forum if you want my answer.