comparison chipsetsw/system/bootloader/inc/target.h @ 0:509db1a7b7b8

initial import: leo2moko-r1
author Space Falcon <falcon@ivan.Harhan.ORG>
date Mon, 01 Jun 2015 03:24:05 +0000
parents
children
comparison
equal deleted inserted replaced
-1:000000000000 0:509db1a7b7b8
1 /******************************************************************************
2 * FLUID (Flash Loader Utility Independent of Device)
3 *
4 * (C) Delta Technologies 2001.
5 * Cleanup, modifications and extensions by Mads Meisner-Jensen, mmj@ti.com.
6 *
7 * Target common definitions
8 *
9 * $Id: target.h,v 1.3 2003/07/10 17:50:21 rlendenmann Exp $
10 *
11 ******************************************************************************/
12 #ifndef __TARGET_H__
13 #define __TARGET_H__
14 #include "protocol.h"
15
16
17 /******************************************************************************
18 * Typedefs and Prototypes
19 ******************************************************************************/
20
21 #ifndef RIVIERA_INCLUDED
22 typedef unsigned char UBYTE;
23 typedef unsigned short UINT16;
24 typedef unsigned long UINT32;
25 typedef signed char INT8;
26 typedef signed short INT16;
27 typedef signed long INT32;
28 #endif
29
30 typedef unsigned char uint8;
31 typedef unsigned short uint16;
32 typedef unsigned long uint32;
33 typedef signed char int8;
34 typedef signed short int16;
35 typedef signed long int32;
36
37 typedef union {
38 UINT32 i; // integer value
39 UBYTE b[4]; // byte array
40 } union32_t;
41
42 typedef union {
43 UINT16 i; // integer value
44 UBYTE b[2]; // byte array
45 } union16_t;
46
47 typedef struct {
48 char (*init)(uint32 addr);
49 char (*erase)(uint32 *addr, int size);
50 char (*program)(uint32 addr, uint16 *buf, int size);
51 uint8 (*getchar)(void);
52 void (*putchar)(uint8 ch);
53 void (*debug_putstr)(uint32 uart, char *string);
54 void (*debug_putnum)(uint32 uart, unsigned int number);
55 uint32 uart_base;
56 } method_table_t;
57
58 // Prototypes for functions in debug.c
59 void debug_putstr(uint32 uart, char *string);
60 void debug_putnum(uint32 uart, unsigned int number);
61
62
63 /******************************************************************************
64 * Macros
65 ******************************************************************************/
66
67 #define REGISTER_8_READ(addr) (*((volatile uint8 *) (addr)))
68 #define REGISTER_8_WRITE(addr, data) (*((volatile uint8 *) (addr)) = data)
69 #define REGISTER_16_READ(addr) (*((volatile uint16 *) (addr)))
70 #define REGISTER_16_WRITE(addr, data) (*((volatile uint16 *) (addr)) = data)
71
72 #define BIT_SET(reg, bit) (*((volatile UINT16 *) (reg)) |= (1 << (bit)))
73 #define BIT_CLR(reg, bit) (*((volatile UINT16 *) (reg)) &= ~(1 << (bit)))
74
75 #define FLASH_READ(addr) (*(volatile uint16 *) (addr))
76 #define FLASH_WRITE(addr, data) (*(volatile uint16 *) (addr)) = data
77
78 #define PUTCHAR_FUNCTION_CODE(uart) \
79 while (!(REGISTER_8_READ(uart + UART_LSR) & STAT_TXRDY)) ; \
80 REGISTER_8_WRITE(uart + UART_THR, ch);
81
82 #define GETCHAR_FUNCTION_CODE(uart) \
83 while (!(REGISTER_8_READ(uart + UART_LSR) & STAT_RXRDY)) ; \
84 return (uint8) REGISTER_8_READ(uart + UART_RHR);
85
86
87 /******************************************************************************
88 * Debug Macros
89 ******************************************************************************/
90
91 #define DEBUG_PUTSTR(uart, text) ((method_table_t *)(my_addr))->debug_putstr(uart, text);
92 #define DEBUG_PUTNUM(uart, num) ((method_table_t *)(my_addr))->debug_putnum(uart, num);
93
94
95 /******************************************************************************
96 * Hardware Definitions
97 ******************************************************************************/
98
99 #define UART_BASE_MODEM (0xFFFF5800)
100 #define UART_BASE_IRDA (0xFFFF5000)
101
102 // ROM/Flash Config register
103 #define WS_REG_ROM 0x400000
104
105 // UART register definitions.
106 #define UART_RHR (0x00) /* Receive Holding Register */
107 #define UART_THR (0x00) /* Transmit Holding Register */
108 #define UART_FCR (0x02) /* FIFO Control Register */
109 #define UART_LCR (0x03) /* Line Control Register */
110 #define UART_LSR (0x05) /* Line Status Register */
111 #define UART_MDR1 (0x08) /* Mode Definition Register 1 */
112 #define UART_EFR (0x02) /* Enhanced Feature Register */
113 #define UART_DLL (0x00) /* Divisor Latches */
114 #define UART_DLH (0x01) /* Divisor Latches */
115 #define UART_UIR (0xFFFF6000) /* UART Interface Register */
116
117 // UART status bit definitions.
118 #define STAT_RXRDY (0x01)
119 #define STAT_TXRDY (0x20)
120 #define STAT_TX_E (0x40)
121
122 // UART_UIR bit definitions.
123 #define UART_ACCESS (0)
124 #define UART_MASK_IT (1)
125
126 // UART_EFR bit definitions.
127 #define ENHANCED_EN (4)
128
129 // UART command bit definitions.
130 #define CMD_UART_RESET (0x07)
131 #define CMD_EFR_EN (0xBF)
132 #define CMD_FCR_MCR_EN (0x80)
133 #define CMD_FIFO_EN (0x07)
134 #define CMD_UART_MODE (0x00)
135 #define CMD_CHAR8_STOP1_NOPAR (0x03)
136
137 // UART ???
138 #define BAUD_38400 (0x15)
139 #define BAUD_115200 (0x07)
140 #define BAUD_406250 (0x02)
141 #define BAUD_812500 (0x01)
142
143
144 // Enable/Disable ROM/Flash write strobe
145 #define ROM_WRITE_ENABLE() *((volatile uint16*) WS_REG_ROM) |= 0x80;
146 #define ROM_WRITE_DISABLE() *((volatile uint16*) WS_REG_ROM) &= ~0x80;
147
148 #endif /* __TARGET_H__ */