Skip to content

Commit 4811eb5

Browse files
tbowmotekka007
authored andcommitted
Added return value for atsha204_getSerialNumber (#487)
Also cleaned up trailing whitespaces.
1 parent 1eabe50 commit 4811eb5

File tree

2 files changed

+37
-37
lines changed

2 files changed

+37
-37
lines changed

libraries/MySensors/drivers/ATSHA204/ATSHA204.cpp

Lines changed: 36 additions & 36 deletions
Original file line numberDiff line numberDiff line change
@@ -15,7 +15,7 @@ static uint8_t swi_send_bytes(uint8_t count, uint8_t *buffer);
1515
static uint8_t swi_send_byte(uint8_t value);
1616
static uint8_t sha204p_receive_response(uint8_t size, uint8_t *response);
1717
static uint8_t sha204m_read(uint8_t *tx_buffer, uint8_t *rx_buffer, uint8_t zone, uint16_t address);
18-
static uint8_t sha204c_resync(uint8_t size, uint8_t *response);
18+
static uint8_t sha204c_resync(uint8_t size, uint8_t *response);
1919
static uint8_t sha204c_send_and_receive(uint8_t *tx_buffer, uint8_t rx_size, uint8_t *rx_buffer, uint8_t execution_delay, uint8_t execution_timeout);
2020

2121
/* SWI bit bang functions */
@@ -40,23 +40,23 @@ static uint8_t swi_send_bytes(uint8_t count, uint8_t *buffer)
4040
// Set signal pin as output.
4141
SHA204_POUT_HIGH();
4242
SHA204_SET_OUTPUT();
43-
43+
4444

4545
// Wait turn around time.
4646
delayMicroseconds(RX_TX_DELAY); //RX_TX_DELAY;
4747

48-
for (i = 0; i < count; i++)
48+
for (i = 0; i < count; i++)
4949
{
50-
for (bit_mask = 1; bit_mask > 0; bit_mask <<= 1)
50+
for (bit_mask = 1; bit_mask > 0; bit_mask <<= 1)
5151
{
52-
if (bit_mask & buffer[i])
52+
if (bit_mask & buffer[i])
5353
{
5454
SHA204_POUT_LOW(); //*device_port_OUT &= ~device_pin;
5555
delayMicroseconds(BIT_DELAY); //BIT_DELAY_1;
5656
SHA204_POUT_HIGH(); //*device_port_OUT |= device_pin;
5757
delayMicroseconds(7*BIT_DELAY); //BIT_DELAY_7;
5858
}
59-
else
59+
else
6060
{
6161
// Send a zero bit.
6262
SHA204_POUT_LOW(); //*device_port_OUT &= ~device_pin;
@@ -92,11 +92,11 @@ static uint8_t swi_receive_bytes(uint8_t count, uint8_t *buffer)
9292

9393
// Configure signal pin as input.
9494
SHA204_SET_INPUT();
95-
95+
9696
// Receive bits and store in buffer.
9797
for (i = 0; i < count; i++)
9898
{
99-
for (bit_mask = 1; bit_mask > 0; bit_mask <<= 1)
99+
for (bit_mask = 1; bit_mask > 0; bit_mask <<= 1)
100100
{
101101
pulse_count = 0;
102102

@@ -106,31 +106,31 @@ static uint8_t swi_receive_bytes(uint8_t count, uint8_t *buffer)
106106
timeout_count = START_PULSE_TIME_OUT;
107107

108108
// Detect start bit.
109-
while (--timeout_count > 0)
109+
while (--timeout_count > 0)
110110
{
111111
// Wait for falling edge.
112112
if (SHA204_PIN_READ() == 0)
113113
break;
114114
}
115115

116-
if (timeout_count == 0)
116+
if (timeout_count == 0)
117117
{
118118
status = SWI_FUNCTION_RETCODE_TIMEOUT;
119119
break;
120120
}
121121

122-
do
122+
do
123123
{
124124
// Wait for rising edge.
125-
if (SHA204_PIN_READ() != 0)
125+
if (SHA204_PIN_READ() != 0)
126126
{
127127
// For an Atmel microcontroller this might be faster than "pulse_count++".
128128
pulse_count = 1;
129129
break;
130130
}
131131
} while (--timeout_count > 0);
132132

133-
if (pulse_count == 0)
133+
if (pulse_count == 0)
134134
{
135135
status = SWI_FUNCTION_RETCODE_TIMEOUT;
136136
break;
@@ -143,9 +143,9 @@ static uint8_t swi_receive_bytes(uint8_t count, uint8_t *buffer)
143143
timeout_count = ZERO_PULSE_TIME_OUT;
144144

145145
// Detect possible edge indicating zero bit.
146-
do
146+
do
147147
{
148-
if (SHA204_PIN_READ() == 0)
148+
if (SHA204_PIN_READ() == 0)
149149
{
150150
// For an Atmel microcontroller this might be faster than "pulse_count++".
151151
pulse_count = 2;
@@ -155,9 +155,9 @@ static uint8_t swi_receive_bytes(uint8_t count, uint8_t *buffer)
155155

156156
// Wait for rising edge of zero pulse before returning. Otherwise we might interpret
157157
// its rising edge as the next start pulse.
158-
if (pulse_count == 2)
158+
if (pulse_count == 2)
159159
{
160-
do
160+
do
161161
{
162162
if (SHA204_PIN_READ() != 0)
163163
break;
@@ -174,7 +174,7 @@ static uint8_t swi_receive_bytes(uint8_t count, uint8_t *buffer)
174174
}
175175
interrupts(); //swi_enable_interrupts();
176176

177-
if (status == SWI_FUNCTION_RETCODE_TIMEOUT)
177+
if (status == SWI_FUNCTION_RETCODE_TIMEOUT)
178178
{
179179
if (i > 0)
180180
// Indicate that we timed out after having received at least one byte.
@@ -197,7 +197,7 @@ static uint8_t sha204p_receive_response(uint8_t size, uint8_t *response)
197197
(void) swi_send_byte(SHA204_SWI_FLAG_TX);
198198

199199
ret_code = swi_receive_bytes(size, response);
200-
if (ret_code == SWI_FUNCTION_RETCODE_SUCCESS || ret_code == SWI_FUNCTION_RETCODE_RX_FAIL)
200+
if (ret_code == SWI_FUNCTION_RETCODE_SUCCESS || ret_code == SWI_FUNCTION_RETCODE_RX_FAIL)
201201
{
202202
count_byte = response[SHA204_BUFFER_POS_COUNT];
203203
if ((count_byte < SHA204_RSP_SIZE_MIN) || (count_byte > size))
@@ -257,7 +257,7 @@ static uint8_t sha204c_send_and_receive(uint8_t *tx_buffer, uint8_t rx_size, uin
257257
// Retry loop for sending a command and receiving a response.
258258
n_retries_send = SHA204_RETRY_COUNT + 1;
259259

260-
while ((n_retries_send-- > 0) && (ret_code != SHA204_SUCCESS))
260+
while ((n_retries_send-- > 0) && (ret_code != SHA204_SUCCESS))
261261
{
262262
// Send command.
263263
ret_code = swi_send_byte(SHA204_SWI_FLAG_CMD);
@@ -266,7 +266,7 @@ static uint8_t sha204c_send_and_receive(uint8_t *tx_buffer, uint8_t rx_size, uin
266266
else
267267
ret_code = swi_send_bytes(count, tx_buffer);
268268

269-
if (ret_code != SHA204_SUCCESS)
269+
if (ret_code != SHA204_SUCCESS)
270270
{
271271
if (sha204c_resync(rx_size, rx_buffer) == SHA204_RX_NO_RESPONSE)
272272
return ret_code; // The device seems to be dead in the water.
@@ -279,22 +279,22 @@ static uint8_t sha204c_send_and_receive(uint8_t *tx_buffer, uint8_t rx_size, uin
279279

280280
// Retry loop for receiving a response.
281281
n_retries_receive = SHA204_RETRY_COUNT + 1;
282-
while (n_retries_receive-- > 0)
282+
while (n_retries_receive-- > 0)
283283
{
284284
// Reset response buffer.
285285
for (i = 0; i < rx_size; i++)
286286
rx_buffer[i] = 0;
287287

288288
// Poll for response.
289289
timeout_countdown = execution_timeout_us;
290-
do
290+
do
291291
{
292292
ret_code = sha204p_receive_response(rx_size, rx_buffer);
293293
timeout_countdown -= SHA204_RESPONSE_TIMEOUT;
294-
}
294+
}
295295
while ((timeout_countdown > SHA204_RESPONSE_TIMEOUT) && (ret_code == SHA204_RX_NO_RESPONSE));
296296

297-
if (ret_code == SHA204_RX_NO_RESPONSE)
297+
if (ret_code == SHA204_RX_NO_RESPONSE)
298298
{
299299
// We did not receive a response. Re-synchronize and send command again.
300300
if (sha204c_resync(rx_size, rx_buffer) == SHA204_RX_NO_RESPONSE)
@@ -324,7 +324,7 @@ static uint8_t sha204c_send_and_receive(uint8_t *tx_buffer, uint8_t rx_size, uin
324324
// We received a response of valid size.
325325
// Check the consistency of the response.
326326
ret_code = sha204c_check_crc(rx_buffer);
327-
if (ret_code == SHA204_SUCCESS)
327+
if (ret_code == SHA204_SUCCESS)
328328
{
329329
// Received valid response.
330330
if (rx_buffer[SHA204_BUFFER_POS_COUNT] > SHA204_RSP_SIZE_MIN)
@@ -340,7 +340,7 @@ static uint8_t sha204c_send_and_receive(uint8_t *tx_buffer, uint8_t rx_size, uin
340340
return SHA204_PARSE_ERROR;
341341
if (status_byte == SHA204_STATUS_BYTE_EXEC)
342342
return SHA204_CMD_FAIL;
343-
if (status_byte == SHA204_STATUS_BYTE_COMM)
343+
if (status_byte == SHA204_STATUS_BYTE_COMM)
344344
{
345345
// In case of the device status byte indicating a communication
346346
// error this function exits the retry loop for receiving a response
@@ -355,7 +355,7 @@ static uint8_t sha204c_send_and_receive(uint8_t *tx_buffer, uint8_t rx_size, uin
355355
return ret_code;
356356
}
357357

358-
else
358+
else
359359
{
360360
// Received response with incorrect CRC.
361361
ret_code_resync = sha204c_resync(rx_size, rx_buffer);
@@ -410,7 +410,7 @@ static void sha204c_calculate_crc(uint8_t length, uint8_t *data, uint8_t *crc)
410410

411411
for (counter = 0; counter < length; counter++)
412412
{
413-
for (shift_register = 0x01; shift_register > 0x00; shift_register <<= 1)
413+
for (shift_register = 0x01; shift_register > 0x00; shift_register <<= 1)
414414
{
415415
data_bit = (data[counter] & shift_register) ? 1 : 0;
416416
crc_bit = crc_register >> 15;
@@ -441,11 +441,11 @@ static uint8_t sha204c_check_crc(uint8_t *response)
441441
/* Public functions */
442442

443443
void atsha204_init(uint8_t pin)
444-
{
444+
{
445445
#if defined(ARDUINO_ARCH_AVR)
446446
device_pin = digitalPinToBitMask(pin); // Find the bit value of the pin
447447
uint8_t port = digitalPinToPort(pin); // temoporarily used to get the next three registers
448-
448+
449449
// Point to data direction register port of pin
450450
device_port_DDR = portModeRegister(port);
451451
// Point to output register of pin
@@ -483,7 +483,7 @@ uint8_t atsha204_wakeup(uint8_t *response)
483483
ret_code = SHA204_INVALID_SIZE;
484484
else if (response[SHA204_BUFFER_POS_STATUS] != SHA204_STATUS_BYTE_WAKEUP)
485485
ret_code = SHA204_COMM_FAIL;
486-
else
486+
else
487487
{
488488
if ((response[SHA204_RSP_SIZE_MIN - SHA204_CRC_SIZE] != 0x33)
489489
|| (response[SHA204_RSP_SIZE_MIN + 1 - SHA204_CRC_SIZE] != 0x43))
@@ -502,9 +502,9 @@ uint8_t atsha204_execute(uint8_t op_code, uint8_t param1, uint16_t param2,
502502
uint8_t *p_buffer;
503503
uint8_t len;
504504
(void)tx_size;
505-
505+
506506
// Supply delays and response size.
507-
switch (op_code)
507+
switch (op_code)
508508
{
509509
case SHA204_GENDIG:
510510
poll_delay = GENDIG_DELAY;
@@ -571,7 +571,7 @@ uint8_t atsha204_execute(uint8_t op_code, uint8_t param1, uint16_t param2,
571571
&rx_buffer[0], poll_delay, poll_timeout);
572572
}
573573

574-
void atsha204_getSerialNumber(uint8_t * response)
574+
uint8_t atsha204_getSerialNumber(uint8_t * response)
575575
{
576576
uint8_t readCommand[READ_COUNT];
577577
uint8_t readResponse[READ_4_RSP_SIZE];
@@ -596,5 +596,5 @@ void atsha204_getSerialNumber(uint8_t * response)
596596
}
597597
}
598598

599-
return;
599+
return returnCode;
600600
}

libraries/MySensors/drivers/ATSHA204/ATSHA204.h

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -246,7 +246,7 @@ uint8_t atsha204_wakeup(uint8_t *response);
246246
uint8_t atsha204_execute(uint8_t op_code, uint8_t param1, uint16_t param2,
247247
uint8_t datalen1, uint8_t *data1, uint8_t tx_size,
248248
uint8_t *tx_buffer, uint8_t rx_size, uint8_t *rx_buffer);
249-
void atsha204_getSerialNumber(uint8_t *response);
249+
uint8_t atsha204_getSerialNumber(uint8_t *response);
250250

251251
#endif
252252
#endif

0 commit comments

Comments
 (0)