Advertisement
Not a member of Pastebin yet?
Sign Up,
it unlocks many cool features!
- /*
- * main.c
- *
- * Created: 26.01.2015 12:07:55
- * Author: Wolfgang Neff
- */
- #include <avr/io.h>
- #include "FreeRTOS.h"
- #include "task.h"
- #include "board.h"
- #include <queue.h>
- #include <stdlib.h>
- #define CAPACITY 8
- QueueHandle_t xQueue;
- void vSensor(void* pvParameters)
- {
- int iCompareValue;
- while (1)
- {
- ADCB.CH0.CTRL |= ADC_CH_START_bm;
- while(!(ADCB.CH0.INTFLAGS & ADC_CH_CHIF_bm));
- iCompareValue = ADCB.CH0.RES;
- //iCompareValue = (rand() % 10) * 1000 + 1;
- xQueueSend(xQueue, &iCompareValue, portMAX_DELAY);
- }
- }
- void vLED(void* pvParameters)
- {
- int iCompareValue;
- while(1)
- {
- xQueueReceive(xQueue, &iCompareValue, portMAX_DELAY);
- TCE0.CCA = iCompareValue;
- LED_PORT.OUT =~ LED0_PIN_bm;
- }
- }
- int main(void)
- {
- // Setup the microcontroller hardware
- LED_PORT.DIR = LED0_PIN_bm;
- LED_PORT.OUT = LED0_PIN_bm;
- PORTE.DIRSET = PIN0_bm;
- TCE0.CTRLA = TC_CLKSEL_DIV2_gc;
- TCE0.CTRLB = TC0_CCAEN_bm | TC_WGMODE_SS_gc;
- TCE0.PER = 10000;
- PORTB.DIRCLR = PIN1_bm;
- ADCB.CTRLA = ADC_ENABLE_bm;
- ADCB.CTRLB = ADC_RESOLUTION_12BIT_gc;
- ADCB.REFCTRL = ADC_REFSEL_INT1V_gc | ADC_BANDGAP_bm;
- ADCB.PRESCALER = ADC_PRESCALER_DIV8_gc;
- ADCB.CH0.CTRL = ADC_CH_INPUTMODE_SINGLEENDED_gc;
- ADCB.CH0.MUXCTRL = ADC_CH_MUXPOS_PIN1_gc;
- //Create Queue
- xQueue= xQueueCreate(CAPACITY, sizeof(int));
- // Create tasks
- xTaskCreate(vSensor, "SensorTask", configMINIMAL_STACK_SIZE, NULL, tskIDLE_PRIORITY+1, NULL);
- xTaskCreate(vLED, "LEDTask", configMINIMAL_STACK_SIZE, NULL, tskIDLE_PRIORITY+1, NULL);
- // Start the RTOS scheduler
- vTaskStartScheduler();
- }
Advertisement
Add Comment
Please, Sign In to add comment
Advertisement