-
Notifications
You must be signed in to change notification settings - Fork 1
Expand file tree
/
Copy pathadc_dive.c
More file actions
51 lines (45 loc) · 1.17 KB
/
adc_dive.c
File metadata and controls
51 lines (45 loc) · 1.17 KB
1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
22
23
24
25
26
27
28
29
30
31
32
33
34
35
36
37
38
39
40
41
42
43
44
45
46
47
48
49
50
51
/*
* adc_dive.c
*
* Created on: Aug 17, 2017
* Author: a0227225
*/
#include <stdint.h>
#include <stddef.h>
#include <stdio.h>
// RTOS header files
#include <ti/sysbios/BIOS.h>
#include <ti/sysbios/knl/Task.h>
#include <ti/sysbios/knl/Mailbox.h>
#include <ti/sysbios/knl/Event.h>
#include <xdc/runtime/Error.h>
#include <ti/drivers/ADC.h>
/* Example/Board Header files */
#include "main.h"
#include "Board.h"
#include "bsp.h"
#include "bsp_led.h"
#include "common.h"
#include "adc_dive.h"
Mailbox_Handle g_adc_mbox;
extern Event_Handle g_event_handle;
void adc_task (unsigned int task_arg0, unsigned int task_arg1){
int_fast16_t res;
uint16_t adcValue;
ADC_Handle adc;
ADC_Params params;
ADC_Params_init(¶ms);
adc = ADC_open(Board_ADC_JOYSTICK_Y, ¶ms);
if (adc == NULL) {
ADC_close(adc);
}
for(;;){
res = ADC_convert(adc, &adcValue);
if (res == ADC_STATUS_SUCCESS) {
adcValue = adcValue >> 2;
Mailbox_post(g_adc_mbox, &adcValue, BIOS_WAIT_FOREVER);
Event_post(g_event_handle, 0x08);
}
Task_sleep(125);
}
}