#include "def21369.h"
#include "sru21369.h"

.section/pm seg_rth;

	nop;nop;nop;nop;
	nop; jump start;
	
.section/pm seg_pmco;

start:

	call Init_PLL;
	
	call Init_SRU;
	
	bit set FLAGS FLG4O|FLG5O|FLG6O|FLG7O;
	
blink:


	
	call delay;
	
	bit set FLAGS FLG7;
	bit clr FLAGS FLG5|FLG6|FLG4;

	call delay;
	
	bit set FLAGS FLG6;
	bit clr FLAGS FLG5|FLG4|FLG7;
	
	call delay;
	
	bit set FLAGS FLG5;
	bit clr FLAGS FLG4|FLG6|FLG7;
	
	call delay;
	
	bit set FLAGS FLG4;
	bit clr FLAGS FLG5|FLG6|FLG7;
	
	
	
	jump blink;
		
	
	jump(pc,0);
	
	
delay:

	lcntr=0x1fff, do blink1 until lce;
	
		lcntr=0xfff, do blink2 until lce;
		blink2: nop;
	
	blink1: nop;
	
	rts;
	
	
Init_PLL:

	ustat1=PLLM27|INDIV|DIVEN;
	dm(PMCTL)=ustat1;
	
	ustat1=dm(PMCTL);
	bit set ustat1 PLLBP;
	bit clr ustat1 DIVEN;
	dm(PMCTL)=ustat1;
	
	lcntr=5000,do(pc,1) until lce;
	nop;
	
	ustat1=dm(PMCTL);
	bit clr ustat1 PLLBP;
	dm(PMCTL)=ustat1;
	
	rts;

Init_SRU:

	SRU(HIGH,DPI_PBEN06_I);	
	SRU(HIGH,DPI_PBEN07_I);
	SRU(HIGH,DPI_PBEN08_I);
	SRU(HIGH,DPI_PBEN13_I);
	
	SRU(FLAG4_O,DPI_PB06_I);
	SRU(FLAG5_O,DPI_PB07_I);
	SRU(FLAG6_O,DPI_PB08_I);
	SRU(FLAG7_O,DPI_PB13_I);
	
	rts;
	
	
	
	
	
	
		