⭐ 欢迎来到虫虫下载站! | 📦 资源下载 📁 资源专辑 ℹ️ 关于我们
⭐ 虫虫下载站

📄 dec5502_esam.c

📁 DSP开发可以用来看外设情况的程序
💻 C
字号:


/******************************************************************************/
/*  Copyright 2004 by SEED Electronic Technology LTD.                         */
/*  All rights reserved. SEED Electronic Technology LTD.                      */
/*  Restricted rights to use, duplicate or disclose this code are             */
/*  granted through contract.                                                 */
/*                                                                            */
/*                                                                            */
/******************************************************************************/
/* MODULE NAME... UART and ESAM												  */
/* FILENAME...... DEC5502_ESAM.c										  	  */
/* DATE CREATED.. Wed 10/21/2004 											  */
/* PROJECT....... Communicate between ESAM and on-chip UART of 5502			  */
/* COMPONENT..... 															  */
/* PREREQUISITS.. 															  */
/*----------------------------------------------------------------------------*/
/* DESCRIPTION:  															  */
/*   																		  */
/* This is an example of communication between ESAM and on-chip UART of 5502  */
/******************************************************************************/

#include <stdio.h>
#include <csl.h>
#include <csl_pll.h>
#include <csl_chip.h>
#include <csl_irq.h>
#include <csl_uart.h>

#include "Esam_Function.h"
#include "Uart_Function.h"
#include "DEC5502_MAC.h"
#include "DEC5502_DES.h"
#include "Emif.h"
#include "Timer.h"

Uint16 MK[8] = {0x11,0x22,0x33,0x44,0x55,0x66,0x77,0x88};
Uint16 CSK[8] = {0x00,0x00,0x00,0x00,0x00,0x00,0x00,0x00};
Uint16 MK16[16] = {0x11,0x22,0x33,0x44,0x55,0x66,0x77,0x88,
				   0xAA,0xBB,0xCC,0xDD,0xEE,0xFF,0x11,0x22};							

Uint16 i;
Uint16 Temp;
Uint16 SerialNum[8];			// 存储ESAM复位后获取的序列号
Uint16 RandomData[8];			// 存储取得的随机数
Uint16 Input[48]; 
Uint16 Output[48];

/* 外部认证密钥 */			
//Uint16 AuthenKey[16] = {0x57,0x41,0x54,0x43,0x48,0x44,0x41,0x54,   
//					    0x41,0x54,0x69,0x6D,0x65,0x43,0x4F,0x53};
						
/* 操作的返回状态 */
Uint16 FeedState = 0x00;

