File tree Expand file tree Collapse file tree 14 files changed +129
-59
lines changed Expand file tree Collapse file tree 14 files changed +129
-59
lines changed Original file line number Diff line number Diff line change @@ -55,19 +55,19 @@ class AnalogIn {
55
55
* @param name (optional) A string to identify the object
56
56
*/
57
57
AnalogIn (PinName pin) {
58
- _mutex. lock ();
58
+ lock ();
59
59
analogin_init (&_adc, pin);
60
- _mutex. unlock ();
60
+ unlock ();
61
61
}
62
62
63
63
/* * Read the input voltage, represented as a float in the range [0.0, 1.0]
64
64
*
65
65
* @returns A floating-point value representing the current input voltage, measured as a percentage
66
66
*/
67
67
float read () {
68
- _mutex. lock ();
68
+ lock ();
69
69
float ret = analogin_read (&_adc);
70
- _mutex. unlock ();
70
+ unlock ();
71
71
return ret;
72
72
}
73
73
@@ -77,9 +77,9 @@ class AnalogIn {
77
77
* 16-bit unsigned short representing the current input voltage, normalised to a 16-bit value
78
78
*/
79
79
unsigned short read_u16 () {
80
- _mutex. lock ();
80
+ lock ();
81
81
unsigned short ret = analogin_read_u16 (&_adc);
82
- _mutex. unlock ();
82
+ unlock ();
83
83
return ret;
84
84
}
85
85
@@ -104,6 +104,15 @@ class AnalogIn {
104
104
#endif
105
105
106
106
protected:
107
+
108
+ virtual void lock () {
109
+ _mutex.lock ();
110
+ }
111
+
112
+ virtual void unlock () {
113
+ _mutex.unlock ();
114
+ }
115
+
107
116
analogin_t _adc;
108
117
static rtos::Mutex _mutex;
109
118
};
Original file line number Diff line number Diff line change @@ -66,9 +66,9 @@ class AnalogOut {
66
66
* Values outside this range will be saturated to 0.0f or 1.0f.
67
67
*/
68
68
void write (float value) {
69
- _mutex. lock ();
69
+ lock ();
70
70
analogout_write (&_dac, value);
71
- _mutex. unlock ();
71
+ unlock ();
72
72
}
73
73
74
74
/* * Set the output voltage, represented as an unsigned short in the range [0x0, 0xFFFF]
@@ -77,9 +77,9 @@ class AnalogOut {
77
77
* normalised to a 16-bit value (0x0000 = 0v, 0xFFFF = 3.3v)
78
78
*/
79
79
void write_u16 (unsigned short value) {
80
- _mutex. lock ();
80
+ lock ();
81
81
analogout_write_u16 (&_dac, value);
82
- _mutex. unlock ();
82
+ unlock ();
83
83
}
84
84
85
85
/* * Return the current output voltage setting, measured as a percentage (float)
@@ -93,9 +93,9 @@ class AnalogOut {
93
93
* This value may not match exactly the value set by a previous write().
94
94
*/
95
95
float read () {
96
- _mutex. lock ();
96
+ lock ();
97
97
float ret = analogout_read (&_dac);
98
- _mutex. unlock ();
98
+ unlock ();
99
99
return ret;
100
100
}
101
101
@@ -123,6 +123,15 @@ class AnalogOut {
123
123
#endif
124
124
125
125
protected:
126
+
127
+ virtual void lock () {
128
+ _mutex.lock ();
129
+ }
130
+
131
+ virtual void unlock () {
132
+ _mutex.unlock ();
133
+ }
134
+
126
135
dac_t _dac;
127
136
rtos::Mutex _mutex;
128
137
};
Original file line number Diff line number Diff line change @@ -94,6 +94,8 @@ class BusIn {
94
94
95
95
/* disallow copy constructor and assignment operators */
96
96
private:
97
+ virtual void lock ();
98
+ virtual void unlock ();
97
99
BusIn (const BusIn&);
98
100
BusIn & operator = (const BusIn&);
99
101
};
Original file line number Diff line number Diff line change @@ -101,6 +101,8 @@ class BusInOut {
101
101
#endif
102
102
103
103
protected:
104
+ virtual void lock ();
105
+ virtual void unlock ();
104
106
DigitalInOut* _pin[16 ];
105
107
106
108
/* * Mask of bus's NC pins
Original file line number Diff line number Diff line change @@ -85,6 +85,8 @@ class BusOut {
85
85
#endif
86
86
87
87
protected:
88
+ virtual void lock ();
89
+ virtual void unlock ();
88
90
DigitalOut* _pin[16 ];
89
91
90
92
/* * Mask of bus's NC pins
Original file line number Diff line number Diff line change @@ -242,6 +242,8 @@ class CAN {
242
242
static void _irq_handler (uint32_t id, CanIrqType type);
243
243
244
244
protected:
245
+ virtual void lock ();
246
+ virtual void unlock ();
245
247
can_t _can;
246
248
Callback<void ()> _irq[9 ];
247
249
rtos::Mutex _mutex;
Original file line number Diff line number Diff line change @@ -139,11 +139,11 @@ class I2C {
139
139
140
140
/* * Acquire exclusive access to this I2C bus
141
141
*/
142
- void lock (void );
142
+ virtual void lock (void );
143
143
144
144
/* * Release exclusive access to this I2C bus
145
145
*/
146
- void unlock (void );
146
+ virtual void unlock (void );
147
147
148
148
#if DEVICE_I2C_ASYNCH
149
149
Original file line number Diff line number Diff line change @@ -113,6 +113,10 @@ class InterruptManager {
113
113
*/
114
114
bool remove_handler (pFunctionPointer_t handler, IRQn_Type irq);
115
115
116
+ protected:
117
+ virtual void lock ();
118
+ virtual void unlock ();
119
+
116
120
private:
117
121
InterruptManager ();
118
122
~InterruptManager ();
Original file line number Diff line number Diff line change @@ -116,11 +116,11 @@ class SPI {
116
116
117
117
/* * Acquire exclusive access to this SPI bus
118
118
*/
119
- void lock (void );
119
+ virtual void lock (void );
120
120
121
121
/* * Release exclusive access to this SPI bus
122
122
*/
123
- void unlock (void );
123
+ virtual void unlock (void );
124
124
125
125
#if DEVICE_SPI_ASYNCH
126
126
Original file line number Diff line number Diff line change @@ -53,23 +53,31 @@ BusIn::~BusIn() {
53
53
54
54
int BusIn::read () {
55
55
int v = 0 ;
56
- _mutex. lock ();
56
+ lock ();
57
57
for (int i=0 ; i<16 ; i++) {
58
58
if (_pin[i] != 0 ) {
59
59
v |= _pin[i]->read () << i;
60
60
}
61
61
}
62
- _mutex. unlock ();
62
+ unlock ();
63
63
return v;
64
64
}
65
65
66
66
void BusIn::mode (PinMode pull) {
67
- _mutex. lock ();
67
+ lock ();
68
68
for (int i=0 ; i<16 ; i++) {
69
69
if (_pin[i] != 0 ) {
70
70
_pin[i]->mode (pull);
71
71
}
72
72
}
73
+ unlock ();
74
+ }
75
+
76
+ void BusIn::lock () {
77
+ _mutex.lock ();
78
+ }
79
+
80
+ void BusIn::unlock () {
73
81
_mutex.unlock ();
74
82
}
75
83
Original file line number Diff line number Diff line change @@ -52,55 +52,55 @@ BusInOut::~BusInOut() {
52
52
}
53
53
54
54
void BusInOut::write (int value) {
55
- _mutex. lock ();
55
+ lock ();
56
56
for (int i=0 ; i<16 ; i++) {
57
57
if (_pin[i] != 0 ) {
58
58
_pin[i]->write ((value >> i) & 1 );
59
59
}
60
60
}
61
- _mutex. unlock ();
61
+ unlock ();
62
62
}
63
63
64
64
int BusInOut::read () {
65
- _mutex. lock ();
65
+ lock ();
66
66
int v = 0 ;
67
67
for (int i=0 ; i<16 ; i++) {
68
68
if (_pin[i] != 0 ) {
69
69
v |= _pin[i]->read () << i;
70
70
}
71
71
}
72
- _mutex. unlock ();
72
+ unlock ();
73
73
return v;
74
74
}
75
75
76
76
void BusInOut::output () {
77
- _mutex. lock ();
77
+ lock ();
78
78
for (int i=0 ; i<16 ; i++) {
79
79
if (_pin[i] != 0 ) {
80
80
_pin[i]->output ();
81
81
}
82
82
}
83
- _mutex. unlock ();
83
+ unlock ();
84
84
}
85
85
86
86
void BusInOut::input () {
87
- _mutex. lock ();
87
+ lock ();
88
88
for (int i=0 ; i<16 ; i++) {
89
89
if (_pin[i] != 0 ) {
90
90
_pin[i]->input ();
91
91
}
92
92
}
93
- _mutex. unlock ();
93
+ unlock ();
94
94
}
95
95
96
96
void BusInOut::mode (PinMode pull) {
97
- _mutex. lock ();
97
+ lock ();
98
98
for (int i=0 ; i<16 ; i++) {
99
99
if (_pin[i] != 0 ) {
100
100
_pin[i]->mode (pull);
101
101
}
102
102
}
103
- _mutex. unlock ();
103
+ unlock ();
104
104
}
105
105
106
106
#ifdef MBED_OPERATORS
@@ -129,4 +129,12 @@ BusInOut::operator int() {
129
129
}
130
130
#endif
131
131
132
+ void BusInOut::lock () {
133
+ _mutex.lock ();
134
+ }
135
+
136
+ void BusInOut::unlock () {
137
+ _mutex.unlock ();
138
+ }
139
+
132
140
} // namespace mbed
Original file line number Diff line number Diff line change @@ -52,24 +52,24 @@ BusOut::~BusOut() {
52
52
}
53
53
54
54
void BusOut::write (int value) {
55
- _mutex. lock ();
55
+ lock ();
56
56
for (int i=0 ; i<16 ; i++) {
57
57
if (_pin[i] != 0 ) {
58
58
_pin[i]->write ((value >> i) & 1 );
59
59
}
60
60
}
61
- _mutex. unlock ();
61
+ unlock ();
62
62
}
63
63
64
64
int BusOut::read () {
65
- _mutex. lock ();
65
+ lock ();
66
66
int v = 0 ;
67
67
for (int i=0 ; i<16 ; i++) {
68
68
if (_pin[i] != 0 ) {
69
69
v |= _pin[i]->read () << i;
70
70
}
71
71
}
72
- _mutex. unlock ();
72
+ unlock ();
73
73
return v;
74
74
}
75
75
@@ -99,4 +99,12 @@ BusOut::operator int() {
99
99
}
100
100
#endif
101
101
102
+ void BusOut::lock () {
103
+ _mutex.lock ();
104
+ }
105
+
106
+ void BusOut::unlock () {
107
+ _mutex.unlock ();
108
+ }
109
+
102
110
} // namespace mbed
You can’t perform that action at this time.
0 commit comments