Example #1
0
/** Public method to send messages to the Module. This will send one message and then receive the 
Synchronous Response (SRSP) message from the Module to indicate the command was received.
@pre zmBuf contains a properly formatted message
@pre Module has been initialized
@post buffer zmBuf contains the response (if any) from the Module. 
*/
moduleResult_t sendMessage()
{
#ifdef ZM_PHY_SPI_VERBOSE    
  printf("Tx: ");
  printHexBytes(zmBuf, zmBuf[0] + 3);
#endif    
  
  uint8_t expectedSrspCmdMsb = zmBuf[1] + SRSP_OFFSET;    //store these so we can compare with what is returned
  uint8_t expectedSrspCmdLsb = zmBuf[2];
  
  moduleResult_t result = sendSreq();                     //send message, buffer now holds received data
  
  if (result != MODULE_SUCCESS)                           //ERROR - sendSreq() timeout
  {
#ifdef ZM_PHY_SPI_VERBOSE_ERRORS    
    printf("ERROR - sreq() timeout %02X\r\n", result);
#endif 
    return result;
  }
  
  /* The correct SRSP will always be 0x4000 + cmd, or simpler 0x4000 | cmd
  For example, if the SREQ is 0x2605 then the corresponding SRSP is 0x6605 */
  if ((zmBuf[SRSP_CMD_MSB_FIELD] == expectedSrspCmdMsb) && (zmBuf[SRSP_CMD_LSB_FIELD] == expectedSrspCmdLsb))    //verify the correct SRSP was received
  {
    return MODULE_SUCCESS;
  } else {
#ifdef ZM_PHY_SPI_VERBOSE_ERRORS    
    printf("ERROR - Wrong SRSP - received %02X-%02X, expected %02X-%02X\r\n", zmBuf[1], zmBuf[2],expectedSrspCmdMsb,expectedSrspCmdLsb);
#endif          
    return ZM_PHY_INCORRECT_SRSP;   //Wrong SRSP received
  }
}
/** Public method to send messages to the ZNP. This will send one message and then receive the 
Synchronous Response (SRSP) message from the ZNP to indicate the command was received.
@pre znpBuf contains a properly formatted message
@pre ZNP has been initialized
@post buffer znpBuf contains the response (if any) from the ZNP.
@return 0 if the SRSP received was the expected SRSP, -11 if it was NOT the expected SRSP, 
-12 if sendSreq timeout, or -13 if too many bytes received. 
*/
signed int sendMessage()
{
#ifdef ZNP_INTERFACE_SPI_VERBOSE    
    printf("Tx: ");
    printHexBytes(znpBuf, znpBuf[0] + 3);
#endif    
    
    unsigned char expectedSrspCmdMsb = znpBuf[1] + 0x40;
    unsigned char expectedSrspCmdLsb = znpBuf[2];

    signed int result = sendSreq(); //send message, buffer now holds received data
    
    if (result != 0)                            //ERROR - spiSreq() timeout
    {
        #ifdef ZNP_INTERFACE_SPI_VERBOSE    
        printf("ERROR - sreq() timeout %i\r\n", result);
        #endif 
        return -12;
    }
    if (znpBuf[0] > SRSP_BUFFER_SIZE)           //Error - SRSP length exceeds buffer size
    {
        #ifdef ZNP_INTERFACE_SPI_VERBOSE    
        printf("ERROR - SRSP too long %u > %u\r\n", znpBuf[0], SRSP_BUFFER_SIZE);
        #endif         
        return -13;
    }

    //The correct SRSP will always be 0x4000 + cmd, or simpler 0x4000 | cmd
    //For example, if the SREQ is 0x2605 then the corresponding SRSP is 0x6605
    if ((znpBuf[1] == expectedSrspCmdMsb) && (znpBuf[2] == expectedSrspCmdLsb))    //verify the correct SRSP was received
        return 0;
    else
    {
        #ifdef ZNP_INTERFACE_SPI_VERBOSE    
        printf("ERROR - Wrong SRSP - received %02X-%02X, expected %02X-%02X\r\n", znpBuf[1], znpBuf[2],expectedSrspCmdMsb,expectedSrspCmdLsb);
        #endif          
        return -11;   //Wrong SRSP received
        
    }
}
Example #3
0
/** Reset the ZNP and then get the MAC. */
int main( void )
{
    halInit();                          //Initialize hardware
    halSpiInitZnp();
    printf("Resetting ZNP to get MAC address\r\n");
    RADIO_OFF();
    delayMs(1);
    RADIO_ON();
    spiPoll();
    for (int i=0; i< (znpBuf[0] + 3); i++)
        printf("%02X ", znpBuf[i]);
    printf("\r\n");
    
    znpBuf[0] = 1;      //ZB_GET_DEVICE_INFO_PAYLOAD_LEN;
    znpBuf[1] = 0x26;   //MSB(ZB_GET_DEVICE_INFO);
    znpBuf[2] = 0x06;   //LSB(ZB_GET_DEVICE_INFO);
    znpBuf[3] = 1;      //DIP_MAC_ADDRESS;
    sendSreq();
    printf("MAC Address, LSB first:");
    for (int i=4; i< (znpBuf[0] + 3); i++)
        printf("%02X ", znpBuf[i]);
    printf("\r\n");
}
Example #4
0
//moduleResult_t spiPoll()
moduleResult_t getMessage()
{
  *zmBuf = 0; *(zmBuf+1) = 0; *(zmBuf+2) = 0;  //poll message is 0,0,0 
  return(sendSreq());
}
Example #5
0
/** From znp_interface_spi.c */
signed int spiPoll()
{
    *znpBuf = 0; *(znpBuf+1) = 0; *(znpBuf+2) = 0;  //poll message is 0,0,0 
    return(sendSreq());
}