Advertisement
Not a member of Pastebin yet?
Sign Up,
it unlocks many cool features!
- /**
- * @file
- * @brief Main program logic
- *
- * S1 Button: push to change states
- * - State 1: Reads POT value, writes to LEDs and send the value to UART \n
- * Push S2 button to invert LEDs
- * - State 2: Read TOUCH value then change the LED states if touched. \n
- * Send the readed values via UART
- * - State 3: Read character from UART then put the value to LEDs \n
- * Send the readed character ASCII code back to UART
- * @test
- * MPLABX 3.40 XC16 v1.26, XC8 v1.38
- * X2C Development board REV.C
- * dsPIC33EP256MC502 and PIC16F18855
- *
- * @author Mark Wendler
- * @author Jozsef KOPJAK
- * @see info@microstickplus.com
- * @see http://www.microstickplus.com
- *
- * @date 20-09-2016
- */
- #include <xc.h>
- #include <stdint.h>
- #include "HardwareProfile.h"
- #include "Drivers/functions.h"
- /* FreeRTOS.org includes. */
- #include "FreeRTOS.h"
- #include "task.h"
- #include "semphr.h"
- /**
- * @brief Initialise the hardware
- * - Init LED
- * - Init Buttons
- * - Init AD
- * - Init UART
- **/
- void vInitApp(void);
- /**
- * @brief Task invert LED1 (1 Hz)
- **/
- void vTask1( void *pvParameters );
- void vTask2( void *pvParameters );
- void vTask3( void *pvParameters );
- void vTask4( void *pvParameters );
- /**
- * @brief Main program logic
- * 1. Configure the hardware
- * 2. Start tasks
- * */
- xSemaphoreHandle xBinarySemaphore1;
- xSemaphoreHandle xBinarySemaphore2;
- xSemaphoreHandle xBinarySemaphore3;
- xSemaphoreHandle xBinarySemaphore4;
- int main(void) {
- vSemaphoreCreateBinary(xBinarySemaphore1);
- vSemaphoreCreateBinary(xBinarySemaphore2);
- vSemaphoreCreateBinary(xBinarySemaphore3);
- vSemaphoreCreateBinary(xBinarySemaphore4);
- xSemaphoreTake( xBinarySemaphore1, 10 );
- xSemaphoreTake( xBinarySemaphore2, 10 );
- xSemaphoreTake( xBinarySemaphore3, 10 );
- xSemaphoreTake( xBinarySemaphore4, 10 ) ;
- vInitApp(); /* Hardware initialization */
- xTaskCreate( vTask1, "Task1", 256, NULL, 1, NULL );
- xTaskCreate( vTask2, "Task2", 256, NULL, 1, NULL );
- xTaskCreate( vTask3, "Task3", 256, NULL, 1, NULL );
- xTaskCreate( vTask4, "Task4", 256, NULL, 1, NULL );
- xSemaphoreGive( xBinarySemaphore1 );
- vTaskStartScheduler();
- for( ;; );
- }
- // Task Function
- void vTask1 ( void *pvParameters) {
- for(;;)
- {
- if( xBinarySemaphore1 != NULL )
- {
- if( xSemaphoreTake( xBinarySemaphore1, 10 ) == pdTRUE )
- {
- mTurnOnLED(0);
- vTaskDelay( 250 / portTICK_PERIOD_MS );
- mTurnOffLED(0);
- xSemaphoreGive( xBinarySemaphore2 );
- }
- }
- }
- }
- void vTask2 ( void *pvParameters) {
- for(;;)
- {
- if( xBinarySemaphore2 != NULL )
- {
- if( xSemaphoreTake( xBinarySemaphore2, 10 ) == pdTRUE )
- {
- mTurnOnLED(1);
- vTaskDelay( 250 / portTICK_PERIOD_MS );
- mTurnOffLED(1);
- xSemaphoreGive( xBinarySemaphore3 );
- }
- }
- }
- }
- void vTask3 ( void *pvParameters) {
- for(;;)
- {
- if( xBinarySemaphore3 != NULL )
- {
- if( xSemaphoreTake( xBinarySemaphore3, 10 ) == pdTRUE )
- {
- mTurnOnLED(2);
- vTaskDelay( 250 / portTICK_PERIOD_MS );
- mTurnOffLED(2);
- xSemaphoreGive( xBinarySemaphore4 );
- }
- }
- }
- }
- void vTask4 ( void *pvParameters) {
- for(;;)
- {
- if( xBinarySemaphore4 != NULL )
- {
- if( xSemaphoreTake( xBinarySemaphore4, 10 ) == pdTRUE )
- {
- mTurnOnLED(3);
- vTaskDelay(250 / portTICK_PERIOD_MS );
- mTurnOffLED(3);
- xSemaphoreGive( xBinarySemaphore1 );
- }
- }
- }
- }
- /**
- * @brief Initialise the hardware
- * - Init LED
- * - Init Buttons
- * - Init AD
- * - Init UART
- **/
- void vInitApp(void) {
- mInitLEDs(); /* Initialisation of LEDs */
- mInitButtons(); /* Initialisation of Button */
- mTurnOffAnalogMode(); /* Turn off analog mode */
- vInitAD(); /* Initialisation of AD module */
- vInitUART(); /* Initialisation of UART1 module */
- }
- void __attribute__ ((__interrupt__, __auto_psv__)) _StackError(void)
- {
- while(1){
- Nop();
- }
- }
Advertisement
Add Comment
Please, Sign In to add comment
Advertisement