Embed:
(wiki syntax)
Show/hide line numbers
plat.cpp
00001 /* 00002 # This file is Copyright 2009 Dean Hall. 00003 # 00004 # This file is part of the Python-on-a-Chip program. 00005 # Python-on-a-Chip is free software: you can redistribute it and/or modify 00006 # it under the terms of the GNU LESSER GENERAL PUBLIC LICENSE Version 2.1. 00007 # 00008 # Python-on-a-Chip is distributed in the hope that it will be useful, 00009 # but WITHOUT ANY WARRANTY; without even the implied warranty of 00010 # MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. 00011 # A copy of the GNU LESSER GENERAL PUBLIC LICENSE Version 2.1 00012 # is seen in the file COPYING up one directory from this. 00013 */ 00014 00015 00016 #undef __FILE_ID__ 00017 #define __FILE_ID__ 0x70 00018 00019 00020 /** PyMite platform-specific routines for ARM7 target */ 00021 00022 00023 #include "mbed.h" 00024 #include "pm.h" 00025 00026 00027 #define CALLBACK_MS 100 00028 00029 00030 Serial serial(USBTX, USBRX, "serial"); 00031 Ticker ticker; 00032 00033 00034 static void 00035 ticker_callback(void) 00036 { 00037 PmReturn_t retval; 00038 00039 retval = pm_vmPeriodic(CALLBACK_MS); 00040 PM_REPORT_IF_ERROR(retval); 00041 } 00042 00043 00044 PmReturn_t 00045 plat_init(void) 00046 { 00047 serial.baud(19200); 00048 serial.format(8, serial.None, 1); 00049 00050 ticker.attach_us(ticker_callback, CALLBACK_MS * 1000); 00051 00052 return PM_RET_OK; 00053 } 00054 00055 00056 PmReturn_t 00057 plat_deinit(void) 00058 { 00059 /* Detach the callback from the ticker */ 00060 ticker.detach(); 00061 00062 return PM_RET_OK; 00063 } 00064 00065 00066 uint8_t 00067 plat_memGetByte(PmMemSpace_t memspace, uint8_t const **paddr) 00068 { 00069 uint8_t b = 0; 00070 00071 switch (memspace) 00072 { 00073 case MEMSPACE_RAM: 00074 case MEMSPACE_PROG: 00075 b = **paddr; 00076 *paddr += 1; 00077 return b; 00078 00079 case MEMSPACE_EEPROM: 00080 case MEMSPACE_SEEPROM: 00081 case MEMSPACE_OTHER0: 00082 case MEMSPACE_OTHER1: 00083 case MEMSPACE_OTHER2: 00084 case MEMSPACE_OTHER3: 00085 default: 00086 return 0; 00087 } 00088 } 00089 00090 00091 PmReturn_t 00092 plat_getByte(uint8_t *b) 00093 { 00094 int c; 00095 PmReturn_t retval = PM_RET_OK; 00096 00097 c = serial.getc(); 00098 *b = c & 0xFF; 00099 00100 if (c > 0xFF) 00101 { 00102 PM_RAISE(retval, PM_RET_EX_IO); 00103 } 00104 00105 return retval; 00106 } 00107 00108 00109 PmReturn_t 00110 plat_putByte(uint8_t b) 00111 { 00112 while (!serial.writeable()); 00113 serial.putc(b); 00114 00115 return PM_RET_OK; 00116 } 00117 00118 00119 PmReturn_t 00120 plat_getMsTicks(uint32_t *r_ticks) 00121 { 00122 *r_ticks = pm_timerMsTicks; 00123 00124 return PM_RET_OK; 00125 } 00126 00127 00128 void 00129 plat_reportError(PmReturn_t result) 00130 { 00131 /* Print error */ 00132 serial.printf("Error: 0x%02X\n", result); 00133 serial.printf(" Release: 0x%02X\n", gVmGlobal.errVmRelease); 00134 serial.printf(" FileId: 0x%02X\n", gVmGlobal.errFileId); 00135 serial.printf(" LineNum: %d\n", gVmGlobal.errLineNum); 00136 00137 /* Print traceback */ 00138 { 00139 pPmObj_t pframe; 00140 pPmObj_t pstr; 00141 PmReturn_t retval; 00142 00143 serial.printf("Traceback (top first):\n"); 00144 00145 /* Get the top frame */ 00146 pframe = (pPmObj_t)gVmGlobal.pthread->pframe; 00147 00148 /* If it's the native frame, print the native function name */ 00149 if (pframe == (pPmObj_t)&(gVmGlobal.nativeframe)) 00150 { 00151 00152 /* The last name in the names tuple of the code obj is the name */ 00153 retval = tuple_getItem((pPmObj_t)gVmGlobal.nativeframe.nf_func-> 00154 f_co->co_names, -1, &pstr); 00155 if ((retval) != PM_RET_OK) 00156 { 00157 serial.printf(" Unable to get native func name.\n"); 00158 return; 00159 } 00160 else 00161 { 00162 serial.printf(" %s() __NATIVE__\n", ((pPmString_t)pstr)->val); 00163 } 00164 00165 /* Get the frame that called the native frame */ 00166 pframe = (pPmObj_t)gVmGlobal.nativeframe.nf_back; 00167 } 00168 00169 /* Print the remaining frame stack */ 00170 for (; 00171 pframe != C_NULL; 00172 pframe = (pPmObj_t)((pPmFrame_t)pframe)->fo_back) 00173 { 00174 /* The last name in the names tuple of the code obj is the name */ 00175 retval = tuple_getItem((pPmObj_t)((pPmFrame_t)pframe)-> 00176 fo_func->f_co->co_names, -1, &pstr); 00177 if ((retval) != PM_RET_OK) break; 00178 00179 serial.printf(" %s()\n", ((pPmString_t)pstr)->val); 00180 } 00181 serial.printf(" <module>.\n"); 00182 } 00183 }
Generated on Tue Jul 12 2022 17:07:01 by
1.7.2