Search This Blog

Dec 5, 2013

HTML 5 desktop application for embedded system


Introduction

   In embedded system design, we need to design desktop application to communicate with embedded devices. It is normally written by C++, C#, or TCL. And it is limited with OS environment. Developer needs to design different software version for Windows, Mac OS and Linux. For those cross platform requirement, we have better solution on it. Browser is common thing on various OS, just follow the HTML5 standard. Design a desktop application with HTML5, we can achieve the cross platform target, it can runs on Windows, Linux and Mac. The programing languages are HTML5, JavaScript and CSS. In the below section, we will investigate it in detail on how to design a HTML5 desktop application in embedded system design.

Sublime Text 2

Sublime is wonderful text editor which support multi-platform.  It is recommended to install it before we start looking into HTML5 things.
1.       Install the Sublime Text 2
Go to http://www.sublimetext.com/2, download Sublime Text 2 according your OS environment.
·         OS X (OS X 10.6 or later is required)
·         Windows - also available as a portable version
·         Windows 64 bit - also available as a portable version
·         Linux 32 bit
·         Linux 64 bit
2.       Install package control
This helps us easier to install other plugin. Press CTRL+ ~ to console displayed, past below scripts in console and press ENTER.
import urllib2,os;pf='Package Control.sublime-package';ipp=sublime.installed_packages_path();os.makedirs(ipp) if not os.path.exists(ipp) else None;open(os.path.join(ipp,pf),'wb').write(urllib2.urlopen('http://sublime.wbond.net/'+pf.replace(' ','%20')).read())
Once installation completed, restart Sublime Text2, we will see Package Control in Preference -> Package Settings.
3.       Plugin install
·         jsFormat
Sometimes we got JavaScript code which has been compressed. Like below.
It is no convenient to understand the code, press CTRL+ALT+F, the code has been formatted with beautiful form.

