osc.c 2.3 KB

1234567891011121314151617181920212223242526272829303132333435363738394041424344454647484950515253545556575859606162636465666768697071727374
  1. #include "hal.h"
  2. #include "uart/uart.h"
  3. #include "osc.h"
  4. #include "os_except.h"
  5. #define osc_hisr_TASK_PRIORITY 31 // osc_hisr must be the highest priority task of all tasks.
  6. /*
  7. *********************************************************************************************************
  8. * Overlay SRAM Controller (OSC) initialize
  9. *
  10. * Description : This function is called to initialize overlay SRAM controller,
  11. * including setting upfixed region size and overlay region base.
  12. *
  13. * Arguments :
  14. *
  15. * Notes :
  16. *********************************************************************************************************
  17. */
  18. void _osc_init(void)
  19. {
  20. register unsigned int ovly_region_szie;
  21. register unsigned int fix_regiion_size;
  22. register unsigned int ovly_region_base_addr;
  23. /* Read the initial OSC overlay region size. */
  24. ovly_region_szie = (REG32(OSC_CTRL) & OSC_CTRL_OVL_SZ_MASK) >> 12;
  25. /* Initialize OSC fix region size */
  26. fix_regiion_size = OSC_EILM_SIZE - ovly_region_szie;
  27. REG32(OSC_OVLFS) = fix_regiion_size;
  28. /* Initialize OSC overlay region to the end of all overlay text. */
  29. ovly_region_base_addr = fix_regiion_size + ovly_region_szie * _novlys;
  30. REG32(OSC_OVLBASE) = ovly_region_base_addr;
  31. }
  32. int _osc_drv_init(void (*handler)(unsigned int ipc),
  33. void (*osc_hisr)(void *arg),
  34. OSC_DRV_INFO *osc_info)
  35. {
  36. hal_queue_t *queue = &osc_info->queue;
  37. hal_thread_t *th = &osc_info->th;
  38. // Initial the Fixed/Overlap regions.
  39. _osc_init();
  40. // Register a user-define handler which is called from OSC exception handler.
  41. register_exception_handler(GE_RESERVED_INST, handler);
  42. // Register a user-define hisr which will be woken up by lisr sending msg to queue.
  43. th->fn = osc_hisr;
  44. th->name = "bh_osc";
  45. th->stack_size = 0x400;
  46. th->arg = queue;
  47. th->prio = osc_hisr_TASK_PRIORITY;
  48. th->task = NULL;
  49. th->ptos = NULL;
  50. // Create a bottom half.
  51. // The bottom half is a thread task with a sync queue.
  52. queue->size = 1;
  53. if(hal_create_queue(queue) == HAL_FAILURE)
  54. return HAL_FAILURE;
  55. if(hal_create_thread(th) != HAL_SUCCESS)
  56. return HAL_FAILURE;
  57. puts("OSC driver init success!\n");
  58. return HAL_SUCCESS;
  59. }