You can not select more than 25 topics Topics must start with a letter or number, can include dashes ('-') and can be up to 35 characters long.
 
 
 
 

48 lines
1020 B

  1. #include "packet.h"
  2. #include "uart.h"
  3. /* 5 byte packets. 5 bytes * 10 bits/byte * 8 khz = 400 kbits/sec */
  4. void packet_send_adc_dac(int16_t adc, uint16_t dac, int overflow)
  5. {
  6. char b[4];
  7. /* Packet format for DAC/ADC values:
  8. 10100000 ffffAaaa aaaaaaaa Dddddddd dddddddd
  9. ffff = flags, default 0000
  10. ...1 = possible overflow
  11. Aaaaaaaaaaaa = 12-bit ADC value (2s compliment signed)
  12. Dddddddddddddddd = 16-bit DAC command (unsigned)
  13. */
  14. uart1_put(PACKET_ADC_DAC);
  15. b[0] = (adc & 0x0F00) >> 8;
  16. if (overflow)
  17. b[0] |= 0x10;
  18. b[1] = adc & 0xFF;
  19. b[2] = (dac & 0xFF00) >> 8;
  20. b[3] = dac & 0xFF;
  21. uart1_put(b[0]);
  22. uart1_put(b[1]);
  23. uart1_put(b[2]);
  24. uart1_put(b[3]);
  25. }
  26. void packet_send_calibration(float scale)
  27. {
  28. /* Packet format for calibration data:
  29. A1 xx xx xx xx
  30. where xx xx xx xx = 32-bit floating point value, little
  31. endian IEEE 754 */
  32. uint8_t *b = (uint8_t *)&scale;
  33. uart1_put(PACKET_CALIBRATION);
  34. uart1_put(b[0]);
  35. uart1_put(b[1]);
  36. uart1_put(b[2]);
  37. uart1_put(b[3]);
  38. }