int main( void )
{
    halInit();
    moduleInit();
    printf("\r\nWriting NV Items\r\n");
    result = moduleReset();
    if (result == MODULE_SUCCESS)
    {
        displaySysResetInd();  // Display the contents of the received SYS_RESET_IND message
    } else {
        printf("Module Reset ERROR 0x%02X\r\n", result);
    }
    debugConsoleIsr = &handleDebugConsoleInterrupt;   //call method handleDebugConsoleInterrupt() when a byte is received    
    HAL_ENABLE_INTERRUPTS();              //Enable Interrupts

    while (1)
    {
        uint8_t whichNvItem = getWhichNvItemToWrite();  
        if (whichNvItem != NO_CHARACTER_RECEIVED)
        {
            uint8_t nvItemSize = getNvItemSize(whichNvItem);
            printf("\r\nWriting to NV item %u, L%u:", whichNvItem, nvItemSize);    
            printHexBytes(dataToWrite, nvItemSize);
            result = sysNvWrite(whichNvItem, dataToWrite);
            if (result != MODULE_SUCCESS)
            {
                printf("sysNvWrite ERROR 0x%02X\r\n", result);
            }
        }
    }
}
int main( void )
{
    halInit();
    printf("NV Items:\r\n");
    znpInit();  
    while (1)
    {
                    printf("Reading NV Items from ZNP:\r\n");
        for (unsigned int itemNum = MIN_NV_ITEM; itemNum < (MAX_NV_ITEM+1); itemNum++)   //iterate through all NV items
        {
            unsigned char* buf = readNvItem(itemNum);
            if (znpResult == ZNP_SUCCESS)
            {
                printf("NV Item %u:", itemNum);
                for (int i=0; i<getNvItemSize(itemNum); i++)
                    printf("%02X(%c)", buf[i], buf[i]);
                printf("\r\n");
            }
            else
            {
                printf("ERROR %i\r\n", znpResult); 
            }
        }
        printf("\r\n");
        delayMs(1000);
    }
}
Example #3
0
/** Writes the specified Non-Volatile (NV) memory item to the ZNP. 
The contents of the selected nvItem will be overwritten from memory starting at data.
@pre ZNP was initialized.
@param nvItem which nvItem to write, 1 through 6 inclusive
@param data the data to write
@post znpResult contains the error code, or ZNP_SUCCESS if success.
*/
void writeNvItem(unsigned char nvItem, unsigned char* data)
{
    if ((nvItem < MIN_NV_ITEM) || (nvItem > MAX_NV_ITEM))
    {
        znpResult = -1;
        return;
    }   
    unsigned char nvItemSize = getNvItemSize(nvItem);
#ifdef ZNP_INTERFACE_VERBOSE
    printf("Writing NV Item %u (length %u) with data: ", nvItem, nvItemSize);
    printHexBytes(data, nvItemSize);
#endif      
    znpBuf[0] = SYS_OSAL_NV_WRITE_PAYLOAD_LEN + nvItemSize;
    znpBuf[1] = MSB(SYS_OSAL_NV_WRITE);
    znpBuf[2] = LSB(SYS_OSAL_NV_WRITE);  
    
    znpBuf[3] = nvItem;         //item number, 1-6
    znpBuf[4] = 0x0F;           //MSB of item number, but only items 1-6 are supported
    znpBuf[5] = 0;              //offset from beginning of the NV item, not used
    znpBuf[6] = nvItemSize;     //length
    
    memcpy(znpBuf+7, data, nvItemSize);
    znpResult = sendMessage();    
}