bcm.h 2.0 KB

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