1 /*****************************************************************************
3 *! FILE NAME : common_init.c
5 *! DESCRIPTION: This piece of code is loaded at bootstrap and is put in the
6 *! cache at 0x380000F0. Depending of how R_BUS_STATUS<2:1> is
7 *! set different kinds of bootstrap is performed.
9 *! 00 - Normal boot. No bootstrap is performed and this code
11 *! 01 - Serial boot. 784 bytes is loaded and execution starts
13 *! 11 - Parallel boot. 784 bytes is loaded and execution starts
15 *! 10 - Network boot. 1484 bytes is loaded and execution start
18 *! ---------------------------------------------------------------------------
23 *! 980326 Ronny Ranerup Initial version
24 *! Sep 20 1999 Jonas Dellenvall Added port3 debug support
25 *! 20020206 ronny Yeah, and I removed it again...
27 *! ---------------------------------------------------------------------------
28 *! (C) Copyright 1998-2002, Axis Communications AB, LUND, SWEDEN
29 *!***************************************************************************/
35 It is very important to keep this file short. This and the boot
36 interface specific parts must fit into the first boot packet.
40 /****************** INCLUDE FILES SECTION ***********************************/
45 /****************** CONSTANT AND MACRO SECTION ******************************/
47 /****************** TYPE DEFINITION SECTION *********************************/
49 /****************** LOCAL FUNCTION DECLARATION SECTION **********************/
51 static int timeout(void);
53 /****************** GLOBAL VARIABLE DECLARATION SECTION *********************/
55 udword nbr_read; /* How many bytes has been read from current file */
56 byte interface; /* Which I/O interface is the current one */
57 byte set_dest; /* Have we set the destination address in tx_header */
60 struct packet_header_T tx_header;
61 dma_descr_T tx_descr; /* For packet header */
62 dma_descr_T tx_descr2; /* packet data */
64 struct packet_header_T rx_header;
65 dma_descr_T rx_descr; /* For packet header */
66 dma_descr_T rx_descr2; /* packet data */
68 udword seq; /* Sequence number of next wanted packet */
71 /****************** LOCAL VARIABLE DECLARATION SECTION **********************/
73 /****************** FUNCTION DEFINITION SECTION *****************************/
78 /* Do this only once so we don't reset the timers and destroy the 32
79 bit timer-register used as random number generator */
81 REG_SET__R_TIMER_CTRL(
93 REG_SET__R_TIMER_CTRL(
112 REG_SET__R_PORT_PA_DIR(
120 dir0, input); /* not for prodtest */
122 REG_SET__R_PORT_PA_DATA(data_out, 0);
124 REG_SET__R_PORT_PB_DIR(
134 REG_SET__R_PORT_PB_DATA(data_out, 0xff);
137 /* We must initialize all (global) variables here, since the .data
138 and .bss area are used before they are loaded. */
143 /* Get a random value to use as id. */
144 tx_header.id = htonl(REG_RD(R_TIMER_DATA));
146 /* timer01 is used as timer. */
147 last_timeout = REG_GET(R_TIMER01_DATA, count);
149 interface = REG_GET(R_BUS_STATUS, boot) - 1; /* 0,1,2 */
150 rx_descr2.status = 0;
152 /* Initialize the boot interface */
154 send_ack(); /* Ack the first bootpacket, i.e. this code. seq 0. */
158 if (nbr_read >= (udword)bytes_to_read) {
161 else if (interface == NETWORK) {
162 REG_SET(R_DMA_CH1_CMD, cmd, start);
168 REG_SET(R_PORT_PA_DATA, data_out, 0x55);
191 volatile int now = REG_GET(R_TIMER01_DATA, count);
193 int wait_time = 9600;
195 elapsed = last_timeout - now;
201 if (elapsed > wait_time) {
209 /****************** END OF FILE common_init.c *******************************/