3 FreeRTOS V8.2.2 - Copyright (C) 2015 Real Time Engineers Ltd.
\r
6 VISIT http://www.FreeRTOS.org TO ENSURE YOU ARE USING THE LATEST VERSION.
\r
8 This file is part of the FreeRTOS distribution.
\r
10 FreeRTOS is free software; you can redistribute it and/or modify it under
\r
11 the terms of the GNU General Public License (version 2) as published by the
\r
12 Free Software Foundation >>!AND MODIFIED BY!<< the FreeRTOS exception.
\r
14 ***************************************************************************
\r
15 >>! NOTE: The modification to the GPL is included to allow you to !<<
\r
16 >>! distribute a combined work that includes FreeRTOS without being !<<
\r
17 >>! obliged to provide the source code for proprietary components !<<
\r
18 >>! outside of the FreeRTOS kernel. !<<
\r
19 ***************************************************************************
\r
21 FreeRTOS is distributed in the hope that it will be useful, but WITHOUT ANY
\r
22 WARRANTY; without even the implied warranty of MERCHANTABILITY or FITNESS
\r
23 FOR A PARTICULAR PURPOSE. Full license text is available on the following
\r
24 link: http://www.freertos.org/a00114.html
\r
26 ***************************************************************************
\r
28 * FreeRTOS provides completely free yet professionally developed, *
\r
29 * robust, strictly quality controlled, supported, and cross *
\r
30 * platform software that is more than just the market leader, it *
\r
31 * is the industry's de facto standard. *
\r
33 * Help yourself get started quickly while simultaneously helping *
\r
34 * to support the FreeRTOS project by purchasing a FreeRTOS *
\r
35 * tutorial book, reference manual, or both: *
\r
36 * http://www.FreeRTOS.org/Documentation *
\r
38 ***************************************************************************
\r
40 http://www.FreeRTOS.org/FAQHelp.html - Having a problem? Start by reading
\r
41 the FAQ page "My application does not run, what could be wrong?". Have you
\r
42 defined configASSERT()?
\r
44 http://www.FreeRTOS.org/support - In return for receiving this top quality
\r
45 embedded software for free we request you assist our global community by
\r
46 participating in the support forum.
\r
48 http://www.FreeRTOS.org/training - Investing in training allows your team to
\r
49 be as productive as possible as early as possible. Now you can receive
\r
50 FreeRTOS training directly from Richard Barry, CEO of Real Time Engineers
\r
51 Ltd, and the world's leading authority on the world's leading RTOS.
\r
53 http://www.FreeRTOS.org/plus - A selection of FreeRTOS ecosystem products,
\r
54 including FreeRTOS+Trace - an indispensable productivity tool, a DOS
\r
55 compatible FAT file system, and our tiny thread aware UDP/IP stack.
\r
57 http://www.FreeRTOS.org/labs - Where new FreeRTOS products go to incubate.
\r
58 Come and try FreeRTOS+TCP, our new open source TCP/IP stack for FreeRTOS.
\r
60 http://www.OpenRTOS.com - Real Time Engineers ltd. license FreeRTOS to High
\r
61 Integrity Systems ltd. to sell under the OpenRTOS brand. Low cost OpenRTOS
\r
62 licenses offer ticketed support, indemnification and commercial middleware.
\r
64 http://www.SafeRTOS.com - High Integrity Systems also provide a safety
\r
65 engineered and independently SIL3 certified version for use in safety and
\r
66 mission critical applications that require provable dependability.
\r
71 /******************************************************************************
\r
72 * This project provides two demo applications. A simple blinky style project,
\r
73 * and a more comprehensive test and demo application. The
\r
74 * mainCREATE_SIMPLE_BLINKY_DEMO_ONLY setting (defined in this file) is used to
\r
75 * select between the two. The simply blinky demo is implemented and described
\r
76 * in main_blinky.c. The more comprehensive test and demo application is
\r
77 * implemented and described in main_full.c.
\r
79 * This file implements the code that is not demo specific, including the
\r
80 * hardware setup, standard FreeRTOS hook functions, and the ISR hander called
\r
81 * by the RTOS after interrupt entry (including nesting) has been taken care of.
\r
83 * ENSURE TO READ THE DOCUMENTATION PAGE FOR THIS PORT AND DEMO APPLICATION ON
\r
84 * THE http://www.FreeRTOS.org WEB SITE FOR FULL INFORMATION ON USING THIS DEMO
\r
85 * APPLICATION, AND ITS ASSOCIATE FreeRTOS ARCHITECTURE PORT!
\r
89 /* Standard includes. */
\r
92 /* Scheduler include files. */
\r
93 #include "FreeRTOS.h"
\r
97 /* Renesas includes. */
\r
98 #include "r_cg_macrodriver.h"
\r
99 #include "r_cg_icu.h"
\r
100 #include "r_cg_scifa.h"
\r
101 #include "r_cg_rspi.h"
\r
102 #include "r_system.h"
\r
103 #include "r_reset.h"
\r
104 #include "siochar.h"
\r
105 #include "r_cg_userdefine.h"
\r
107 /* Set mainCREATE_SIMPLE_BLINKY_DEMO_ONLY to one to run the simple blinky demo,
\r
108 or 0 to run the more comprehensive test and demo application. */
\r
109 #define mainCREATE_SIMPLE_BLINKY_DEMO_ONLY 1
\r
111 /*-----------------------------------------------------------*/
\r
113 static void prvClearBSS( void );
\r
116 * Configure the hardware as necessary to run this demo.
\r
118 static void prvSetupHardware( void );
\r
121 * main_blinky() is used when mainCREATE_SIMPLE_BLINKY_DEMO_ONLY is set to 1.
\r
122 * main_full() is used when mainCREATE_SIMPLE_BLINKY_DEMO_ONLY is set to 0.
\r
124 #if( mainCREATE_SIMPLE_BLINKY_DEMO_ONLY == 1 )
\r
125 extern void main_blinky( void );
\r
127 extern void main_full( void );
\r
128 #endif /* #if mainCREATE_SIMPLE_BLINKY_DEMO_ONLY == 1 */
\r
130 /* Prototypes for the standard FreeRTOS callback/hook functions implemented
\r
131 within this file. */
\r
132 void vApplicationMallocFailedHook( void );
\r
133 void vApplicationIdleHook( void );
\r
134 void vApplicationStackOverflowHook( TaskHandle_t pxTask, char *pcTaskName );
\r
135 void vApplicationTickHook( void );
\r
137 /* Prototype for the IRQ handler called by the generic Cortex-A5 RTOS port
\r
139 void vApplicationIRQHandler( void );
\r
141 /* Library initialisation. */
\r
142 extern void R_Systeminit( void );
\r
144 /*-----------------------------------------------------------*/
\r
146 volatile uint32_t ultest = 0, ultest2 = 9999;
\r
152 configASSERT( ultest == 0 );
\r
153 configASSERT( ultest2 == 9999 );
\r
155 /* Configure the hardware ready to run the demo. */
\r
156 prvSetupHardware();
\r
158 /* The mainCREATE_SIMPLE_BLINKY_DEMO_ONLY setting is described at the top
\r
160 #if( mainCREATE_SIMPLE_BLINKY_DEMO_ONLY == 1 )
\r
172 /*-----------------------------------------------------------*/
\r
174 static void prvSetupHardware( void )
\r
178 /* Enable RSPI1 (serial peripheral interface). */
\r
181 /* Configure the UART channel for communication with a host PC via on-board
\r
182 RL78/G1C device. */
\r
185 /* Enable SCIFA2 (serial communications interface with FIFO). */
\r
188 /* SW3 interrupts. */
\r
189 R_ICU_IRQ12_Start();
\r
191 /*-----------------------------------------------------------*/
\r
193 void vApplicationMallocFailedHook( void )
\r
195 /* Called if a call to pvPortMalloc() fails because there is insufficient
\r
196 free memory available in the FreeRTOS heap. pvPortMalloc() is called
\r
197 internally by FreeRTOS API functions that create tasks, queues, software
\r
198 timers, and semaphores. The size of the FreeRTOS heap is set by the
\r
199 configTOTAL_HEAP_SIZE configuration constant in FreeRTOSConfig.h. */
\r
201 /* Force an assert. */
\r
202 configASSERT( ( volatile void * ) NULL );
\r
204 /*-----------------------------------------------------------*/
\r
206 void vApplicationStackOverflowHook( TaskHandle_t pxTask, char *pcTaskName )
\r
208 ( void ) pcTaskName;
\r
211 /* Run time stack overflow checking is performed if
\r
212 configCHECK_FOR_STACK_OVERFLOW is defined to 1 or 2. This hook
\r
213 function is called if a stack overflow is detected. */
\r
215 /* Force an assert. */
\r
216 configASSERT( ( volatile void * ) NULL );
\r
218 /*-----------------------------------------------------------*/
\r
220 void vApplicationIdleHook( void )
\r
222 volatile size_t xFreeHeapSpace;
\r
224 /* This is just a trivial example of an idle hook. It is called on each
\r
225 cycle of the idle task. It must *NOT* attempt to block. In this case the
\r
226 idle task just queries the amount of FreeRTOS heap that remains. See the
\r
227 memory management section on the http://www.FreeRTOS.org web site for memory
\r
228 management options. If there is a lot of heap memory free then the
\r
229 configTOTAL_HEAP_SIZE value in FreeRTOSConfig.h can be reduced to free up
\r
231 // xFreeHeapSpace = xPortGetFreeHeapSize();
\r
233 /* Remove compiler warning about xFreeHeapSpace being set but never used. */
\r
234 ( void ) xFreeHeapSpace;
\r
236 /*-----------------------------------------------------------*/
\r
238 void vApplicationTickHook( void )
\r
240 #if mainCREATE_SIMPLE_BLINKY_DEMO_ONLY == 0
\r
242 extern void vFullDemoTickHook( void );
\r
244 vFullDemoTickHook();
\r
248 /*-----------------------------------------------------------*/
\r
250 /* The function called by the RTOS port layer after it has managed interrupt
\r
252 void vApplicationIRQHandler( void )
\r
255 extern void FreeRTOS_Tick_Handler( void );
\r
257 /* Clear the interrupt source CMI5. */
\r
258 VIC.PIC9.LONG = 0x00001000UL;
\r
260 FreeRTOS_Tick_Handler();
\r
263 portDISABLE_INTERRUPTS();
\r
264 // Done in the epilogue code VIC.HVA0.LONG = 0x00000000UL;
\r
267 typedef void (*ISRFunction_t)( void );
\r
268 ISRFunction_t pxISRFunction;
\r
269 volatile uint32_t * pulAIC_IVR = ( uint32_t * ) configINTERRUPT_VECTOR_ADDRESS;
\r
271 /* Obtain the address of the interrupt handler from the AIR. */
\r
272 pxISRFunction = ( ISRFunction_t ) *pulAIC_IVR;
\r
274 /* Write back to the SAMA5's interrupt controller's IVR register in case the
\r
275 CPU is in protect mode. If the interrupt controller is not in protect mode
\r
276 then this write is not necessary. */
\r
277 *pulAIC_IVR = ( uint32_t ) pxISRFunction;
\r
279 /* Ensure the write takes before re-enabling interrupts. */
\r
284 /* Call the installed ISR. */
\r
288 /*-----------------------------------------------------------*/
\r
290 static void prvClearBSS( void )
\r
292 extern uint32_t __bss_start__[];
\r
293 extern uint32_t __bss_end__[];
\r
296 /* Zero out bss. */
\r
297 xSize = ( ( size_t ) __bss_end__ ) - ( ( size_t ) __bss_start__ );
\r
298 memset( ( void * ) __bss_start__, 0x00, xSize );
\r
344 #include "FreeRTOS.h"
\r
347 /***********************************************************************************************************************
\r
349 ***********************************************************************************************************************/
\r
350 #include "r_cg_macrodriver.h"
\r
351 #include "r_cg_cgc.h"
\r
352 #include "r_cg_icu.h"
\r
353 #include "r_cg_port.h"
\r
354 #include "r_cg_tpu.h"
\r
355 #include "r_cg_cmt.h"
\r
356 #include "r_cg_scifa.h"
\r
357 #include "r_cg_rspi.h"
\r
358 #include "r_cg_s12ad.h"
\r
359 /* Start user code for include. Do not edit comment generated here */
\r
360 #include "r_cg_mpc.h"
\r
361 #include "r_system.h"
\r
362 #include "r_reset.h"
\r
363 #include "lcd_pmod.h"
\r
364 #include "logo_data.h"
\r
366 #include "siochar.h"
\r
367 /* End user code. Do not edit comment generated here */
\r
368 #include "r_cg_userdefine.h"
\r
370 /* Start user code for global. Do not edit comment generated here */
\r
372 #define LZ_ENABLE (1)
\r
373 #define LZ_DISABLE (0)
\r
375 /* Welcome banner - displayed on serial port at startup*/
\r
376 static uint8_t welcome_banner[] = "\n\n\rRSK+RZT1 \n\n\r- Tutorial - Press 'c' or SW3 for ADC Conversion\r\n\0";
\r
378 /* Used as a Data Transmit counter */
\r
379 static uint8_t uart_buffer[] = " ADC count: x. Value: xxxxx\r\n";
\r
381 /* Used as a Data Transmit counter */
\r
382 static uint8_t lcd_buffer[] = " ADC = xxxx ";
\r
384 /* Function prototype for displaying the 2 bit binary counter using LEDs */
\r
385 static void led_display_count (const uint8_t count);
\r
387 extern void R_Systeminit(void);
\r
388 void R_MAIN_UserInit(void);
\r
390 /* Prototypes for the standard FreeRTOS callback/hook functions implemented
\r
391 within this file. */
\r
392 void vApplicationMallocFailedHook( void );
\r
393 void vApplicationIdleHook( void );
\r
394 void vApplicationStackOverflowHook( TaskHandle_t pxTask, char *pcTaskName );
\r
395 void vApplicationTickHook( void );
\r
398 /* Prototype for the IRQ handler called by the generic Cortex-A5 RTOS port
\r
400 void vApplicationIRQHandler( void );
\r
404 uint32_t adc_count = 0;
\r
410 /* SW3 interrupts */
\r
411 R_ICU_IRQ12_Start();
\r
414 g_switch_press_flg = 0;
\r
415 g_terminal_request = 0;
\r
417 /* Display the welcome banner on the serial terminal */
\r
418 R_SCIFA2_Serial_Send((uint8_t *)&welcome_banner, sizeof(welcome_banner));
\r
420 /* Data transmission and reception done in the infinite loop */
\r
423 /* Check for a valid request from the switch or serial terminal */
\r
424 if ((g_terminal_request) || (g_switch_press_flg & SW3_PRESS_FLG))
\r
426 /* Update the binary count using LED2 and LED3 */
\r
427 led_display_count(adc_count);
\r
429 while(0u == SCIFA2.FSR.BIT.TDFE)
\r
431 /* Wait for previous transmission to complete */
\r
434 /* Write send data */
\r
435 R_SCIFA2_Serial_Send((uint8_t *)&uart_buffer, sizeof(uart_buffer));
\r
438 SCIFA2.FSR.BIT.TDFE = 0U;
\r
440 if (g_terminal_request)
\r
442 /* Clear the request */
\r
443 g_terminal_request = 0U;
\r
446 if (g_switch_press_flg & SW3_PRESS_FLG)
\r
448 /* Clear the request */
\r
449 g_switch_press_flg &= ((uint8_t)~SW3_PRESS_FLG);
\r
456 /***********************************************************************************************************************
\r
457 * Function Name: R_MAIN_UserInit
\r
458 * Description : This function adds user code before implementing main function.
\r
460 * Return Value : None
\r
461 ***********************************************************************************************************************/
\r
462 void R_MAIN_UserInit(void)
\r
464 /* Enable RSPI1 operations */
\r
467 /* Configure UART channel for communication with host PC via RL78/G1C device */
\r
470 /* Enable SCIFA2 operations */
\r
474 static void led_display_count (const uint8_t count)
\r
476 /* Set LEDs according to lower nibble of count parameter */
\r
477 LED2 = (uint8_t) ((count & 0x01) ? LED_ON : LED_OFF);
\r
478 LED3 = (uint8_t) ((count & 0x02) ? LED_ON : LED_OFF);
\r
481 /*-----------------------------------------------------------*/
\r
483 void vApplicationMallocFailedHook( void )
\r
485 /* Called if a call to pvPortMalloc() fails because there is insufficient
\r
486 free memory available in the FreeRTOS heap. pvPortMalloc() is called
\r
487 internally by FreeRTOS API functions that create tasks, queues, software
\r
488 timers, and semaphores. The size of the FreeRTOS heap is set by the
\r
489 configTOTAL_HEAP_SIZE configuration constant in FreeRTOSConfig.h. */
\r
491 /* Force an assert. */
\r
492 configASSERT( ( volatile void * ) NULL );
\r
494 /*-----------------------------------------------------------*/
\r
496 void vApplicationStackOverflowHook( TaskHandle_t pxTask, char *pcTaskName )
\r
498 ( void ) pcTaskName;
\r
501 /* Run time stack overflow checking is performed if
\r
502 configCHECK_FOR_STACK_OVERFLOW is defined to 1 or 2. This hook
\r
503 function is called if a stack overflow is detected. */
\r
505 /* Force an assert. */
\r
506 configASSERT( ( volatile void * ) NULL );
\r
508 /*-----------------------------------------------------------*/
\r
510 void vApplicationIdleHook( void )
\r
512 volatile size_t xFreeHeapSpace;
\r
514 /* This is just a trivial example of an idle hook. It is called on each
\r
515 cycle of the idle task. It must *NOT* attempt to block. In this case the
\r
516 idle task just queries the amount of FreeRTOS heap that remains. See the
\r
517 memory management section on the http://www.FreeRTOS.org web site for memory
\r
518 management options. If there is a lot of heap memory free then the
\r
519 configTOTAL_HEAP_SIZE value in FreeRTOSConfig.h can be reduced to free up
\r
521 xFreeHeapSpace = xPortGetFreeHeapSize();
\r
523 /* Remove compiler warning about xFreeHeapSpace being set but never used. */
\r
524 ( void ) xFreeHeapSpace;
\r
526 /*-----------------------------------------------------------*/
\r
528 void vApplicationTickHook( void )
\r
531 /*-----------------------------------------------------------*/
\r
533 void vApplicationIRQHandler( void )
\r