Advertisement
Guest User

asdfghjklöä_Brrrz

a guest
May 26th, 2015
196
0
Never
Not a member of Pastebin yet? Sign Up, it unlocks many cool features!
C++ 1.60 KB | None | 0 0
  1. /*
  2.  * main.c
  3.  *
  4.  * Created: 26.01.2015 12:07:55
  5.  *  Author: Wolfgang Neff
  6.  */
  7.  
  8.  
  9. #include <avr/io.h>
  10. #include "FreeRTOS.h"
  11. #include "task.h"
  12. #include "board.h"
  13. #include <queue.h>
  14. #include <stdlib.h>
  15.  
  16. #define CAPACITY 8
  17.  
  18. QueueHandle_t xQueue;
  19.  
  20. void vSensor(void* pvParameters)
  21. {
  22.     int iCompareValue;
  23.     while (1)
  24.     {
  25.         ADCB.CH0.CTRL |= ADC_CH_START_bm;
  26.         while(!(ADCB.CH0.INTFLAGS & ADC_CH_CHIF_bm));
  27.         iCompareValue = ADCB.CH0.RES;
  28.         //iCompareValue = (rand() % 10) * 1000 + 1;    
  29.         xQueueSend(xQueue, &iCompareValue, portMAX_DELAY);
  30.     }
  31. }
  32.  
  33. void vLED(void* pvParameters)
  34. {
  35.     int iCompareValue;
  36.     while(1)
  37.     {
  38.         xQueueReceive(xQueue, &iCompareValue, portMAX_DELAY);
  39.         TCE0.CCA = iCompareValue;
  40.         LED_PORT.OUT =~ LED0_PIN_bm;
  41.     }
  42. }
  43.  
  44. int main(void)
  45. {
  46.     // Setup the microcontroller hardware
  47.     LED_PORT.DIR = LED0_PIN_bm;
  48.     LED_PORT.OUT = LED0_PIN_bm;
  49.     PORTE.DIRSET = PIN0_bm;
  50.     TCE0.CTRLA = TC_CLKSEL_DIV2_gc;
  51.     TCE0.CTRLB = TC0_CCAEN_bm | TC_WGMODE_SS_gc;
  52.     TCE0.PER = 10000;
  53.    
  54.     PORTB.DIRCLR = PIN1_bm;
  55.     ADCB.CTRLA = ADC_ENABLE_bm;
  56.     ADCB.CTRLB = ADC_RESOLUTION_12BIT_gc;
  57.     ADCB.REFCTRL = ADC_REFSEL_INT1V_gc | ADC_BANDGAP_bm;
  58.     ADCB.PRESCALER = ADC_PRESCALER_DIV8_gc;
  59.     ADCB.CH0.CTRL = ADC_CH_INPUTMODE_SINGLEENDED_gc;
  60.     ADCB.CH0.MUXCTRL = ADC_CH_MUXPOS_PIN1_gc;
  61.    
  62.     //Create Queue
  63.     xQueue= xQueueCreate(CAPACITY, sizeof(int));
  64.        
  65.     // Create tasks
  66.     xTaskCreate(vSensor, "SensorTask", configMINIMAL_STACK_SIZE, NULL, tskIDLE_PRIORITY+1, NULL);
  67.     xTaskCreate(vLED, "LEDTask", configMINIMAL_STACK_SIZE, NULL, tskIDLE_PRIORITY+1, NULL);
  68.  
  69.     // Start the RTOS scheduler
  70.     vTaskStartScheduler();
  71. }
Advertisement
Add Comment
Please, Sign In to add comment
Advertisement