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 /* Baud rate: 115200 bps, INC=767, MOD=9999, 24Mhz 8x samp */
00022 #define INC 767
00023 #define MOD 9999
00024 #define SAMP UCON_SAMP_8X
00025 
00026 /* Timer setup */
00027 #define COUNT_MODE 1      /* Use rising edge of primary source */
00028 #define PRIME_SRC 0xe     /* Div-64 prescale (for 24Mhz = 375000Hz)*/
00029 #define LEN 1             /* Count until compare then reload with LOAD */
00030 
00031 /* TMR0 ISR is 1000 Hz == 1 ms == 1000 us) */
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; /* clear compare flag */
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     /* Use GPIO44 to flash red LED when transmission occurs */
00056     *GPIO_FUNC_SEL2 = (0x01 << ((44-16*2)*2));
00057     gpio_pad_dir_set( 1ULL << 44 );
00058 
00059     *TMR_ENBL = 0;          /* Tmrs reset to enabled */
00060     *TMR0_SCTRL = 0;
00061     *TMR0_CSCTRL = 0x0040;
00062     *TMR0_LOAD = 0;         /* Reload to zero */
00063     *TMR0_COMP_UP = 375;    /* Trigger a reload at the end */
00064     *TMR0_CMPLD1 = 375;     /* Compare 1 triggered reload level */
00065     *TMR0_CNTR = 0;         /* Reset count register */
00066     *TMR0_CTRL = (COUNT_MODE<<13) | (PRIME_SRC<<9) | (LEN<<5);
00067     *TMR_ENBL = 1;          /* Enable Timer0 */
00068 
00069     /* Seed the random number generator */
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     /* Disable UART1 */
00085     *UART1_UCON = 0;
00086 
00087     return PM_RET_OK;
00088 }
00089 
00090 
00091 /*
00092  * Gets a byte from the address in the designated memory space
00093  * Post-increments *paddr.
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     /* Print error */
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     /* Print traceback */
00158     {
00159         pPmObj_t pframe;
00160         pPmObj_t pstr;
00161         PmReturn_t retval;
00162 
00163         printf("Traceback (top first):\n");
00164 
00165         /* Get the top frame */
00166         pframe = (pPmObj_t)gVmGlobal.pthread->pframe;
00167 
00168         /* If it's the native frame, print the native function name */
00169         if (pframe == (pPmObj_t)&(gVmGlobal.nativeframe))
00170         {
00171 
00172             /* The last name in the names tuple of the code obj is the name */
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             /* Get the frame that called the native frame */
00186             pframe = (pPmObj_t)gVmGlobal.nativeframe.nf_back;
00187         }
00188 
00189         /* Print the remaining frame stack */
00190         for (;
00191              pframe != C_NULL;
00192              pframe = (pPmObj_t)((pPmFrame_t)pframe)->fo_back)
00193         {
00194             /* The last name in the names tuple of the code obj is the name */
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 }

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