2a5cae2ed8ec3f30384125955fe10d2fcb7eea8d
[pyfrprog.git] / pkernel / main.c
1 #include "mb91465k.h"
2 #include "vectors.h"
3 #include "rlt.h"
4 #include "flash.h"
5
6 void main(void)
7 {
8         unsigned char error = 0;
9         unsigned char global_error = 0; 
10         unsigned int i, baseaddr;
11         
12         /*      Enable Clock Monitor    */
13         CSCFG_MONCKI = 1;
14         CMCFG = 0x0D;
15                 
16         __EI();                    /* enable interrupts */
17         __set_il(31);              /* allow all levels */
18         InitIrqLevels();           /* init interrupts */
19
20         PORTEN = 0x3;           /* enable I/O Ports */
21                                 /* This feature is not supported by MB91V460A */
22                                /* For all other devices the I/O Ports must be enabled*/
23
24         /*      Enable LEDs     */
25         DDR14 = 0xFF;
26         PDR14 = 0xff;
27
28         /*      Initialize Reload Timer Channel 0       */
29         RLT_InitializeTimer(0, RLT_RUMMODE_RELOAD, RLT_CLOCKMODE_DIV32, RLT_TRIGGER_SOFTWARE, RLT_OUTOUTMODE_HIGHLEVEL);
30         RLT_SetReloadValue(0,0xfffe);
31         RLT_TriggerTimer(0);
32         RLT_EnableInterrupt(0, 1);
33
34         /*      Initialize UART4        */
35         InitUart4();
36
37         /*      Output Welcome Message  */
38         Puts4(" \n\n");
39         Puts4("\n\n********** Welcome to FUJITSU FLASH Programming Demo **********\n");
40
41         i = 0;
42         baseaddr = 0xf4000;
43         for (; i <0x30; i+=4) {
44                 error = FLASH_SectorErase(baseaddr + i);
45                 Puts4("\nerased: ");
46                 Puts4(error == 1 ? "[success] " : "[failed] ");
47                 Puthex4(baseaddr + i, 6);
48         }
49
50         Puts4("Write simpleprog to 0xf4000 ... ");
51         error = FLASH_WriteHalfWord(0xf4000,0x9b00);
52         error = FLASH_WriteHalfWord(0xf4002,0x0d4e);
53         error = FLASH_WriteHalfWord(0xf4004,0xcff1);
54         error = FLASH_WriteHalfWord(0xf4006,0x1601);
55         error = FLASH_WriteHalfWord(0xf4008,0x9b05);
56         error = FLASH_WriteHalfWord(0xf4010,0x04c7);
57         error = FLASH_WriteHalfWord(0xf4012,0xc106);
58         error = FLASH_WriteHalfWord(0xf4014,0x1656);
59         error = FLASH_WriteHalfWord(0xf4016,0xe0fb);
60         if( error == 1 )
61         {
62                 Puts4("done.\n");
63         }
64         else
65         {
66                 global_error = 1;
67                 Puts4("failed.\n");
68         }
69                 
70         i=0;
71         Puts4("\nCurrent Content of FLASH at 0xf4000 ... 0xf401F:\n");
72         while(i < 0x20)
73         {
74                 Puts4("0x"); Puthex4( *(unsigned char *)(0xf4000 + i), 2); Puts4("  ");
75                 i++;
76                 if( (i % 0x10) == 0 ) Puts4("\n");
77         }
78         Puts4("\n");
79
80                                 
81         /*      Output Ready Meassage   */
82         if( global_error != 0 )
83         {
84                 Puts4("\n********* FLASH Programming Demo failed **********\n");
85         }
86         else
87         {
88                 Puts4("\n********* FLASH Programming Demo done **********\n");
89         }
90
91         RLT_EnableInterrupt(0, 0);
92                                         
93     while(1)
94     {    
95          
96        HWWD_CL = 0;   
97     }   
98 }
99