[Tinyos-contrib-commits] CVS: tinyos-1.x/contrib/umass/tos/platform/telosb FalC.nc, NONE, 1.1 FlashM.nc, NONE, 1.1 platform.h, NONE, 1.1

Gaurav gmathur at users.sourceforge.net
Sat Dec 9 13:05:52 PST 2006


Update of /cvsroot/tinyos/tinyos-1.x/contrib/umass/tos/platform/telosb
In directory sc8-pr-cvs10.sourceforge.net:/tmp/cvs-serv17795/tos/platform/telosb

Added Files:
	FalC.nc FlashM.nc platform.h 
Log Message:
Added contrib/umass containing Capsule -- a storage system for sensors

--- NEW FILE: FalC.nc ---
/*
 * file:        FalC.nc
 * description: Abstracts the platform flash
 *
 */

includes platform;

configuration FalC {
    provides {
    	interface GenericFlash[uint8_t id];
        interface StdControl;
    }
    uses interface Console;
}

/* Using the separate configuration file lets us #ifdef the wiring for
 *the serial debug console.
 */
implementation {
    components HALSTM25PC, FlashM;

    GenericFlash = FlashM.GenericFlash;
    FlashM.HALSTM25P -> HALSTM25PC.HALSTM25P[unique("Flash")];
    StdControl = HALSTM25PC.StdControl;
    Console = FlashM.Console;
}

    

--- NEW FILE: FlashM.nc ---
/*
 * file:        FlashM.nc
 * description: Component that abstracts the NOR flash
 *
 */

includes common_header;

#define FLASH_DEBUG

module FlashM {
    provides interface GenericFlash[uint8_t id];

    uses {
        interface HALSTM25P;
        interface Console;
    }
}

