hlsdk

Windows baudrate mapping

May 7th, 2012
81
0
Never
Not a member of Pastebin yet? Sign Up, it unlocks many cool features!
C 1.75 KB | None | 0 0
  1. //
  2. // ---=== Winbase.h ===---
  3. #define CBR_110 0xFF10
  4. #define CBR_300 0xFF11
  5. #define CBR_600 0xFF12
  6. #define CBR_1200        0xFF13
  7. #define CBR_2400        0xFF14
  8. #define CBR_4800        0xFF15
  9. #define CBR_9600        0xFF16
  10. #define CBR_14400       0xFF17
  11. #define CBR_19200       0xFF18
  12. #define CBR_38400       0xFF1B
  13. #define CBR_56000       0xFF1F
  14. #define CBR_57600       0xFF20
  15. #define CBR_115200      0xFF21
  16. #define CBR_128000      0xFF23
  17. #define CBR_256000      0xFF27
  18. // ---===           ===---
  19.  
  20. // ---=== http://fenrir.naruoka.org/download/autopilot/common/util/comstream.h ===---
  21. typedef struct speedmap_e
  22. {
  23.     uint32_t baudrate;
  24.     uint32_t cbr;
  25.    
  26. } speedmap_t;
  27.  
  28. // Associate a meaningful # with a meaningless Windows constant.
  29. static const speedmap_t speed_map[] =
  30. {
  31.     { 110,    CBR_110 },
  32.     { 300,    CBR_300 },
  33.     { 600,    CBR_600 },
  34.     { 1200,   CBR_1200 },
  35.     { 2400,   CBR_2400 },
  36.     { 4800,   CBR_4800 },
  37.     { 9600,   CBR_9600 },
  38.     { 14400,  CBR_14400 },
  39.     { 19200,  CBR_19200 },
  40.     { 38400,  CBR_38400 },
  41.     { 56000,  CBR_56000 },
  42.     { 57600,  CBR_57600 },
  43.     { 115200, CBR_115200 },
  44.     { 128000, CBR_128000 },
  45.     { 256000, CBR_256000 },
  46. };
  47.  
  48. static uint32_t baud_to_cbr(uint32_t baudrate)
  49. {
  50.     uint32_t i;
  51.     for(i = 0; i < sizeof(speed_map) / sizeof(speed_map[0]); i++)
  52.         if(speed_map[i].baudrate == baudrate)
  53.             return speed_map[i].cbr;
  54.     return 0; // Error condition -- cound not find baudrate in table
  55. }
  56.  
  57. static uint32_t cbr_to_baud(uint32_t cbr)
  58. {
  59.     uint32_t i;
  60.     for(i = 0; i < sizeof(speed_map) / sizeof(speed_map[0]); i++)
  61.         if(speed_map[i].cbr == cbr)
  62.             return speed_map[i].baudrate;
  63.     return 0; // Error condition -- cound not find CBR_* value in table
  64. }
  65. // ---===                                                                      ===---
Advertisement
Add Comment
Please, Sign In to add comment