]> git.sur5r.net Git - freertos/blobdiff - Demo/MicroBlaze_Spartan-6_EthernetLite/SDKProjects/RTOSDemoSource/main-blinky.c
Add LED output to the new MicroBlaze blinky demo - still a work in progress.
[freertos] / Demo / MicroBlaze_Spartan-6_EthernetLite / SDKProjects / RTOSDemoSource / main-blinky.c
index 18fcc1019b8f2acc6a60cb8b77f2a8b0e73a5da0..f3f95a1c0bebe4e844f9614ac55826d6ccf10c95 100644 (file)
 #include "xtmrctr.h"\r
 #include "xil_exception.h"\r
 #include "microblaze_exceptions_g.h"\r
+#include "xgpio.h"\r
 \r
 /* Priorities at which the tasks are created. */\r
 #define mainQUEUE_RECEIVE_TASK_PRIORITY                ( tskIDLE_PRIORITY + 2 )\r
@@ -165,14 +166,16 @@ function. */
 static xTimerHandle xLEDTimer = NULL;\r
 \r
 /* Maintains the current LED output state. */\r
-static volatile unsigned long ulGPIOState = 0UL;\r
+static volatile unsigned char ucGPIOState = 0U;\r
 \r
 /*-----------------------------------------------------------*/\r
 \r
 static XTmrCtr xTimer0Instance;\r
+static XGpio xOutputGPIOInstance;\r
+static const unsigned portBASE_TYPE uxGPIOOutputChannel = 1UL;\r
 \r
 /*-----------------------------------------------------------*/\r
-#define JUST_TESTING\r
+#define NOT_JUST_TESTING\r
 #ifdef JUST_TESTING\r
 volatile unsigned long ul1 = 0, ul2 = 0;\r
 \r
@@ -198,6 +201,12 @@ void main( void )
 {\r
        prvSetupHardware();\r
 \r
+       XGpio_DiscreteWrite( &xOutputGPIOInstance, uxGPIOOutputChannel, 1 << 0 );\r
+       XGpio_DiscreteWrite( &xOutputGPIOInstance, uxGPIOOutputChannel, 1 << 1 );\r
+       XGpio_DiscreteWrite( &xOutputGPIOInstance, uxGPIOOutputChannel, 1 << 2 );\r
+       XGpio_DiscreteWrite( &xOutputGPIOInstance, uxGPIOOutputChannel, 1 << 3 );\r
+\r
+\r
        xTaskCreate( vTemp1, ( signed char * ) "Test1", configMINIMAL_STACK_SIZE, NULL, tskIDLE_PRIORITY + 1, NULL );\r
        xTaskCreate( vTemp2, ( signed char * ) "Test2", configMINIMAL_STACK_SIZE, NULL, tskIDLE_PRIORITY + 1, NULL );\r
 \r
@@ -253,8 +262,8 @@ static void vLEDTimerCallback( xTimerHandle xTimer )
        a critical section because it is accessed from multiple tasks, and the\r
        button interrupt - in this trivial case, for simplicity, the critical\r
        section is omitted. */\r
-       ulGPIOState |= mainTIMER_CONTROLLED_LED;\r
-//_RB_ MSS_GPIO_set_outputs( ulGPIOState );\r
+       ucGPIOState |= mainTIMER_CONTROLLED_LED;\r
+       XGpio_DiscreteWrite( &xOutputGPIOInstance, uxGPIOOutputChannel, ucGPIOState );\r
 }\r
 /*-----------------------------------------------------------*/\r
 \r
@@ -266,8 +275,8 @@ portBASE_TYPE xHigherPriorityTaskWoken = pdFALSE;
        /* The button was pushed, so ensure the LED is on before resetting the\r
        LED timer.  The LED timer will turn the LED off if the button is not\r
        pushed within 5000ms. */\r
-       ulGPIOState &= ~mainTIMER_CONTROLLED_LED;\r
-//_RB_ MSS_GPIO_set_outputs( ulGPIOState );\r
+       ucGPIOState &= ~mainTIMER_CONTROLLED_LED;\r
+       XGpio_DiscreteWrite( &xOutputGPIOInstance, uxGPIOOutputChannel, ucGPIOState );\r
 \r
        /* This interrupt safe FreeRTOS function can be called from this interrupt\r
        because the interrupt priority is below the\r
@@ -330,15 +339,16 @@ unsigned long ulReceivedValue;
                        because it is accessed from multiple tasks, and the button interrupt\r
                        - in this trivial case, for simplicity, the critical section is\r
                        omitted. */\r
-                       if( ( ulGPIOState & mainTASK_CONTROLLED_LED ) != 0 )\r
+                       if( ( ucGPIOState & mainTASK_CONTROLLED_LED ) != 0 )\r
                        {\r
-                               ulGPIOState &= ~mainTASK_CONTROLLED_LED;\r
+                               ucGPIOState &= ~mainTASK_CONTROLLED_LED;\r
                        }\r
                        else\r
                        {\r
-                               ulGPIOState |= mainTASK_CONTROLLED_LED;\r
+                               ucGPIOState |= mainTASK_CONTROLLED_LED;\r
                        }\r
-//_RB_                 MSS_GPIO_set_outputs( ulGPIOState );\r
+\r
+                       XGpio_DiscreteWrite( &xOutputGPIOInstance, uxGPIOOutputChannel, ucGPIOState );\r
                }\r
        }\r
 }\r
@@ -346,6 +356,23 @@ unsigned long ulReceivedValue;
 \r
 static void prvSetupHardware( void )\r
 {\r
+portBASE_TYPE xStatus;\r
+const unsigned char ucSetToOutput = 0U;\r
+\r
+       /* Initialize the GPIO. */\r
+       xStatus = XGpio_Initialize( &xOutputGPIOInstance, XPAR_LEDS_4BITS_DEVICE_ID );\r
+       if( xStatus == XST_SUCCESS )\r
+       {\r
+               /* All LEDs on this channel are going to be outputs. */\r
+               XGpio_SetDataDirection( &xOutputGPIOInstance, uxGPIOOutputChannel, ucSetToOutput );\r
+\r
+               /* Start with all LEDs off. */\r
+               ucGPIOState = 0U;\r
+               XGpio_DiscreteWrite( &xOutputGPIOInstance, uxGPIOOutputChannel, ucGPIOState );\r
+       }\r
+\r
+       configASSERT( ( xStatus == XST_SUCCESS ) );\r
+\r
        #ifdef MICROBLAZE_EXCEPTIONS_ENABLED\r
                microblaze_enable_exceptions();\r
        #endif\r
@@ -449,7 +476,7 @@ extern void vTickISR( void *pvUnused );
 \r
        configASSERT( ( xStatus == pdPASS ) );\r
 }\r
-\r
+/*-----------------------------------------------------------*/\r
 \r
 void vApplicationClearTimerInterrupt( void )\r
 {\r