implementation 
{
    uint8_t Tid;

    task void initDone()
    {
        signal GenericFlash.initDone[Tid](SUCCESS);
    }

    command result_t GenericFlash.init[uint8_t id]()
    {
        Tid = id;
        post initDone();

        return (SUCCESS);
    }

    command pageptr_t GenericFlash.numPages[uint8_t id]()
    {
        return(4096);
    }
    
    command result_t GenericFlash.write[uint8_t id](pageptr_t page, offsetptr_t offset,
                                        void *data, offsetptr_t len)
    {
        Tid = id;
#ifdef FLASH_DEBUG
        call Console.string("FlashM: Writing.. pg:");
        call Console.decimal(page);
        call Console.string(" off:");
        call Console.decimal(offset);
        call Console.string(" len:");
        call Console.decimal(len);
        call Console.string("\n");
        TOSH_uwait(10000);
#endif
        return(call HALSTM25P.pageProgram((page * 256) + offset, data, len));
    }

    event void HALSTM25P.pageProgramDone()
    {
#ifdef FLASH_DEBUG
        call Console.string("FlashM: Write done");
        TOSH_uwait(10000);
#endif
        signal GenericFlash.writeDone[Tid](SUCCESS);
    }

    task void readSignal()
    {
        signal GenericFlash.readDone[Tid](SUCCESS);
    }

    task void falReadSignal()
    {
#ifdef FLASH_DEBUG
        call Console.string("FlashM: Read done");
        TOSH_uwait(10000);
#endif

        signal GenericFlash.falReadDone[Tid](SUCCESS);
    }


    uint8_t headerBuf[MAX_HEADERS_LEN];
    command result_t GenericFlash.falRead[uint8_t id](pageptr_t page, offsetptr_t offset,
                                          void *header, 
                                          void *app_buff, offsetptr_t app_len, 
                                          void *data_buff)
    {
        uint32_t accessLocation = (page * 256) + offset;

        Tid = id;

#ifdef FLASH_DEBUG
        call Console.string("FlashM: Read 1.. pg:");
        call Console.decimal(page);
        call Console.string(" off:");
        call Console.decimal(offset);
        call Console.string(" len:");
        call Console.decimal(sizeof(chunk_header) + app_len);
        call Console.string("\n");
        TOSH_uwait(10000);
#endif

        if (SUCCESS != call HALSTM25P.read(accessLocation, headerBuf, 
                                           sizeof(chunk_header) + app_len))
        {
#ifdef FLASH_DEBUG
            call Console.string("FlashM: Read 1 failed");
            TOSH_uwait(10000);
#endif
            return (FAIL);
        }
        else
        {
            chunk_header *h;

#ifdef FLASH_DEBUG
            {
                int i=0;

                for (i=0; i<(sizeof(chunk_header) + app_len); i++)
                {
                    call Console.string(" ");
                    call Console.decimal(headerBuf[i]);
                }
                call Console.string("\n");
            }
#endif 

            memcpy(header, headerBuf, sizeof(chunk_header));
            h = (chunk_header *) &header;

            if(app_len > 0)
            {
                memcpy(app_buff, &headerBuf[sizeof(chunk_header)], app_len);
            }

#ifdef FLASH_DEBUG
            call Console.string("FlashM: Read 2.. pg:");
            call Console.decimal(page);
            call Console.string(" off:");
            call Console.decimal(offset + sizeof(chunk_header) + app_len);
            call Console.string(" len:");
            call Console.decimal(h->data_len - app_len);
            call Console.string(" h->data_len:");
            call Console.decimal(h->data_len);
            call Console.string(" app_len:");
            call Console.decimal(app_len);
            call Console.string("\n");
            TOSH_uwait(10000);
#endif

            /* Now retrieve the chunk data */
            if ( (h->data_len - app_len) && 
                 (SUCCESS != call HALSTM25P.read(accessLocation + sizeof(chunk_header) + app_len, 
                                                 data_buff, h->data_len - app_len)) )
            {
#ifdef FLASH_DEBUG
                call Console.string("FlashM: Read 2 failed");
                TOSH_uwait(10000);
#endif
                return (FAIL);
            }
            else
            {
                post falReadSignal();
            }
        }

        return (SUCCESS);
    }

    command result_t GenericFlash.read[uint8_t id](pageptr_t page, offsetptr_t offset,
                                                   void *buff, offsetptr_t app_len)
    {
        uint32_t accessLocation = (page * 256) + offset;

        Tid = id;

#ifdef FLASH_DEBUG
        call Console.string("FlashM: Reading");
        TOSH_uwait(10000);
#endif

        if (SUCCESS != call HALSTM25P.read(accessLocation, buff, app_len))
        {
            return (FAIL);
        }
        else
        {
            post readSignal();
        }

        return (SUCCESS);
    }


    command result_t GenericFlash.erase[uint8_t id](pageptr_t page)
    {
        Tid = id;
        return(call HALSTM25P.sectorErase(page));
    }

    event void HALSTM25P.sectorEraseDone()
    {
        signal GenericFlash.eraseDone[Tid](SUCCESS);
    }

    event void HALSTM25P.bulkEraseDone()
    {}

    event void HALSTM25P.writeSRDone()
    {}

    default event result_t GenericFlash.initDone[uint8_t id](result_t result)
    {
        return (SUCCESS);
    }

    default event result_t GenericFlash.writeDone[uint8_t id](result_t result)
    {
        return (SUCCESS);
    }

    default event result_t GenericFlash.readDone[uint8_t id](result_t result)
    {
        return (SUCCESS);
    }

    default event result_t GenericFlash.eraseDone[uint8_t id](result_t result)
    {
        return (SUCCESS);
    }

    default event result_t GenericFlash.falReadDone[uint8_t id](result_t result)
    {
        return (SUCCESS);
    }

#ifdef FLASH_DEBUG
    event void Console.input(char *s)
    {}
#endif
}

--- NEW FILE: platform.h ---
/*
 * file:        platform.h
 * description: Platform-specific definition
 */

/*
 * Common declarations
 */

#ifndef PLATFORM_H
#define PLATFORM_H

//#define PLATFORM_TELOSB

/*
 * NOTE : These need to be set according to flash and user configuration
 */
typedef uint16_t pageptr_t;
typedef uint16_t offsetptr_t;
typedef uint16_t datalen_t; 

/* The size of each page on the NAND flash */
#define PAGE_SIZE 256

/* The size of each page on the NAND flash */
#define ERASE_BLOCK_SIZE 256

/* XXX --------------- SET THE FOLLOWING BEFORE OPERATION ----------------- XXX
 * The following both should be calculated based on the size of a page
 * NAND_BUFFER_SIZE = NAND_PAGE_SIZE (set in common_header.h) / number of
 *                       times write is possible to a page
 */
#define BUFFER_SIZE 256

/*
 * The allocated root directory area in units of erase blocks
 * 1 erase block = NAND_ERASE_BLOCK_SIZE pages
 */
#define ROOT_DIRECTORY_AREA 10

#define DELUGE_AREA 0

#endif



More information about the Tinyos-contrib-commits mailing list