2e024d27c89614751f1a5f28ba3a4ea5ebe2d133
[pyfrprog.git] / pkernel / main.c
1 #include "mb91465k.h"
2 #include "vectors.h"
3 #include "rlt.h"
4 #include "flash.h"
5
6 #pragma section CODE=IRAM,attr=CODE
7 void main(void)
8 {
9         unsigned char error = 0;
10         unsigned char global_error = 0; 
11         unsigned int i, baseaddr;
12         unsigned int toflash2[] = {0x9b00,
13                                                                 0x0d4e,
14                                                                 0xcff1,
15                                                                 0x1601,
16                                                                 0x9b05,
17                                                                 0x04c7,
18                                                                 0xc106,
19                                                                 0x1656,
20                                                                 0xe0fb}; //len = 9
21         unsigned int toflash[] = {0x0000, 0x0000, 0x0000, 0x0000, 0x0000, 0x0000, 0x0000, 0x0000, 0x0000}; //len = 9
22         
23         /*      Enable Clock Monitor    */
24         CSCFG_MONCKI = 1;
25         CMCFG = 0x0D;
26                 
27         __EI();                    /* enable interrupts */
28         __set_il(31);              /* allow all levels */
29         InitIrqLevels();           /* init interrupts */
30
31         PORTEN = 0x3;           /* enable I/O Ports */
32                                 /* This feature is not supported by MB91V460A */
33                                /* For all other devices the I/O Ports must be enabled*/
34
35         /*      Enable LEDs     */
36         DDR14 = 0xFF;
37         PDR14 = 0xff;
38
39         /*      Initialize Reload Timer Channel 0       */
40         RLT_InitializeTimer(0, RLT_RUMMODE_RELOAD, RLT_CLOCKMODE_DIV32, RLT_TRIGGER_SOFTWARE, RLT_OUTOUTMODE_HIGHLEVEL);
41         RLT_SetReloadValue(0,0xfffe);
42         RLT_TriggerTimer(0);
43         RLT_EnableInterrupt(0, 1);
44
45         /*      Initialize UART4        */
46         InitUart4();
47
48         /*      Output Welcome Message  */
49         Puts4(" \n\n");
50         Puts4("\n\n********** Welcome to FUJITSU FLASH Programming Demo **********\n");
51
52 #if 0
53         i = 0;
54         baseaddr = 0xf4000;
55         for (; i <0x30; i+=4) {
56                 error = FLASH_SectorErase(baseaddr + i);
57                 Puts4("\nerased: ");
58                 Puts4(error == 1 ? "[success] " : "[failed] ");
59                 Puthex4(baseaddr + i, 6);
60         }
61 #endif
62         i=0;
63         Puts4("\nCurrent Content of FLASH at 0xf4000 ... 0xf401F:\n");
64         while(i < 0x20)
65         {
66                 Puts4("0x"); Puthex4( *(unsigned char *)(0xf4000 + i), 2); Puts4(" ");
67                 i++;
68                 if( (i % 0x10) == 0 ) Puts4("\n");
69         }
70         Puts4("\n");
71
72
73         i = 0;
74         baseaddr = 0xf4000;
75         for(; i<9; i++) {
76                 Puts4("\nwrite: ");
77                 error = FLASH_WriteHalfWord(baseaddr + (2*i), toflash[i]);
78                 Puts4(error == 1 ? "[sucess] " : "[failed] ");
79                 Puts4("0x");
80                 Puthex4(toflash[i], 4);
81                 Puts4(" @0x");
82                 Puthex4(baseaddr + (2*i), 6);
83         }
84
85         i=0;
86         Puts4("\nCurrent Content of FLASH at 0xf4000 ... 0xf401F:\n");
87         while(i < 0x20)
88         {
89                 Puts4("0x"); Puthex4( *(unsigned char *)(0xf4000 + i), 2); Puts4(" ");
90                 i++;
91                 if( (i % 0x10) == 0 ) Puts4("\n");
92         }
93         Puts4("\n================================================================\n");
94
95         i = 0;
96         baseaddr = 0xf4000;
97         for(; i<9; i++) {
98                 Puts4("\nwrite: ");
99                 error = FLASH_WriteHalfWord(baseaddr + (2*i), toflash2[i]);
100                 Puts4(error == 1 ? "[sucess] " : "[failed] ");
101                 Puts4("0x");
102                 Puthex4(toflash2[i], 4);
103                 Puts4(" @0x");
104                 Puthex4(baseaddr + (2*i), 6);
105         }
106
107         i=0;
108         Puts4("\nCurrent Content of FLASH at 0xf4000 ... 0xf401F:\n");
109         while(i < 0x20)
110         {
111                 Puts4("0x"); Puthex4( *(unsigned char *)(0xf4000 + i), 2); Puts4(" ");
112                 i++;
113                 if( (i % 0x10) == 0 ) Puts4("\n");
114         }
115                                 
116         /*      Output Ready Meassage   */
117         if( global_error != 0 )
118         {
119                 Puts4("\n********* FLASH Programming Demo failed **********\n");
120         }
121         else
122         {
123                 Puts4("\n********* FLASH Programming Demo done **********\n");
124         }
125
126         RLT_EnableInterrupt(0, 0);
127                                         
128     while(1)
129     {    
130          
131        HWWD_CL = 0;   
132     }   
133 }
134