Skip to content

Commit

Permalink
Added App/Tool/Example for usage of additional flash on econotag/mc1322x
Browse files Browse the repository at this point in the history
  • Loading branch information
Lars Schmertmann committed Sep 14, 2015
1 parent 552408b commit 46ffc50
Show file tree
Hide file tree
Showing 14 changed files with 1,124 additions and 0 deletions.
1 change: 1 addition & 0 deletions .travis.yml
Original file line number Diff line number Diff line change
Expand Up @@ -36,6 +36,7 @@ before_script:
tar xjf arm-2008q3*.tar.bz2 -C /tmp/ &&
sudo cp -f -r /tmp/arm-2008q3/* /usr/ &&
rm -rf /tmp/arm-2008q3 arm-2008q3*.tar.bz2 &&
sudo apt-get -qq install libconfig-dev uuid-dev libqrencode-dev &&
arm-none-eabi-gcc --version ;
fi

Expand Down
31 changes: 31 additions & 0 deletions examples/econotag-flash-test/Makefile
Original file line number Diff line number Diff line change
@@ -0,0 +1,31 @@
CONTIKI = ../..
LIBMC1322X = ../../../libmc1322x

CONTIKI_PROJECT = econotag-flash-test
TARGET = econotag
CLEAN = *.d $(CONTIKI_PROJECT)_e_$(TARGET).bin $(CONTIKI_PROJECT)_e_$(TARGET).txt $(CONTIKI_PROJECT)_e_$(TARGET).pbm

all: $(CONTIKI_PROJECT) blast

CFLAGS += -DFLASH_CONF_B1=30
CFLAGS += -DFLASH_CONF_B2=10

APPS += flash

flash:
$(LIBMC1322X)/tools/mc1322x-load \
-f $(LIBMC1322X)/tests/flasher_$(TARGET).bin \
-s $(CONTIKI_PROJECT)_e_$(TARGET).bin \
-c 'sudo $(LIBMC1322X)/tools/ftditools/bbmc -l $(TARGET) -i 0 reset' \
-t /dev/ttyUSB1 -l

clear:
$(LIBMC1322X)/tools/ftditools/bbmc -l $(TARGET) -i 0 erase

blast: $(CONTIKI)/tools/blaster/blaster
$(CONTIKI)/tools/blaster/blaster $(CONTIKI_PROJECT).cfg

$(CONTIKI)/tools/blaster/blaster: $(CONTIKI)/tools/blaster/blaster.c
(cd $(CONTIKI)/tools/blaster && $(MAKE))

include $(CONTIKI)/Makefile.include
6 changes: 6 additions & 0 deletions examples/econotag-flash-test/README
Original file line number Diff line number Diff line change
@@ -0,0 +1,6 @@
Its important to use -l as a flash parameter for mc1322xload.

Use "make flash" to start upload. Maybe u need
to change the location of libmc1322x in Makefile.

With "make clear" you can erase all flash data.
195 changes: 195 additions & 0 deletions examples/econotag-flash-test/econotag-flash-test.c
Original file line number Diff line number Diff line change
@@ -0,0 +1,195 @@
/*
* Copyright (c) 2014, Lars Schmertmann <[email protected]>.
* 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.
*
* This file is part of the Contiki operating system.
*
*/

/**
* \file
* Flash test
*
* This file contains tests for econotag flash app
*
* \author
* Lars Schmertmann <[email protected]>
*/

#include "flash.h"
#include "contiki.h"

#include <stdio.h>
#include <stdint.h>
#include <string.h>

#include "../../tools/blaster/blaster.h"
#include "econotag-flash-test.h"

