init
[pyfrprog.git] / MAIN.c
1 /* THIS SAMPLE CODE IS PROVIDED AS IS AND IS SUBJECT TO ALTERATIONS. FUJITSU */\r
2 /* MICROELECTRONICS ACCEPTS NO RESPONSIBILITY OR LIABILITY FOR ANY ERRORS OR */\r
3 /* ELIGIBILITY FOR ANY PURPOSES.                                             */\r
4 /*                 (C) Fujitsu Microelectronics Europe GmbH                  */\r
5 /*------------------------------------------------------------------------\r
6   MAIN.C\r
7   - description\r
8   - See README.TXT for project description and disclaimer.\r
9 \r
10   06.10.06  1.01   UMa    changed includes\r
11 -------------------------------------------------------------------------*/\r
12 \r
13  \r
14 /*************************@INCLUDE_START************************/\r
15 #include "mb91465k.h"\r
16 #include "vectors.h"\r
17 #include "RLT.h"\r
18 #include "Flash.h"\r
19 /**************************@INCLUDE_END*************************/\r
20 \r
21 /*********************@GLOBAL_VARIABLES_START*******************/\r
22 /**********************@GLOBAL_VARIABLES_END********************/\r
23 \r
24 \r
25 /*******************@FUNCTION_DECLARATION_START*****************/\r
26 \r
27 /*********************@FUNCTION_HEADER_START*********************\r
28 *@FUNCTION NAME:    main()                                      *\r
29 *                                                               *\r
30 *@DESCRIPTION:      The main function controls the program flow *\r
31 *                                                               *\r
32 *@PARAMETER:        none                                        *\r
33 *                                                               *\r
34 *@RETURN:           none                                        *\r
35 *                                                               *\r
36 ***********************@FUNCTION_HEADER_END*********************/\r
37 \r
38 \r
39 void main(void)\r
40 {\r
41     unsigned char error = 0;\r
42         unsigned char global_error = 0; \r
43         unsigned int i;\r
44         \r
45         /*      Enable Clock Monitor    */\r
46         CSCFG_MONCKI = 1;\r
47         CMCFG = 0x0D;\r
48                 \r
49     __EI();                    /* enable interrupts */\r
50     __set_il(31);              /* allow all levels */\r
51     InitIrqLevels();           /* init interrupts */\r
52 \r
53     PORTEN = 0x3;              /* enable I/O Ports */\r
54                                /* This feature is not supported by MB91V460A */\r
55                                /* For all other devices the I/O Ports must be enabled*/\r
56 \r
57         /*      Enable LEDs     */\r
58         DDR27 = 0xFF;\r
59         PDR27 = 0x00;\r
60 \r
61         /*      Initialize Reload Timer Channel 0       */\r
62         RLT_InitializeTimer(0, RLT_RUMMODE_RELOAD, RLT_CLOCKMODE_DIV32, RLT_TRIGGER_SOFTWARE, RLT_OUTOUTMODE_HIGHLEVEL);\r
63         RLT_SetReloadValue(0,0x1388);   // CLKP/32, 0.01s Interval => 0x1388 counts\r
64         RLT_EnableInterrupt(0);\r
65         RLT_TriggerTimer(0);\r
66                  \r
67         /*      Initialize UART4        */\r
68         InitUart4();\r
69 \r
70         /*      Output Welcome Message  */\r
71         Puts4(" \n\n");\r
72         Puts4("\n\n********** Welcome to FUJITSU FLASH Programming Demo **********\n");\r
73 \r
74         /*      Do BlankCheck on Sector at 0xA0000      */\r
75         Puts4("Blank Check of FLASH Sector at 0xA0000 ... ");\r
76         error = FLASH_SectorBlankCheck(0xA0000, 0x4000);\r
77         if( error == 1 )\r
78         {\r
79                 Puts4("done.\n");\r
80         }\r
81         else\r
82         {\r
83                 Puts4("failed.\n");\r
84         }\r
85                 \r
86         /*      Show Current Content of 0xA0000 ... 0xA001F     */\r
87         i=0;\r
88         Puts4("\nCurrent Content of FLASH at 0xA0000 ... 0xA001F:\n");\r
89         while(i < 0x20)\r
90         {\r
91                 Puts4("0x"); Puthex4( *(unsigned char *)(0xA0000 + i), 2); Puts4("  ");\r
92                 i++;\r
93                 if( (i % 0x10) == 0 ) Puts4("\n");\r
94         }\r
95         Puts4("\n");\r
96         \r
97         /*      SectorErase of FLASH Memory     0xA0000*/\r
98         Puts4("Sector Erase of 0xA0000 ... ");\r
99         error = FLASH_SectorErase(0xA0000);\r
100         error = FLASH_SectorErase(0xA0004);\r
101         if( error == 1 )\r
102         {\r
103                 Puts4("done.\n");\r
104         }\r
105         else\r
106         {\r
107                 global_error = 1;\r
108                 Puts4("failed.\n");\r
109         }\r
110 \r
111         /*      Do BlankCheck on Sectors at 0xA0000 */\r
112         Puts4("Blank Check of FLASH Sector at 0xA0000 ... ");\r
113         error = FLASH_SectorBlankCheck(0xA0000, 0x4000);\r
114         if( error == 1 )\r
115         {\r
116                 Puts4("done.\n");\r
117         }\r
118         else\r
119         {\r
120                 global_error = 1;\r
121                 Puts4("failed.\n");\r
122         }\r
123                 \r
124         /*      Show Current Content of 0xA0000 ... 0xA001F     */\r
125         i=0;\r
126         Puts4("\nCurrent Content of FLASH at 0xA0000 ... 0xA001F:\n");\r
127         while(i < 0x20)\r
128         {\r
129                 Puts4("0x"); Puthex4( *(unsigned char *)(0xA0000 + i), 2); Puts4("  ");\r
130                 i++;\r
131                 if( (i % 0x10) == 0 ) Puts4("\n");\r
132         }\r
133         Puts4("\n");\r
134         \r
135         /*      Write 0x55AA to 0xA0002 */\r
136         Puts4("Write 0x55AA to 0xA0002 ... ");\r
137         error = FLASH_WriteHalfWord(0xA0002,0x55AA);\r
138         if( error == 1 )\r
139         {\r
140                 Puts4("done.\n");\r
141         }\r
142         else\r
143         {\r
144                 global_error = 1;\r
145                 Puts4("failed.\n");\r
146         }\r
147 \r
148         /*      Write 0x33CC to 0xA0004 */\r
149         Puts4("Write 0x33CC to 0xA0004 ... ");\r
150         error = FLASH_WriteHalfWord(0xA0004,0x33CC);\r
151         if( error == 1 )\r
152         {\r
153                 Puts4("done.\n");\r
154         }\r
155         else\r
156         {\r
157                 global_error = 1;\r
158                 Puts4("failed.\n");\r
159         }\r
160                 \r
161         /*      Show Current Content of 0xA0000 ... 0xA001F     */\r
162         i=0;\r
163         Puts4("\nCurrent Content of FLASH at 0xA0000 ... 0xA001F:\n");\r
164         while(i < 0x20)\r
165         {\r
166                 Puts4("0x"); Puthex4( *(unsigned char *)(0xA0000 + i), 2); Puts4("  ");\r
167                 i++;\r
168                 if( (i % 0x10) == 0 ) Puts4("\n");\r
169         }\r
170         Puts4("\n");\r
171 \r
172                                 \r
173         /*      Output Ready Meassage   */\r
174         if( global_error != 0 )\r
175         {\r
176                 Puts4("\n********* FLASH Programming Demo failed **********\n");\r
177         }\r
178         else\r
179         {\r
180                 Puts4("\n********* FLASH Programming Demo done **********\n");\r
181         }\r
182                                         \r
183     while(1)                   /* endless loop */\r
184     {    \r
185          \r
186        HWWD_CL = 0;   \r
187        \r
188        /* feed hardware watchdog */\r
189        /* (Only for devices with hardware (R/C based) watchdog) */\r
190        /* The hardware (R/C based) watchdog is started */\r
191        /* automatically after power-up and can not be stopped */\r
192        /* If the hardware watchdog is not cleared frequently */\r
193        /* a reset is generated. */           \r
194     }   \r
195 }\r
196 \r
197 \r
198 /********************@FUNCTION_DECLARATION_END******************/\r