void main(void)
{
	Uint16 i;
	
 	/* Initialize CSL library - This is REQUIRED !!! */
	CSL_init();
	
	/* 设置锁相环 */
	PLL_setFreq(1,		// PLL mode
	 		  0xF, 		// Multiply factor, Valid values are (multiply by)10
	 		    0,		// Sysclk 0 Divide Down
	 		    1,		// Sysclk1 Divider 150MHz
	 		    3,		// Sysclk2 Divider 75MHz
	 		    3,		// Sysclk3 Divider
	 		    0);		// DSP core clock 300MHz,单指令执行时间为3.33纳秒	 	
	
	/* 清空序列号 */
	for(i=0; i<8; i++)
	{
	 	SerialNum[i] = 0;
	}	
		    
	/* 配置EMIF */
	Emif_Config();
	
	/* 配置定时器 */
	Config_Timer();
	
	/* Configure UART registers */
    Uart_Config();
    
    /* 填写欲写入的数据,清空接收数据缓冲区 */
    for(i=0; i<0x30; i++)
    {
    	Input[i] = i+1;
    	Output[i] = 0;
    }
    
    /* 复位ESAM卡,用来获取ESAM卡的序列号*/						
	FeedState = Reset_Esam(SerialNum);	
   	
   	/* 利用MK和序列号作DES加密运算来获取CSK */	
   	//Des8(SerialNum,MK,CSK,EN0,1);
    
	/* 向ESAM发取随机数命令,获取随机数 */
	//FeedState = Get_Random(RandomData, 0x08);
	
	/* 主控密钥的外部认证 */
	//FeedState = Extern_Authen(RandomData,0x00,CSK,DES8);
	
	/* 删除目录 */
	//FeedState = Del_Direct();	
	
	/* 建立Key文件 */
	//FeedState = Create_Keyfile(0x0000, 0x50, 0xF0);
	
	/* 建立主控密钥,密钥标识为0x00 */
	//FeedState = Increase_Key(0x00, 0x39, 0xF0, 0xF0, 0x0A, 0xFF, CSK, DES8);
	
	/* 建立线路保护加密密钥,密钥标识为0x01 */
	//FeedState = Increase_Key(0x01, 0x36, 0xF0, 0xEF, 0xFF, 0xFF, MK, DES8);
	
	/* 建立线路保护加密密钥,密钥标识为0x02 */
	//FeedState = Increase_Key(0x02, 0x36, 0xF0, 0xEF, 0xFF, 0xFF, MK16, DES16);
	
	/* 建立第1个线路加密和MAC保护二进制文件,文件标识为0x3F01,线路保护密钥为0x01 */
	//FeedState = Create_Binaryfile(0x3F01, 0x0050, 0xF0, 0xF0, 0x01);
	
	/* 建立第2个线路加密和MAC保护二进制文件,文件标识为0x3F02,线路保护密钥为0x01 */
	// 通过外部认证之后才能建立文件
	//FeedState = Create_Binaryfile(0x3F02, 0x0400, 0xF0, 0xF0, 0x01);
	
	/* 建立第3个线路加密和MAC保护二进制文件,文件标识为0x3F03,线路保护密钥为0x02 */
	// 通过外部认证之后才能建立文件
	//FeedState = Create_Binaryfile(0x3F03, 0x0400, 0xF0, 0xF0, 0x02);
	
	/* 选择该二进制文件 */
	//FeedState = Select_File(0x3F03);
	
	/* 写二进制文件 */
	//FeedState = Write_Binaryfile(Input,0x30, 0x0000, MK16, DES16);
	
	/* 读二进制文件 */
	//FeedState = Read_Binaryfile(0x0000, 0x30, MK16, Output, DES16);
	
	/*建立第4个线路加密和MAC保护二进制文件,文件标识为0x3F04,线路保护密钥为0x02,
	  读权限为F9,写权限为FA,长度为1K */
	//FeedState = Create_Binaryfile(0x3F04, 0x0400, 0xF9, 0xFA, 0x02);
	
	/* 建立外部认证密钥,密钥标识为0x04,后续状态为0x0B */
	//FeedState = Increase_Key(0x04, 0x39, 0xF0, 0xF0, 0x0B, 0xFF, MK, DES8);
	
	 /* 复位ESAM卡,用来获取ESAM卡的序列号*/						
	//FeedState = Reset_Esam(SerialNum);	
   	
   	/* 利用MK和序列号作DES加密运算来获取CSK */	
   	//Des8(SerialNum,MK,CSK,EN0,1);
    
	/* 向ESAM发取随机数命令,获取随机数 */
	//FeedState = Get_Random(RandomData, 0x08);
	
	/* 主控密钥的外部认证 */
	//FeedState = Extern_Authen(RandomData,0x00,CSK,DES8);
	
	/* 选择该二进制文件 */
	//FeedState = Select_File(0x3F04);
	
	/* 向ESAM发取随机数命令,获取随机数 */
	//FeedState = Get_Random(RandomData, 0x08);
	
	/* 外部认证密钥的外部认证 */
	//FeedState = Extern_Authen(RandomData,0x04,MK,DES8);
	
	/* 写二进制文件 */
	//FeedState = Write_Binaryfile(Input,0x30, 0x0000, MK16, DES16);
	
	/* 读二进制文件 */
	//FeedState = Read_Binaryfile(0x0000, 0x30, MK16, Output, DES16);
}

/******************************************************************************/
/*	No more																	  */
/******************************************************************************/

⌨️ 快捷键说明

复制代码 Ctrl + C
搜索代码 Ctrl + F
全屏模式 F11
切换主题 Ctrl + Shift + D
显示快捷键 ?
增大字号 Ctrl + =
减小字号 Ctrl + -