usci.h 2.9 KB

123456789101112131415161718192021222324252627282930313233343536373839404142434445464748495051525354555657585960616263646566676869707172737475767778798081828384858687888990919293949596979899100
  1. /*
  2. MSP430 Emulator
  3. Copyright (C) 2020 Rudolf Geosits (rgeosits@live.esu.edu)
  4. "MSP430 Emulator" is free software: you can redistribute it and/or modify
  5. it under the terms of the GNU General Public License as published by
  6. the Free Software Foundation, either version 3 of the License, or
  7. (at your option) any later version.
  8. "MSP430 Emulator" is distributed in the hope that it will be useful,
  9. but WITHOUT ANY WARRANTY; without even the implied warranty of
  10. MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the
  11. GNU General Public License for more details.
  12. You should have received a copy of the GNU General Public License
  13. along with this program. If not, see <https://www.gnu.org/licenses/>.
  14. */
  15. #pragma once
  16. #include <stdlib.h>
  17. #include <stdio.h>
  18. #include <termios.h>
  19. #include <stdint.h>
  20. #include <fcntl.h>
  21. #include "../cpu/registers.h"
  22. #include "../utilities.h"
  23. // USCI_Ax Control Register 0
  24. typedef struct Ctl0
  25. {
  26. bool UCPEN; // Parity Enable: Disabled (0) Enabled (1)
  27. bool UCPAR; // Parity Select: Odd (0) Even (1)
  28. bool UCMSB; // MSB first: LSB first (0) MSB first (1)
  29. bool UC7BIT; // Char Len: 8-bit (0) 7-bit (1)
  30. bool UCSPB; // Stop bit select: One STP bits (0) Two STP bits (1)
  31. // USCI Mode - When UCSYNC = 0, its asynchronous mode
  32. // UART Mode (00)
  33. // Idle-line multiprocessor mode (01)
  34. // Address-bit multiprocessor mode (10)
  35. // UART mode with automatic baud rate detection (11)
  36. uint8_t UCMODE : 2;
  37. bool UCSYNC; // Synchronous mode enable: Async (0) Sync (1)
  38. } Ctl0;
  39. // USCI_Ax Control Register 1
  40. typedef struct Ctl1 {
  41. // USCI clock source select, these bits select the Baud rate source clock.
  42. // UCLK: 00 | ACLK: 01 | SMCLK: 10 | SMCLK: 11
  43. uint8_t UCSSEL : 2;
  44. bool UCRXEIE : 1; // Recv erroneous-character interrupt enable
  45. bool UCBRKIE : 1; // receive break character interrupt enable
  46. // dormant. Puts SCI into sleep mode:
  47. // 0 - Not dormant. All received chars will set UCAxRXIFG
  48. // 1 - Dormant. Only chars that are preceded by an idle line or addr bit
  49. bool UCDORM : 1;
  50. // Transmit address, Next frame to be transmitted will be marked as address
  51. // Depedning on the selected multiproc mode. Data (0) Address (1)
  52. bool UCTXADDR : 1;
  53. // Transmit break, transmits a break with the next write to the TX buffer
  54. // Not a break (0) Transmit a break (1)
  55. bool UCTXBRK : 1;
  56. // Software reset enable:
  57. // Disabled. USCI reset released for operation (0)
  58. // Enabled. USCI logic held in reset start. (1)
  59. bool UCSWRST : 1;
  60. } Ctl1;
  61. typedef struct Usci
  62. {
  63. // USCI_A0 Module Register Pointers
  64. uint8_t *UCA0CTL0;
  65. uint8_t *UCA0CTL1;
  66. uint8_t *UCA0BR0;
  67. uint8_t *UCA0BR1;
  68. uint8_t *UCA0MCTL;
  69. uint8_t *UCA0STAT;
  70. uint8_t *UCA0RXBUF;
  71. uint8_t *UCA0TXBUF;
  72. uint8_t *UCA0ABCTL;
  73. uint8_t *UCA0IRTCTL;
  74. uint8_t *UCA0IRRCTL;
  75. uint8_t *IFG2;
  76. Ctl0 ctl0;
  77. Ctl1 ctl1;
  78. }
  79. Usci;
  80. void setup_usci(Emulator *emu);
  81. void handle_usci(Emulator *emu);