X-Git-Url: https://oss.titaniummirror.com/gitweb/?a=blobdiff_plain;f=tools%2Ftinyos%2Fmisc%2Ftos-storage-stm25p.in;h=ed9eb63aa6c65acc36a61bd2a61e4b406feb9941;hb=005f20955c13e13ea1ab79aec8b8f0b18f128838;hp=79cb09885d976fbffd770a318a6e98ed5497290e;hpb=4dc7ca80ef46f88cfcb52e9f806a75bcaa64b20a;p=tinyos-2.x.git diff --git a/tools/tinyos/misc/tos-storage-stm25p.in b/tools/tinyos/misc/tos-storage-stm25p.in index 79cb0988..ed9eb63a 100644 --- a/tools/tinyos/misc/tos-storage-stm25p.in +++ b/tools/tinyos/misc/tos-storage-stm25p.in @@ -39,17 +39,50 @@ # @author Jonathan Hui # @author David Gay +# @author Kevin Klues +# @author R. Steve McKown # # $Revision$ # $Date$ # +from __future__ import with_statement # Does this require too new a python? + +import os +import re from re import match from sys import * from xml.dom import * from xml.dom.minidom import * from subprocess import Popen, PIPE +from getopt import * +import string +import commands +#New way of handling arguments........ +try: + opts, args = getopt(argv[1:], "t", []) +except GetoptError, err: + print str(err) # will print something like "option -a not recognized" + stderr.write( "Usage: tos-storage-stm25p [-t] \n" ) + +if len( args ) == 1: + platformdir = args[0] + # This gives the whole string when there's no / in platformdir + platform = platformdir[platformdir.rfind( "/" ) + 1:] +elif len( args ) == 0: + platformdir = "" + platform = "" +else: + stderr.write( "Usage: tos-storage-stm25p [-t] \n" ) + +cthreads = False +for o, a in opts: + if o == "-t": + cthreads = True + else: + assert False, "unhandled option" + def error_exit( s ): stderr.write( "ERROR: " + s + "\n" ) exit( 2 ) @@ -84,26 +117,86 @@ def expand_path( path ): return path -NUM_SECTORS = 16 -SECTOR_SIZE = 65536 +HEADER_FILE = 'Stm25p.h' +NUM_SECTORS = 0 +SECTOR_SIZE = 0 + +def parseHeader( dotplatform ): + """ Return an ordered list of paths from the dotplatform file """ + paths = [] + inArray = False + p = re.compile('push\s*\(\s*@includes,\s*qw\s*\('); + q = re.compile('\)\s*\)\s*;'); + try: + with open(dotplatform, 'r') as file: + for line in file: + path = line.strip() + if path: + if p.match(path): + inArray = True + elif q.match(path): + inArray = False + elif inArray == True: + paths.append(path) + return paths + except: + return None + +def findFile( paths, filename ): + """ Find the first occurrence of 'filename' in the list of paths given. """ + for path in paths: + rpath = expand_path(path) + try: + for file in os.listdir(rpath): + if file == filename: + return rpath + '/' + filename + except OSError: + None + return None + +def findVars( path, vars ): + """ Finds values for the variables already present in vars from path """ + inEnum = False + p = re.compile('enum\s.*{'); + q = re.compile('}s*;'); + r = re.compile('^\s*([A-Z0-9_]*)\s*=\s*([^,]*)'); + with open(path, 'r') as file: + for line in file: + line = line.strip() + if line: + if p.match(line): + inEnum = True + elif q.match(line): + inEnum = False + elif inEnum == True: + m = r.search(line) + if vars.has_key(m.group(1)): + vars[m.group(1)] = m.group(2) + +paths = parseHeader(platformdir + '/.platform') +if paths: + path = findFile(paths, HEADER_FILE) + if path: + enums = {} + enums["STM25P_NUM_SECTORS"] = 0 + enums["STM25P_SECTOR_SIZE_LOG2"] = 0 + findVars(path, enums) + NUM_SECTORS = int(enums["STM25P_NUM_SECTORS"]) + SECTOR_SIZE = 2**int(enums["STM25P_SECTOR_SIZE_LOG2"]) +if NUM_SECTORS == 0 or SECTOR_SIZE == 0: + stderr.write( "tos-storage-stm25p: no valid Stm25p.h found.\n\t" + "Check @includes in the platform's .platform file\n" ) + exit(2) volumes = {} volumeNames = [] volumeSizes = [] volumeOffsets = [] +volumeTypes = dict() +volumeOptions = dict() freeSectors = NUM_SECTORS*[ True ] -if len( argv ) == 2: - platformdir = argv[1] - # This gives the whole string when there's no / in platformdir - platform = platformdir[platformdir.rfind( "/" ) + 1:] -elif len( argv ) == 1: - platformdir = "" - platform = "" -else: - error_exit( "Usage: tos-storage-stm25p " ) - def volumeparse( file, fname, depth ): if depth > 10: error_exit( "include nesting too deep - check for cycles" ) @@ -119,6 +212,11 @@ def volumeparse( file, fname, depth ): name = volume.getAttribute( "name" ) size = volume.getAttribute( "size" ) base = volume.getAttribute( "base" ) + type = string.lower(volume.getAttribute("type")) + isCircular = string.upper(volume.getAttribute("circular")) + if isCircular == "": + isCircular = "FALSE" + if name == "": error_exit( "volume has no name" ) elif not match( "^[a-zA-Z0-9_]+$", name ): @@ -148,6 +246,9 @@ def volumeparse( file, fname, depth ): volumeNames.append( "VOLUME_" + name ) volumeSizes.append( size / SECTOR_SIZE ) + volumeTypes["VOLUME_" + name] = type + volumeOptions["VOLUME_" + name] = isCircular + if base == "": volumeOffsets.append( -1 ) else: @@ -207,3 +308,50 @@ print "};" print "" print "#endif" + +# output nc file for threads +if cthreads == True: + outFile = open(commands.getstatusoutput("pwd")[1] + "/VolumeMapC.nc", "w") + outFile.write("#include \"StorageVolumes.h\" \n") + outFile.write("\n") + outFile.write("configuration VolumeMapC { \n") + outFile.write(" provides { \n") + outFile.write(" interface BlockRead[uint8_t volume_id]; \n") + outFile.write(" interface BlockWrite[uint8_t volume_id]; \n") + outFile.write(" interface LogRead[uint8_t volumeId]; \n") + outFile.write(" interface LogWrite[uint8_t volumeId]; \n") + outFile.write(" interface Mount[uint8_t volumeId]; \n") + outFile.write(" interface ConfigStorage[uint8_t volumeId]; \n") + outFile.write(" } \n") + outFile.write("} \n") + outFile.write("\n") + outFile.write("implementation { \n") + outFile.write(" components VolumeMapP; \n") + outFile.write("\n") + outFile.write(" BlockRead = VolumeMapP; \n") + outFile.write(" BlockWrite = VolumeMapP; \n") + outFile.write(" LogRead = VolumeMapP; \n") + outFile.write(" LogWrite = VolumeMapP; \n") + outFile.write(" Mount = VolumeMapP; \n") + outFile.write(" ConfigStorage = VolumeMapP; \n") + + for i in range(len(volumeNames)): + if volumeTypes[volumeNames[i]] == "block": + outFile.write("\n") + outFile.write(" components new BlockStorageC(" + volumeNames[i] + ") as BlockStorageC_" + volumeNames[i] + "; \n") + outFile.write(" VolumeMapP.SubBlockRead[" + volumeNames[i] + "] -> BlockStorageC_" + volumeNames[i] + "; \n") + outFile.write(" VolumeMapP.SubBlockWrite[" + volumeNames[i] + "] -> BlockStorageC_" + volumeNames[i] + "; \n") + outFile.write("\n") + + elif volumeTypes[volumeNames[i]] == "log": + outFile.write("\n") + outFile.write(" components new LogStorageC(" + volumeNames[i] + ", " + volumeOptions[volumeNames[i]] + ") as LogStorageC_" + volumeNames[i] + "; \n") + outFile.write(" VolumeMapP.SubLogRead[" + volumeNames[i] + "] -> LogStorageC_" + volumeNames[i] + "; \n") + outFile.write(" VolumeMapP.SubLogWrite[" + volumeNames[i] + "] -> LogStorageC_" + volumeNames[i] + "; \n") + outFile.write("\n") + + elif volumeTypes[volumeNames[i]] == "config": + outFile.write(" components new ConfigStorageC(" + volumeNames[i] + ") as ConfigStorageC_" + volumeNames[i] + "; \n") + outFile.write(" Mount[" + volumeNames[i] + "] = ConfigStorageC_" + volumeNames[i] + "; \n") + outFile.write(" ConfigStorage[" + volumeNames[i] + "] = ConfigStorageC_" + volumeNames[i] + "; \n") + outFile.write("} \n")