bcm.h 2.0 KB

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