[keystone-rtos/mcsdk-tools.git] / boot_loader / examples / srio / srioboot_helloworld / src / srioboot_helloworld.c
1 /******************************************************************************
2 * Copyright (c) 2011-2012 Texas Instruments Incorporated - http://www.ti.com
3 *
4 * Redistribution and use in source and binary forms, with or without
5 * modification, are permitted provided that the following conditions
6 * are met:
7 *
8 * Redistributions of source code must retain the above copyright
9 * notice, this list of conditions and the following disclaimer.
10 *
11 * Redistributions in binary form must reproduce the above copyright
12 * notice, this list of conditions and the following disclaimer in the
13 * documentation and/or other materials provided with the
14 * distribution.
15 *
16 * Neither the name of Texas Instruments Incorporated emac the names of
17 * its contributors may be used to endorse or promote products derived
18 * from this software without specific prior written permission.
19 *
20 * THIS SOFTWARE IS PROVIDED BY THE COPYRIGHT HOLDERS AND CONTRIBUTORS
21 * "AS IS" AND ANY EXPRESS OR IMPLIED WARRANTIES, INCLUDING, BUT NOT
22 * LIMITED TO, THE IMPLIED WARRANTIES OF MERCHANTABILITY AND FITNESS FOR
23 * A PARTICULAR PURPOSE ARE DISCLAIMED. IN NO EVENT SHALL THE COPYRIGHT
24 * OWNER OR CONTRIBUTORS BE LIABLE FOR ANY DIRECT, INDIRECT, INCIDENTAL,
25 * SPECIAL, EXEMPLARY, OR CONSEQUENTIAL DAMAGES (INCLUDING, BUT NOT
26 * LIMITED TO, PROCUREMENT OF SUBSTITUTE GOODS OR SERVICES; LOSS OF USE,
27 * DATA, OR PROFITS; OR BUSINESS INTERRUPTION) HOWEVER CAUSED AND ON ANY
28 * THEORY OF LIABILITY, WHETHER IN CONTRACT, STRICT LIABILITY, OR TORT
29 * (INCLUDING NEGLIGENCE OR OTHERWISE) ARISING IN ANY WAY OUT OF THE USE
30 * OF THIS SOFTWARE, EVEN IF ADVISED OF THE POSSIBILITY OF SUCH DAMAGE.
31 *
32 *****************************************************************************/
34 /**************************************************************************************
35 * FILE PURPOSE: SRIO Boot Hello World Example
36 **************************************************************************************
37 * FILE NAME: srioboot_helloworld.c
38 *
39 * DESCRIPTION: A simple hello world example demonstrating SRIO boot.
40 *
41 ***************************************************************************************/
42 #include <stdlib.h>
43 #include <stdio.h>
44 #include <string.h>
45 #include "platform.h"
47 #define DEVICE_REG32_W(x,y) *(volatile uint32_t *)(x)=(y)
48 #define DEVICE_REG32_R(x) (*(volatile uint32_t *)(x))
50 #define CHIP_LEVEL_REG 0x02620000
51 #define KICK0 (CHIP_LEVEL_REG + 0x0038)
52 #define KICK1 (CHIP_LEVEL_REG + 0x003C)
54 /* Magic address RBL is polling */
55 #ifdef _EVMC6657L_
56 #define MAGIC_ADDR 0x8ffffc
57 #endif
59 #ifdef _EVMC6678L_
60 #define MAGIC_ADDR 0x87fffc
61 #endif
63 #ifdef _EVMC6670L_
64 #define MAGIC_ADDR 0x8ffffc
65 #endif
67 #ifdef DEVICE_K2K
68 #define MAGIC_ADDR 0x8ffffc
69 #endif
71 #define BOOT_MAGIC_ADDR(x) (MAGIC_ADDR + (1<<28) + (x<<24))
72 #define IPCGR(x) (0x02620240 + x*4)
74 #define BOOT_MAGIC_NUMBER 0xBABEFACE
76 #define BOOT_UART_BAUDRATE 115200
78 /* srioboot_helloworld version */
79 char version[] = "01.00.00.02";
81 /* OSAL functions for Platform Library */
82 uint8_t *Osal_platformMalloc (uint32_t num_bytes, uint32_t alignment)
83 {
84 return malloc(num_bytes);
85 }
87 void Osal_platformFree (uint8_t *dataPtr, uint32_t num_bytes)
88 {
89 /* Free up the memory */
90 if (dataPtr)
91 {
92 free(dataPtr);
93 }
94 }
96 void Osal_platformSpiCsEnter(void)
97 {
98 return;
99 }
101 void Osal_platformSpiCsExit (void)
102 {
103 return;
104 }
106 /******************************************************************************
107 * Function: write_uart
108 ******************************************************************************/
109 void
110 write_uart
111 (
112 char* msg
113 )
114 {
115 uint32_t i;
116 uint32_t msg_len = strlen(msg);
118 /* Write the message to the UART */
119 for (i = 0; i < msg_len; i++)
120 {
121 platform_uart_write(msg[i]);
122 }
123 }
125 void
126 write_boot_magic_number
127 (
128 void
129 )
130 {
131 DEVICE_REG32_W(MAGIC_ADDR, BOOT_MAGIC_NUMBER);
132 while(1);
133 }
135 /******************************************************************************
136 * Function: main
137 ******************************************************************************/
138 void main ()
139 {
140 char version_msg[] = "\r\n\r\nSRIO Boot Hello World Example Version ";
141 char boot_msg[80];
142 platform_info pform_info;
143 uint32_t coreNum, core;
145 /* Initialize UART */
146 coreNum = platform_get_coreid();
147 if (coreNum == 0)
148 {
149 platform_uart_init();
150 platform_uart_set_baudrate(BOOT_UART_BAUDRATE);
153 printf("%s%s\n\n", version_msg, version);
154 write_uart(version_msg);
155 write_uart(version);
157 write_uart("\r\n\r\nBooting Hello World image on Core 0 from SRIO ...");
159 platform_get_info(&pform_info);
161 /* Unlock the chip registers */
162 DEVICE_REG32_W(KICK0, 0x83e70b13);
163 DEVICE_REG32_W(KICK1, 0x95a4f1e0);
165 /* Writing the entry address to other cores */
166 for (core = 1; core < pform_info.cpu.core_count; core++)
167 {
168 sprintf(boot_msg, "\r\n\r\nBooting Hello World image on Core %d from Core 0 ...", core);
169 write_uart(boot_msg);
171 DEVICE_REG32_W(BOOT_MAGIC_ADDR(core), (uint32_t)write_boot_magic_number);
173 /* Delay 1 sec */
174 platform_delay(1);
175 }
176 for (core = 1; core < pform_info.cpu.core_count; core++)
177 {
178 /* IPC interrupt other cores */
179 DEVICE_REG32_W(IPCGR(core), 1);
180 platform_delay(1000);
181 }
183 }
184 else
185 {
186 write_boot_magic_number();
187 }
189 while(1);
190 }