<tool id="cdt.managedbuild.tool.gnu.cross.cpp.linker.2105463183" name="Cross G++ Linker" superClass="cdt.managedbuild.tool.gnu.cross.cpp.linker"/>\r
<tool id="cdt.managedbuild.tool.gnu.cross.archiver.424513814" name="Cross GCC Archiver" superClass="cdt.managedbuild.tool.gnu.cross.archiver"/>\r
<tool command="riscv64-unknown-elf-gcc.exe" id="cdt.managedbuild.tool.gnu.cross.assembler.825438707" name="Cross GCC Assembler" superClass="cdt.managedbuild.tool.gnu.cross.assembler">\r
- <option id="gnu.both.asm.option.flags.1946908814" name="Assembler flags" superClass="gnu.both.asm.option.flags" useByScannerDiscovery="false" value="-march=rv32imac -mabi=ilp32 -mcmodel=medlow -c -DportasmHANDLE_INTERRUPT=handle_trap" valueType="string"/>\r
+ <option id="gnu.both.asm.option.flags.1946908814" name="Assembler flags" superClass="gnu.both.asm.option.flags" useByScannerDiscovery="false" value="-march=rv32imac -mabi=ilp32 -mcmodel=medlow -c -DportasmHANDLE_INTERRUPT=handle_trap -g3" valueType="string"/>\r
<option id="gnu.both.asm.option.include.paths.1448234506" name="Include paths (-I)" superClass="gnu.both.asm.option.include.paths" useByScannerDiscovery="false" valueType="includePath">\r
<listOptionValue builtIn="false" value=""${workspace_loc:/${ProjName}/FreeRTOS_Source/portable/GCC/RISC-V/chip_specific_extensions/RV32I_CLINT_no_extensions}""/>\r
</option>\r
#ifndef FREERTOS_CONFIG_H\r
#define FREERTOS_CONFIG_H\r
\r
-/*\r
- * For some reason the standard demo timer demo/test tasks fail when executing\r
- * in QEMU, although they pass on other RISC-V platforms. This requires\r
- * further investigation, but for now, defining _WINDOWS_ has the effect of\r
- * using the wider timer test thresholds that are normally only used when the\r
- * tests are used with the FreeRTOS Windows port (which is not deterministic\r
- * and therefore requires wider margins).\r
- */\r
-#define _WINDOWS_\r
-\r
/*-----------------------------------------------------------\r
* Application specific definitions.\r
*\r
#define configUSE_PREEMPTION 1\r
#define configUSE_IDLE_HOOK 0\r
#define configUSE_TICK_HOOK 1\r
-#define configCPU_CLOCK_HZ ( 10000000 ) /*QEMU*/\r
+#define configCPU_CLOCK_HZ ( 32768 ) /*QEMU*/\r
#define configTICK_RATE_HZ ( ( TickType_t ) 1000 )\r
#define configMAX_PRIORITIES ( 7 )\r
#define configMINIMAL_STACK_SIZE ( ( unsigned short ) 70 )\r
-#define configTOTAL_HEAP_SIZE ( ( size_t ) 14100 )\r
+#define configTOTAL_HEAP_SIZE ( ( size_t ) 10000 )\r
#define configMAX_TASK_NAME_LEN ( 16 )\r
#define configUSE_TRACE_FACILITY 0\r
#define configUSE_16_BIT_TICKS 0\r
--- /dev/null
+/*\r
+ * FreeRTOS Kernel V10.2.1\r
+ * Copyright (C) 2019 Amazon.com, Inc. or its affiliates. All Rights Reserved.\r
+ *\r
+ * Permission is hereby granted, free of charge, to any person obtaining a copy of\r
+ * this software and associated documentation files (the "Software"), to deal in\r
+ * the Software without restriction, including without limitation the rights to\r
+ * use, copy, modify, merge, publish, distribute, sublicense, and/or sell copies of\r
+ * the Software, and to permit persons to whom the Software is furnished to do so,\r
+ * subject to the following conditions:\r
+ *\r
+ * The above copyright notice and this permission notice shall be included in all\r
+ * copies or substantial portions of the Software.\r
+ *\r
+ * THE SOFTWARE IS PROVIDED "AS IS", WITHOUT WARRANTY OF ANY KIND, EXPRESS OR\r
+ * IMPLIED, INCLUDING BUT NOT LIMITED TO THE WARRANTIES OF MERCHANTABILITY, FITNESS\r
+ * FOR A PARTICULAR PURPOSE AND NONINFRINGEMENT. IN NO EVENT SHALL THE AUTHORS OR\r
+ * COPYRIGHT HOLDERS BE LIABLE FOR ANY CLAIM, DAMAGES OR OTHER LIABILITY, WHETHER\r
+ * IN AN ACTION OF CONTRACT, TORT OR OTHERWISE, ARISING FROM, OUT OF OR IN\r
+ * CONNECTION WITH THE SOFTWARE OR THE USE OR OTHER DEALINGS IN THE SOFTWARE.\r
+ *\r
+ * http://www.FreeRTOS.org\r
+ * http://aws.amazon.com/freertos\r
+ *\r
+ * 1 tab == 4 spaces!\r
+ */\r
+\r
+/******************************************************************************\r
+ * NOTE 1: This project provides two demo applications. A simple blinky\r
+ * style project, and a more comprehensive test and demo application. The\r
+ * mainCREATE_SIMPLE_BLINKY_DEMO_ONLY setting in main.c is used to select\r
+ * between the two. See the notes on using mainCREATE_SIMPLE_BLINKY_DEMO_ONLY\r
+ * in main.c. This file implements the simply blinky style version.\r
+ *\r
+ * NOTE 2: This file only contains the source code that is specific to the\r
+ * basic demo. Generic functions, such FreeRTOS hook functions, and functions\r
+ * required to configure the hardware are defined in main.c.\r
+ ******************************************************************************\r
+ *\r
+ * main_blinky() creates one queue, and two tasks. It then starts the\r
+ * scheduler.\r
+ *\r
+ * The Queue Send Task:\r
+ * The queue send task is implemented by the prvQueueSendTask() function in\r
+ * this file. prvQueueSendTask() sits in a loop that causes it to repeatedly\r
+ * block for 1000 milliseconds, before sending the value 100 to the queue that\r
+ * was created within main_blinky(). Once the value is sent, the task loops\r
+ * back around to block for another 1000 milliseconds...and so on.\r
+ *\r
+ * The Queue Receive Task:\r
+ * The queue receive task is implemented by the prvQueueReceiveTask() function\r
+ * in this file. prvQueueReceiveTask() sits in a loop where it repeatedly\r
+ * blocks on attempts to read data from the queue that was created within\r
+ * main_blinky(). When data is received, the task checks the value of the\r
+ * data, and if the value equals the expected 100, writes 'Blink' to the UART\r
+ * (the UART is used in place of the LED to allow easy execution in QEMU). The\r
+ * 'block time' parameter passed to the queue receive function specifies that\r
+ * the task should be held in the Blocked state indefinitely to wait for data to\r
+ * be available on the queue. The queue receive task will only leave the\r
+ * Blocked state when the queue send task writes to the queue. As the queue\r
+ * send task writes to the queue every 1000 milliseconds, the queue receive\r
+ * task leaves the Blocked state every 1000 milliseconds, and therefore toggles\r
+ * the LED every 200 milliseconds.\r
+ */\r
+\r
+/* Standard includes. */\r
+#include <stdio.h>\r
+#include <string.h>\r
+#include <unistd.h>\r
+\r
+/* Kernel includes. */\r
+#include "FreeRTOS.h"\r
+#include "task.h"\r
+#include "queue.h"\r
+\r
+/* Priorities used by the tasks. */\r
+#define mainQUEUE_RECEIVE_TASK_PRIORITY ( tskIDLE_PRIORITY + 2 )\r
+#define mainQUEUE_SEND_TASK_PRIORITY ( tskIDLE_PRIORITY + 1 )\r
+\r
+/* The rate at which data is sent to the queue. The 200ms value is converted\r
+to ticks using the pdMS_TO_TICKS() macro. */\r
+#define mainQUEUE_SEND_FREQUENCY_MS pdMS_TO_TICKS( 1000 )\r
+\r
+/* The maximum number items the queue can hold. The priority of the receiving\r
+task is above the priority of the sending task, so the receiving task will\r
+preempt the sending task and remove the queue items each time the sending task\r
+writes to the queue. Therefore the queue will never have more than one item in\r
+it at any time, and even with a queue length of 1, the sending task will never\r
+find the queue full. */\r
+#define mainQUEUE_LENGTH ( 1 )\r
+\r
+/*-----------------------------------------------------------*/\r
+\r
+/*\r
+ * Called by main when mainCREATE_SIMPLE_BLINKY_DEMO_ONLY is set to 1 in\r
+ * main.c.\r
+ */\r
+void main_blinky( void );\r
+\r
+/*\r
+ * The tasks as described in the comments at the top of this file.\r
+ */\r
+static void prvQueueReceiveTask( void *pvParameters );\r
+static void prvQueueSendTask( void *pvParameters );\r
+\r
+/*-----------------------------------------------------------*/\r
+\r
+/* The queue used by both tasks. */\r
+static QueueHandle_t xQueue = NULL;\r
+\r
+/*-----------------------------------------------------------*/\r
+\r
+void main_blinky( void )\r
+{\r
+ /* Create the queue. */\r
+ xQueue = xQueueCreate( mainQUEUE_LENGTH, sizeof( uint32_t ) );\r
+\r
+ if( xQueue != NULL )\r
+ {\r
+ /* Start the two tasks as described in the comments at the top of this\r
+ file. */\r
+ xTaskCreate( prvQueueReceiveTask, /* The function that implements the task. */\r
+ "Rx", /* The text name assigned to the task - for debug only as it is not used by the kernel. */\r
+ configMINIMAL_STACK_SIZE * 2U, /* The size of the stack to allocate to the task. */\r
+ NULL, /* The parameter passed to the task - not used in this case. */\r
+ mainQUEUE_RECEIVE_TASK_PRIORITY, /* The priority assigned to the task. */\r
+ NULL ); /* The task handle is not required, so NULL is passed. */\r
+\r
+ xTaskCreate( prvQueueSendTask, "TX", configMINIMAL_STACK_SIZE * 2U, NULL, mainQUEUE_SEND_TASK_PRIORITY, NULL );\r
+\r
+ /* Start the tasks and timer running. */\r
+ vTaskStartScheduler();\r
+ }\r
+\r
+ /* If all is well, the scheduler will now be running, and the following\r
+ line will never be reached. If the following line does execute, then\r
+ there was insufficient FreeRTOS heap memory available for the Idle and/or\r
+ timer tasks to be created. See the memory management section on the\r
+ FreeRTOS web site for more details on the FreeRTOS heap\r
+ http://www.freertos.org/a00111.html. */\r
+ for( ;; );\r
+}\r
+/*-----------------------------------------------------------*/\r
+\r
+static void prvQueueSendTask( void *pvParameters )\r
+{\r
+TickType_t xNextWakeTime;\r
+const unsigned long ulValueToSend = 100UL;\r
+BaseType_t xReturned;\r
+\r
+ /* Remove compiler warning about unused parameter. */\r
+ ( void ) pvParameters;\r
+\r
+ /* Initialise xNextWakeTime - this only needs to be done once. */\r
+ xNextWakeTime = xTaskGetTickCount();\r
+\r
+ for( ;; )\r
+ {\r
+ /* Place this task in the blocked state until it is time to run again. */\r
+ vTaskDelayUntil( &xNextWakeTime, mainQUEUE_SEND_FREQUENCY_MS );\r
+\r
+ /* Send to the queue - causing the queue receive task to unblock and\r
+ toggle the LED. 0 is used as the block time so the sending operation\r
+ will not block - it shouldn't need to block as the queue should always\r
+ be empty at this point in the code. */\r
+ xReturned = xQueueSend( xQueue, &ulValueToSend, 0U );\r
+ configASSERT( xReturned == pdPASS );\r
+ }\r
+}\r
+/*-----------------------------------------------------------*/\r
+\r
+static void prvQueueReceiveTask( void *pvParameters )\r
+{\r
+unsigned long ulReceivedValue;\r
+const unsigned long ulExpectedValue = 100UL;\r
+const char * const pcPassMessage = "Blink\r\n";\r
+const char * const pcFailMessage = "Unexpected value received\r\n";\r
+extern void vToggleLED( void );\r
+\r
+ /* Remove compiler warning about unused parameter. */\r
+ ( void ) pvParameters;\r
+\r
+ for( ;; )\r
+ {\r
+ /* Wait until something arrives in the queue - this task will block\r
+ indefinitely provided INCLUDE_vTaskSuspend is set to 1 in\r
+ FreeRTOSConfig.h. */\r
+ xQueueReceive( xQueue, &ulReceivedValue, portMAX_DELAY );\r
+\r
+ /* To get here something must have been received from the queue, but\r
+ is it the expected value? If it is, toggle the LED. */\r
+ if( ulReceivedValue == ulExpectedValue )\r
+ {\r
+ write( STDOUT_FILENO, pcPassMessage, strlen( pcPassMessage ) );\r
+ vToggleLED();\r
+ ulReceivedValue = 0U;\r
+ }\r
+ else\r
+ {\r
+ write( STDOUT_FILENO, pcFailMessage, strlen( pcFailMessage ) );\r
+ }\r
+ }\r
+}\r
+/*-----------------------------------------------------------*/\r
+\r
PROVIDE( end = . );
PROVIDE( metal_segment_bss_target_end = . );
-
.stack :
{
- PROVIDE(metal_segment_stack_begin = .);
- . = __stack_size;
- PROVIDE( _sp = . );
+ . = ALIGN(16);
+ metal_segment_stack_begin = .;
+ . += __stack_size;
+ _sp = .;
PROVIDE(metal_segment_stack_end = .);
+ __freertos_irq_stack_top = .;
} >ram AT>ram :ram
+#if 1\r
/*\r
* FreeRTOS Kernel V10.2.1\r
* Copyright (C) 2019 Amazon.com, Inc. or its affiliates. All Rights Reserved.\r
#include <FreeRTOS.h>\r
#include <task.h>\r
\r
+/* Freedom metal driver includes. */\r
+#include <metal/cpu.h>\r
+#include <metal/led.h>\r
+#include <metal/button.h>\r
+\r
+\r
/******************************************************************************\r
* This project provides two demo applications. A simple blinky style project,\r
* and a more comprehensive test and demo application. The\r
\r
#warning Also test in QEMU and add instructions above.\r
\r
+/* Index to first HART (there is only one). */\r
+#define mainHART_0 0\r
\r
/* Set mainCREATE_SIMPLE_BLINKY_DEMO_ONLY to one to run the simple blinky demo,\r
or 0 to run the more comprehensive test and demo application. */\r
void vApplicationStackOverflowHook( TaskHandle_t pxTask, char *pcTaskName );\r
void vApplicationTickHook( void );\r
\r
-/*-----------------------------------------------------------*/\r
+/* Setup the hardware to run this demo. */\r
+static void prvSetupHardware( void );\r
\r
-void main_blinky( void )\r
-{\r
-#warning Not implemented yet.\r
- for( ;; );\r
-}\r
+/* Used by the Freedom Metal drivers. */\r
+static struct metal_led *pxLED = NULL;\r
+\r
+/*-----------------------------------------------------------*/\r
\r
int main( void )\r
{\r
+ prvSetupHardware();\r
+\r
/* The mainCREATE_SIMPLE_BLINKY_DEMO_ONLY setting is described at the top\r
of this file. */\r
#if( mainCREATE_SIMPLE_BLINKY_DEMO_ONLY == 1 )\r
}\r
/*-----------------------------------------------------------*/\r
\r
+static void prvSetupHardware( void )\r
+{\r
+struct metal_cpu *pxCPU;\r
+struct metal_interrupt *pxInterruptController;\r
+\r
+ /* Initialise the red LED. */\r
+ pxLED = metal_led_get_rgb( "LD0", "red" );\r
+ configASSERT( pxLED );\r
+ metal_led_enable( pxLED );\r
+ metal_led_off( pxLED );\r
+\r
+ /* Initialise the interrupt controller. */\r
+ pxCPU = metal_cpu_get( mainHART_0 );\r
+ configASSERT( pxCPU );\r
+ pxInterruptController = metal_cpu_interrupt_controller( pxCPU );\r
+ configASSERT( pxInterruptController );\r
+ metal_interrupt_init( pxInterruptController );\r
+}\r
+/*-----------------------------------------------------------*/\r
+\r
void vApplicationMallocFailedHook( void )\r
{\r
/* vApplicationMallocFailedHook() will only be called if\r
\r
void vAssertCalled( void )\r
{\r
-volatile uint32_t ulSetTo1ToExitFunction = 0;\r
-\r
taskDISABLE_INTERRUPTS();\r
- while( ulSetTo1ToExitFunction != 1 )\r
- {\r
- __asm volatile( "NOP" );\r
- }\r
+ for( ;; );\r
}\r
+/*-----------------------------------------------------------*/\r
+\r
+void handle_trap( void )\r
+{\r
+#warning Not implemented.\r
+\r
+ configASSERT( metal_cpu_get( mainHART_0 ) == 0x00 );\r
+}\r
+/*-----------------------------------------------------------*/\r
+\r
+void vToggleLED( void )\r
+{\r
+ metal_led_toggle( pxLED );\r
+}\r
+\r
+\r
+\r
+\r
+#else\r
+\r
+static void prvSetupTimerInterrupt( void )\r
+{\r
+ int rc, up_cnt, dn_cnt;\r
+\r
+ // Setup Timer and its interrupt so we can toggle LEDs on 1s cadence\r
+ tmr_intr = metal_cpu_timer_interrupt_controller(pxCPU);\r
+ if (tmr_intr == NULL) {\r
+ printf("TIMER interrupt controller is null.\n");\r
+ return 4;\r
+ }\r
+ metal_interrupt_init(tmr_intr);\r
+ tmr_id = metal_cpu_timer_get_interrupt_id(pxCPU);\r
+ rc = metal_interrupt_register_handler(tmr_intr, tmr_id, timer_isr, pxCPU);\r
+ if (rc < 0) {\r
+ printf("TIMER interrupt handler registration failed\n");\r
+ return (rc * -1);\r
+ }\r
+\r
+ // Lastly CPU interrupt\r
+ if (metal_interrupt_enable(pxInterruptController, 0) == -1) {\r
+ printf("CPU interrupt enable failed\n");\r
+ return 6;\r
+ }\r
+\r
+ // Red -> Green -> Blue, repeat\r
+ while (1) {\r
+\r
+ // Turn on RED\r
+ wait_for_timer(pxLED);\r
+\r
+ // Turn on Green\r
+ wait_for_timer(led0_green);\r
+\r
+ // Turn on Blue\r
+ wait_for_timer(led0_blue);\r
+ }\r
+\r
+ // return\r
+ return 0;\r
+}\r
+/*-----------------------------------------------------------*/\r
+\r
+\r
+#include <stdio.h>\r
+#include <metal/cpu.h>\r
+#include <metal/led.h>\r
+#include <metal/button.h>\r
+#include <metal/switch.h>\r
+\r
+#define RTC_FREQ 32768\r
+\r
+struct metal_cpu *pxCPU;\r
+struct metal_interrupt *pxInterruptController, *tmr_intr;\r
+int tmr_id;\r
+volatile uint32_t timer_isr_flag;\r
+\r
+\r
+void timer_isr (int id, void *data) {\r
+\r
+ // Disable Timer interrupt\r
+ metal_interrupt_disable(tmr_intr, tmr_id);\r
+\r
+ // Flag showing we hit timer isr\r
+ timer_isr_flag = 1;\r
+}\r
+\r
+void wait_for_timer(struct metal_led *which_led) {\r
+\r
+ // clear global timer isr flag\r
+ timer_isr_flag = 0;\r
+\r
+ // Turn on desired LED\r
+ metal_led_on(which_led);\r
+\r
+ // Set timer\r
+ metal_cpu_set_mtimecmp(pxCPU, metal_cpu_get_mtime(pxCPU) + RTC_FREQ);\r
+\r
+ // Enable Timer interrupt\r
+ metal_interrupt_enable(tmr_intr, tmr_id);\r
+\r
+ // wait till timer triggers and isr is hit\r
+ while (timer_isr_flag == 0){};\r
+\r
+ timer_isr_flag = 0;\r
+\r
+ // Turn off this LED\r
+ metal_led_off(which_led);\r
+}\r
+\r
+\r
+\r
+#endif\r
+\r
+\r
+++ /dev/null
-This source repository is release under Apache2 and MIT licenses.
-
-See LICENSE.Apache2 and LICENSE.MIT for details.
+++ /dev/null
-
- Apache License
- Version 2.0, January 2004
- http://www.apache.org/licenses/
-
- TERMS AND CONDITIONS FOR USE, REPRODUCTION, AND DISTRIBUTION
-
- 1. Definitions.
-
- "License" shall mean the terms and conditions for use, reproduction,
- and distribution as defined by Sections 1 through 9 of this document.
-
- "Licensor" shall mean the copyright owner or entity authorized by
- the copyright owner that is granting the License.
-
- "Legal Entity" shall mean the union of the acting entity and all
- other entities that control, are controlled by, or are under common
- control with that entity. For the purposes of this definition,
- "control" means (i) the power, direct or indirect, to cause the
- direction or management of such entity, whether by contract or
- otherwise, or (ii) ownership of fifty percent (50%) or more of the
- outstanding shares, or (iii) beneficial ownership of such entity.
-
- "You" (or "Your") shall mean an individual or Legal Entity
- exercising permissions granted by this License.
-
- "Source" form shall mean the preferred form for making modifications,
- including but not limited to software source code, documentation
- source, and configuration files.
-
- "Object" form shall mean any form resulting from mechanical
- transformation or translation of a Source form, including but
- not limited to compiled object code, generated documentation,
- and conversions to other media types.
-
- "Work" shall mean the work of authorship, whether in Source or
- Object form, made available under the License, as indicated by a
- copyright notice that is included in or attached to the work
- (an example is provided in the Appendix below).
-
- "Derivative Works" shall mean any work, whether in Source or Object
- form, that is based on (or derived from) the Work and for which the
- editorial revisions, annotations, elaborations, or other modifications
- represent, as a whole, an original work of authorship. For the purposes
- of this License, Derivative Works shall not include works that remain
- separable from, or merely link (or bind by name) to the interfaces of,
- the Work and Derivative Works thereof.
-
- "Contribution" shall mean any work of authorship, including
- the original version of the Work and any modifications or additions
- to that Work or Derivative Works thereof, that is intentionally
- submitted to Licensor for inclusion in the Work by the copyright owner
- or by an individual or Legal Entity authorized to submit on behalf of
- the copyright owner. For the purposes of this definition, "submitted"
- means any form of electronic, verbal, or written communication sent
- to the Licensor or its representatives, including but not limited to
- communication on electronic mailing lists, source code control systems,
- and issue tracking systems that are managed by, or on behalf of, the
- Licensor for the purpose of discussing and improving the Work, but
- excluding communication that is conspicuously marked or otherwise
- designated in writing by the copyright owner as "Not a Contribution."
-
- "Contributor" shall mean Licensor and any individual or Legal Entity
- on behalf of whom a Contribution has been received by Licensor and
- subsequently incorporated within the Work.
-
- 2. Grant of Copyright License. Subject to the terms and conditions of
- this License, each Contributor hereby grants to You a perpetual,
- worldwide, non-exclusive, no-charge, royalty-free, irrevocable
- copyright license to reproduce, prepare Derivative Works of,
- publicly display, publicly perform, sublicense, and distribute the
- Work and such Derivative Works in Source or Object form.
-
- 3. Grant of Patent License. Subject to the terms and conditions of
- this License, each Contributor hereby grants to You a perpetual,
- worldwide, non-exclusive, no-charge, royalty-free, irrevocable
- (except as stated in this section) patent license to make, have made,
- use, offer to sell, sell, import, and otherwise transfer the Work,
- where such license applies only to those patent claims licensable
- by such Contributor that are necessarily infringed by their
- Contribution(s) alone or by combination of their Contribution(s)
- with the Work to which such Contribution(s) was submitted. If You
- institute patent litigation against any entity (including a
- cross-claim or counterclaim in a lawsuit) alleging that the Work
- or a Contribution incorporated within the Work constitutes direct
- or contributory patent infringement, then any patent licenses
- granted to You under this License for that Work shall terminate
- as of the date such litigation is filed.
-
- 4. Redistribution. You may reproduce and distribute copies of the
- Work or Derivative Works thereof in any medium, with or without
- modifications, and in Source or Object form, provided that You
- meet the following conditions:
-
- (a) You must give any other recipients of the Work or
- Derivative Works a copy of this License; and
-
- (b) You must cause any modified files to carry prominent notices
- stating that You changed the files; and
-
- (c) You must retain, in the Source form of any Derivative Works
- that You distribute, all copyright, patent, trademark, and
- attribution notices from the Source form of the Work,
- excluding those notices that do not pertain to any part of
- the Derivative Works; and
-
- (d) If the Work includes a "NOTICE" text file as part of its
- distribution, then any Derivative Works that You distribute must
- include a readable copy of the attribution notices contained
- within such NOTICE file, excluding those notices that do not
- pertain to any part of the Derivative Works, in at least one
- of the following places: within a NOTICE text file distributed
- as part of the Derivative Works; within the Source form or
- documentation, if provided along with the Derivative Works; or,
- within a display generated by the Derivative Works, if and
- wherever such third-party notices normally appear. The contents
- of the NOTICE file are for informational purposes only and
- do not modify the License. You may add Your own attribution
- notices within Derivative Works that You distribute, alongside
- or as an addendum to the NOTICE text from the Work, provided
- that such additional attribution notices cannot be construed
- as modifying the License.
-
- You may add Your own copyright statement to Your modifications and
- may provide additional or different license terms and conditions
- for use, reproduction, or distribution of Your modifications, or
- for any such Derivative Works as a whole, provided Your use,
- reproduction, and distribution of the Work otherwise complies with
- the conditions stated in this License.
-
- 5. Submission of Contributions. Unless You explicitly state otherwise,
- any Contribution intentionally submitted for inclusion in the Work
- by You to the Licensor shall be under the terms and conditions of
- this License, without any additional terms or conditions.
- Notwithstanding the above, nothing herein shall supersede or modify
- the terms of any separate license agreement you may have executed
- with Licensor regarding such Contributions.
-
- 6. Trademarks. This License does not grant permission to use the trade
- names, trademarks, service marks, or product names of the Licensor,
- except as required for reasonable and customary use in describing the
- origin of the Work and reproducing the content of the NOTICE file.
-
- 7. Disclaimer of Warranty. Unless required by applicable law or
- agreed to in writing, Licensor provides the Work (and each
- Contributor provides its Contributions) on an "AS IS" BASIS,
- WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or
- implied, including, without limitation, any warranties or conditions
- of TITLE, NON-INFRINGEMENT, MERCHANTABILITY, or FITNESS FOR A
- PARTICULAR PURPOSE. You are solely responsible for determining the
- appropriateness of using or redistributing the Work and assume any
- risks associated with Your exercise of permissions under this License.
-
- 8. Limitation of Liability. In no event and under no legal theory,
- whether in tort (including negligence), contract, or otherwise,
- unless required by applicable law (such as deliberate and grossly
- negligent acts) or agreed to in writing, shall any Contributor be
- liable to You for damages, including any direct, indirect, special,
- incidental, or consequential damages of any character arising as a
- result of this License or out of the use or inability to use the
- Work (including but not limited to damages for loss of goodwill,
- work stoppage, computer failure or malfunction, or any and all
- other commercial damages or losses), even if such Contributor
- has been advised of the possibility of such damages.
-
- 9. Accepting Warranty or Additional Liability. While redistributing
- the Work or Derivative Works thereof, You may choose to offer,
- and charge a fee for, acceptance of support, warranty, indemnity,
- or other liability obligations and/or rights consistent with this
- License. However, in accepting such obligations, You may act only
- on Your own behalf and on Your sole responsibility, not on behalf
- of any other Contributor, and only if You agree to indemnify,
- defend, and hold each Contributor harmless for any liability
- incurred by, or claims asserted against, such Contributor by reason
- of your accepting any such warranty or additional liability.
-
- END OF TERMS AND CONDITIONS
-
- APPENDIX: How to apply the Apache License to your work.
-
- To apply the Apache License to your work, attach the following
- boilerplate notice, with the fields enclosed by brackets "[]"
- replaced with your own identifying information. (Don't include
- the brackets!) The text should be enclosed in the appropriate
- comment syntax for the file format. We also recommend that a
- file or class name and description of purpose be included on the
- same "printed page" as the copyright notice for easier
- identification within third-party archives.
-
- Copyright [yyyy] [name of copyright owner]
-
- Licensed under the Apache License, Version 2.0 (the "License");
- you may not use this file except in compliance with the License.
- You may obtain a copy of the License at
-
- http://www.apache.org/licenses/LICENSE-2.0
-
- Unless required by applicable law or agreed to in writing, software
- distributed under the License is distributed on an "AS IS" BASIS,
- WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied.
- See the License for the specific language governing permissions and
- limitations under the License.
+++ /dev/null
-The MIT License
-
-Copyright (c) 2019 SiFive, Inc.
-
-Permission is hereby granted, free of charge, to any person obtaining a
-copy of this software and associated documentation files (the "Software"),
-to deal in the Software without restriction, including without limitation
-the rights to use, copy, modify, merge, publish, distribute, sublicense,
-and/or sell copies of the Software, and to permit persons to whom the
-Software is furnished to do so, subject to the following conditions:
-
-The above copyright notice and this permission notice shall be included in
-all copies or substantial portions of the Software.
-
-THE SOFTWARE IS PROVIDED "AS IS", WITHOUT WARRANTY OF ANY KIND, EXPRESS OR
-IMPLIED, INCLUDING BUT NOT LIMITED TO THE WARRANTIES OF MERCHANTABILITY,
-FITNESS FOR A PARTICULAR PURPOSE AND NONINFRINGEMENT. IN NO EVENT SHALL THE
-AUTHORS OR COPYRIGHT HOLDERS BE LIABLE FOR ANY CLAIM, DAMAGES OR OTHER
-LIABILITY, WHETHER IN AN ACTION OF CONTRACT, TORT OR OTHERWISE, ARISING
-FROM, OUT OF OR IN CONNECTION WITH THE SOFTWARE OR THE USE OR OTHER
-DEALINGS IN THE SOFTWARE.
+++ /dev/null
-# sifive-welcome
-A simple welcome example which prints SiFive banner and uses board LEDs
+++ /dev/null
-/* Copyright 2019 SiFive, Inc */
-/* SPDX-License-Identifier: Apache-2.0 */
-
-#include <stdio.h>
-#include <metal/cpu.h>
-#include <metal/led.h>
-#include <metal/button.h>
-#include <metal/switch.h>
-
-#define RTC_FREQ 32768
-
-struct metal_cpu *cpu0;
-struct metal_interrupt *cpu_intr, *tmr_intr;
-int tmr_id;
-volatile uint32_t timer_isr_flag;
-
-void display_banner (void) {
-
- printf("\n");
- printf("\n");
- printf(" SIFIVE, INC.\n");
- printf("\n");
- printf(" 5555555555555555555555555\n");
- printf(" 5555 5555\n");
- printf(" 5555 5555\n");
- printf(" 5555 5555\n");
- printf(" 5555 5555555555555555555555\n");
- printf(" 5555 555555555555555555555555\n");
- printf(" 5555 5555\n");
- printf(" 5555 5555\n");
- printf(" 5555 5555\n");
- printf(" 5555555555555555555555555555 55555\n");
- printf(" 55555 555555555 55555\n");
- printf(" 55555 55555 55555\n");
- printf(" 55555 5 55555\n");
- printf(" 55555 55555\n");
- printf(" 55555 55555\n");
- printf(" 55555 55555\n");
- printf(" 55555 55555\n");
- printf(" 55555 55555\n");
- printf(" 555555555\n");
- printf(" 55555\n");
- printf(" 5\n");
- printf("\n");
-
- printf("\n");
- printf(" Welcome to SiFive!\n");
-
-}
-
-void timer_isr (int id, void *data) {
-
- // Disable Timer interrupt
- metal_interrupt_disable(tmr_intr, tmr_id);
-
- // Flag showing we hit timer isr
- timer_isr_flag = 1;
-}
-
-void wait_for_timer(struct metal_led *which_led) {
-
- // clear global timer isr flag
- timer_isr_flag = 0;
-
- // Turn on desired LED
- metal_led_on(which_led);
-
- // Set timer
- metal_cpu_set_mtimecmp(cpu0, metal_cpu_get_mtime(cpu0) + RTC_FREQ);
-
- // Enable Timer interrupt
- metal_interrupt_enable(tmr_intr, tmr_id);
-
- // wait till timer triggers and isr is hit
- while (timer_isr_flag == 0){};
-
- timer_isr_flag = 0;
-
- // Turn off this LED
- metal_led_off(which_led);
-}
-
-int original_main (void)
-{
- int rc, up_cnt, dn_cnt;
- struct metal_led *led0_red, *led0_green, *led0_blue;
-
- // This demo will toggle LEDs colors so we define them here
- led0_red = metal_led_get_rgb("LD0", "red");
- led0_green = metal_led_get_rgb("LD0", "green");
- led0_blue = metal_led_get_rgb("LD0", "blue");
- if ((led0_red == NULL) || (led0_green == NULL) || (led0_blue == NULL)) {
- printf("At least one of LEDs is null.\n");
- return 1;
- }
-
- // Enable each LED
- metal_led_enable(led0_red);
- metal_led_enable(led0_green);
- metal_led_enable(led0_blue);
-
- // All Off
- metal_led_off(led0_red);
- metal_led_off(led0_green);
- metal_led_off(led0_blue);
-
- // Lets get the CPU and and its interrupt
- cpu0 = metal_cpu_get(0);
- if (cpu0 == NULL) {
- printf("CPU null.\n");
- return 2;
- }
- cpu_intr = metal_cpu_interrupt_controller(cpu0);
- if (cpu_intr == NULL) {
- printf("CPU interrupt controller is null.\n");
- return 3;
- }
- metal_interrupt_init(cpu_intr);
-
- // display welcome banner
- display_banner();
-
- // Setup Timer and its interrupt so we can toggle LEDs on 1s cadence
- tmr_intr = metal_cpu_timer_interrupt_controller(cpu0);
- if (tmr_intr == NULL) {
- printf("TIMER interrupt controller is null.\n");
- return 4;
- }
- metal_interrupt_init(tmr_intr);
- tmr_id = metal_cpu_timer_get_interrupt_id(cpu0);
- rc = metal_interrupt_register_handler(tmr_intr, tmr_id, timer_isr, cpu0);
- if (rc < 0) {
- printf("TIMER interrupt handler registration failed\n");
- return (rc * -1);
- }
-
- // Lastly CPU interrupt
- if (metal_interrupt_enable(cpu_intr, 0) == -1) {
- printf("CPU interrupt enable failed\n");
- return 6;
- }
-
- // Red -> Green -> Blue, repeat
- while (1) {
-
- // Turn on RED
- wait_for_timer(led0_red);
-
- // Turn on Green
- wait_for_timer(led0_green);
-
- // Turn on Blue
- wait_for_timer(led0_blue);
- }
-
- // return
- return 0;
-}