bcm.h 2.0 KB

12345678910111213141516171819202122232425262728293031323334353637383940414243444546474849505152535455565758596061626364656667686970
  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. #ifndef _BCM_H_
  16. #define _BCM_H_
  17. #include <stdlib.h>
  18. #include <stdio.h>
  19. #include "../cpu/registers.h"
  20. #include "../utilities.h"
  21. enum {DCOCLK = 0, XT2CLK, VLOCLK, TACLK, ACLK, SMCLK, MCLK, INCLK, NUM_CLOCKS};
  22. struct Bcm {
  23. // Peripheral register pointers //
  24. // DCO Control Register
  25. uint8_t *DCOCTL; // r/w, @0x56, PUC:0x60
  26. // Basic Clock System Control 1
  27. uint8_t *BCSCTL1; // r/w, @0x57, POR: 0x87
  28. // Basic Clock System Control 2
  29. uint8_t *BCSCTL2; // r/w, @0x58, PUC: 0x0
  30. // Basic Clock System Control 3
  31. uint8_t *BCSCTL3; // r/w, @0x53, PUC: 0x5
  32. // SFR Interrupt Enable Register 1
  33. uint8_t *IE1; // r/w, @0x0, PUC: 0x0
  34. // SFR Interrupt Flag Register 1
  35. uint8_t *IFG1; // r/w, @0x2, PUC: 0x0
  36. // -----
  37. uint64_t dco_freq; // In Hz
  38. uint64_t dco_period; // In nanosecs
  39. uint64_t dco_pulse_width; // In nanosecs
  40. // ----
  41. uint8_t mclk_source;
  42. uint64_t mclk_div;
  43. uint64_t mclk_freq;
  44. };
  45. uint64_t nanosec_diff(struct timespec *timeA_p, struct timespec *timeB_p);
  46. void mclk_wait_cycles (Emulator *emu, uint64_t cycles);
  47. void smclk_wait_cycles (Emulator *emu, uint64_t cycles);
  48. void aclk_wait_cycles (Emulator *emu, uint64_t cycles);
  49. //void *DCO_source (void *data);
  50. void setup_bcm (Emulator *emu);
  51. void handle_bcm (Emulator *emu);
  52. #endif