Example #1
0
//====================================================
//	PPS
void	PPS(void)
{	
	HALFWX P12;

	P12=((HALFW)iso7816_buffer[2] << 8) + (HALFW)iso7816_buffer[3];
	switch(P12)
	{	
		case 0x11FE:	{ PPS_ACK(); IoInit(0x11); break; }
		case 0x947B:	{ PPS_ACK(); IoInit(0x94); break; }
		case 0x957A:	{ PPS_ACK(); IoInit(0x95); break; }
		case 0x9679:	{ PPS_ACK(); IoInit(0x96); break; }
		default: return;
	}
} 
Example #2
0
static void WcDemoUseMainOsc(void)
{
    stc_wc_config_t stcWcConfig;
    stc_wc_pres_clk_t stcWcPresClk;
    uint32_t u32Cnt=0UL;

    // Clear structure
    PDL_ZERO_STRUCT(stcWcConfig);
    PDL_ZERO_STRUCT(stcWcPresClk);
    
    // Initialize GPIO for watch counter demo
    IoInit();
#ifdef DEBUG_PRINT
    printf("1st demo\n");
    printf("Source clock = Main OSC \n");
    m_u16ValidFlag = 0;
#endif
#if (PDL_MCU_TYPE == PDL_FM3_TYPE12) || (PDL_MCU_CORE == PDL_FM0P_CORE) || (PDL_MCU_CORE == PDL_FM4_CORE)    
    stcWcPresClk.enOutputClk = WcPresOutClkArray6;          // Set counter value, 2^20/4000000 = 0.26S, 1 step = 0.26S
#else
    stcWcPresClk.enOutputClk = WcPresOutClkArray1;          // Watch counter prescaler output array0: 2^22/src clock       
#endif
    stcWcPresClk.enInputClk = WcPresInClkMainOsc;           // Select watch counter prescaler source clock as Main OSC 
    Wc_Pres_SelClk((stc_wcn_t*)&WC0, &stcWcPresClk);

    stcWcConfig.enCntClk = WcCntClkWcck0;                   // Select watch counter source clock WCCK0                         
    stcWcConfig.u8ReloadValue = 1;                          // Set watch counter reload value
    Wc_Init((stc_wcn_t*)&WC0, &stcWcConfig);  
    
    Wc_Pres_EnableDiv((stc_wcn_t*)&WC0);  
    
#ifdef DEBUG_PRINT
    printf("==================================================\n");
    printf("Start counter, waiting several seconds approximately\n");
#endif
    // Start counter
    Wc_EnableCount((stc_wcn_t*)&WC0);
    do
    {
        if( PdlSet == Wc_GetIrqFlag((stc_wcn_t*)&WC0))
        {
            Wc_ClearIrqFlag((stc_wcn_t*)&WC0);
            IoPolling();
        }
        u32Cnt++;
    } while(u32Cnt <SystemCoreClock/10);
    // Delay some time
#ifdef DEBUG_PRINT
    printf("==================================================\n");
    printf("Stop counter, waiting several seconds approximately\n");
    printf("\n");
#endif
    // Stop counter
    Wc_DisableCount((stc_wcn_t*)&WC0);
    // Delay some time
    Delay();
}
Example #3
0
/*!
 ******************************************************************************
 ** \brief Watch counter polling example code(Use Sub Cr)
 **
 ** 1. Initialization.
 ** 2. Set counter clock as SubCr.
 ** 3. Enable interrupt.
 ** 4. Enable count operation and delay some time.
 ** 5. Stop counter.
 ******************************************************************************
 */
