1 /******************************************************************************
2 * Copyright (c) 2011 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 nor 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: NOR Boot Over I2C Example
36 **************************************************************************************
37 * FILE NAME: i2c_boot_nor_example.c
38 *
39 * DESCRIPTION: A simple hello world example demonstrating NOR boot over I2C.
40 *
41 ***************************************************************************************/
42 #include <stdlib.h>
43 #include <stdio.h>
44 #include <string.h>
45 #include "platform.h"
47 #define BOOT_UART_BAUDRATE 115200
49 /* i2c_boot_nor_example version */
50 char version[] = "01.00.00.00";
52 /* OSAL functions for Platform Library */
53 uint8_t *Osal_platformMalloc (uint32_t num_bytes, uint32_t alignment)
54 {
55 return malloc(num_bytes);
56 }
58 void Osal_platformFree (uint8_t *dataPtr, uint32_t num_bytes)
59 {
60 /* Free up the memory */
61 if (dataPtr)
62 {
63 free(dataPtr);
64 }
65 }
67 /******************************************************************************
68 * Function: print_platform_errno
69 ******************************************************************************/
70 void
71 print_platform_errno
72 (
73 void
74 )
75 {
76 printf ("Returned platform error number is %d\n", platform_errno);
77 }
79 /******************************************************************************
80 * Function: write_uart
81 ******************************************************************************/
82 void
83 write_uart
84 (
85 char* msg
86 )
87 {
88 uint32_t i;
89 uint32_t msg_len = strlen(msg);
91 /* Write the message to the UART */
92 for (i = 0; i < msg_len; i++)
93 {
94 platform_uart_write(msg[i]);
95 }
96 }
99 /******************************************************************************
100 * Function: main
101 ******************************************************************************/
102 void main ()
103 {
104 platform_init_flags init_flags;
105 platform_init_config init_config;
106 char version_msg[] = "\r\n\r\nNOR Boot Over I2C Example Version ";
107 char boot_msg[] = "\r\n\r\nBooting Hello World image from NOR flash via IBL over I2C 0x51 ...";
109 printf("%s%s\n\n", version_msg, version);
111 /* Initialize main Platform lib */
112 memset(&init_config, 0, sizeof(platform_init_config));
113 memset(&init_flags, 1, sizeof(platform_init_flags));
114 if (platform_init(&init_flags, &init_config) != Platform_EOK)
115 {
116 printf ("Platform init failed!\n");
117 print_platform_errno();
118 return;
119 }
120 platform_uart_init();
121 platform_uart_set_baudrate(BOOT_UART_BAUDRATE);
123 write_uart(version_msg);
124 write_uart(version);
126 printf("%s", boot_msg);
127 write_uart(boot_msg);
128 }