plat.c
Go to the documentation of this file.00001
00010 #undef __FILE_ID__
00011 #define __FILE_ID__ 0x52
00012
00013 #include <stdio.h>
00014
00015 #include <mc1322x.h>
00016 #include <board.h>
00017
00018 #include "pm.h"
00019
00020
00021
00022 #define INC 767
00023 #define MOD 9999
00024 #define SAMP UCON_SAMP_8X
00025
00026
00027 #define COUNT_MODE 1
00028 #define PRIME_SRC 0xe
00029 #define LEN 1
00030
00031
00032 #define PLAT_TIME_PER_TICK_USEC 1000
00033
00034
00035 void
00036 tmr0_isr(void)
00037 {
00038 pm_vmPeriodic(PLAT_TIME_PER_TICK_USEC);
00039
00040 *TMR0_SCTRL = 0;
00041 *TMR0_CSCTRL = 0x0040;
00042 }
00043
00044
00045 PmReturn_t
00046 plat_init(void)
00047 {
00048 trim_xtal();
00049 uart1_init(INC,MOD,SAMP);
00050 vreg_init();
00051 maca_init();
00052 set_power(0x12);
00053 set_channel(0);
00054
00055
00056 *GPIO_FUNC_SEL2 = (0x01 << ((44-16*2)*2));
00057 gpio_pad_dir_set( 1ULL << 44 );
00058
00059 *TMR_ENBL = 0;
00060 *TMR0_SCTRL = 0;
00061 *TMR0_CSCTRL = 0x0040;
00062 *TMR0_LOAD = 0;
00063 *TMR0_COMP_UP = 375;
00064 *TMR0_CMPLD1 = 375;
00065 *TMR0_CNTR = 0;
00066 *TMR0_CTRL = (COUNT_MODE<<13) | (PRIME_SRC<<9) | (LEN<<5);
00067 *TMR_ENBL = 1;
00068
00069
00070 *MACA_RANDOM = 42;
00071
00072 enable_irq(TMR);
00073
00074 return PM_RET_OK;
00075 }
00076
00077
00078 PmReturn_t
00079 plat_deinit(void)
00080 {
00081 maca_off();
00082 disable_irq(TMR);
00083
00084
00085 *UART1_UCON = 0;
00086
00087 return PM_RET_OK;
00088 }
00089
00090
00091
00092
00093
00094
00095 uint8_t
00096 plat_memGetByte(PmMemSpace_t memspace, uint8_t const **paddr)
00097 {
00098 uint8_t b = 0;
00099
00100 switch (memspace)
00101 {
00102 case MEMSPACE_RAM:
00103 case MEMSPACE_PROG:
00104 b = **paddr;
00105 *paddr += 1;
00106 return b;
00107 case MEMSPACE_EEPROM:
00108 case MEMSPACE_SEEPROM:
00109 case MEMSPACE_OTHER0:
00110 case MEMSPACE_OTHER1:
00111 case MEMSPACE_OTHER2:
00112 case MEMSPACE_OTHER3:
00113 default:
00114 return 0;
00115 }
00116 }
00117
00118
00119 PmReturn_t
00120 plat_getByte(uint8_t *b)
00121 {
00122 *b = uart1_getc();
00123
00124 return PM_RET_OK;
00125 }
00126
00127
00128 PmReturn_t
00129 plat_putByte(uint8_t b)
00130 {
00131 uart1_putc(b);
00132
00133 return PM_RET_OK;
00134 }
00135
00136
00137 PmReturn_t
00138 plat_getMsTicks(uint32_t *r_ticks)
00139 {
00140 global_irq_disable();
00141 *r_ticks = pm_timerMsTicks;
00142 global_irq_enable();
00143
00144 return PM_RET_OK;
00145 }
00146
00147
00148 void
00149 plat_reportError(PmReturn_t result)
00150 {
00151
00152 printf("Error: 0x%02X\n", result);
00153 printf(" Release: 0x%02X\n", gVmGlobal.errVmRelease);
00154 printf(" FileId: 0x%02X\n", gVmGlobal.errFileId);
00155 printf(" LineNum: %d\n", gVmGlobal.errLineNum);
00156
00157
00158 {
00159 pPmObj_t pframe;
00160 pPmObj_t pstr;
00161 PmReturn_t retval;
00162
00163 printf("Traceback (top first):\n");
00164
00165
00166 pframe = (pPmObj_t)gVmGlobal.pthread->pframe;
00167
00168
00169 if (pframe == (pPmObj_t)&(gVmGlobal.nativeframe))
00170 {
00171
00172
00173 retval = tuple_getItem((pPmObj_t)gVmGlobal.nativeframe.nf_func->
00174 f_co->co_names, -1, &pstr);
00175 if ((retval) != PM_RET_OK)
00176 {
00177 printf(" Unable to get native func name.\n");
00178 return;
00179 }
00180 else
00181 {
00182 printf(" %s() __NATIVE__\n", ((pPmString_t)pstr)->val);
00183 }
00184
00185
00186 pframe = (pPmObj_t)gVmGlobal.nativeframe.nf_back;
00187 }
00188
00189
00190 for (;
00191 pframe != C_NULL;
00192 pframe = (pPmObj_t)((pPmFrame_t)pframe)->fo_back)
00193 {
00194
00195 retval = tuple_getItem((pPmObj_t)((pPmFrame_t)pframe)->
00196 fo_func->f_co->co_names, -1, &pstr);
00197 if ((retval) != PM_RET_OK) break;
00198
00199 printf(" %s()\n", ((pPmString_t)pstr)->val);
00200 }
00201 printf(" <module>.\n");
00202 }
00203 }