EDK2 doxygen online documents - Firmware Encoding Index 1
EDK2 doxygen online documents - Firmware Encoding Index

S3C24xxPkg/Sec/test.c

Go to the documentation of this file.
00001 #include "config.h"
00002 #include "bootconfig.h"
00003 #include "command-lib.h"
00004 #include <types.h>
00005 #ifdef CONFIG_MTD_CFI
00006 #include "cfi.h"
00007 #else
00008 #include "flash.h"
00009 #endif
00010 #include "mtd.h"
00011 #include "heap.h"
00012 #include "debug.h"
00013 #if defined(CONFIG_S3C2400_SMDK)
00014 #include "smdk-cfg.h"
00015 #elif defined(CONFIG_ARCH_S3C2400)
00016 #include "s3c2400.h"
00017 #elif defined(CONFIG_ARCH_SA1100)
00018 #include "sa1100.h"
00019 #elif defined(CONFIG_ARCH_S3C2410)
00020 #include "s3c2410.h"
00021 #endif
00022 
00023 
00024 
00025 static void command_led1(int argc, const char **argv);
00026 static void command_led2(int argc, const char **argv);
00027 static void command_led3(int argc, const char **argv);
00028 static void command_rtcdump(int argc, const char **argv);
00029 static void command_resetrtc(int argc, const char **argv);
00030 static void command_timer(int argc, const char **argv);
00031 static void command_show_timer_reg(int argc, const char **argv);
00032 static void command_enable_irq(int argc, const char **argv);
00033 static void command_stop(int argc, const char **argv);
00034 static void command_go_gpos(int argc, const char **argv);
00035 static void command_led_key(int argc, const char **argv);
00036 static void command_question(int argc, const char **argv);
00037 
00038 extern struct mtd_info g_mtd;
00039 extern struct cfi_private g_cfi;
00040 
00041 void tests_usage(void);
00042 
00043 static struct bootblk_command tests_commands[] = {
00044 #if defined(CONFIG_S3C2400_SMDK)
00045         { "led1",       command_led1,           NULL },
00046         { "led2",       command_led2,           NULL },
00047         { "led3",       command_led3,           NULL },
00048         { "rtcdump",    command_rtcdump,        NULL },
00049         { "restorertc", command_resetrtc,       NULL },
00050         { "timer",      command_timer,          NULL },
00051         { "show_timer_reg",     command_show_timer_reg, NULL },
00052         { "enable_irq", command_enable_irq,     NULL },
00053 #endif
00054 #ifdef CONFIG_S3C2400_GAMEPARK
00055         { "led_key",    command_led_key,        "key-led" },
00056         { "gpos",       command_go_gpos,        "gpos" },
00057         { "stop",       command_stop,           "stop" },
00058 #endif
00059         { "q",          command_question,       "q" },
00060         { NULL,         NULL,                   NULL }
00061 };
00062 
00063 void command_tests(int argc, const char **argv)
00064 {
00065         if (argc == 1) {
00066                 putstr("invalid 'test' command: too few arguments\r\n");
00067                 tests_usage();
00068         } else {
00069                 execcmd(tests_commands, argc - 1, argv + 1);
00070         }
00071 }
00072 
00073 static void command_question(int argc, const char **argv)
00074 {
00075         int retry = 3;
00076         __u8 c[2];
00077 
00078         while (retry > 0) {
00079                 putstr("are you sure (y/n) ? ");
00080                 *c = getc();
00081                 c[1] = '\0';
00082                 if ((strcmp(c, "y") == 0) || (strcmp(c, "n") == 0)) {
00083                         putstr(c);
00084                         putstr("\r\n");
00085                         break;
00086                 }
00087                 retry--;
00088                 putstr("\r\n");
00089         }
00090 }
00091 
00092 #ifdef CONFIG_S3C2400_GAMEPARK
00093 #define TMP_REG (*(volatile unsigned long *)(0x15a00034))
00094 static void command_go_gpos(int argc, const char **argv)
00095 {
00096         putstr("Go GPOS\r\n");
00097 
00098         TMP_REG = 0x17;
00099 
00100         _SRCPND = 0xffffffff;
00101         _INTPND = 0xffffffff;
00102 
00103         cpu_arm920_cache_clean_invalidate_all();
00104         cpu_arm920_tlb_invalidate_all();
00105 
00106         __asm__("mov    r1, #0\n"
00107                 "mov    r2, #0\n"
00108                 "mrc    p15, 0, r1, c1, c0, 0\n"        /* read ctrl register */
00109                 "bic    r1, r1, #0x1100\n"              /* ...i...s........ */
00110                 "bic    r1, r1, #0x000f\n"              /* .............cam */
00111                 "mcr    p15, 0, r1, c1, c0, 0\n"        /* write ctrl register */
00112                 "mov    pc, r2\n"
00113                 "nop\n"
00114                 "nop\n");
00115 }
00116 
00117 static void command_led_key(int argc, const char **argv)
00118 {
00119         _PDCON = (1 << 10);
00120         _PDDAT = (1 << 5);
00121 }
00122 
00123 extern void go_sleep(void);
00124 static void command_stop(int argc, const char **argv)
00125 {
00126 
00127         unsigned long cpsr;
00128 
00129         __asm__("mrs %0, cpsr" : "=r" (cpsr));
00130         cpsr &= ~(I_BIT);
00131         __asm__("msr cpsr_c, %0" : : "r" (cpsr));       /* enable IRQ */
00132 
00133 #ifdef CONFIG_S3C2400_SMDK
00134         _PECON = 0x2;
00135         _INTMOD = 0x00000000;
00136         _INTMSK = ~(IRQ_EINT0);
00137 #elif defined(CONFIG_S3C2400_GAMEPARK)
00138         _PECON = (0x2 << 14);
00139         _PEUP = (0 << 7);
00140         _EXTINT = (4 << 28);
00141         _INTMOD = 0x00000000;
00142         _INTMSK = ~(IRQ_EINT7);
00143 #endif
00144 
00145         //go_sleep();
00146 
00147         _SRCPND = 0xffffffff;
00148         _INTPND = 0xffffffff;
00149         _PECON = (0x2 << 14);
00150         _PEUP = (0 << 7);
00151         _EXTINT = (4 << 28);
00152 
00153         cpu_arm920_cache_clean_invalidate_all();
00154         cpu_arm920_tlb_invalidate_all();
00155 
00156         __asm__("mov    r1, #0\n"
00157                 "mov    r2, #0x34\n"
00158                 "mrc    p15, 0, r1, c1, c0, 0\n"        /* read ctrl register */
00159                 "bic    r1, r1, #0x1100\n"              /* ...i...s........ */
00160                 "bic    r1, r1, #0x000f\n"              /* .............cam */
00161                 "mcr    p15, 0, r1, c1, c0, 0\n"        /* write ctrl register */
00162                 "mov    pc, r2\n"
00163                 "nop\n"
00164                 "nop\n");
00165 }
00166 #endif
00167 
00168 #if defined(CONFIG_S3C2400_SMDK)
00169 #define PCDAT *(volatile unsigned long *)(S3C2400_IOPORT_BASE_ADDR + S3C2400_PCDAT)
00170 static void command_led1(int argc, const char **argv)
00171 {
00172         int i;
00173 
00174         for (i = 0; i < 3; i++) {
00175                 PCDAT = (PCDAT & 0xfff) | ((0xf & 0xf) << 12);
00176                 udelay(10000);
00177                 PCDAT = (PCDAT & 0xfff) | ((0x0 & 0xf) << 12);
00178                 udelay(10000);
00179         }
00180 }
00181 
00182 static void command_led2(int argc, const char **argv)
00183 {
00184         PCDAT = (PCDAT & 0xfff) | ((0x7 & 0xf) << 12);
00185         udelay(10000);
00186         PCDAT = (PCDAT & 0xfff) | ((0x3 & 0xf) << 12);
00187         udelay(10000);
00188         PCDAT = (PCDAT & 0xfff) | ((0x1 & 0xf) << 12);
00189         udelay(10000);
00190         PCDAT = (PCDAT & 0xfff) | ((0x0 & 0xf) << 12);
00191         udelay(10000);
00192 }
00193 
00194 static void command_led3(int argc, const char **argv)
00195 {
00196         unsigned long temp;
00197 
00198         PCDAT |= (1 << 12);
00199         temp = 1000000;
00200         while (temp != 0)
00201                 temp--;
00202         PCDAT &= ~(1 << 12);
00203 }
00204 
00205 static void command_rtcdump(int argc, const char **argv)
00206 {
00207         putLabeledWord("TICNT = 0x", _TICNT);
00208         putLabeledWord("RTCALM = 0x", _RTCALM);
00209         putLabeledWord("BCDSEC = 0x", _BCDSEC);
00210         putLabeledWord("BCDMIN = 0x", _BCDMIN);
00211         putLabeledWord("BCDHOUR = 0x", _BCDHOUR);
00212         putLabeledWord("BCDDAY = 0x", _BCDDAY);
00213         putLabeledWord("BCDDATE = 0x", _BCDDATE);
00214         putLabeledWord("BCDMON = 0x", _BCDMON);
00215         putLabeledWord("BCDYEAR = 0x", _BCDYEAR);
00216 
00217 }
00218 
00219 /* reset rtc to 1970. 1. 1. 0. 0. 0 */
00220 static void command_resetrtc(int argc, const char **argv)
00221 {
00222         _RTCCON = (unsigned char)0x1;
00223         _TICNT = (unsigned char)0x0;
00224         _RTCALM = (unsigned char)0x0;
00225         _BCDSEC = (unsigned char)0x0;
00226         _BCDMIN = (unsigned char)0x0;
00227         _BCDHOUR = (unsigned char)0x0;
00228         _BCDDAY = (unsigned char)0x0;
00229         _BCDDATE = (unsigned char)0x1;
00230         _BCDMON = (unsigned char)0x1;
00231         _BCDYEAR = (unsigned char)0x70;
00232 }
00233 
00234 static void command_show_timer_reg(int argc, const char **argv)
00235 {
00236         unsigned long cpsr = 0;
00237 
00238         putLabeledWord("TCON = ", _TCON);
00239         putLabeledWord("TCNTO4 = ", _TCNTO4);
00240         putLabeledWord("SRCPND = ", _SRCPND);
00241         putLabeledWord("INTPND = ", _INTPND);
00242         putLabeledWord("INTMSK = ", _INTMSK);
00243         __asm__("mrs %0, cpsr" : "=r" (cpsr));
00244         putLabeledWord(">> current CPSR = ", cpsr);
00245 }
00246 
00247 static void command_enable_irq(int argc, const char **argv)
00248 {
00249         unsigned long cpsr = 0;
00250 
00251         __asm__("mrs %0, cpsr" : "=r" (cpsr));
00252         cpsr &= ~(I_BIT);
00253         __asm__("msr cpsr_c, %0" : : "r" (cpsr));       /* enable IRQ */
00254 }
00255 
00256 static void command_timer(int argc, const char **argv)
00257 {
00258         unsigned long cpsr = 0;
00259         unsigned long count = 0;
00260 
00261         __asm__("mrs %0, cpsr" : "=r" (cpsr));
00262         /*putLabeledWord(">> current CPSR = ", cpsr);*/
00263 #if 1 /* hacked by nandy */
00264         cpsr &= ~(I_BIT);
00265         __asm__("msr cpsr_c, %0" : : "r" (cpsr));       /* enable IRQ */
00266         /*putLabeledWord(">> current CPSR = ", cpsr);*/
00267 #endif
00268         _TCFG0 = 0x0f00;        /* prescaler value = 15 */
00269 
00270 #if 1
00271         _TCNTB4 = 15626;        /* down-counter, maximum value is 65535 (2^16) */
00272 #else
00273         _TCNTB4 = 65535;        /* down-counter, maximum value is 65535 (2^16) */
00274 #endif
00275 
00276         _INTMOD = 0x00000000;
00277 #if 0
00278         _INTMSK = 0xffffbfff;
00279 #else
00280         _INTMSK = 0x00000000;
00281 #endif
00282         _SRCPND = 0x00000000;
00283         _INTPND = 0x00000000;
00284 
00285         _TCON = 0x600000; /* internal mode (auto reload), update TCNTB4, stop Timer 4 */
00286         _TCON = 0x500000;       /* interval mode, no operation, start Timer 4 */
00287 
00288 #if 0
00289         count = 0;
00290         while (1) {
00291                 if ((_INTPND & 0x00004000) && (0x00004000)) {
00292                         if (count < 100000) {
00293                                 count++;
00294                                 _INTPND = 0x00000000;
00295                         } else {
00296                                 count = 0;
00297                                 putstr(".\n");
00298                                 _INTPND = 0x00000000;
00299                         }
00300                 }
00301         }
00302 #endif
00303 #if 0
00304         putLabeledWord("SRCPND = ", _SRCPND);
00305         putLabeledWord("TCON = ", _TCON);
00306         putLabeledWord("TCNTB4 = ", _TCNTB4);
00307 #endif
00308 }
00309 #endif
00310 
00311 
00312 /*
00313  * Messages
00314  */
00315 
00316 void tests_usage(void)
00317 {
00318         int i = 0;
00319         putstr("Usage:\r\n");
00320         putstr("  test <items>\r\n");
00321         putstr("  items: ");
00322         for (i = 0; tests_commands[i].cmdstr != NULL; i++) {
00323                 if (!(i % 5)) {
00324                         putstr("\r\n"); 
00325                         putstr("         "); 
00326                 }
00327                 putstr(tests_commands[i].helpstr); putstr(", ");
00328         }
00329         putstr("\r\n");
00330 }
 All Data Structures Namespaces Files Functions Variables Typedefs Enumerations Enumerator Properties Defines