mirror of
https://github.com/espressif/openthread.git
synced 2026-09-30 21:07:39 +00:00
Dataset storage (#866)
* Store active dataset and pending dataset in non-volatile memory. * Retrieve active dataset and pending dataset from non-volatile memory after each reboot. * Leader will generate the active dataset if it is not initialized. * Clear pending dataset after it replaces active dataset. * Create different pseudo flash files for posix nodes.
This commit is contained in:
@@ -33,6 +33,7 @@
|
||||
*/
|
||||
|
||||
#include <platform/uart.h>
|
||||
#include <platform/flash.h>
|
||||
#include "platform-cc2538.h"
|
||||
|
||||
otInstance *sInstance;
|
||||
@@ -43,6 +44,7 @@ void PlatformInit(int argc, char *argv[])
|
||||
cc2538RandomInit();
|
||||
cc2538RadioInit();
|
||||
otPlatUartEnable();
|
||||
otPlatFlashInit();
|
||||
|
||||
(void)argc;
|
||||
(void)argv;
|
||||
|
||||
@@ -0,0 +1,59 @@
|
||||
/*
|
||||
* Copyright (c) 2016, The OpenThread Authors.
|
||||
* All rights reserved.
|
||||
*
|
||||
* Redistribution and use in source and binary forms, with or without
|
||||
* modification, are permitted provided that the following conditions are met:
|
||||
* 1. Redistributions of source code must retain the above copyright
|
||||
* notice, this list of conditions and the following disclaimer.
|
||||
* 2. Redistributions in binary form must reproduce the above copyright
|
||||
* notice, this list of conditions and the following disclaimer in the
|
||||
* documentation and/or other materials provided with the distribution.
|
||||
* 3. Neither the name of the copyright holder nor the
|
||||
* names of its contributors may be used to endorse or promote products
|
||||
* derived from this software without specific prior written permission.
|
||||
*
|
||||
* THIS SOFTWARE IS PROVIDED BY THE COPYRIGHT HOLDERS AND CONTRIBUTORS "AS IS"
|
||||
* AND ANY EXPRESS OR IMPLIED WARRANTIES, INCLUDING, BUT NOT LIMITED TO, THE
|
||||
* IMPLIED WARRANTIES OF MERCHANTABILITY AND FITNESS FOR A PARTICULAR PURPOSE
|
||||
* ARE DISCLAIMED. IN NO EVENT SHALL THE COPYRIGHT HOLDER OR CONTRIBUTORS BE
|
||||
* LIABLE FOR ANY DIRECT, INDIRECT, INCIDENTAL, SPECIAL, EXEMPLARY, OR
|
||||
* CONSEQUENTIAL DAMAGES (INCLUDING, BUT NOT LIMITED TO, PROCUREMENT OF
|
||||
* SUBSTITUTE GOODS OR SERVICES; LOSS OF USE, DATA, OR PROFITS; OR BUSINESS
|
||||
* INTERRUPTION) HOWEVER CAUSED AND ON ANY THEORY OF LIABILITY, WHETHER IN
|
||||
* CONTRACT, STRICT LIABILITY, OR TORT (INCLUDING NEGLIGENCE OR OTHERWISE)
|
||||
* ARISING IN ANY WAY OUT OF THE USE OF THIS SOFTWARE, EVEN IF ADVISED OF THE
|
||||
* POSSIBILITY OF SUCH DAMAGE.
|
||||
*/
|
||||
|
||||
#include "platform-posix.h"
|
||||
|
||||
ThreadError otPlatFlashInit(void)
|
||||
{
|
||||
return kThreadError_NotImplemented;
|
||||
}
|
||||
|
||||
uint32_t otPlatFlashGetSize(void)
|
||||
{
|
||||
return 0;
|
||||
}
|
||||
|
||||
ThreadError otPlatFlashErasePage(uint32_t aAddress)
|
||||
{
|
||||
return kThreadError_NotImplemented;
|
||||
}
|
||||
|
||||
ThreadError otPlatFlashStatusWait(uint32_t aTimeout)
|
||||
{
|
||||
return kThreadError_None;
|
||||
}
|
||||
|
||||
uint32_t otPlatFlashWrite(uint32_t aAddress, uint8_t *aData, uint32_t aSize)
|
||||
{
|
||||
return 0;
|
||||
}
|
||||
|
||||
uint32_t otPlatFlashRead(uint32_t aAddress, uint8_t *aData, uint32_t aSize)
|
||||
{
|
||||
return 0;
|
||||
}
|
||||
@@ -53,9 +53,12 @@ enum
|
||||
ThreadError otPlatFlashInit(void)
|
||||
{
|
||||
ThreadError error = kThreadError_None;
|
||||
char fileName[16];
|
||||
char fileName[20];
|
||||
struct stat st;
|
||||
bool create = false;
|
||||
struct timeval tv;
|
||||
|
||||
gettimeofday(&tv, NULL);
|
||||
|
||||
memset(&st, 0, sizeof(st));
|
||||
|
||||
@@ -64,7 +67,7 @@ ThreadError otPlatFlashInit(void)
|
||||
mkdir("tmp", 0777);
|
||||
}
|
||||
|
||||
snprintf(fileName, sizeof(fileName), "tmp/%d.flash", NODE_ID);
|
||||
snprintf(fileName, sizeof(fileName), "tmp/%d_%d.flash", NODE_ID, (uint32_t)tv.tv_usec);
|
||||
|
||||
if (access(fileName, 0))
|
||||
{
|
||||
|
||||
@@ -43,6 +43,7 @@
|
||||
|
||||
#include <openthread.h>
|
||||
#include <platform/alarm.h>
|
||||
#include <platform/flash.h>
|
||||
#include <platform/uart.h>
|
||||
|
||||
uint32_t NODE_ID = 1;
|
||||
@@ -68,6 +69,7 @@ void PlatformInit(int argc, char *argv[])
|
||||
platformAlarmInit();
|
||||
platformRadioInit();
|
||||
platformRandomInit();
|
||||
otPlatFlashInit();
|
||||
}
|
||||
|
||||
bool UartInitialized = false;
|
||||
|
||||
Reference in New Issue
Block a user