Changeset 1120 for trunk/buspirate_spi.c
- Timestamp:
- 07/29/10 18:24:09 (22 months ago)
- File:
-
- 1 edited
-
trunk/buspirate_spi.c (modified) (2 diffs)
Legend:
- Unmodified
- Added
- Removed
-
trunk/buspirate_spi.c
r1112 r1120 261 261 return SPI_INVALID_LENGTH; 262 262 263 /* +2 is pretty arbitrary. */264 buf = realloc(buf, writecnt + readcnt + 2);263 /* 3 bytes extra for CS#, len, CS#. */ 264 buf = realloc(buf, writecnt + readcnt + 3); 265 265 if (!buf) { 266 266 msg_perr("Out of memory!\n"); … … 270 270 /* Assert CS# */ 271 271 buf[i++] = 0x02; 272 ret = buspirate_sendrecv(buf, 1, 1); 273 if (ret) 274 return SPI_GENERIC_ERROR; 275 if (buf[0] != 0x01) { 276 msg_perr("Protocol error while lowering CS#!\n"); 277 return SPI_GENERIC_ERROR; 278 } 279 280 i = 0; 272 281 273 buf[i++] = 0x10 | (writecnt + readcnt - 1); 282 274 memcpy(buf + i, writearr, writecnt); 283 275 i += writecnt; 284 276 memset(buf + i, 0, readcnt); 285 ret = buspirate_sendrecv(buf, i + readcnt, i + readcnt); 286 if (ret) 277 278 i += readcnt; 279 /* De-assert CS# */ 280 buf[i++] = 0x03; 281 282 ret = buspirate_sendrecv(buf, i, i); 283 284 if (ret) { 285 msg_perr("Bus Pirate communication error!\n"); 287 286 return SPI_GENERIC_ERROR; 288 if (buf[0] != 0x01) { 287 } 288 289 if (buf[0] != 0x01) { 290 msg_perr("Protocol error while lowering CS#!\n"); 291 return SPI_GENERIC_ERROR; 292 } 293 294 if (buf[1] != 0x01) { 289 295 msg_perr("Protocol error while reading/writing SPI!\n"); 290 296 return SPI_GENERIC_ERROR; 291 297 } 292 memcpy(readarr, buf + i, readcnt); 293 294 i = 0; 295 /* De-assert CS# */ 296 buf[i++] = 0x03; 297 ret = buspirate_sendrecv(buf, 1, 1); 298 if (ret) 299 return SPI_GENERIC_ERROR; 300 if (buf[0] != 0x01) { 298 299 if (buf[i - 1] != 0x01) { 301 300 msg_perr("Protocol error while raising CS#!\n"); 302 301 return SPI_GENERIC_ERROR; 303 302 } 304 303 304 /* Skip CS#, length, writearr. */ 305 memcpy(readarr, buf + 2 + writecnt, readcnt); 306 305 307 return ret; 306 308 }
Note: See TracChangeset
for help on using the changeset viewer.
