fork download
  1. #include <stdio.h>
  2. #include <stdint.h>
  3. #include <stdbool.h>
  4.  
  5. #define NUM_DRV_REGS (18)
  6. #define PWM_MODE_7_INDEPENDENT_FETS (0x70)
  7. #define PWM_MODE_MASK (0x70)
  8. #define DRV8340_WRITE (0x0000)
  9.  
  10. static inline uint32_t DRV8340_ADDR(uint32_t n)
  11. {
  12. return ((n) << 8);
  13. }
  14.  
  15. int main(void) {
  16. // your code goes here
  17. bool isPoly = true;
  18. int reg = 4;
  19. int val = 0x000a;
  20. if (reg >= 0 && reg < NUM_DRV_REGS)
  21. {
  22. uint8_t u8_val =((uint32_t)val) & 0xff; /* Only 8 bits of data available */
  23. printf("\n%u", (u8_val & PWM_MODE_MASK));
  24. printf("Setting %s DRV[%d] = 0x%04x\n",
  25. isPoly ? "Poly" : "Elevation",
  26. reg,
  27. u8_val);
  28. if (4 == reg &&
  29. (u8_val & PWM_MODE_MASK) != PWM_MODE_7_INDEPENDENT_FETS &&
  30. (u8_val & PWM_MODE_MASK) != 0)
  31. {
  32. printf("Error: PWM_MODE must be 0 or 7, write not executed\n");
  33. }
  34. else if (reg >= 6 && reg <= 8 && (u8_val >> 4) != (u8_val & 0xf))
  35. {
  36. printf("Error: Setting IDRIVEP_* must set same value for low and high!\n");
  37. }
  38. else if (isPoly)
  39. {
  40. if (4 == reg)
  41. {
  42. // pr->polyDriverModeZero = ((u8_val & PWM_MODE_MASK)==0);
  43. }
  44. // uint16_t polyTransmitData = DRV8340_WRITE | DRV8340_ADDR(reg) | (u8_val);
  45. // (void) System_SPI_AzimuthReadWrite(&polyTransmitData, sizeof(polyTransmitData),NULL,0);
  46. }
  47. else
  48. {
  49. if (4 == reg)
  50. {
  51. // pr->elevationDriverModeZero = ((u8_val & PWM_MODE_MASK)==0);
  52. }
  53.  
  54. // uint16_t elevationTransmitData = DRV8340_WRITE | DRV8340_ADDR(reg) | (u8_val);
  55. // (void) System_SPI_ElevationReadWrite(&elevationTransmitData, sizeof(elevationTransmitData),NULL,0);
  56.  
  57. }
  58. }
  59.  
  60. return 0;
  61. }
  62.  
Success #stdin #stdout 0.01s 5316KB
stdin
Standard input is empty
stdout
0Setting Poly DRV[4] = 0x000a