ipm.py

Go to the documentation of this file.
00001 # This file is Copyright 2007, 2009, 2010 Dean Hall.
00002 #
00003 # This file is part of the Python-on-a-Chip program.
00004 # Python-on-a-Chip is free software: you can redistribute it and/or modify
00005 # it under the terms of the GNU LESSER GENERAL PUBLIC LICENSE Version 2.1.
00006 #
00007 # Python-on-a-Chip is distributed in the hope that it will be useful,
00008 # but WITHOUT ANY WARRANTY; without even the implied warranty of
00009 # MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE.
00010 # A copy of the GNU LESSER GENERAL PUBLIC LICENSE Version 2.1
00011 # is seen in the file COPYING in this directory.
00012 
00013 ## @file
00014 #  @copybrief ipm_target
00015 
00016 ## @package ipm_target
00017 #  @brief Provides PyMite's interactive interface for the target.
00018 
00019 
00020 ##
00021 # Receives an image over the platform's standard connection.
00022 # Returns the image in a string object
00023 #
00024 def _getImg():
00025     """__NATIVE__
00026     PmReturn_t retval;
00027     uint8_t imgType;
00028     uint16_t imgSize;
00029     uint8_t *pchunk;
00030     pPmCodeImgObj_t pimg;
00031     uint16_t i;
00032     uint8_t b;
00033 
00034     /* Get the image type */
00035     retval = plat_getByte(&imgType);
00036     PM_RETURN_IF_ERROR(retval);
00037 
00038     /* Quit if a code image type was not received */
00039     if (imgType != OBJ_TYPE_CIM)
00040     {
00041         PM_RAISE(retval, PM_RET_EX_STOP);
00042         return retval;
00043     }
00044 
00045     /* Get the image size (little endien) */
00046     retval = plat_getByte(&b);
00047     PM_RETURN_IF_ERROR(retval);
00048     imgSize = b;
00049     retval = plat_getByte(&b);
00050     PM_RETURN_IF_ERROR(retval);
00051     imgSize |= (b << 8);
00052 
00053     /* Get space for CodeImgObj */
00054     retval = heap_getChunk(sizeof(PmCodeImgObj_t) + imgSize, &pchunk);
00055     PM_RETURN_IF_ERROR(retval);
00056     pimg = (pPmCodeImgObj_t)pchunk;
00057     OBJ_SET_TYPE(pimg, OBJ_TYPE_CIO);
00058 
00059     /* Start the image with the bytes that have already been received */
00060     i = 0;
00061     pimg->val[i++] = imgType;
00062     pimg->val[i++] = imgSize & 0xFF;
00063     pimg->val[i++] = (imgSize >> 8) & 0xFF;
00064 
00065     /* Get the remaining bytes in the image */
00066     for(; i < imgSize; i++)
00067     {
00068         retval = plat_getByte(&b);
00069         PM_RETURN_IF_ERROR(retval);
00070 
00071         pimg->val[i] = b;
00072     }
00073 
00074     /* Return the image as a code image object on the stack */
00075     NATIVE_SET_TOS((pPmObj_t)pimg);
00076     return retval;
00077     """
00078     pass
00079 
00080 
00081 def x04():
00082     """__NATIVE__
00083     NATIVE_SET_TOS(PM_NONE);
00084     return plat_putByte(0x04);
00085     """
00086     pass
00087 
00088 
00089 ##
00090 # Runs the target device-side interactive session.
00091 #
00092 def ipm(g={}):
00093     while 1:
00094         # Wait for a code image, make a code object from it
00095         # and evaluate the code object.
00096         # #180: One-liner turned into 3 so that objects get bound to roots
00097         s = _getImg()
00098         co = Co(s)
00099         rv = eval(co, g)
00100         x04()
00101 
00102     # Execution should never reach here
00103     # The while loop (above) probably caught a StopIteration, accidentally
00104     assert False
00105 
00106 # :mode=c:

Generated on Mon Oct 18 07:40:46 2010 for Python-on-a-chip by  doxygen 1.5.9