]> oss.titaniummirror.com Git - tinyos-2.x.git/blobdiff - tools/tinyos/misc/tos-storage-stm25p.in
Teach tos-storage-stm25p to derive NUM_SECTORS and SECTOR_SIZE.
[tinyos-2.x.git] / tools / tinyos / misc / tos-storage-stm25p.in
index 1256b8776b04d8b0c94f7e24793658121a6c0e58..ed9eb63aa6c65acc36a61bd2a61e4b406feb9941 100644 (file)
 # @author Jonathan Hui <jhui@archedrock.com>
 # @author David Gay
 # @author Kevin Klues <klueska@cs.stanford.edu>
+# @author R. Steve McKown <rsmckown@gmail.com>
 #
 # $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 *
@@ -112,8 +117,76 @@ 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 = {}
 
@@ -247,7 +320,7 @@ if cthreads == True:
   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 as ConfigMount[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")
@@ -259,6 +332,8 @@ if cthreads == True:
   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":
@@ -277,6 +352,6 @@ if cthreads == True:
 
     elif volumeTypes[volumeNames[i]] == "config":
       outFile.write("  components new ConfigStorageC(" + volumeNames[i] + ") as ConfigStorageC_" + volumeNames[i] + "; \n")
-      outFile.write("  ConfigMount[" + volumeNames[i] + "] = 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")