static void WcDemoUseSubCr(void)
{
    stc_wc_config_t stcWcConfig;
    stc_wc_pres_clk_t stcWcPresClk;
    uint32_t u32Cnt=0UL;

    // Clear structure
    PDL_ZERO_STRUCT(stcWcConfig);
    PDL_ZERO_STRUCT(stcWcPresClk);
    
    // Initialize GPIO for watch counter demo
    IoInit();
#ifdef DEBUG_PRINT
    printf("4th demo\n");
    printf("Source clock = Low CR \n");
    m_u16ValidFlag = 0;
#endif
    
    stcWcPresClk.enOutputClk = WcPresOutClkArray4;          // Set counter value, 2^10/100000, 1 step = 10.24mS
    stcWcPresClk.enInputClk = WcPresInClkLowCr;             // Select watch counter prescaler source clock as Low CR
    Wc_Pres_SelClk((stc_wcn_t*)&WC0, &stcWcPresClk);
    
    stcWcConfig.enCntClk = WcCntClkWcck1;                   // Select watch counter source clock WCCK0                     
    stcWcConfig.u8ReloadValue = 1;                          // Set watch counter reload value  
    Wc_Init((stc_wcn_t*)&WC0, &stcWcConfig);
    
    Wc_Pres_EnableDiv((stc_wcn_t*)&WC0);
     

#ifdef DEBUG_PRINT
    printf("==================================================\n");
    printf("Start counter, waiting several seconds approximately\n");
#endif
    // Start counter
    Wc_EnableCount((stc_wcn_t*)&WC0);
    do
    {
        if( PdlSet == Wc_GetIrqFlag((stc_wcn_t*)&WC0))
        {
            Wc_ClearIrqFlag((stc_wcn_t*)&WC0);
            IoPolling();
        }
        u32Cnt++;
    } while(u32Cnt <SystemCoreClock/10);
#ifdef DEBUG_PRINT
    printf("==================================================\n");
    printf("Stop counter, waiting several seconds approximately\n");
    printf("\n");
#endif
    // Stop counter
    Wc_DisableCount((stc_wcn_t*)&WC0);
    // Delay some time
    Delay();
}
Example #4
0
void DevInit()
{
	DevInitPlatform();

	auto kio = new KIODriver;
	if (kio)
	{
		DevRegister(kio);
		kio->Release();
	}

	LINK_MODULE(ConsoleDrv);
	LINK_MODULE(InitRdDrv);

	IoInit();
}
Example #5
0
/**

  This function initialize guest common context.

**/
VOID
InitGuestContextCommon (
  VOID
  )
{
  UINT32  Index;

  //
  // CompatiblePageTable for IA32 flat mode only
  //
  mGuestContextCommon.CompatiblePageTable = CreateCompatiblePageTable ();
  mGuestContextCommon.CompatiblePageTablePae = CreateCompatiblePageTablePae ();

  mGuestContextCommon.MsrBitmap = (UINT64)(UINTN)AllocatePages (1);

  EptInit ();

  IoInit ();

  VmxTimerInit ();

  //
  // Init GuestContextPerCpu
  //
  for (Index = 0; Index < mHostContextCommon.CpuNum; Index++) {
    mGuestContextCommon.GuestContextPerCpu[Index].Stack = (UINTN)AllocatePages (1);
    mGuestContextCommon.GuestContextPerCpu[Index].Stack += FRM_PAGES_TO_SIZE (1);

    mGuestContextCommon.GuestContextPerCpu[Index].Cr0 = mGuestContextCommon.GuestContextPerCpu[mBspIndex].Cr0;
    mGuestContextCommon.GuestContextPerCpu[Index].Cr3 = mGuestContextCommon.GuestContextPerCpu[mBspIndex].Cr3;
    mGuestContextCommon.GuestContextPerCpu[Index].Cr4 = mGuestContextCommon.GuestContextPerCpu[mBspIndex].Cr4;
    CopyMem (&mGuestContextCommon.GuestContextPerCpu[Index].Gdtr, &mGuestContextCommon.GuestContextPerCpu[mBspIndex].Gdtr, sizeof(IA32_DESCRIPTOR));
    CopyMem (&mGuestContextCommon.GuestContextPerCpu[Index].Idtr, &mGuestContextCommon.GuestContextPerCpu[mBspIndex].Idtr, sizeof(IA32_DESCRIPTOR));

    mGuestContextCommon.GuestContextPerCpu[Index].VmExitMsrStore = (UINT64)(UINTN)AllocatePages (1);
    mGuestContextCommon.GuestContextPerCpu[Index].VmExitMsrLoad  = (UINT64)(UINTN)AllocatePages (1);
    mGuestContextCommon.GuestContextPerCpu[Index].VmEnterMsrLoad = (UINT64)(UINTN)AllocatePages (1);

    //
    // Allocate GuestVmcs
    //
    InitGuestVmcs (Index);
  }

}
Example #6
0
//	Main process
void ISO7816_main(void)
{
	//register uint16 i=0;
	//register uint16 len;
	uint16 sw;
	while(1) {
		switch(_iso7816_state) {
		 	case ISO7816_DORMANT: 
				VDCON = 0x00;						//	VD closed
				FDCON = 0X00;						//	FD closed
				IoInit(0x11);						//	H/W initial	 
				//rP0 = 0x00;							//	disable output, low voltage level
				Tx_n_Bytes(1, ATR);		   			//kirim 3B	 (ask for T=0 protocol)	
				Initialize_Hardware();							  
				Initialize_Operating_System();	 	 
				Send_ATR();	//	Send ATR
				_iso7816_state = ISO7816_RECEIVE_CMD;
				Sleep_Mode();
				break;
			case ISO7816_WAIT_PPS:

				break;
			case ISO7816_READY:		
				//Sleep_Mode();			//	Power down mode after thread has been executed
				/*_iso7816_cla = iso7816_buffer[0] = receive_byte();		//CLA
				_iso7816_ins = iso7816_buffer[1] = receive_byte();		//INS
				iso7816_buffer[2] = receive_byte();		//P1
				iso7816_buffer[3] = receive_byte();		//P2
				iso7816_buffer[4] = receive_byte();		//P3
				len = (5 + iso7816_buffer[4]);
				
				if(len > 5) {
					//if(iso7816_buffer[1] == 0xA4) {
					send_byte(iso7816_buffer[1]);
					//send_byte(0);
					for(i=5;i<len;i++) {
						iso7816_buffer[i] = receive_byte();
					} 
					//}
				}
				//iso7816_buffer[5] = receive_byte();
				//iso7816_buffer[6] = receive_byte();
				_iso7816_state = ISO7816_RUNNING;  */
				break;
			case ISO7816_RECEIVE_CMD:
				/*if(_os_config.os_state & YGG_ST_LOAD_APP) {	   //load app into user program space
					//Sleep_Mode();	
					Load_User_App();
					_os_config.os_state &= ~(YGG_ST_LOAD_APP);
					Save_State();
				}
				if(_os_config.os_state & YGG_ST_SLEEP) {		   //sleep MCU
					Sleep_Mode();
					_os_config.os_state &= ~(YGG_ST_SLEEP);
				} */
				//do nothing
				break;
			case ISO7816_SEND_ACK:
				send_byte(iso7816_buffer[1]);			//send acknowledgement in order to and wait for data
				_iso7816_state = YGG_RECEIVE_DATA;
				break;
			case ISO7816_RECEIVE_DATA:
				//do nothing
				break;
			case ISO7816_WAIT_LE:		//wait for at least 1 etu 
				break;
			case ISO7816_RUNNING:
				switch(iso7816_buffer[0]) {
					case 0xff:	 						//default iso7816 system class
						PPS_Handler(iso7816_buffer);
						break;
					default:
						TX_NULL_BYTE_ON(8000)
						StartTimeoutSequence();
						//if(iso7816_buffer[1] == 0xC0 && iso7816_buffer[0] == _iso7816_cla) {									//get response
							/*if(iso7816_buffer[4] > get_resp_length) {				//check for response length	  
								//return (APDU_WRONG_LENGTH | get_resp_length); 	//wrong length .OR. requested length
								sw = (APDU_WRONG_LENGTH | get_resp_length); 	//wrong length .OR. requested length
							} else {
								get_resp_length = iso7816_buffer[4];
								//Set_Response(command->bytes, get_resp_length); 
								_iso7816_ins = iso7816_buffer[1];
								memcopy(iso7816_buffer, iso7816_buffer + 5, 0, get_resp_length);
								response_length = get_resp_length;
								get_resp_length = 0;
								sw = APDU_SUCCESS;
							}*/
						//} else {
						_iso7816_cla = iso7816_buffer[0];
						_iso7816_ins = iso7816_buffer[1];
						sw = Yggdrasil_Decode((apdu_command *)iso7816_buffer);
						//}
						
						if(_os_config.os_state & YGG_ST_LOAD_APP) {
							if(Load_User_App() == APDU_SUCCESS) {
								_os_config.os_state	&= ~YGG_ST_LOAD_APP;
								Save_State();
							}
						}
						EndTimeoutSequence();
						TX_NULL_BYTE_OFF(8000)
						ioman_transmit(response_length, _iso7816_ins, iso7816_buffer, sw);
						//Response();
						//TxStatus(SWptr);					//	Tx SW
						break;
				}
				_iso7816_state = ISO7816_RECEIVE_CMD;
				Sleep_Mode();
				break;
			case ISO7816_STOP:			//if the operation didn't response within 2 sec then cancel all pending operation
				EndTimeoutSequence();
				TX_NULL_BYTE_OFF(8000)
				ioman_transmit(0, _iso7816_ins, iso7816_buffer, APDU_FATAL_ERROR);
				_iso7816_state = ISO7816_RECEIVE_CMD;
				Initialize_Operating_System();
				break;
		}
	}
	/*if(ISO7816_Time == 0)
	{
		IoInit(0x11);						//	H/W initial
		Send_ATR();							//	Send ATR
		PPSFlag = 0;  						//	Enable PPS
		ISO7816_Time ++;
		return;								//	Return to the main process after sending ATR	
	}
	if(RcvAPDU())							//	Rcv APDU,include PPS
	{	
		Foffset = (P1 << 8) + P2;			//	Start address of flash reading/writing
		SWptr = SUCCESS;					//	9000

		TX_NULL_BYTE_ON(8000)
		CMMD_Handle();
		TX_NULL_BYTE_OFF(8000)
		
		Response();
		TxStatus(SWptr);					//	Tx SW
	} */
}
Example #7
0
int main (void)
{
	FRESULT rc;				/* Result code */
	DIR dir;				/* Directory object */
	FILINFO fno;			/* File information object */
	unsigned long br, i;
	alt_u32* active_buff;

 	printf("System started\r\n");
 	lcd_off();
    for(i=0;i<5000000;i++){}

    alt_sgdma_dev *dma = alt_avalon_sgdma_open("/dev/sgdma");
    printf("open dma returned %ld\n", (alt_u32)dma);
    printf("framebuffer 1 at %lx\n", (alt_u32)frameBufferA);
    printf("framebuffer 2 at %lx\n", (alt_u32)frameBufferB);

    active_buff = frameBufferA;
    //printf("framebuffer 1 at %lx\n", (alt_u32)active_buff);

    printf("Turning LCD on \r\n");
    lcd_on();
    printf("Starting DMA\r\n");
    init_and_start_framebuffer(dma);

	IoInit();

    Color col2;
    col2.color32 = 0x00ff0000;

    memset(frameBufferA, col2.color32,  522240/4);

	f_mount(0, &Fatfs);		/* Register volume work area (never fails) */

	for (;;) {
	printf("\nOpen root directory.\n");
	rc = f_opendir(&dir, "");
	if (rc) die(rc);

	printf("\nDirectory listing...\n");
	for (;;) {
		rc = f_readdir(&dir, &fno);		/* Read a directory item */
		if (rc || !fno.fname[0]) break;	/* Error or end of dir */
		if (fno.fattrib & AM_DIR)
			printf("   <dir>  %s\n", fno.fname);
		else {
			printf("%8lu  %s\n", fno.fsize, fno.fname);
		//printf("\nOpen an existing file.\n");
		rc = f_open(&Fil, fno.fname, FA_READ);
		if (rc) die(rc);

		if (active_buffer == 0) {
			active_buffer = 1;
			active_buff = frameBufferA;
		} else {
			active_buff = frameBufferB;
			active_buffer = 0;
		}

		for (;;) {
			rc = f_read(&Fil, (alt_u32*)active_buff, f_size(&Fil), &br);	/* Read a chunk of file */
			if (rc || !br)
				break;			/* Error or end of file */
		}
		if (rc) die(rc);
		rc = f_close(&Fil);
		if (rc) die(rc);
		}

	}
	if (rc) die(rc);
	}
}