Go to the documentation of this file.00001
00002
00003
00004
00005
00006
00007
00008
00009
00010
00011
00012
00013
00014
00015
00016
00017
00018
00019
00020
00021
00022
00023
00024
00025
00026
00027
00028
00029
00030
00031
00032
00033
00034
00035
00036
00037
00038
00039
00040
00041
00042
00043
00044
00045
00046
00047
00048
00049
00050
00051
00052
00053
00054
00055
00056
00057
00058
00059
00060
00061
00062
00063
00064
00065
00066
00067
00068
00069
00070
00071
00072
00073
00074
00075
00076
00077
00078
00079
00080
00081
00082
00083
00084
00085
00086
00087
00088 #include "board.h"
00089
00090 #include <stdbool.h>
00091 #include <stdio.h>
00092
00093
00094
00095
00096
00097
00098 Pin pinwp = PIN_LED_1;
00099
00100
00101 uint32_t offset[] =
00102 {
00103 0x0000, 0x0004, 0x0010, 0x0014, 0x0020, 0x0024, 0x0050, 0x0054,
00104 0x0060, 0x0064, 0x0070, 0x0074, 0x00A0, 0x00A4, 0x0090, 0x0094
00105 };
00106
00107
00108
00109
00110
00111
00112
00113
00114
00115
00116 static uint32_t *_GetPioFromPin(const Pin *pin)
00117 {
00118 Pio *pio = pin->pio;
00119 return (uint32_t *)pio;
00120 }
00121
00122
00123
00124
00125
00126
00127 static void _DisplayMenu(void)
00128 {
00129 printf("\n\r\n\r");
00130 printf("Enter 'l' to enable Write Protect and ");
00131 printf("enter 'u' to disable Write Protect.\r\n");
00132 printf("\n\r");
00133 printf("Select the register to be written by a value(0x12345678).\n\r");
00134 printf(" 0 : PIO Enable Register\t(0x0000)\n\r");
00135 printf(" 1 : PIO Disable Register\t(0x0004)\n\r");
00136 printf(" 2 : PIO Output Enable Register\t(0x0010)\n\r");
00137 printf(" 3 : PIO Output Disable Register\t(0x0014)\n\r");
00138 printf(" 4 : PIO Input Filter Enable Register\t(0x0020)\n\r");
00139 printf(" 5 : PIO Input Filter Disable Register\t(0x0024)\n\r");
00140 printf(" 6 : PIO Multi-driver Enable Register\t(0x0050)\n\r");
00141 printf(" 7 : PIO Multi-driver Disable Register\t(0x0054)\n\r");
00142 printf(" 8 : PIO Pull Up Disable Register\t(0x0060)\n\r");
00143 printf(" 9 : PIO Pull Up Enable Register\t(0x0064)\n\r");
00144 printf(" a : PIO Peripheral ABCD Select Register 1\t(0x0070)\n\r");
00145 printf(" b : PIO Peripheral ABCD Select Register 2\t(0x0074)\n\r");
00146 printf(" c : PIO Output Write Enable Register\t(0x00A0)\n\r");
00147 printf(" d : PIO Output Write Disable Register\t(0x00A4)\n\r");
00148 printf(" e : PIO Pad Pull Down Disable Register\t(0x0090)\n\r");
00149 printf(" f : PIO Pad Pull Down Enable Register\t(0x0094)\n\r");
00150 printf("\n\r\n\r");
00151 }
00152
00153
00154
00155
00156
00157
00158
00159
00160
00161
00162 extern int main(void)
00163 {
00164 uint8_t cmd;
00165 uint32_t wpsr;
00166 uint32_t *pReg;
00167 const uint32_t dummy = 0x12345678;
00168
00169
00170 WDT_Disable(WDT);
00171
00172 SCB_EnableICache();
00173 SCB_EnableDCache();
00174
00175
00176 printf("-- Peripheral Protect Example %s --\n\r", SOFTPACK_VERSION);
00177 printf("-- %s\n\r", BOARD_NAME);
00178 printf( "-- Compiled: %s %s With %s--\n\r", __DATE__, __TIME__ , COMPILER_NAME) ;
00179 _DisplayMenu();
00180
00181
00182 PMC_EnablePeripheral(pinwp.id);
00183
00184 pReg = _GetPioFromPin(&pinwp);
00185
00186 while (1) {
00187
00188 cmd = DBG_GetChar();
00189
00190 switch (cmd) {
00191 case 'm':
00192 _DisplayMenu();
00193 break;
00194
00195 case 'l':
00196 PIO_EnableWriteProtect(&pinwp);
00197 printf("The Write Protect is enabled.\r\n");
00198 break;
00199
00200 case 'u':
00201 PIO_DisableWriteProtect(&pinwp);
00202 printf("The Write Protect is disabled.\r\n");
00203 break;
00204
00205 case '0':
00206 case '1':
00207 case '2':
00208 case '3':
00209 case '4':
00210 case '5':
00211 case '6':
00212 case '7':
00213 case '8':
00214 case '9':
00215 *(pReg + offset[cmd - '0'] / 4) = dummy;
00216 break;
00217
00218 case 'a':
00219 case 'b':
00220 case 'c':
00221 case 'd':
00222 case 'e':
00223 case 'f':
00224 *(pReg + offset[cmd - 'a' + 10] / 4) = dummy;
00225 break;
00226
00227 default:
00228 cmd = 'x';
00229 break;
00230 }
00231
00232 if ((cmd != 'x') && (cmd != 'm') && (cmd != 'l') && (cmd != 'u')) {
00233
00234 wpsr = PIO_GetWriteProtectViolationInfo(&pinwp);
00235 if ((wpsr & PIO_WPMR_WPEN_EN) == PIO_WPMR_WPEN_EN) {
00236
00237 printf("Write protect violation is detected!\r\n");
00238 printf("The offset of write-protected register is 0x%04x.\r\n",
00239 (unsigned int)((wpsr & 0x00FFFF00) >> 8));
00240 } else {
00241
00242 printf("No write protect violation is detected.\r\n");
00243 }
00244 }
00245 }
00246 }