·         DocBlockr
Type /** and press enter, it will automatically generate doxygen compatible function description.

·         SublimeLinter
Automatically check programming language grammar error. Below example shows missing semicolon case, it shows a red exclamation mark on left of the line.  And display the error information in status bar at bottom of the window.


HTML5

Introduction

HTML5 is a markup language used for structuring and presenting content for the World Wide Web and a core technology of the Internet. It is the fifth revision of the HTML standard.


In addition to specifying markup, HTML5 specifies scripting application programming Interfaces (APIs) that can be used with JavaScript. Existing document object model (DOM) interfaces are extended and de facto features documented. There are also new APIs, such as:
HTML5 related APIs.
·         The canvas element for immediate mode 2D drawing. See Canvas 2D API Specification 1.0 specification
·         Timed media playback
·         Offline Web Applications
·         Document editing
·         Drag-and-drop
·         Cross-document messaging
·         Browser history management
·         MIME type and protocol handler registration
·         Microdata
·         Web Storage, a key-value pair storage framework that provides behaviour similar to cookies but with larger storage capacity and improved API.

 

Useful stuffs


JavaScript


Introduction

JavaScript (JS) is an interpreted computer programming language. As part of web browsers, implementations allow client-side scripts to interact with the user, control the browser, communicate asynchronously, and alter the document content that is displayed. It has also become common in server-side programming, game development and the creation of desktop applications.
JavaScript is a prototype-based scripting language with dynamic typing and has first-class functions. Its syntax was influenced by C. JavaScript copies many names and naming conventions from Java, but the two languages are otherwise unrelated and have very different semantics. The key design principles within JavaScript are taken from the Self and Scheme programming languages. It is a multi-paradigm language, supporting object-oriented, imperative, and functional programming styles.
JavaScript was originally developed by Brendan Eich in Netscape.
Although it was developed under the name Mocha, the language was officially called LiveScript when it first shipped in beta releases of Netscape Navigator 2.0 in September 1995, but it was renamed JavaScript when it was deployed in the Netscape browser version 2.0B3.
The change of name from LiveScript to JavaScript roughly coincided with Netscape adding support for Java technology in its Netscape Navigator web browser. The final choice of name caused confusion, giving the impression that the language was a spin-off of the Java programming language, and the choice has been characterized by many as a marketing ploy by Netscape to give JavaScript the cachet of what was then the hot new web programming language.

 

Node.js


Introduction

Node.js is a software platform that is used to build scalable network (especially server-side) applications. Node.js utilizes JavaScript as its scripting language, and achieves high throughput via non-blocking I/O and a single-threaded event loop.
Node.js contains a built-in HTTP server library, making it possible to run a web server without the use of external software, such as Apache or Lighttpd, and allowing more control of how the web server works.
Node.js was created by Ryan Dahl starting in 2009. Its development and maintenance is sponsored by Joyent.
Node.js is a packaged compilation of Google's V8 JavaScript engine, the platform abstraction layer, and a core library, which is itself primarily written in JavaScript.
Dahl's original goal was to create web sites with push capabilities as seen in web applications like Gmail. After trying solutions in several other programming languages he chose JavaScript because of the lack of an existing I/O API. This allowed him to define a convention of non-blocking, event-driven I/O.

Useful stuffs

·         Download Node.js from http://nodejs.org/
It support Windows, Macintosh and Lnux
Node.js is released under the MIT license, and bundles other liberally licensed OSS components.
·         A good place to study node.js, http://www.nodebeginner.org/

Webkit


Introduction

  WebKit is a layout engine software component designed to allow web browsers to render web pages. WebKit is used as the rendering engine within Safari and was formerly used by Google's Chrome web browser on Windows, OS X, iOS and Android (however, Chrome only used WebCore, and also incorporated its own JavaScript engine and multi-process system). Other applications on OS X make use of WebKit, such as Apple's e-mail client Mail and the 2008 version of Microsoft's Entourage personal information manager, both of which make use of WebKit to render e-mail messages with HTML content.

Node-webkit

Introduction

  Node-webkit is an app runtime based on Chromium and node.js. You can write native apps in HTML and JavaScript with node-webkit. It also lets you call Node.js modules directly from the DOM and enables a new way of writing native applications with all Web technologies.

Features

·         Apps written in modern HTML5, CSS3, JS and WebGL.
·         Complete support for Node.js APIs and all its third party modules.
·         Good performance: Node and WebKit runs in the same thread: Function calls are made straightforward; objects are in the same heap and can just reference each other;
·         Easy to package and distribute apps.
·         Available on Linux, Mac OSX and Windows

 

Installation

1.       Download latest version from https://github.com/rogerwang/node-webkit
2.       Extract the package and copy all files into directory C:\Program Files\node-webkit
3.       Configure build and debugging setting in Sublime Text2  for Node-webkit
Windows
·         Select Tools->Build system->New Build System, it opens a new file named “untiled.sublime-build”.
·         Copy below code into untiled.sublime-build and save it as “Node-webkit.sublime-build”
{
    "cmd": ["nw.exe", "--enable-logging", "${project_path:${file_path}}"],
    "working_dir": "${project_path:${file_path}}",
    "path": "C:/Program Files/node-webkit/"
}
·         Press Ctrl+B to build your project.
Please find more information from official website. 

Desktop application example

Hello World example

1.       Create index.html

2.       Create package.json
{  "name": "nw-demo",    "main": "index.html"}
3.       Run project by pressing Ctrl+B,  it shows below window,

Official demo code

There are several example codes in https://github.com/zcbenz/nw-sample-apps
Here is snap of one example code “menus”

Real Desktop application example

Now we can start working on a real application examples. According the procedure, we can familiar with desktop application development with Node-webkit.
We have an F33x UART bootloader PC application, written by C#, the user interface shows below, let us make same one with HTML5 and JavaScript.
Get reference from


UI implementation:

There are four buttons, two check boxes, six drop down lists, one table, and one text area.
1.       Add drop down lists.
The effort shows close to C# appearance.

2.       Add button
Get reference from http://www.w3schools.com/tags/tag_button.asp
The effort looks good.

3.       Add Tables
Get reference from http://www.w3schools.com/html/html_tables.asp
The effort looks good too.

4.       Checkbox
Get reference from http://www.w3schools.com/jsref/prop_checkbox_checked.asp
The effort looks good.
5.       Text area
Get reference from http://www.w3schools.com/tags/tag_textarea.asp
The effort looks good too.

6.       Final display effort
After fine tune UI layout, the final appearance looks like below snapshot.

File system access

We need open hex file from explorer window and read file contents.
1.       Open file Dialog
Here we want click on button “Select Hex File(s)”, it should display file open dialog to select input file. Here we need start coding JavaScript to achieve file access function.
·         In index.html,
Add input tag to for file upload, the id is “openFile”, the id can be access by JavaScript code. And set it not display style. Also add script tag to execute script.js.
And then change button tag of “Select Hex File(s)”, id is “openHexFile”, onClick event handler function is openFileOption().
·         In script.js,
Add openFileOption(), notice getElementById() with id ‘openFile’, which defined in indel.html input TAG. And with onClick event of input tag, it call handleFiles, which print out selected file name on console.
function openFileOption() {
  document.getElementById("openFile").click();
}
function handleFiles(files) {
  for (var i = 0; i < files.length; ++i)
         console.log(files[i].name);
}
·         Press Ctrl+B, click on button “Select Hex File(s)”, we can see a file dialog appeared.


2.       Read file contents
Here we need node.js to access local storage file.
In script.js
var fs = require('fs');
function handleFiles(files) {
  fs.readFile(files[0].name, 'utf8', function(err,data) {
         if (err) throw err;
         console.log(data);
  });
}
Press Ctrl+B, click on button ”Select Hex File(s)”, select Sample_User_Application.hex file, and then we can see Hex file contents output in console.
[3928:1120/153906:INFO:CONSOLE(6)] "":03040000020447AC\r\n:0C044700787FE4F6D8FD758107020433CD\r\n:1004330053D9BF1204037FB07E63120415D2AFE415\r\n:04044300F5A780FE9B\r\n:0D040300AFA775A70F75E24043AF048FA7A8\r\n:0104100022C9\r\n:10041500ADA775A70FE4F5C8C39FFFE49EF5CB8F85\r\n:0D042500CA74FFF5CDF5CCD2ADD2CA8DA7BB\r\n:0104320022A7\r\n:030412000204538E\r\n:05045300C2CFB2B2327D\r\n:0B77F500250101020136071BA5C23D63\r\n:00000001FF\r\n"",

Hex file analysis

1.       Introduction
Intel HEX is a file format for conveying binary information for applications like programming microcontrollers, EPROMs, and other kinds of chips. The format is a text file, with each line containing hexadecimal values encoding a sequence of data and their starting offset or absolute address.
Each line of Intel HEX file consists of six parts:
·         Start code, one character, an ASCII colon ':'.
·         Byte count, two hex digits, a number of bytes (hex digit pairs) in the data field. 16 (0x10) or 32 (0x20) bytes of data are the usual compromise values between line length and address overhead.
·         Address, four hex digits, a 16-bit address of the beginning of the memory position for the data. Limited to 64 kilobytes, the limit is worked around by specifying higher bits via additional record types.
·         Record type, two hex digits, 00 to 05, defining the type of the data field.
·         Data, a sequence of n bytes of the data themselves, represented by 2n hex digits.
·         Checksum, two hex digits 
Example of Hex file

2.       Hex parser coding
·         User firmware structure:
The user firmware application structure look like below. The user firmware start address from 0x400, and at end of user firmware area, there is application info block which record the user firmware information, something like App start Address, App End Address, BL type, etc.

In our example, the user application firmware start address is 0x400, however, the application info block address at 0x77F5. That means two pages are needed for this firmware, and a lot of pages bare between first occurred page and last occurred page.

·         Modification on Intel-hex.js:
The original hex parser JavaScript will fill 0xFF in page which is not used. In our case, it will generate a big image from address 0x0000 to 0x7800, which is too large for us.  So an array flashPageInUse added in intel-hex.js to record which page is being used. It also as one of return values.

Part of original hex file:
:03040000020447AC
The data segment is “020447”.

Part of parsed hex file output:
[3572:1121/101801:INFO:CONSOLE(18)] "{"0":2,"1":4,"2":71,
It is 02, 04, 71(0x47), the result shows correct value.
·         Parse application info block
Here is definition of info block, these information needed display to Table in UI.
SEGMENT_VARIABLE(TGT_App_InfoBlock[], const U8, SEG_CODE) =
{
  BL_SPECIFIC_BYTE,
  APP_FW_VERSION_HIGH,
  APP_FW_VERSION_LOW,
  TGT_FLASH_PAGE_SIZE_CODE,
  TGT_BL_TYPE,
  TGT_MCU_CODE,
  TGT_APP_INFOBLOCK_LENGTH,
  SIG_BYTE3,
  SIG_BYTE2,
  SIG_BYTE1,
  SIG_BYTE0,

};
·         Output to Table
Named table id = ‘infoBlock’ in index.html
Open the table by id in script.js, and handle info block from hex parse result.
function infoBlockDisplay(tmp) {
  var infoTable = document.getElementById('infoBlock');
  // MCU code
  infoTable.rows[1].cells[1].innerHTML = '0x' + tmp[FLASH_PAGE_SIZE - 6].toString(16);
  // BL type
  if (tmp[FLASH_PAGE_SIZE - 7] == 1) {
         infoTable.rows[2].cells[1].innerHTML = 'UART';
  }
  // Flash page size
  if (tmp[FLASH_PAGE_SIZE - 8] == 2) {
         infoTable.rows[3].cells[1].innerHTML = '1024';
  } else if(tmp[FLASH_PAGE_SIZE - 8] == 1) {
         infoTable.rows[3].cells[1].innerHTML = '512';
  }
  // App FW Version
  var ver_high = tmp[FLASH_PAGE_SIZE - 10].toString();
  var ver_low  = tmp[FLASH_PAGE_SIZE - 9].toString();
  infoTable.rows[4].cells[1].innerHTML = ver_high + '.' + ver_low;
  // Reserved
  infoTable.rows[5].cells[1].innerHTML = '0x' + tmp[FLASH_PAGE_SIZE - 11].toString(16);
  // App Start Addr
  infoTable.rows[6].cells[1].innerHTML = firmwareStartAddress;
  // App End Addr
  infoTable.rows[7].cells[1].innerHTML = firmwareEndAddress;
}
·         Run result
Press Ctrl + b, click on button “Select Hex file(s)”, and choose Sample_User_Application.hex in file dialog. The result looks good.

Serial port communication

1.       Install serialport plug in for Node.js
Before install serialport plug in for Node.js, we need to install Python 2.76. http://www.python.org/download/releases/2.7.6/,
$npm install serialport
2.       Install nw-gyp
Things become a little difference between normal node.js third party plugin, node-webkit need to rebuild the plug in. Get reference from  https://github.com/rogerwang/node-webkit/wiki/Using-Node-modules 3rd party modules with C/C++ addons.
$ npm install nw-gyp –g
3.       Rebuild node-webkit
Enter serialport module directory.
$ nw-gyp rebuild --target=0.8.0
4.       To use
·         Output string “OMG IT WORS” to COM4,
var serialport = require('serialport');
var com = serialport.SerialPort;
var serialPort = new com('COM4', {
  baudrate: 115200
});
function serialPortTesting() {
  console.log('COM port open test\n');
  serialPort.write("OMG IT WORKS\r");
}
Also add serialPortTesting() function in anywhere you want. Check the COM4 output with serial terminal tool, we can see sting “OMG IT WORKS” appear on the terminal tool. That means the serial port operation works.
·         List all COM ports
  serialport.list(function (err, ports) {
         ports.forEach(function(port) {
                 console.log(port.comName);
                 console.log(port.pnpId);
                 console.log(port.manufacturer);
         });

  });
We can see the output from console.
 ""COM3"",
 ""USB\\VID_10C4&PID_EA60\\0001"",
 ""Silicon Laboratories"" ,
 ""COM1"",
 ""ACPI\\PNP0501\\0"",
 ""(Standard port types)"",
 ""COM4"",
 ""USB\\VID_10C4&PID_EA60\\0003""
 ""Silicon Laboratories"",
·         Update COM port dropdown list
function serialPortList() {
  serialport.list(function (err, ports) {
         var coms = [];
         var cnt = 0;
         ports.forEach(function(port) {
                 coms[cnt++] = port.comName;
         });
         coms.sort();
         var comPortInput = document.getElementById('comPort');
         coms.forEach(function(com) {
                 var option = document.createElement('option');
                 option.text = com;
                 comPortInput.add(option, null);
         });
  });

}

·         Open COM Port button function implementation
function serialPortOpen() {
  var comPortInput = document.getElementById('comPort');
  var comSelected = comPortInput.options[comPortInput.selectedIndex].text;
  console.log(comSelected);
  var SerialPort = serialport.SerialPort;
  var serialPort = new SerialPort(comSelected, {
         baudrate: 115200
  }, false);
  serialPort.open(function (err) {
         if (err) {
                 var textArea = document.getElementById('textArea');
                 var tmp = textArea.value + err + '\n';
                 textArea.value = tmp;
                 return;
         }
         serialPort.write('OMG IT WORKS\r');
  });
}

Firmware update control function implementation.

·         The protocol can get reference from F330 UART bootloader firmware. For quick demonstration purpose, we remove CRC function from firmware. The firmware main loop like below.
 while(SRC_Disp_TGT_Info() != SRC_RSP_OK);
  SRC_Response = SRC_Get_Info();
  SRC_Validate_Response(SRC_Response, SRC_CMD_GET_INFO);
  if (Last_Error != 0)
     goto error;
  Flash_Key0 = rx_buf[5];
  Flash_Key1 = rx_buf[6];
  while(1){
      SRC_Response = SRC_Get_Page_Info();
      SRC_Page_CRC = rx_buf[4] | (rx_buf[5] << 8);
      page_addr = rx_buf[1] | (rx_buf[2] << 8);
      SRC_Validate_Response(SRC_Response, SRC_CMD_GET_PAGE_INFO);
      if (Last_Error != 0)
          break;
      // Exit this loop if no more pages are available from source
      if (SRC_Response == SRC_RSP_DATA_END)
         break;
      SRC_Response = SRC_Get_Page(Page_Buf);
      SRC_Validate_Response(SRC_Response, SRC_CMD_GET_PAGE);
      if (Last_Error != 0)
         break;
      TGT_Erase_Page(page_addr);
      TGT_Write_Flash(Page_Buf, page_addr);

}
·         Test result.
a.       Prepare C8051F330-TB board.
b.      Download UART bootloader firmware in it.
c.       Connect UART interface to PC, it appears COM4.
d.      Press Ctrl+b to run the HTML5 updater.
e.      Select blink sample application hex file by clicking Select Hex Files button.
f.        Select COM4 from dropdown list, and click on Open COM Port button.
g.       The blinky application will download to target board automatically. And reset MCU at end of updating.
h.      We can see a green LED(D2) on board is blinking.
i.        We are done!

Source code

      The source code can be found from https://github.com/MarkDing/HTML5_UART_BL

Sep 25, 2013

EEPROM EMULATION FOR 8-BIT FLASH MCU

1           Introduction

This post demonstrates a way to use the flash memory of the 8-bit flash MCU families to emulate single variable rewritable EEPROM memory through software. The example API provided enables reading and writing of single variables to non-volatile flash memory. The erase-rewrite algorithm distributes page erases and thereby doing wear leveling.

2           General Theory


2.1          EEPROM and Flash Based Memory

EEPROM stands for Electrically Erasable Programmable Read-Only Memory and is a type of nonvolatile memory that is byte erasable and therefore often used to store small amounts of data that must be saved when power is removed. Most of 8 bit MCU does not include an embedded EEPROM module for byte erasable non-volatile storage, but for C8051Fxxx MCU families do provide flash memory for non-volatile data storage. The main difference between flash memory and EEPROM is the erasable unit size. Flash memory is block-erasable which means that bytes cannot be erased individually, instead a block consisting of several bytes need to be erased at the same time. Through software however, it is possible to emulate individually erasable rewritable byte memory using block-erasable flash memory.

To provide EEPROM functionality for the 8 bit flash MCU in an application, there are at least two options available. The first one is to include an external EEPROM module when designing the hardware layout of the application. The other is to use the on-chip flash memory and emulate EEPROM functionality through a software API. There are however some key differences between these two methods.
• First, the write access time for flash memory is shorter than for external EEPROM. This means that writing to emulated EEPROM is faster than writing to an external EEPROM.
• Second, while a standalone EEPROM will be able to complete a write operation even if the system is reset, the emulated EEPROM will need the CPU to be active throughout the entire flash operation. This is an important difference. The consequences of an aborted flash operation should be taken into account when designing an application. The flash based EEPROM emulation could use checksums and logging to ensure the integrity of written data.
• Lastly the emulated EEPROM will regularly need to erase pages in flash, to free space and be able to write to the same page more than once. On a standalone EEPROM there is no need for a dedicated erase operation, since all bytes can be rewritten independently. Here it is also important to notice that the flash erase operation will need the CPU to be running safely for the entire operation.

In addition to the risk of power failure or system reset aborting flash write or erase operations, one must also handle internal sources like disable interrupts and enable VDD monitor while performing the flash write/erase operations. This can be done in software.

1.1          Flash Limitations

Flash memory is limited to a finite number of program-erase cycles. This means that the embedded flash memory of the MCU can be erased only a certain number of times, before the wear will begin to affect the integrity of the storage. This deterioration applies to all kinds of flash memory. All 8 bit flash MCUs are guaranteed to withstand a number of erase cycles. This number can be found in the data sheet for each part.
All flash memory is divided into pages that each must be erased as single units. The amount of on-chip flash memory and the page size found in the different 8 bit MCU varies depending on the specific part. See the Reference Manual for more information about the page size. Because the erase operation erases only whole pages, it is important to write as much data as possible to a single page of flash, before erasing the page.

2           Implementation

There are different ways to implement an EEPROM Emulator using flash memory. The idea behind the example attached in this application note, is to allocate a certain number of pages of flash memory for the entire lifetime of the application. The wear is then leveled among these by alternating which pages are used. The number of pages allocated must reflect the amount of data that will be written throughout the application lifetime.

2.1          Pages and Their States

In every page allocated to the EEPROM Emulator provided, the first dword is reserved for page head data. This head dword contains the status of the page and the erase count. The erase count is the number of times the page has been erased. The erase count is incremented each time the page is erased. Each page will always be in one of three different states. Active, Receiving or Erased.
• After a page is erased, all bits in the entire page are 1's except head data of the page.
• When a page is receiving, it means that a transfer of variables from a full active page is in progress. After the transfer is complete, the receiving page is made the new active one, and the old active page is erased.
• The active page is the page that contains the currently valid data. All read and write operations are made on the active page. There should never be more than one active or receiving page at any time in this implementation.

Fig 3.1 shows the state flow for a realization using 2 pages. The flow would be similar if more pages are allocated; only more pages would be in the erased state simultaneously.
          Figure 3.1 EEPROM Emulation Page Status Flow. 
During initialization, the page status for the selected number of pages is checked, to ensure that a legal set of page-states are obtained. If there is more than one active page, the page which is full will be erased. And receiving status page will be erased. This minimizes the probability for data collisions with program instructions, which are located at the base of the flash. In applications where much of the available flash memory is in use, it can be critical to know where all data is stored in the flash to avoid collisions.  

The remaining words of each page, after the page head data, are free to be used for data storage. Each data storage word is divided into two parts; one virtual address field and one data field. Each of them is 8 bits wide. Whenever a page is full, a page transfer is initiated. This operation consists of several steps to always ensure that all variables are non-volatile in case of an external event. First, an erased page is located to store the valid data present in the full page. This page is marked as receiving. Next, the most recent data associated with each variable is transferred to the top of the new page. When this is done, the old active page is erased, the erase count is written to the old active page header, and receiving page is labeled as the new active page. This process is illustrated in Figure 3.2.
Figure 3.2. EEPRO Emulation Variable Flow.

3.2.           Read and Write

Reading consists of iteration through the active page, starting from the bottom. When the correct virtual address is found for the first time, the corresponding data is returned as the currently valid data.
The write operation consists of a similar iteration, only which it is starting at the top of the active page. When an empty word is found, the correct virtual address and data are written, and the function returns. If no empty word is found, and the end of the page is reached, the page is considered full.
In this implementation all valid data has to fit in one page (the active page). The page size therefore puts a direct limitation on the number of variables. Each variable uses 2 bytes (1 byte for data and 1 byte for the virtual address) and 4 bytes per page is reserved for the Page Status Header. We default set the EEPROM size no more than 1/4 flash page size. And also 8 bit alignment. For example, 512 bytes page size, the maximum EEPROM size is:
Nmax = ((512 - 4) / 4) & 0xF8 = 127 & 0xF8 = 120.

3.3.         Initialization and Recovery

An important part of EEPROM emulation software, is to ensure correct page state, and data recovery on system startup. For this reason, the initialization function should be run near the start of the software, before any data is written or read to/from EEPROM. The initializing function will decide how many pages that are allocated to the emulator, it will then check the head of each of these pages to ensure that the set of pages are valid. There are several conditions we need to handle.
·         Erased page
It is not formatted, simply format this page. The format operation contains erase the page, and update erase count in page header data.
·         Page with receiving status
Simply format this page; this situation can be caused by an uncompleted page transfer.
·         Two more pages with active status.
Compare with two pages; simply format the page which is full.

Once status check completed, it will scan current active page, and update page information.

3.4          Configurable Options

The firmware supports all 8 bit flash MCU families. Define the device being used in flash_parameters.h, (i.e. C8051F850)
#define C8051F850
The EEPROM emulation firmware has following parameters can be configured. These parameters are located in head file eeprom_config.h. 

Parameter
Options
FL_PAGES
Pages used for EEPROM emulation: 2
EE_BASE_ADDR
EEPROM storage area begins: LOCK_PAGE - FL_PAGE_SIZE * FL_PAGES
EE_SIZE
Number of bytes of EEPROM: 16
EE_TAG_SIZE
Number of bytes for page head data: 4
EE_VARIABLE_SIZE
Number of bytes used per EEPROM data: 2

4. Source code

Source code can be found in https://github.com/MarkDing/eeprom-emulation

Jun 27, 2013

How to install JekyII under windows (Github wiki page)



How to install JekyII under windows.
1.       Install Ruby 2.0.0
2.       Install Ruby DevKit for Ruby 2.0.0
Extract it to C:\devkit, enter the directory and execute below commands.
$ ruby dk.rb init
to generate the config.yml file to be used later in this Step
$ ruby dk.rb install
 This step installs (or updates) an operating_system.rb file into the relevant directory needed to implement a RubyGems
3.       Add Taobao ruby in  gem mirror list. This is because GFW blocking.
$ gem sources --remove http://gemcutter.org/
$ gem sources --remove http://rubygems.org/
$ gem sources -a http://ruby.taobao.org/
4.       Install jekyll
$ gem install jekyll rdiscount
This might be long time, please be patient to wait for it complete. 
...
Fetching: liquid-2.5.0.gem (100%)
Successfully installed liquid-2.5.0
Fetching: fast-stemmer-1.0.2.gem (100%)
Temporarily enhancing PATH to include DevKit...
Building native extensions.  This could take a while...
Successfully installed fast-stemmer-1.0.2
Fetching: classifier-1.3.3.gem (100%)
Successfully installed classifier-1.3.3
Fetching: directory_watcher-1.4.1.gem (100%)
Successfully installed directory_watcher-1.4.1
Fetching: syntax-1.0.0.gem (100%)
Successfully installed syntax-1.0.0
Fetching: maruku-0.6.1.gem (100%)
Successfully installed maruku-0.6.1
Fetching: kramdown-1.0.2.gem (100%)
Successfully installed kramdown-1.0.2
Fetching: yajl-ruby-1.1.0-x86-mingw32.gem (100%)
Successfully installed yajl-ruby-1.1.0-x86-mingw32
Fetching: posix-spawn-0.3.6.gem (100%)
Temporarily enhancing PATH to include DevKit...
Building native extensions.  This could take a while...
Successfully installed posix-spawn-0.3.6
Fetching: pygments.rb-0.5.1.gem (100%)
Successfully installed pygments.rb-0.5.1
Fetching: highline-1.6.19.gem (100%)
Successfully installed highline-1.6.19
Fetching: commander-4.1.3.gem (100%)
Successfully installed commander-4.1.3
Fetching: safe_yaml-0.7.1.gem (100%)
Successfully installed safe_yaml-0.7.1
Fetching: colorator-0.1.gem (100%)
Successfully installed colorator-0.1
Fetching: jekyll-1.0.3.gem (100%)
Successfully installed jekyll-1.0.3
Parsing documentation for yajl-ruby-1.1.0-x86-mingw32
unable to convert "\x90" from ASCII-8BIT to UTF-8 for lib/yajl/1.8/yajl.so, skip
ping
unable to convert "\x90" from ASCII-8BIT to UTF-8 for lib/yajl/1.9/yajl.so, skip
ping
Installing ri documentation for yajl-ruby-1.1.0-x86-mingw32
Parsing documentation for posix-spawn-0.3.6
Installing ri documentation for posix-spawn-0.3.6
Parsing documentation for pygments.rb-0.5.1
Installing ri documentation for pygments.rb-0.5.1
Parsing documentation for highline-1.6.19
Installing ri documentation for highline-1.6.19
Parsing documentation for commander-4.1.3
Installing ri documentation for commander-4.1.3
Parsing documentation for safe_yaml-0.7.1
Installing ri documentation for safe_yaml-0.7.1
Parsing documentation for colorator-0.1
Installing ri documentation for colorator-0.1
Parsing documentation for jekyll-1.0.3
Installing ri documentation for jekyll-1.0.3
Fetching: rdiscount-2.1.6.gem (100%)
Building native extensions.  This could take a while...
Successfully installed rdiscount-2.1.6
Parsing documentation for rdiscount-2.1.6
unable to convert "\x90" from ASCII-8BIT to UTF-8 for lib/rdiscount.so, skipping

Installing ri documentation for rdiscount-2.1.6
9 gems installed
…
5.       Check  Jekyll version
$ jekyll -v
jekyll 1.0.3
6.       Install RedCloth
$ gem install RedCloth
7.       Download Tom Preston-Werner Jekyll example
Extract it into your own github local directory. I changed the name to "blog"
8.       Highlight code

    9. Reference