usci.h 2.9 KB

123456789101112131415161718192021222324252627282930313233343536373839404142434445464748495051525354555657585960616263646566676869707172737475767778798081828384858687888990919293949596979899100101
  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 <stdint.h>
  19. #include <fcntl.h>
  20. #include "../cpu/registers.h"
  21. #include "../utilities.h"
  22. #define TXIFG 0x02
  23. #define RXIFG 0x01
  24. // USCI_Ax Control Register 0
  25. typedef struct Ctl0
  26. {
  27. bool UCPEN; // Parity Enable: Disabled (0) Enabled (1)
  28. bool UCPAR; // Parity Select: Odd (0) Even (1)
  29. bool UCMSB; // MSB first: LSB first (0) MSB first (1)
  30. bool UC7BIT; // Char Len: 8-bit (0) 7-bit (1)
  31. bool UCSPB; // Stop bit select: One STP bits (0) Two STP bits (1)
  32. // USCI Mode - When UCSYNC = 0, its asynchronous mode
  33. // UART Mode (00)
  34. // Idle-line multiprocessor mode (01)
  35. // Address-bit multiprocessor mode (10)
  36. // UART mode with automatic baud rate detection (11)
  37. uint8_t UCMODE;
  38. bool UCSYNC; // Synchronous mode enable: Async (0) Sync (1)
  39. } Ctl0;
  40. // USCI_Ax Control Register 1
  41. typedef struct Ctl1 {
  42. // USCI clock source select, these bits select the Baud rate source clock.
  43. // UCLK: 00 | ACLK: 01 | SMCLK: 10 | SMCLK: 11
  44. uint8_t UCSSEL;
  45. bool UCRXEIE; // Recv erroneous-character interrupt enable
  46. bool UCBRKIE; // receive break character interrupt enable
  47. // dormant. Puts SCI into sleep mode:
  48. // 0 - Not dormant. All received chars will set UCAxRXIFG
  49. // 1 - Dormant. Only chars that are preceded by an idle line or addr bit
  50. bool UCDORM;
  51. // Transmit address, Next frame to be transmitted will be marked as address
  52. // Depedning on the selected multiproc mode. Data (0) Address (1)
  53. bool UCTXADDR;
  54. // Transmit break, transmits a break with the next write to the TX buffer
  55. // Not a break (0) Transmit a break (1)
  56. bool UCTXBRK;
  57. // Software reset enable:
  58. // Disabled. USCI reset released for operation (0)
  59. // Enabled. USCI logic held in reset start. (1)
  60. bool UCSWRST;
  61. } Ctl1;
  62. typedef struct Usci
  63. {
  64. // USCI_A0 Module Register Pointers
  65. uint8_t *UCA0CTL0;
  66. uint8_t *UCA0CTL1;
  67. uint8_t *UCA0BR0;
  68. uint8_t *UCA0BR1;
  69. uint8_t *UCA0MCTL;
  70. uint8_t *UCA0STAT;
  71. uint8_t *UCA0RXBUF;
  72. uint8_t *UCA0TXBUF;
  73. uint8_t *UCA0ABCTL;
  74. uint8_t *UCA0IRTCTL;
  75. uint8_t *UCA0IRRCTL;
  76. uint8_t *IFG2;
  77. Ctl0 ctl0;
  78. Ctl1 ctl1;
  79. }
  80. Usci;
  81. void setup_usci(Emulator *emu);
  82. void handle_usci(Emulator *emu);