1 #define __ADSPLPBLACKFIN__
6 typedef unsigned char uchar;
7 typedef unsigned short ushort;
8 typedef unsigned long ulong;
11 uchar sno; /* Sequence number. */
12 uchar pad; /* Unused, padding. */
13 int xfertot; /* Running total of transfer. */
14 int pktcnt; /* Running tally of number of packets processed. */
15 long size; /* Size of upload. */
16 ulong base; /* Starting address for data transfer. */
17 ulong dataddr; /* Running address for data transfer. */
20 /* X/Ymodem protocol: */
29 #define NAK_DELAY 1500000
36 int getPacket(uchar *,struct xinfo *);
45 *pPORTFIO_SET |= LED_BITMASK;
46 for(i=0;i<9000000;i++);
47 *pPORTFIO_CLEAR |= LED_BITMASK;
48 for(i=0;i<5000000;i++);
52 * Initialize console...
58 unsigned short lctl, hi, lo;
60 *pUART0_GCTL = 1; /* Set the UCEN bit (enable UART clocks) */
67 lo = SYSCLKFREQ/(baud*16);
68 hi = (lo & 0xff00) >> 8;
79 * When buffer has space available, load the incoming character
83 target_putchar(char c)
85 /* Wait for transmit ready bit */
86 while(!(*pUART0_LSR & THRE));
88 *pUART0_THR = (unsigned short)c;
104 return((int)*pUART0_RBR);
110 while((*pUART0_LSR & DR) == 0);
111 return((int)*pUART0_RBR);
117 volatile long i, *lp;
119 lp = (volatile long *)BASE;
121 for(i=0;i<(1024*256);i++) {
124 for(i=0;i<(1024*256);i++) {
139 volatile unsigned short stmp;
140 volatile unsigned long ltmp;
145 *pPLL_CTL = (MSEL_VAL << 9) | PLL_DF_VAL;
153 *pPLL_LOCKCNT = 0x0300;
154 *pPLL_DIV = (SSEL_VAL) | (CSEL_VAL << 4);
161 *pEBIU_AMBCTL0 = 0x7bb07bb0;
162 *pEBIU_AMBCTL1 = 0xffc27bb0;
166 * (should be done 100us after reset)
167 * Refer to pg 6-60 of HW reference.
169 for(c=0;c<10000000;c++);
170 *pEBIU_SDRRC = (((SYSCLKFREQ/1000) * 64) / 8192) - (TRAS + TRP);
172 *pEBIU_SDBCTL = (EBCAW_10 | EBSZ_64 | EBE);
174 if (*pEBIU_SDSTAT & SDRS)
175 *pEBIU_SDGCTL = (PSS | TWR_2 | TRCD_2 | TRP_2 | TRAS_5 | CL_3 | SCTLE);
177 *pEBIU_SDGCTL = (TWR_2 | TRCD_2 | TRP_2 | TRAS_5 | CL_3 | SCTLE);
180 *pEBIU_AMGCTL = 0x00ff;
183 for(c=0;c<10000;c++);
184 *(char *)c = (char)c;
188 /* Port F configuration:
191 *pPORTF_FER = 0x000f;
192 *pPORTF_FER = 0x000f;
193 *pPORTFIO_DIR = LED_BITMASK;
194 *pPORTF_FER = 0x000f;
195 *pPORTF_FER = 0x000f;
197 /* Port G configuration:
200 *pPORTG_FER = 0x0000;
201 *pPORTG_FER = 0x0000;
203 /* Port H configuration:
206 *pPORTH_FER = 0xffff;
207 *pPORTH_FER = 0xffff;
209 devInit(DEFAULT_BAUD_RATE);
212 if (target_gotachar()) {
213 c = target_getchar();
236 * Used by Xdown to retrieve packets.
239 getPacket(uchar *tmppkt, struct xinfo *xip)
243 uchar csum, xcsum, seq[2];
248 pkt = (char *)xip->dataddr;
249 for(i=0;i<PKTLEN;i++)
251 pkt = (char *)xip->dataddr;
253 xcsum = (uchar)getchar();
255 for(i=0;i<PKTLEN;i++)
258 target_putchar(XNAK);
262 /* Test the sequence number compliment...
264 if ((uchar)seq[0] != (uchar)~seq[1]) {
265 target_putchar(XNAK);
269 /* Verify that the incoming sequence number is the expected value...
271 if ((uchar)seq[0] != xip->sno) {
272 /* If the incoming sequence number is one less than the expected
273 * sequence number, then we assume that the sender did not recieve
274 * our previous ACK, and they are resending the previously received
275 * packet. In that case, we send ACK and don't process the
278 if ((uchar)seq[0] == xip->sno-1) {
283 /* Otherwise, something's messed up...
289 xip->dataddr += PKTLEN;
292 xip->xfertot += PKTLEN;
298 * Called when a transfer from host to target is being made
299 * (considered an download).
307 static char pkt[PKTLEN];
311 xi.dataddr = xi.base = BASE;
316 /* Startup synchronization... */
317 /* Continuously send XNAK or 'C' until sender responds. */
320 target_putchar(XNAK);
322 for(i=0;i<NAK_DELAY;i++) {
323 if (target_gotachar())
326 if (target_gotachar())
332 if (c == SOH) { /* 128-byte incoming packet */
333 done = getPacket((uchar *)tmppkt,&xi);
339 else if (c == EOF) { /* 0x1a sent by MiniCom, just ignore it. */
354 entry = (void(*)(void))ENTRY;