platform.c 2.4 KB

1234567891011121314151617181920212223242526272829303132333435363738394041424344454647484950515253545556575859606162636465666768697071
  1. /****************************************************************************
  2. * Copyright 2021 Gorgon Meducer (Email:embedded_zhuoran@hotmail.com) *
  3. * *
  4. * Licensed under the Apache License, Version 2.0 (the "License"); *
  5. * you may not use this file except in compliance with the License. *
  6. * You may obtain a copy of the License at *
  7. * *
  8. * http://www.apache.org/licenses/LICENSE-2.0 *
  9. * *
  10. * Unless required by applicable law or agreed to in writing, software *
  11. * distributed under the License is distributed on an "AS IS" BASIS, *
  12. * WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied. *
  13. * See the License for the specific language governing permissions and *
  14. * limitations under the License. *
  15. * *
  16. ****************************************************************************/
  17. #include <stdio.h>
  18. #include <stdint.h>
  19. #include <stdbool.h>
  20. #include "perf_counter.h"
  21. #include "ARMCM0.h" // Keil::Board Support:V2M-MPS2:Common
  22. #include <assert.h>
  23. #include <RTE_Components.h>
  24. #if defined(RTE_Compiler_EventRecorder)
  25. # include <EventRecorder.h>
  26. #endif
  27. extern
  28. void uart_config(uint32_t wUARTFrequency);
  29. __attribute__((weak))
  30. void systimer_1ms_handler(void)
  31. {
  32. //assert(false);
  33. }
  34. static volatile uint32_t s_wMSCounter = 0;
  35. /*----------------------------------------------------------------------------
  36. SysTick / Timer0 IRQ Handler
  37. *----------------------------------------------------------------------------*/
  38. void SysTick_Handler (void)
  39. {
  40. if (s_wMSCounter) {
  41. s_wMSCounter--;
  42. }
  43. systimer_1ms_handler();
  44. }
  45. /*! \brief initialise platform before main()
  46. */
  47. __attribute__((constructor(101)))
  48. void platform_init(void)
  49. {
  50. SystemCoreClockUpdate();
  51. /* Generate interrupt each 1 ms */
  52. SysTick_Config(SystemCoreClock / 1000);
  53. #if defined(RTE_Compiler_EventRecorder) && defined(RTE_Compiler_IO_STDOUT_EVR)
  54. EventRecorderInitialize(0,1);
  55. #else
  56. uart_config(25000000ul);
  57. #endif
  58. }