samo.h 3.6 KB

123456789101112131415161718192021222324252627282930313233343536373839404142434445464748495051525354555657585960616263646566676869707172737475767778798081828384858687888990919293949596979899100101102103104105106107108109110111112113114115116117118119120121122123124125126127128129130131132133134135136137138139140141
  1. #if !defined(_SAMO_H)
  2. #define _SAMO_H 1
  3. #include <config.h>
  4. #include <regs.h>
  5. // available range 10 .. 715 seconds (10 sec .. 11 min 55 sec)
  6. #define SUSPEND_AUTO_POWER_OFF_SECONDS 120
  7. #if !defined(ARRAY_SIZE)
  8. #define ARRAY_SIZE(a) (sizeof(a) / sizeof((a)[0]))
  9. #endif
  10. #if !defined(NULL)
  11. #define NULL 0
  12. #endif
  13. #if !defined(SAMO_RESTRICTIONS)
  14. #define SAMO_RESTRICTIONS 0
  15. #endif
  16. //#define DEBUGLED1_ON() do { REG_P1_P1D &= ~(1 << 4); } while (0)
  17. //#define DEBUGLED1_OFF() do { REG_P1_P1D |= (1 << 4); } while (0)
  18. //#define DEBUGLED2_ON() do { REG_P1_P1D &= ~(1 << 3); } while (0)
  19. //#define DEBUGLED2_OFF() do { REG_P1_P1D |= (1 << 3); } while (0)
  20. #define EEPROM_CS_LO() do { REG_P5_P5D &= ~(1 << 2); } while (0)
  21. #define EEPROM_CS_HI() do { REG_P5_P5D |= (1 << 2); } while (0)
  22. #define LCD_CS_LO() do { REG_P8_P8D &= ~(1 << 5); } while (0)
  23. #define LCD_CS_HI() do { REG_P8_P8D |= (1 << 5); } while (0)
  24. #define LCD_DISPLAY_ON() do { REG_P3_P3D |= (1 << 0); } while (0)
  25. #define LCD_DISPLAY_OFF() do { REG_P3_P3D &= ~(1 << 0); } while (0)
  26. // remove this later - this pin is used by LCD controller!
  27. //#define TFT_CTL1_LO() do { REG_P8_P8D &= ~(1 << 3); } while (0)
  28. //#define TFT_CTL1_HI() do { REG_P8_P8D |= (1 << 3); } while (0)
  29. // macro to busy wait
  30. #define BUSY_WAIT_FOR(cond) \
  31. do { \
  32. asm volatile ("\tnop\n"); \
  33. } while (0 == (cond))
  34. #define MCLK 48000000
  35. #define MCLK_MHz (MCLK / 1000000)
  36. //#define SERIAL_DIVMD 16
  37. #define SERIAL_DIVMD 8
  38. #define PLL_CLK 60000000
  39. #define PLL_CLK_MHz (PLL_CLK / 1000000)
  40. //#define CALC_BAUD(fbrclk, divmd, bps) ((fbrclk / divmd)/(2 * bps) - 1)
  41. #define CALC_BAUD(fbrclk, div, divmd, bps) (((((10 * fbrclk) / div / divmd)/(2 * bps)) + 5) / 10 - 1)
  42. #define SET_BRTRD(ch, value) do { \
  43. REG_EFSIF##ch##_BRTRUN = 0; \
  44. REG_EFSIF##ch##_BRTRDM = value >> 8; \
  45. REG_EFSIF##ch##_BRTRDL = value & 0xff; \
  46. REG_EFSIF##ch##_BRTRUN = BRTRUNx; \
  47. } while(0)
  48. #define SERIAL_8N1 (NO_PARx | ONE_STPBx | INT_CLKx | EIGHT_BIT_ASYNx)
  49. // include the board specific macros and functions
  50. // if only building simulator the configure as if for production hardware
  51. #if SIMULATOR
  52. #define BOARD_SAMO_V1 1
  53. #endif
  54. #if BOARD_S1C33E07
  55. #include <boards/s1c33e07.h>
  56. #elif BOARD_PROTO1
  57. #include <boards/proto1.h>
  58. #elif BOARD_PROTO2
  59. #include <boards/proto2.h>
  60. #elif BOARD_SAMO_A1 || BOARD_SAMO_A3 || BOARD_SAMO_A5
  61. #define BOARD_SAMO_Ax 1
  62. #include <boards/samo_a1.h>
  63. #elif BOARD_SAMO_V1 || BOARD_SAMO_V2
  64. #define BOARD_SAMO_Vx 1
  65. #include <boards/samo_a1.h>
  66. #elif BOARD_PRT33L17LCD
  67. #include <boards/prt33l17lcd.h>
  68. #else
  69. #error "unsupported board type - see config.h"
  70. #endif
  71. #if !defined(CONSOLE_BPS)
  72. #define CONSOLE_BPS 57600
  73. #endif
  74. #if !defined(CTP_BPS)
  75. #define CTP_BPS 38400
  76. #endif
  77. // common functions
  78. #if 8 == SERIAL_DIVMD
  79. #define DIVMD_set DIVMD_8x
  80. #elif 16 == SERIAL_DIVMD
  81. #define DIVMD_set DIVMD_16x
  82. #else
  83. #error SERIAL_DIVMD must be set to 8 or 16
  84. #endif
  85. static inline void init_rs232_ch0(void)
  86. {
  87. /* serial line 0: 8-bit async, no parity, internal clock, 1 stop bit */
  88. REG_EFSIF0_CTL = TXENx | RXENx | SERIAL_8N1;
  89. /* DIVMD = 1/8, General I/F mode */
  90. REG_EFSIF0_IRDA = DIVMD_set | IRMD_GEN_IFx;
  91. /* set up baud rate timer reload data */
  92. SET_BRTRD(0, CALC_BAUD(MCLK, 1, SERIAL_DIVMD, CONSOLE_BPS));
  93. /* clear interrupt flags */
  94. REG_INT_FSIF01 = FSRX0 | FSTX0 | FSERR0;
  95. }
  96. static inline void init_rs232_ch1(void)
  97. {
  98. REG_EFSIF1_CTL = RXENx | SERIAL_8N1;
  99. REG_EFSIF1_IRDA = DIVMD_set | IRMD_GEN_IFx;
  100. SET_BRTRD(1, CALC_BAUD(MCLK, 1, SERIAL_DIVMD, CTP_BPS));
  101. REG_INT_FSIF01 = FSRX1 | FSTX1 | FSERR1;
  102. }
  103. #endif