2 FreeRTOS V7.5.2 - Copyright (C) 2013 Real Time Engineers Ltd.
\r
4 VISIT http://www.FreeRTOS.org TO ENSURE YOU ARE USING THE LATEST VERSION.
\r
6 ***************************************************************************
\r
8 * FreeRTOS provides completely free yet professionally developed, *
\r
9 * robust, strictly quality controlled, supported, and cross *
\r
10 * platform software that has become a de facto standard. *
\r
12 * Help yourself get started quickly and support the FreeRTOS *
\r
13 * project by purchasing a FreeRTOS tutorial book, reference *
\r
14 * manual, or both from: http://www.FreeRTOS.org/Documentation *
\r
18 ***************************************************************************
\r
20 This file is part of the FreeRTOS distribution.
\r
22 FreeRTOS is free software; you can redistribute it and/or modify it under
\r
23 the terms of the GNU General Public License (version 2) as published by the
\r
24 Free Software Foundation >>!AND MODIFIED BY!<< the FreeRTOS exception.
\r
26 >>! NOTE: The modification to the GPL is included to allow you to distribute
\r
27 >>! a combined work that includes FreeRTOS without being obliged to provide
\r
28 >>! the source code for proprietary components outside of the FreeRTOS
\r
31 FreeRTOS is distributed in the hope that it will be useful, but WITHOUT ANY
\r
32 WARRANTY; without even the implied warranty of MERCHANTABILITY or FITNESS
\r
33 FOR A PARTICULAR PURPOSE. Full license text is available from the following
\r
34 link: http://www.freertos.org/a00114.html
\r
38 ***************************************************************************
\r
40 * Having a problem? Start by reading the FAQ "My application does *
\r
41 * not run, what could be wrong?" *
\r
43 * http://www.FreeRTOS.org/FAQHelp.html *
\r
45 ***************************************************************************
\r
47 http://www.FreeRTOS.org - Documentation, books, training, latest versions,
\r
48 license and Real Time Engineers Ltd. contact details.
\r
50 http://www.FreeRTOS.org/plus - A selection of FreeRTOS ecosystem products,
\r
51 including FreeRTOS+Trace - an indispensable productivity tool, a DOS
\r
52 compatible FAT file system, and our tiny thread aware UDP/IP stack.
\r
54 http://www.OpenRTOS.com - Real Time Engineers ltd license FreeRTOS to High
\r
55 Integrity Systems to sell under the OpenRTOS brand. Low cost OpenRTOS
\r
56 licenses offer ticketed support, indemnification and middleware.
\r
58 http://www.SafeRTOS.com - High Integrity Systems also provide a safety
\r
59 engineered and independently SIL3 certified version for use in safety and
\r
60 mission critical applications that require provable dependability.
\r
65 /* FreeRTOS includes. */
\r
66 #include "FreeRTOS.h"
\r
69 /* Library includes. */
\r
72 void usart_read_callback(const struct usart_module *const usart_module);
\r
73 void usart_write_callback(const struct usart_module *const usart_module);
\r
74 static void prvSetupHardware( void );
\r
75 void configure_usart(void);
\r
76 void configure_usart_callbacks(void);
\r
77 void vApplicationMallocFailedHook( void );
\r
78 void vApplicationIdleHook( void );
\r
79 void vApplicationStackOverflowHook( xTaskHandle pxTask, signed char *pcTaskName );
\r
80 void vApplicationTickHook( void );
\r
82 struct usart_module usart_instance;
\r
83 #define MAX_RX_BUFFER_LENGTH 5
\r
84 volatile uint8_t rx_buffer[MAX_RX_BUFFER_LENGTH];
\r
86 char cChars[ NUM ] = { 0 };
\r
88 void usart_read_callback(const struct usart_module *const usart_module)
\r
90 usart_write_buffer_job(&usart_instance, (uint8_t *)rx_buffer, MAX_RX_BUFFER_LENGTH);
\r
93 void usart_write_callback(const struct usart_module *const usart_module)
\r
95 port_pin_toggle_output_level(LED_0_PIN);
\r
98 void configure_usart(void)
\r
100 struct usart_config config_usart;
\r
101 usart_get_config_defaults(&config_usart);
\r
102 config_usart.baudrate = 115200;
\r
103 config_usart.mux_setting = EDBG_CDC_SERCOM_MUX_SETTING;
\r
104 config_usart.pinmux_pad0 = EDBG_CDC_SERCOM_PINMUX_PAD0;
\r
105 config_usart.pinmux_pad1 = EDBG_CDC_SERCOM_PINMUX_PAD1;
\r
106 config_usart.pinmux_pad2 = EDBG_CDC_SERCOM_PINMUX_PAD2;
\r
107 config_usart.pinmux_pad3 = EDBG_CDC_SERCOM_PINMUX_PAD3;
\r
108 while (usart_init(&usart_instance,
\r
109 EDBG_CDC_MODULE, &config_usart) != STATUS_OK) {
\r
111 usart_enable(&usart_instance);
\r
114 void configure_usart_callbacks(void)
\r
116 usart_register_callback(&usart_instance,
\r
117 usart_write_callback, USART_CALLBACK_BUFFER_TRANSMITTED);
\r
118 usart_register_callback(&usart_instance,
\r
119 usart_read_callback, USART_CALLBACK_BUFFER_RECEIVED);
\r
120 usart_enable_callback(&usart_instance, USART_CALLBACK_BUFFER_TRANSMITTED);
\r
121 usart_enable_callback(&usart_instance, USART_CALLBACK_BUFFER_RECEIVED);
\r
129 prvSetupHardware();
\r
132 configure_usart_callbacks();
\r
133 system_interrupt_enable_global();
\r
135 uint8_t string[] = "Hello World!\r\n";
\r
136 usart_write_buffer_job(&usart_instance, string, sizeof(string));
\r
141 usart_read_buffer_job(&usart_instance,
\r
142 (uint8_t *)rx_buffer, MAX_RX_BUFFER_LENGTH);
\r
146 if (port_pin_get_input_level(BUTTON_0_PIN) == BUTTON_0_ACTIVE) {
\r
147 port_pin_set_output_level(LED_0_PIN, LED_0_ACTIVE);
\r
149 port_pin_set_output_level(LED_0_PIN, !LED_0_ACTIVE);
\r
153 /*-----------------------------------------------------------*/
\r
155 static void prvSetupHardware( void )
\r
159 /*-----------------------------------------------------------*/
\r
161 void vApplicationMallocFailedHook( void )
\r
163 /* vApplicationMallocFailedHook() will only be called if
\r
164 configUSE_MALLOC_FAILED_HOOK is set to 1 in FreeRTOSConfig.h. It is a hook
\r
165 function that will get called if a call to pvPortMalloc() fails.
\r
166 pvPortMalloc() is called internally by the kernel whenever a task, queue,
\r
167 timer or semaphore is created. It is also called by various parts of the
\r
168 demo application. If heap_1.c or heap_2.c are used, then the size of the
\r
169 heap available to pvPortMalloc() is defined by configTOTAL_HEAP_SIZE in
\r
170 FreeRTOSConfig.h, and the xPortGetFreeHeapSize() API function can be used
\r
171 to query the size of free heap space that remains (although it does not
\r
172 provide information on how the remaining heap might be fragmented). */
\r
173 taskDISABLE_INTERRUPTS();
\r
176 /*-----------------------------------------------------------*/
\r
178 void vApplicationIdleHook( void )
\r
180 /* vApplicationIdleHook() will only be called if configUSE_IDLE_HOOK is set
\r
181 to 1 in FreeRTOSConfig.h. It will be called on each iteration of the idle
\r
182 task. It is essential that code added to this hook function never attempts
\r
183 to block in any way (for example, call xQueueReceive() with a block time
\r
184 specified, or call vTaskDelay()). If the application makes use of the
\r
185 vTaskDelete() API function (as this demo application does) then it is also
\r
186 important that vApplicationIdleHook() is permitted to return to its calling
\r
187 function, because it is the responsibility of the idle task to clean up
\r
188 memory allocated by the kernel to any task that has since been deleted. */
\r
190 /*-----------------------------------------------------------*/
\r
192 void vApplicationStackOverflowHook( xTaskHandle pxTask, signed char *pcTaskName )
\r
194 ( void ) pcTaskName;
\r
197 /* Run time stack overflow checking is performed if
\r
198 configCHECK_FOR_STACK_OVERFLOW is defined to 1 or 2. This hook
\r
199 function is called if a stack overflow is detected. */
\r
200 taskDISABLE_INTERRUPTS();
\r
203 /*-----------------------------------------------------------*/
\r
205 void vApplicationTickHook( void )
\r
207 /* This function will be called by each tick interrupt if
\r
208 configUSE_TICK_HOOK is set to 1 in FreeRTOSConfig.h. User code can be
\r
209 added here, but the tick hook is called from an interrupt context, so
\r
210 code must not attempt to block, and only the interrupt safe FreeRTOS API
\r
211 functions can be used (those that end in FromISR()). */
\r