void
output_result(uint32_t i, uint32_t fail)
{
if(fail) {
printf(" Test %u failed!\n", i);
} else { printf(" Test %u succeed!\n", i);
}
}
void
test_flash_1()
{
uint8_t buffer[12];
uint32_t check_int, my_int = 12345678;

flash_setVar("Hello World!", RES_MY_STRING_1, LEN_MY_STRING_1);

flash_getVar(buffer, RES_MY_STRING_1, LEN_MY_STRING_1);
output_result(1, memcmp(buffer, "Hello World!", 12));

flash_setVar("Heureka!", RES_MY_STRING_2, LEN_MY_STRING_2);

flash_getVar(buffer, RES_MY_STRING_1, LEN_MY_STRING_1);
output_result(2, memcmp(buffer, "Hello World!", 12));

flash_getVar(buffer, RES_MY_STRING_2, LEN_MY_STRING_2);
output_result(3, memcmp(buffer, "Heureka!", 8));

flash_setVar(&my_int, RES_MY_INTEGER, LEN_MY_INTEGER);

flash_getVar(&check_int, RES_MY_INTEGER, LEN_MY_INTEGER);
output_result(4, check_int != my_int);

flash_getVar(buffer, RES_MY_STRING_1, LEN_MY_STRING_1);
output_result(5, memcmp(buffer, "Hello World!", 12));

flash_getVar(buffer, RES_MY_STRING_2, LEN_MY_STRING_2);
output_result(6, memcmp(buffer, "Heureka!", 8));
}
void
test_flash_2()
{
uint8_t buffer[12];
uint32_t check_int, my_int = 12345678;

flash_getVar(&check_int, RES_MY_INTEGER, LEN_MY_INTEGER);
output_result(1, check_int != my_int);

flash_getVar(buffer, RES_MY_STRING_1, LEN_MY_STRING_1);
output_result(2, memcmp(buffer, "Hello World!", 12));

flash_getVar(buffer, RES_MY_STRING_2, LEN_MY_STRING_2);
output_result(3, memcmp(buffer, "Heureka!", 8));

/* Block 1 max usage is 30 Byte -> Optimisation in Makefile */
output_result(4, flash_setVar("test", 0, 1) != gNvmErrInvalidPointer_c);
output_result(5, flash_setVar("test", 30, 1) != gNvmErrInvalidPointer_c);
output_result(6, flash_setVar("test", 29, 2) != gNvmErrAddressSpaceOverflow_c);

/* Block 2 max usage is 10 Byte -> Optimisation in Makefile */
output_result(7, flash_setVar("test", 4096, 1) != gNvmErrInvalidPointer_c);
output_result(8, flash_setVar("test", 4096 + 10, 1) != gNvmErrInvalidPointer_c);
output_result(9, flash_setVar("test", 4096 + 9, 2) != gNvmErrAddressSpaceOverflow_c);
}
void
test_flash_blaster()
{
uint8_t buffer[64];

flash_getVar(buffer, RES_NAME, LEN_NAME);
output_result(1, memcmp(buffer, "Econotag Flash Test Device", 27));

flash_getVar(buffer, RES_MODEL, LEN_MODEL);
output_result(2, memcmp(buffer, "Model 1234 for testing purposes only", 37));
}
void
test_flash_stack()
{
uint8_t buffer[32];
flash_stack_init();

output_result(1, flash_stack_size() != 0);

flash_stack_push("Hello World!", 12);
output_result(2, flash_stack_size() != 12);

flash_stack_read(buffer, 0, 12);
output_result(3, memcmp(buffer, "Hello World!", 12));

flash_stack_push("I love Contiki!", 15);
output_result(4, flash_stack_size() != 27);

flash_stack_read(buffer, 0, 12);
output_result(5, memcmp(buffer, "Hello World!", 12));

flash_stack_read(buffer, 12, 15);
output_result(6, memcmp(buffer, "I love Contiki!", 15));

flash_stack_init();
output_result(7, flash_stack_size() != 0);

uint32_t i;
for(i = 1; i < 256; i++) {
flash_stack_push("I love Contiki! ", 16);
}
output_result(8, flash_stack_size() != 4080);

output_result(9, flash_stack_push("1I love Contiki! ", 17) != gNvmErrAddressSpaceOverflow_c);
}
/* Start Process */
PROCESS(server_firmware, "Server Firmware");
AUTOSTART_PROCESSES(&server_firmware);

PROCESS_THREAD(server_firmware, ev, data) {
PROCESS_BEGIN();

if(flash_cmp("\001", RES_DONTCLEAR, LEN_DONTCLEAR)) {
printf("Initializing flash ... ");
flash_init();
printf("DONE\n");
flash_setVar("\001", RES_DONTCLEAR, LEN_DONTCLEAR);
printf("Starting flash tests 1:\n");
test_flash_1();
int i;
for(i = 0; i < 1024; i++) {
printf("Reboot ...\r");
}
soft_reset();
} else {
printf("Initialization not wished\n");
}
printf("Starting flash tests 2:\n");
test_flash_2();

printf("Starting flash stack tests:\n");
test_flash_stack();

printf("Starting flash blaster tests:\n");
test_flash_blaster();

PROCESS_END();
}
7 changes: 7 additions & 0 deletions examples/econotag-flash-test/econotag-flash-test.cfg
Original file line number Diff line number Diff line change
@@ -0,0 +1,7 @@
input = "econotag-flash-test_econotag";
output = "econotag-flash-test_e_econotag";
eui = [ 0x2, 0x0, 0x0, 0x0, 0x12, 0x34, 0x56, 0x78 ];
uuid = "cbf9889f-dc0e-4c18-9aa9-93509a6c102a";
psk = "yCh0OXnSkFT-eXKE";
name = "Econotag Flash Test Device";
model = "Model 1234 for testing purposes only";
66 changes: 66 additions & 0 deletions examples/econotag-flash-test/econotag-flash-test.h
Original file line number Diff line number Diff line change
@@ -0,0 +1,66 @@
/*
* Copyright (c) 2014, Lars Schmertmann <[email protected]>.
* 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.
*
* This file is part of the Contiki operating system.
*
*/

/**
* \file
* Flash Management
*
* This file contains Pointers for manual flash management.
*
* \author
* Lars Schmertmann <[email protected]>
*/

#ifndef ECONOTAG_FLASH_TEST_H_
#define ECONOTAG_FLASH_TEST_H_

/* Pointer for Block 1 --------------- */

#define RES_DONTCLEAR 1
#define LEN_DONTCLEAR 1

#define RES_MY_STRING_1 2
#define LEN_MY_STRING_1 12

#define RES_MY_STRING_2 14
#define LEN_MY_STRING_2 8

/* Pointer for Block 2 --------------- */

#define RES_MY_INTEGER (4096 + 1)
#define LEN_MY_INTEGER 4

/* ------------------------------------ */

#endif /* ECONOTAG_FLASH_TEST_H_ */
1 change: 1 addition & 0 deletions platform/econotag/apps/flash/Makefile.flash
Original file line number Diff line number Diff line change
@@ -0,0 +1 @@
flash_src = flash.c
Loading

0 comments on commit 46ffc50

Please sign in to comment.