Revision 336
Updated wireless to use a circular buffer instead of a queue using malloc. Tested on both the computer and robots with a token ring, and was successful.
buzzer.c | ||
---|---|---|
1 | 1 |
/** |
2 | 2 |
* Copyright (c) 2007 Colony Project |
3 |
* |
|
3 |
*
|
|
4 | 4 |
* Permission is hereby granted, free of charge, to any person |
5 | 5 |
* obtaining a copy of this software and associated documentation |
6 | 6 |
* files (the "Software"), to deal in the Software without |
... | ... | |
9 | 9 |
* copies of the Software, and to permit persons to whom the |
10 | 10 |
* Software is furnished to do so, subject to the following |
11 | 11 |
* conditions: |
12 |
* |
|
12 |
*
|
|
13 | 13 |
* The above copyright notice and this permission notice shall be |
14 | 14 |
* included in all copies or substantial portions of the Software. |
15 |
* |
|
15 |
*
|
|
16 | 16 |
* THE SOFTWARE IS PROVIDED "AS IS", WITHOUT WARRANTY OF ANY KIND, |
17 | 17 |
* EXPRESS OR IMPLIED, INCLUDING BUT NOT LIMITED TO THE WARRANTIES |
18 | 18 |
* OF MERCHANTABILITY, FITNESS FOR A PARTICULAR PURPOSE AND |
... | ... | |
53 | 53 |
**/ |
54 | 54 |
void buzzer_init( void ) |
55 | 55 |
{ |
56 |
//NOTE: This is mostly handled by buzzer_Set_val for now
|
|
57 |
// Set pin B7 to output - B7 is buzzer pin
|
|
58 |
//DDRB |= _BV(DDB7);
|
|
59 |
//Fast PWM Mode, Clear OCR0 on compare match and set at bottom, clock/64
|
|
60 |
//TCCR2 = _BV(COM20) | _BV(WGM21) | _BV(CS22);
|
|
56 |
//NOTE: This is mostly handled by buzzer_Set_val for now
|
|
57 |
// Set pin B7 to output - B7 is buzzer pin
|
|
58 |
//DDRB |= _BV(DDB7);
|
|
59 |
//Fast PWM Mode, Clear OCR0 on compare match and set at bottom, clock/64
|
|
60 |
//TCCR2 = _BV(COM20) | _BV(WGM21) | _BV(CS22);
|
|
61 | 61 |
} |
62 | 62 |
|
63 | 63 |
/** |
... | ... | |
70 | 70 |
* @see buzzer_init, buzzer_set_freq, buzzer_off |
71 | 71 |
**/ |
72 | 72 |
void buzzer_set_val(unsigned int buzz_value) |
73 |
{ |
|
74 |
TCCR2 = _BV(COM20) | _BV(WGM21) | _BV(CS22);
|
|
75 |
DDRB |= _BV(DDB7);
|
|
76 |
OCR2 = buzz_value;
|
|
73 |
{
|
|
74 |
TCCR2 = _BV(COM20) | _BV(WGM21) | _BV(CS22);
|
|
75 |
DDRB |= _BV(DDB7);
|
|
76 |
OCR2 = buzz_value;
|
|
77 | 77 |
} |
78 | 78 |
|
79 | 79 |
/** |
... | ... | |
89 | 89 |
void buzzer_set_freq(unsigned int buzz_freq) |
90 | 90 |
{ |
91 | 91 |
int buzz_value; |
92 |
|
|
92 |
|
|
93 | 93 |
buzz_value = 62500/buzz_freq - 1; |
94 | 94 |
|
95 |
if (buzz_value > 255) {
|
|
95 |
if(buzz_value > 255){
|
|
96 | 96 |
buzz_value = 255; |
97 |
} else if (buzz_value < 0) {
|
|
97 |
}else if(buzz_value < 0){
|
|
98 | 98 |
buzz_value = 0; |
99 | 99 |
} |
100 |
|
|
100 |
|
|
101 | 101 |
buzzer_set_val(buzz_value); |
102 | 102 |
} |
103 | 103 |
|
... | ... | |
112 | 112 |
* |
113 | 113 |
* @see buzzer_init, buzzer_set_freq |
114 | 114 |
**/ |
115 |
void buzzer_chirp(unsigned int ms, unsigned int buzz_freq) |
|
116 |
{ |
|
115 |
void buzzer_chirp(unsigned int ms, unsigned int buzz_freq)
|
|
116 |
{
|
|
117 | 117 |
buzzer_set_freq(buzz_freq); |
118 | 118 |
delay_ms(ms); |
119 | 119 |
buzzer_off(); |
... | ... | |
128 | 128 |
{ |
129 | 129 |
// Disable clock, to halt counter |
130 | 130 |
TCCR2 &= 0xF8;//0b11111000; |
131 |
|
|
131 |
|
|
132 | 132 |
// Set buzzer pin low in case it's high |
133 | 133 |
PORTB &= 0xBF;//0b10111111; |
134 | 134 |
} |
135 | 135 |
|
136 | 136 |
/** @} **/ // end buzzer group |
137 |
|
Also available in: Unified diff