📄 dsp281x_csmunlock.c
字号:
/*------------------------------------------------------------------
CsmUnlock
Unlock the code security module (CSM)
Parameters:
Return Value:
STATUS_SUCCESS CSM is unlocked
STATUS_FAIL_UNLOCK CSM did not unlock
Notes:
-----------------------------------------------------------------*/
#include "DSP281x_Device.h" // DSP281x Headerfile Include File
#define STATUS_SUCCESS 0
#define STATUS_FAIL_UNLOCK 1
#define PRG_key0 0xFFFF
#define PRG_key1 0xFFFF
#define PRG_key2 0xFFFF
#define PRG_key3 0xFFFF
#define PRG_key4 0xFFFF
#define PRG_key5 0xFFFF
#define PRG_key6 0xFFFF
#define PRG_key7 0xFFFF
#define CSMSCR (volatile Uint16*)0x00000AEF // CSM status and control register
#define KEY0 (volatile Uint16*)0x00000AE0 /* low word of the 128-bit key */
#define KEY1 (volatile Uint16*)0x00000AE1 /* next word in 128-bit key */
#define KEY2 (volatile Uint16*)0x00000AE2 /* next word in 128-bit key */
#define KEY3 (volatile Uint16*)0x00000AE3 /* next word in 128-bit key */
#define KEY4 (volatile Uint16*)0x00000AE4 /* next word in 128-bit key */
#define KEY5 (volatile Uint16*)0x00000AE5 /* next word in 128-bit key */
#define KEY6 (volatile Uint16*)0x00000AE6 /* next word in 128-bit key */
#define KEY7 (volatile Uint16*)0x00000AE7 /* high word of the 128-bit key */
#define PWL0 (volatile Uint16*)0x003F7FF8 /* Password 0 */
#define PWL1 (volatile Uint16*)0x003F7FF9 /* Password 1 */
#define PWL2 (volatile Uint16*)0x003F7FFA /* Password 2 */
#define PWL3 (volatile Uint16*)0x003F7FFB /* Password 3 */
#define PWL4 (volatile Uint16*)0x003F7FFC /* Password 4 */
#define PWL5 (volatile Uint16*)0x003F7FFD /* Password 5 */
#define PWL6 (volatile Uint16*)0x003F7FFE /* Password 6 */
#define PWL7 (volatile Uint16*)0x003F7FFF /* Password 7 */
Uint16 CsmUnlock()
{
volatile Uint16 temp;
// Load the key registers with the current password
// These are defined in Example_Flash2812_CsmKeys.asm
EALLOW;
*KEY0 = PRG_key0;
*KEY1 = PRG_key1;
*KEY2 = PRG_key2;
*KEY3 = PRG_key3;
*KEY4 = PRG_key4;
*KEY5 = PRG_key5;
*KEY6 = PRG_key6;
*KEY7 = PRG_key7;
EDIS;
// Perform a dummy read of the password locations
// if they match the key values, the CSM will unlock
temp = *PWL0;
temp = *PWL1;
temp = *PWL2;
temp = *PWL3;
temp = *PWL4;
temp = *PWL5;
temp = *PWL6;
temp = *PWL7;
// If the CSM unlocked, return succes, otherwise return
// failure.
if ( (*CSMSCR & 0x0001) == 0) return STATUS_SUCCESS;
else return STATUS_FAIL_UNLOCK;
}
//===========================================================================
// No more.
//===========================================================================
⌨️ 快捷键说明
复制代码
Ctrl + C
搜索代码
Ctrl + F
全屏模式
F11
切换主题
Ctrl + Shift + D
显示快捷键
?
增大字号
Ctrl + =
减小字号
Ctrl + -