-
Notifications
You must be signed in to change notification settings - Fork 1
Expand file tree
/
Copy pathalarmtask.c
More file actions
128 lines (114 loc) · 3.95 KB
/
alarmtask.c
File metadata and controls
128 lines (114 loc) · 3.95 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
52
53
54
55
56
57
58
59
60
61
62
63
64
65
66
67
68
69
70
71
72
73
74
75
76
77
78
79
80
81
82
83
84
85
86
87
88
89
90
91
92
93
94
95
96
97
98
99
100
101
102
103
104
105
106
107
108
109
110
111
112
113
114
115
116
117
118
119
120
121
122
123
124
125
126
127
128
//Startup task.
#include <alarmtask.h>
#include <stdint.h>
#include <ti/sysbios/BIOS.h>
#include <ti/sysbios/knl/Task.h>
#include <ti/sysbios/knl/Event.h>
#include <xdc/runtime/Error.h>
#include <ti/drivers/PWM.h>
#include "bsp_led.h"
#include "alarm.h"
//#include "startuptask.h"
/***** Defines *****/
#define ALARM_TASK_STACK_SIZE 1024
#define ALARM_TASK_PRIORITY 2 //todo assign priority
/***** Variable declarations *****/
static Task_Params alarmTaskParams;
Task_Struct alarmTask; /* not static so you can see in ROV */
static uint8_t alarmTaskStack[ALARM_TASK_STACK_SIZE];
uint32_t alarm_event;
Event_Handle g_alarm_event_handle;
PWM_Handle g_pwm_buzzer;
const wave_t *p_waveform;
static const wave_t alarm_low = { TONE_LO, TONE_MED, 2, 0};
static const wave_t alarm_medium = { TONE_MED, TONE_HI, 1, 0};
static const wave_t alarm_high = { TONE_LO, TONE_HI, 1, 1};
/***** Function definitions *****/
void alarmTask_init( void )
{
Task_Params_init(&alarmTaskParams);
alarmTaskParams.stackSize = ALARM_TASK_STACK_SIZE;
alarmTaskParams.priority = ALARM_TASK_PRIORITY;
alarmTaskParams.stack = &alarmTaskStack;
Task_construct(&alarmTask, alarmTaskFunction, &alarmTaskParams, NULL);
}
void alarmTaskFunction(UArg arg0, UArg arg1)
{
// Configure the speaker hardware.
speaker_config();
// Highest Priority: Insufficient air to safely ascend from current depth.
// ii. Medium Priority: The current ascent rate is dangerous (> 15 m/min).
// iii. Lowest Priority: The current depth exceeds the safe maximum (40 m).
for(;;)
{
alarm_event = Event_pend(g_alarm_event_handle, 0, 0xFF, BIOS_WAIT_FOREVER);
switch (alarm_event)
{
case ALARM_H:
{
// Select the correct waveform.
p_waveform = &alarm_high;
}
break;
case ALARM_M:
{
// Select the correct waveform.
p_waveform = &alarm_medium;
}
break;
case ALARM_L:
{
// Select the correct waveform.
p_waveform = &alarm_low;
}
break;
case ALARM_0:
{
PWM_setDuty(g_pwm_buzzer, 0);
}
break;
default:
break;
}
if (p_waveform->b_chopped)
{
// Create a chopped sound.
for (;;)
{
// Play Tone 1.
PWM_setDuty(g_pwm_buzzer, (uint32_t)p_waveform->tone1);
Task_sleep(125);
PWM_setDuty(g_pwm_buzzer, 0);
Task_sleep(125);
PWM_setDuty(g_pwm_buzzer, (uint32_t)p_waveform->tone1);
Task_sleep(125);
PWM_setDuty(g_pwm_buzzer, 0);
Task_sleep(125);
// Play Tone 2.
PWM_setDuty(g_pwm_buzzer, (uint32_t)p_waveform->tone2);
Task_sleep(125);
PWM_setDuty(g_pwm_buzzer, 0);
Task_sleep(125);
PWM_setDuty(g_pwm_buzzer, (uint32_t)p_waveform->tone2);
Task_sleep(125);
PWM_setDuty(g_pwm_buzzer, 0);
Task_sleep(125);
}
}
else
{
// No chopping.
for (;;)
{
// Play Tone 1.
PWM_setDuty(g_pwm_buzzer, (uint32_t)p_waveform->tone1);
Task_sleep(p_waveform->interval);
PWM_setDuty(g_pwm_buzzer, 0);
// Play Tone 2.
PWM_setDuty(g_pwm_buzzer, (uint32_t)p_waveform->tone2);
Task_sleep(p_waveform->interval);
PWM_setDuty(g_pwm_buzzer, 0);
}
}
}
}