+#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