-
Notifications
You must be signed in to change notification settings - Fork 1
Expand file tree
/
Copy pathalarm.c
More file actions
97 lines (89 loc) · 2.73 KB
/
alarm.c
File metadata and controls
97 lines (89 loc) · 2.73 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
/** \file alarm.c
*
* @brief Alarm Manager and buzzer/speaker output
*/
#include <stdint.h>
#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/PWM.h>
#include "main.h"
#include "Board.h"
#include "bsp.h"
#include "alarm.h"
#include "common.h"
// Speaker Task Items
extern PWM_Handle g_pwm_buzzer;
/*!
*
* @brief Configure a timer to drive the speaker via PWM.
*/
void speaker_config (void)
{
PWM_Params params;
/* Call driver init functions. */
PWM_init();
PWM_Params_init(¶ms);
params.dutyUnits = PWM_DUTY_US;
params.dutyValue = 0;
params.periodUnits = PWM_PERIOD_US; // Specified in microseconds
params.periodValue = 1000; // 1000 Hz is our period which happens to be 1000 usec
g_pwm_buzzer = PWM_open(Board_PWMBuzzer, ¶ms);
/* Board_PWM0 did not open */
SYS_ASSERT(g_pwm_buzzer != NULL);
PWM_start(g_pwm_buzzer);
}
/**
* SYS/BIOS task. Handles writing to the speaker.
*
* @param[in] task_arg0 unused, argument from SYS/BIOS task create
* @param[in] task_arg1 unused, argument from SYS/BIOS task create
*/
/*lint -e{715} symbol not referenced */
void speaker_task(uint32_t arg0, uint32_t arg1)
{
wave_t const * p_waveform = (wave_t const *) arg0;
SYS_ASSERT(p_waveform != NULL);
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);
}
}
}