This mail describes how I implemented SQLite3 on a resource limited
processor. The attached zip file contains sources and the IAR project files.

Any missing sources e.g. fatfs are part of the IAR IDE and are freely
available.

 

Enjoy.

 

Development Environment

=======================

1) Stellaris LM3S9B96 ARM processor, 256KB ROM, 96KB RAM, Stellaris
Peripheral Library in ROM

2) IAR IDE (you must use the licensed version because of code size. The free
KickStart version is limited to 32 KB code)

3) SQlite3 Version 3.7.9 source

4) The file system is on a 4GB microSD controlled via the thirdparty/fatfs
code supplied with the IAR IDE. This allows

file sizes up to 4GB and 8.3 filenames.

 

SQLite Compilation Options

==========================

SQLITE_THREADSAFE 0  // single thread

SQLITE_DISABLE_LFS      // no large file system

SQLITE_OMIT_WAL

SQLITE_OMIT_LOAD_EXTENSION

SQLITE_DISABLE_DIRSYNC

SQLITE_OMIT_VACUUM

SQLITE_ENABLE_MEMSYS5

SQLITE_ENABLE_8_3_NAMES 2 // only 8.3 names

 

SQLITE_DEFAULT_CACHE_SIZE 10

SQLITE_DEFAULT_JOURNAL_SIZE_LIMIT 1000000

SQLITE_DEFAULT_PAGE_SIZE 1024

SQLITE_MAX_PAGE_COUNT 102400 // 1K  = max database size 100M

SQLITE_MAX_SQL_LENGTH 1000    // set by trial and error to avoid
corruptSchema messages

YYSTACKDEPTH 20

 

Linker Options

==============

Reserve 83KB RAM for SQLite MALLOC as shown by this excerpt from the linker
configuration file

 

//

// Define a region for the on-chip SRAM.

// also reserve top 83K for sqlite malloc

//

// default is 96KB for application, this split gives 13K for app

// and 83K for SQLite. Adjust as necessary

//

//define region SRAM =       mem:[from 0x20000000 to 0x20017fff];  

define region SRAM =         mem:[from 0x20000000 to 0x200033ff];

define region SQLITEMALLOC = mem:[from 0x20003400 to 0x20017fff];

 

Stack size is set to 4K. Less than this caused processor FAULT interrupts.

 

Implementation

==============

My main program simply opens up a UART which connect to Hyperterminal on a
PC.

An endless loop receives a line of SQL from hyperterminal and does an
sqlite3_exec on it.

An empty line signals no more SQL and the database is closed by
sqlite3_close().

 

Before calling sqlite3_open(), prepare malloc as follows

 

#define END_RAM   0x20017fff  -- match these to SQLITEMALLOC above

#define START_SQL 0x20003400

sqlite3_config(SQLITE_CONFIG_HEAP,START_SQL,END_RAM-START_SQL+1,32);

// Also do the following to avoid "Out Of Memory" errors.

sqlite3_config(SQLITE_CONFIG_LOOKASIDE,0,0);

 

Posix Interface

===============

A wrapper between Posix API e.g. open, close, fstat etc and the fatfs API
was written.

The version I have is a work in progress. See apimap.c in the zip file.

 

MSD.c does the file system initialize/mount stuff for the microSD card.

SQLite3 Source Changes

======================

function sqlite3PagerOpen() tries to create a journal file by appending
"-journal" to the database name, in spite of the SQLITE_ENABLE_8_3_NAMES
option. I changed it to append "_j" and make sure that my database names are
6 characters or less.

 

Performance

===========

The compilation was optimized for balance between speed and size. Code and
RO data occupies 248KB of ROM.

Two tables were created, table A having a primary key and table B having a
foreign key referencing the primary key in table A.

An index was created for the foreign key in table B.

 

1000 rows were inserted into table A and 10000 rows to table B.

 

Typical time to insert a row to table B, 160 millisec.

Typical time to select a row from table B, selected by its indexed column,
35msec.

 

_______________________________________________
sqlite-users mailing list
sqlite-users@sqlite.org
http://sqlite.org:8080/cgi-bin/mailman/listinfo/sqlite-users

Reply via email to