main.py
00001
00002
00003
00004
00005
00006
00007
00008
00009
00010
00011
00012
00013
00014
00015
00016
00017
00018 """__NATIVE__
00019 #include <stdio.h>
00020 #include <avr/io.h>
00021 #include <util/delay.h>
00022 #include "libmmb103.h"
00023 """
00024
00025
00026
00027
00028
00029 if False:
00030 import sys
00031 print sys.heap()
00032
00033 s = "It's alive!"
00034 print s
00035
00036 import mmb
00037 mmb.lcd_print("PyMite on MMB103")
00038
00039 while True:
00040 mmb.lcd_set_line(1)
00041 if mmb.dip_get(1):
00042 mmb.lcd_print("dip1 = ON ")
00043 else:
00044 mmb.lcd_print("dip1 = OFF")
00045 mmb.sleepms(50)
00046 mmb.sleepms(50)
00047 mmb.sleepms(50)
00048 mmb.sleepms(50)
00049 mmb.sleepms(50)
00050
00051
00052
00053
00054
00055
00056
00057
00058
00059
00060 def _getImg():
00061 """__NATIVE__
00062 PmReturn_t retval;
00063 uint8_t imgType;
00064 uint16_t imgSize;
00065 uint8_t *pchunk;
00066 pPmString_t pimg;
00067 uint16_t i;
00068 uint8_t b;
00069
00070 /* Get the image type (skip any trash at beginning) */
00071 do
00072 {
00073 retval = plat_getByte(&imgType);
00074 PM_RETURN_IF_ERROR(retval);
00075 }
00076 while (imgType != OBJ_TYPE_CIM);
00077
00078 /* Quit if a code image type was not received */
00079 if (imgType != OBJ_TYPE_CIM)
00080 {
00081 PM_RAISE(retval, PM_RET_EX_STOP);
00082 return retval;
00083 }
00084
00085 /* Get the image size (little endien) */
00086 retval = plat_getByte(&b);
00087 PM_RETURN_IF_ERROR(retval);
00088 imgSize = b;
00089 retval = plat_getByte(&b);
00090 PM_RETURN_IF_ERROR(retval);
00091 imgSize |= (b << 8);
00092
00093 /* Get space for String obj */
00094 retval = heap_getChunk(sizeof(PmString_t) + imgSize, &pchunk);
00095 PM_RETURN_IF_ERROR(retval);
00096 pimg = (pPmString_t)pchunk;
00097
00098 /* Set the string object's fields */
00099 OBJ_SET_TYPE(pimg, OBJ_TYPE_STR);
00100 pimg->length = imgSize;
00101
00102 /* Start the image with the bytes that have already been received */
00103 i = 0;
00104 pimg->val[i++] = imgType;
00105 pimg->val[i++] = imgSize & 0xFF;
00106 pimg->val[i++] = (imgSize >> 8) & 0xFF;
00107
00108 /* Get the remaining bytes in the image */
00109 for(; i < imgSize; i++)
00110 {
00111 retval = plat_getByte(&b);
00112 PM_RETURN_IF_ERROR(retval);
00113
00114 pimg->val[i] = b;
00115 }
00116
00117 /* Return the image as a string object on the stack */
00118 NATIVE_SET_TOS((pPmObj_t)pimg);
00119 return retval;
00120 """
00121 pass
00122
00123
00124
00125
00126
00127
00128 g = {}
00129 while 1:
00130
00131
00132 rv = eval(Co(_getImg()), g)
00133
00134
00135 print '\x04',
00136
00137
00138
00139