1 /*
2 * board_setup.c
3 *
4 */
5
6
7 #include "board_setup.h"
8 #include "C66XX.h"
9 #include <string.h>
10
11
12 //=============================================================================
13 //============ General definitions ============================================
14 //=============================================================================
15 // DSP Timer-8 definition
16 #define C66XX_DSP_TIMER C66XX_TIMER_8
17 // DSP Timer-8 output frequency in Hz
18 #define C66XX_DSP_TIMER_FREQ 100
19 /* DSP Timer-8 interrupt event ID */
20 #define C66XX_DSP_TIMER_EVENT_ID 67
21 //=============================================================================
22
23
24 //=============================================================================
25 //============ Global functions ===============================================
26 //=============================================================================
27 void _tx_nmi_vector(void);
28 void _tx_int4_vector(void);
29 void _tx_int5_vector(void);
30 void _tx_int6_vector(void);
31 void _tx_int7_vector(void);
32 void _tx_int8_vector(void);
33 void _tx_int9_vector(void);
34 void _tx_int10_vector(void);
35 void _tx_int11_vector(void);
36 void _tx_int12_vector(void);
37 void _tx_int13_vector(void);
38 void _tx_int14_vector(void);
39 void _tx_int15_vector(void);
40 //=============================================================================
41
42
43 //=============================================================================
44 //============ Static functions ===============================================
45 //=============================================================================
46 static int32_t tx_timer_init(C66XX_TIMER timer, uint32_t frequency);
47 static int32_t tx_interrupt_init(void);
48 //=============================================================================
49
50
51 /*------------ init_output_timer() function -----------------------------------
52 * DESCRIPTION: Function initializes Timer64 module
53 * ARGUMENTS:
54 * None
55 * RETURNED VALUE: Error code
56 -----------------------------------------------------------------------------*/
tx_timer_init(C66XX_TIMER timer,uint32_t frequency)57 static int32_t tx_timer_init(C66XX_TIMER timer, uint32_t frequency)
58 {
59 int32_t r;
60 C66XX_TIMER_CFG_DD cfg_dd;
61
62 // Reset 64-bit timer
63 if ((r = C66XX_TIMER_reset(timer, C66XX_TIMER_HW_CFG_64BIT)) != C66XX_OK)
64 goto exit;
65
66 // Fill configuration data descriptor
67 memset(&cfg_dd, 0, C66XX_TIMER_CFG_DD_LEN);
68 cfg_dd.timer_mode = C66XX_TIMER_MODE_32BIT_UNCHAINED;
69 cfg_dd.timer_high.clk_src_output_mode = C66XX_TIMER_CLK_OUTPUT_MODE_CLK;
70 // Init DSP Timer64 module
71 if ((r = C66XX_TIMER_init(timer, frequency, &cfg_dd)) != C66XX_OK)
72 goto exit;
73
74 // Enable timer interrupt
75 if ((r = C66XX_TIMER_enable_interrupts(timer, C66XX_TIMER_HW_CFG_32BIT_HIGH)) != C66XX_OK)
76 goto exit;
77
78 // Start 32-bit timer high to enable continuously
79 if ((r = C66XX_TIMER_start(timer, C66XX_TIMER_HW_CFG_32BIT_HIGH, C66XX_TIMER_COUNT_MODE_CONTINUOUSLY)) != C66XX_OK)
80 goto exit;
81
82 // TIMER module configuration is completed
83 printf("Timer #%u configuration is completed\n", timer);
84
85 exit:
86 return (r);
87 }
88 //-----------------------------------------------------------------------------
89
90
91 /*------------ tx_interrupt_init() function -----------------------------------
92 * DESCRIPTION: Function initializes CorePack interrupt module
93 * ARGUMENTS:
94 * None
95 * RETURNED VALUE: Error code
96 -----------------------------------------------------------------------------*/
tx_interrupt_init(void)97 static int32_t tx_interrupt_init(void)
98 {
99 int32_t r;
100
101 // Set DSP interrupt handlers to the ones defined in tx_initialize_low_level.asm
102 if ((r = C66XX_INT_set_core_dsp_interrupt_handler(C66XX_DSP_VECTID_NMI, _tx_nmi_vector)) != C66XX_OK)
103 goto exit;
104 if ((r = C66XX_INT_set_core_dsp_interrupt_handler(C66XX_DSP_VECTID_4, _tx_int4_vector)) != C66XX_OK)
105 goto exit;
106 if ((r = C66XX_INT_set_core_dsp_interrupt_handler(C66XX_DSP_VECTID_5, _tx_int5_vector)) != C66XX_OK)
107 goto exit;
108 if ((r = C66XX_INT_set_core_dsp_interrupt_handler(C66XX_DSP_VECTID_6, _tx_int6_vector)) != C66XX_OK)
109 goto exit;
110 if ((r = C66XX_INT_set_core_dsp_interrupt_handler(C66XX_DSP_VECTID_7, _tx_int7_vector)) != C66XX_OK)
111 goto exit;
112 if ((r = C66XX_INT_set_core_dsp_interrupt_handler(C66XX_DSP_VECTID_8, _tx_int8_vector)) != C66XX_OK)
113 goto exit;
114 if ((r = C66XX_INT_set_core_dsp_interrupt_handler(C66XX_DSP_VECTID_9, _tx_int9_vector)) != C66XX_OK)
115 goto exit;
116 if ((r = C66XX_INT_set_core_dsp_interrupt_handler(C66XX_DSP_VECTID_10, _tx_int10_vector)) != C66XX_OK)
117 goto exit;
118 if ((r = C66XX_INT_set_core_dsp_interrupt_handler(C66XX_DSP_VECTID_11, _tx_int11_vector)) != C66XX_OK)
119 goto exit;
120 if ((r = C66XX_INT_set_core_dsp_interrupt_handler(C66XX_DSP_VECTID_12, _tx_int12_vector)) != C66XX_OK)
121 goto exit;
122 if ((r = C66XX_INT_set_core_dsp_interrupt_handler(C66XX_DSP_VECTID_13, _tx_int13_vector)) != C66XX_OK)
123 goto exit;
124 if ((r = C66XX_INT_set_core_dsp_interrupt_handler(C66XX_DSP_VECTID_14, _tx_int14_vector)) != C66XX_OK)
125 goto exit;
126 if ((r = C66XX_INT_set_core_dsp_interrupt_handler(C66XX_DSP_VECTID_15, _tx_int15_vector)) != C66XX_OK)
127 goto exit;
128
129 /* CorePack interrupt module configuration is completed */
130 printf("INTC configuration is completed\n");
131 // Exit without errors
132 r = C66XX_OK;
133
134 exit:
135 return (r);
136 }
137 //-----------------------------------------------------------------------------
138
139
140 /*------------ hardware_setup() function --------------------------------------
141 * DESCRIPTION: Function intializes board hardware
142 * ARGUMENTS:
143 * None
144 * RETURNED VALUE: None
145 -----------------------------------------------------------------------------*/
hardware_setup()146 int hardware_setup()
147 {
148 platform_init_flags init_flags;
149 platform_init_config init_config;
150 platform_info p_info;
151 int32_t r;
152
153 /*
154 * Initialize all platform peripherals with default values:
155 * PLL, DDR, TCSL, PHY, ECC
156 */
157 init_flags.pll = 1;
158 init_flags.ddr = 1;
159 init_flags.tcsl = 1;
160 init_flags.phy = 1;
161 init_flags.ecc = 0;
162 memset(&init_config, 0, sizeof(platform_init_config));
163 if ((r = platform_init(&init_flags, &init_config)) != Platform_EOK)
164 goto exit;
165
166 /* Initialize platform UART */
167 if ((r = platform_uart_init()) != Platform_EOK)
168 goto exit;
169 if ((r = platform_uart_set_baudrate(115200)) != Platform_EOK)
170 goto exit;
171
172 /* Get platform info */
173 platform_get_info(&p_info);
174 /* Write data to the UART */
175 platform_write("Platform library version is %s\n", p_info.version);
176 platform_write("Board name is %s\n", p_info.board_name);
177 platform_write("Board serial number is %s\n", p_info.serial_nbr);
178 platform_write("Board revision ID is %u\n", p_info.board_rev);
179 platform_write("CPU name is %s\n", p_info.cpu.name);
180 platform_write("CPU revision ID is %u\n", p_info.cpu.revision_id);
181 platform_write("Number of CPU cores is %u\n", p_info.cpu.core_count);
182 platform_write("CPU frequency is %u MHz\n", p_info.frequency);
183
184 // Init CorePac INTC
185 if ((r = C66XX_INT_init_core()) != C66XX_OK)
186 goto exit;
187
188 // Init DSP Timer
189 if ((r = tx_timer_init(C66XX_DSP_TIMER, C66XX_DSP_TIMER_FREQ)) != C66XX_OK)
190 goto exit;
191
192 // Init DSP interrupt controller
193 if ((r = tx_interrupt_init()) != C66XX_OK)
194 goto exit;
195
196 printf("Board is initialized\n");
197 /* Exit with no errors */
198
199 exit:
200 return (r);
201 }
202 //-----------------------------------------------------------------------------
203
204
205 /*------------ tx_nmi_handler() function --------------------------------------
206 * DESCRIPTION: Function handles NMI interrupt
207 * ARGUMENTS:
208 * None
209 * RETURNED VALUE: None
210 -----------------------------------------------------------------------------*/
tx_nmi_handler(void)211 void tx_nmi_handler(void)
212 {
213 }
214 //-----------------------------------------------------------------------------
215
216
217 /*------------ tx_int4_handler() function -------------------------------------
218 * DESCRIPTION: Function handles INT4 interrupt
219 * ARGUMENTS:
220 * None
221 * RETURNED VALUE: None
222 -----------------------------------------------------------------------------*/
tx_int4_handler(void)223 void tx_int4_handler(void)
224 {
225 }
226 //-----------------------------------------------------------------------------
227
228
229 /*------------ tx_int5_handler() function -------------------------------------
230 * DESCRIPTION: Function handles INT5 interrupt
231 * ARGUMENTS:
232 * None
233 * RETURNED VALUE: None
234 -----------------------------------------------------------------------------*/
tx_int5_handler(void)235 void tx_int5_handler(void)
236 {
237 }
238 //-----------------------------------------------------------------------------
239
240
241 /*------------ tx_int6_handler() function -------------------------------------
242 * DESCRIPTION: Function handles INT6 interrupt
243 * ARGUMENTS:
244 * None
245 * RETURNED VALUE: None
246 -----------------------------------------------------------------------------*/
tx_int6_handler(void)247 void tx_int6_handler(void)
248 {
249 }
250 //-----------------------------------------------------------------------------
251
252
253 /*------------ tx_int7_handler() function -------------------------------------
254 * DESCRIPTION: Function handles INT7 interrupt
255 * ARGUMENTS:
256 * None
257 * RETURNED VALUE: None
258 -----------------------------------------------------------------------------*/
tx_int7_handler(void)259 void tx_int7_handler(void)
260 {
261 }
262 //-----------------------------------------------------------------------------
263
264
265 /*------------ tx_int8_handler() function -------------------------------------
266 * DESCRIPTION: Function handles INT8 interrupt
267 * ARGUMENTS:
268 * None
269 * RETURNED VALUE: None
270 -----------------------------------------------------------------------------*/
tx_int8_handler(void)271 void tx_int8_handler(void)
272 {
273 }
274 //-----------------------------------------------------------------------------
275
276
277 /*------------ tx_int9_handler() function -------------------------------------
278 * DESCRIPTION: Function handles INT9 interrupt
279 * ARGUMENTS:
280 * None
281 * RETURNED VALUE: None
282 -----------------------------------------------------------------------------*/
tx_int9_handler(void)283 void tx_int9_handler(void)
284 {
285 }
286 //-----------------------------------------------------------------------------
287
288
289 /*------------ tx_int10_handler() function ------------------------------------
290 * DESCRIPTION: Function handles INT10 interrupt
291 * ARGUMENTS:
292 * None
293 * RETURNED VALUE: None
294 -----------------------------------------------------------------------------*/
tx_int10_handler(void)295 void tx_int10_handler(void)
296 {
297 }
298 //-----------------------------------------------------------------------------
299
300
301 /*------------ tx_int11_handler() function ------------------------------------
302 * DESCRIPTION: Function handles INT11 interrupt
303 * ARGUMENTS:
304 * None
305 * RETURNED VALUE: None
306 -----------------------------------------------------------------------------*/
tx_int11_handler(void)307 void tx_int11_handler(void)
308 {
309 }
310 //-----------------------------------------------------------------------------
311
312
313 /*------------ tx_int12_handler() function ------------------------------------
314 * DESCRIPTION: Function handles INT12 interrupt
315 * ARGUMENTS:
316 * None
317 * RETURNED VALUE: None
318 -----------------------------------------------------------------------------*/
tx_int12_handler(void)319 void tx_int12_handler(void)
320 {
321 }
322 //-----------------------------------------------------------------------------
323
324
325 /*------------ tx_int13_handler() function ------------------------------------
326 * DESCRIPTION: Function handles INT13 interrupt
327 * ARGUMENTS:
328 * None
329 * RETURNED VALUE: None
330 -----------------------------------------------------------------------------*/
tx_int13_handler(void)331 void tx_int13_handler(void)
332 {
333 }
334 //-----------------------------------------------------------------------------
335
336
337 /*------------ tx_int14_handler() function ------------------------------------
338 * DESCRIPTION: Function handles INT14 interrupt
339 * ARGUMENTS:
340 * None
341 * RETURNED VALUE: None
342 -----------------------------------------------------------------------------*/
tx_int14_handler(void)343 void tx_int14_handler(void)
344 {
345 }
346 //-----------------------------------------------------------------------------
347
348
349 /*------------ tx_int15_handler() function ------------------------------------
350 * DESCRIPTION: Function handles INT15 interrupt
351 * ARGUMENTS:
352 * None
353 * RETURNED VALUE: None
354 -----------------------------------------------------------------------------*/
tx_int15_handler(void)355 void tx_int15_handler(void)
356 {
357 }
358 //-----------------------------------------------------------------------------
359
360
361 //=============================================================================
362 //============ Platform OSAL functions ========================================
363 //=============================================================================
364
365 /*------------ Osal_platformMalloc() function ----------------------------*//**
366 * @brief Function implements the memory allocate function for the platform
367 * library.
368 *
369 * This function allocates a memory block of a given size specified by input
370 * parameter 'num_bytes'.
371 *
372 * @param[in] num_bytes - number of bytes to be allocated
373 * @param[in] alignment - alignment of allocated memory block in bytes
374 *
375 * @return Allocated block address
376 *
377 -----------------------------------------------------------------------------*/
Osal_platformMalloc(uint32_t num_bytes,uint32_t alignment)378 uint8_t *Osal_platformMalloc(uint32_t num_bytes, uint32_t alignment)
379 {
380 // Allocate memory from default system heap
381 return (NULL);
382 }
383 //-----------------------------------------------------------------------------
384
385
386 /*------------ Osal_platformFree() function ------------------------------*//**
387 * @brief Function implements the memory free function for the platform
388 * library.
389 *
390 * This function frees up memory allocated using Osal_platformMalloc()
391 * function call.
392 *
393 * @param[in] mem_ptr - pointer to the memory block to be cleaned up
394 * @param[in] num_bytes - size of the memory block to be cleaned up in bytes
395 *
396 * @return None
397 *
398 -----------------------------------------------------------------------------*/
Osal_platformFree(uint8_t * mem_ptr,uint32_t num_bytes)399 void Osal_platformFree(uint8_t *mem_ptr, uint32_t num_bytes)
400 {
401 }
402 //-----------------------------------------------------------------------------
403
404
405 /*------------ Osal_platformSpiCsEnter() function ------------------------*//**
406 * @brief Function is used to enter a critical section
407 *
408 * Function protects against access from multiple cores and access from
409 * multiple threads on single core
410 *
411 * @param[out] key - pointer to a variable to receive a handle for unlocking
412 * critical section
413
414 * @return None
415 *
416 -----------------------------------------------------------------------------*/
Osal_platformSpiCsEnter(void)417 void Osal_platformSpiCsEnter(void)
418 {
419 }
420 //-----------------------------------------------------------------------------
421
422
423 /*------------ Osal_platformSpiCsExit() function -------------------------*//**
424 * @brief Function is used to exit a critical section protected using
425 * Osal_paMtCsEnter() API.
426 *
427 * @param[in] key - handle for unlocking critical section
428 *
429 * @return None
430 *
431 -----------------------------------------------------------------------------*/
Osal_platformSpiCsExit(void)432 void Osal_platformSpiCsExit(void)
433 {
434 }
435 //-----------------------------------------------------------------------------
436
437
438 //=============================================================================
439
440
441
442