12/08/2018, 16:32

Lập trình C cho hệ thống nhúng (P9- Standby Function- Stop mode trong V850E)

1. Khái niệm Ở trong phần trước mình đã giới thiệu về HALT mode và IDLE mode trong chức năng Standby funtion của V850E . Trong bài viết này mình sẽ tiếp tục giới thiệu về STOP Mode của chức năng này. STOP mode là mode sẽ dừng tất cả các hoạt động của các mạch bên trong ngoại trừ những tính ...

1. Khái niệm

Ở trong phần trước mình đã giới thiệu về HALT mode và IDLE mode trong chức năng Standby funtion của V850E . Trong bài viết này mình sẽ tiếp tục giới thiệu về STOP Mode của chức năng này. STOP mode là mode sẽ dừng tất cả các hoạt động của các mạch bên trong ngoại trừ những tính năng sau : CISB trong slave mode, low-voltage detector(LVI) , power-on-clear circuit (POC)

2. Hoạt động

STOP mode được xác lập bằng cách set (1) cho bit PSMR.PSM0 và set (1) cho bit PSC.STB trong mode hoạt động bình thường. Trong STOP mode , bộ tạo xung clock sẽ dừng hoạt động và xung clock cung cấp cho CPU và các chức năng on-chip peripheral khác cũng sẽ bị dừng lại.

3. Lập trình cho STOP mode hoạt động

Sơ đồ khối MAIN Function

Sơ đồ khối STOP mode Release setting function

Sơ đồ khối STOP mode Setting function

Sourecode

#pragma ioreg							/* Peripheral I/O register name enable specification */
/*───────────────────────────────────
*	Function Prototypes
*───────────────────────────────────
*/
void stop_main(void);					/* STOP mode function */
void stop_init(void);					/* STOP mode release setting function */
void stop_mode(void);					/* STOP mode setting function */
/*───────────────────────────────────
*   Stop_Main Function
* ───────────────────────────────────
*/
void stop_main(void)
{
	__DI();								/* Maskable interrupt disable */
	
	stop_init();						/* STOP mode release setting function */
	
	do{
		stop_mode();					/* STOP mode function */
		
	}while(PRERR);						/* Written in a correct sequence? */
	
	/* The INTP7 interrupt request signal is kept set after STOP mode has been released. */
	
	return;
	
}

/*───────────────────────────────────
*   Stop_Init Function
* ───────────────────────────────────
*/
void stop_init(void)
{
	/* Selection of oscillation stabilization time */
	/* 16.4ms */
	OSTS = 0x07;						/* bit 3, bit 2, bit 1, bit 0: Selection of oscillation stabilization time */
										/* 1000: 32.8 ms, 0111: 16.4 ms, 0110: 8.19 ms, 0101: 4.10 ms, 0100: 2.05 ms */
	
	PFC0 = 0x00;						/* Set INTP7 input. */
	PMC0 = 0x80;						/* Set the P00 pin to the INTP7 input pin. */
	
	/* Detect an edge, because an external interrupt will be used. */
	INTR0 = 0x80;						/* Rising edge */
	INTF0 = 0x00;						/* Rising edge */
	
	PIF07 = 0;							/* INTP7 interrupt request flag clear */
	
	IMR5 = 0xFFFF;						/* Unused interrupt mask */
	IMR4 = 0xFFFF;						/* Unused interrupt mask */
	IMR3 = 0xFFFF;						/* Unused interrupt mask */
	IMR2 = 0xFFFF;						/* Unused interrupt mask */
	IMR1 = 0xFFFF;						/* Unused interrupt mask */
	IMR0 = 0xFFFF;						/* Unused interrupt mask */
	
	PMK07 = 0;							/* INTP7 interrupt processing enabled */
	
	return;
}

/*───────────────────────────────────
*   Stop_Mode Function
* ───────────────────────────────────
*/
void stop_mode(void)
{
	/* Since DMA transfer needs to be terminated before data setting to a special register,
	   DMA is forcibly terminated in this sample. */
	
	if(TC0 == 0 && E00 == 1){			/* DMA0 transfer judgment */
		INIT0 = 1;						/* DMA0 forcible termination */
	}
	if(TC1 == 0 && E11 == 1){			/* DMA1 transfer judgment */
		INIT1 = 1;						/* DMA1 forcible termination */
	}
	if(TC2 == 0 && E22 == 1){			/* DMA2 transfer judgment */
		INIT2 = 1;						/* DMA2 forcible termination */
	}
	if(TC3 == 0 && E33 == 1){			/* DMA3 transfer judgment */
		INIT3 = 1;						/* DMA3 forcible termination */
	}
	
	/* The PCC register, which is a special register, can be written only via a combination of specific sequences. */
	/* bit 1, bit 0: Clock selection */
	/* Clock selection: fxx/8 */
	__asm("mov 0x03, r10");				/* Set in a general-purpose register data to be set in a special register. */
	__asm("st.b r10, PRCMD[r0]");		/* Write to the PRCMD register. */
	__asm("st.b r10, PCC[r0]");			/* PCC register setting */
	__asm("nop");						/* Insert at least five NOP instructions. */
	__asm("nop");
	__asm("nop");
	__asm("nop");
	__asm("nop");
	
	/* Specification of operation in software standby mode */
	/* Set to STOP mode. */
	PSMR = 0x01;						/* bit 0: Bit for specifying IDLE/STOP mode */
										/* 1: STOP mode, 0: IDLE mode */
	
	/* Register for controlling standby function */
	/* bit 4: Control of standby mode by maskable interrupt request */
	/* 1: Standby mode release disabled, 0: Standby mode release enabled */
	/* bit 1: Specification of operating mode */
	/* 1: Standby mode, 0: Normal mod */
	__asm("mov 0x02, r10");				/* Set in a general-purpose register data to be set in a special register. */
	__asm("st.b r10, PRCMD[r0]");		/* Write to the PRCMD register. */
	__asm("st.b r10, PSC[r0]");			/* Standby mode setting */
	__asm("nop");						/* Insert at least five NOP instructions. */
	__asm("nop");
	__asm("nop");
	__asm("nop");
	__asm("nop");
	
	return;
}

0