| 1 | /*************************************************************** |
|---|
| 2 | ** |
|---|
| 3 | ** Broadcom Corp. Confidential |
|---|
| 4 | ** Copyright 1998-2000 Broadcom Corp. All Rights Reserved. |
|---|
| 5 | ** |
|---|
| 6 | ** THIS SOFTWARE MAY ONLY BE USED SUBJECT TO AN EXECUTED |
|---|
| 7 | ** SOFTWARE LICENSE AGREEMENT BETWEEN THE USER AND BROADCOM. |
|---|
| 8 | ** YOU HAVE NO RIGHT TO USE OR EXPLOIT THIS MATERIAL EXCEPT |
|---|
| 9 | ** SUBJECT TO THE TERMS OF SUCH AN AGREEMENT. |
|---|
| 10 | ** |
|---|
| 11 | ** File: bos.h |
|---|
| 12 | ** Description: Encapsulate OS functions. |
|---|
| 13 | ** |
|---|
| 14 | ** Created: Mon Sep 25 18:12:35 PDT 2006 by Jeff Fisher |
|---|
| 15 | ** |
|---|
| 16 | ****************************************************************/ |
|---|
| 17 | |
|---|
| 18 | #ifndef __BOS_H__ |
|---|
| 19 | #define __BOS_H__ |
|---|
| 20 | |
|---|
| 21 | #include "bstd.h" |
|---|
| 22 | #define bresult BERR_Code |
|---|
| 23 | #define berr_invalid_parameter BERR_INVALID_PARAMETER |
|---|
| 24 | #define berr_out_of_memory BERR_OUT_OF_DEVICE_MEMORY |
|---|
| 25 | #define berr_external_error BERR_OS_ERROR |
|---|
| 26 | #define berr_timeout BERR_TIMEOUT |
|---|
| 27 | #define b_ok BERR_SUCCESS |
|---|
| 28 | #define berr_not_supported BERR_NOT_SUPPORTED |
|---|
| 29 | #define berr_not_available BERR_NOT_INITIALIZED |
|---|
| 30 | |
|---|
| 31 | #define TICKS_TO_MS(ticks) ((ticks) * 1000/g_ticks_per_second) |
|---|
| 32 | #define MS_TO_TICKS(x) (((x) * g_ticks_per_second)/ 1000) |
|---|
| 33 | #define MEM_SIZE_8M (0x0800000) |
|---|
| 34 | #define MEM_SIZE_16M (0x1000000) |
|---|
| 35 | #define MEM_SIZE_32M (0x2000000) |
|---|
| 36 | #define MEM_SIZE_64M (0x4000000) |
|---|
| 37 | |
|---|
| 38 | #define BOS_PEND_FOREVER (-1) |
|---|
| 39 | typedef enum b_trace_evt_t |
|---|
| 40 | { |
|---|
| 41 | eTRACE_THREAD_CREATE, |
|---|
| 42 | eTRACE_SCHED, |
|---|
| 43 | eTRACE_TICK, |
|---|
| 44 | eTRACE_INT, |
|---|
| 45 | eTRACE_INT_TRACE, |
|---|
| 46 | eTRACE_USER, |
|---|
| 47 | }b_trace_evt_t; |
|---|
| 48 | |
|---|
| 49 | typedef struct b_timeval |
|---|
| 50 | { |
|---|
| 51 | unsigned int tv_sec; /* seconds */ |
|---|
| 52 | unsigned int tv_usec; /* microseconds */ |
|---|
| 53 | }b_timeval; |
|---|
| 54 | |
|---|
| 55 | typedef struct b_task_params |
|---|
| 56 | { |
|---|
| 57 | uint16_t priority; /* 0 is highest, 63 lowest */ |
|---|
| 58 | uint16_t stack_size; /* stack size in words */ |
|---|
| 59 | unsigned int *stack; /* buffer to be used for thread stack */ |
|---|
| 60 | const char *name; /* thread name */ |
|---|
| 61 | } b_task_params; |
|---|
| 62 | |
|---|
| 63 | typedef struct b_task_stats { |
|---|
| 64 | unsigned clock_cnt; /* number of CPU clocks spent in the task */ |
|---|
| 65 | unsigned instr_cnt; /* perf count 3 (instructions) */ |
|---|
| 66 | uint16_t active_cnt; /* number of context switches into a task */ |
|---|
| 67 | uint16_t stack_size; |
|---|
| 68 | b_timeval last_time; |
|---|
| 69 | const uint32_t *stack; /* pointer to the stack array, it points past the last usable entry in the stack */ |
|---|
| 70 | uint16_t stack_left; |
|---|
| 71 | uint8_t stack_fast_scan; |
|---|
| 72 | char name[16]; /* task name */ |
|---|
| 73 | } b_task_stats; |
|---|
| 74 | |
|---|
| 75 | extern struct b_task_stats g_os_task_stats[]; |
|---|
| 76 | |
|---|
| 77 | typedef unsigned int b_task_t; |
|---|
| 78 | typedef unsigned int b_queue_t; |
|---|
| 79 | typedef unsigned int b_event_t; |
|---|
| 80 | typedef struct b_mutex_t |
|---|
| 81 | { |
|---|
| 82 | b_queue_t queue; |
|---|
| 83 | b_event_t event_queue; |
|---|
| 84 | b_event_t event; |
|---|
| 85 | }b_mutex_t; |
|---|
| 86 | |
|---|
| 87 | typedef struct b_clock { |
|---|
| 88 | uint32_t clock_hi; |
|---|
| 89 | uint32_t clock_low; |
|---|
| 90 | unsigned clock_freq; |
|---|
| 91 | } b_clock; |
|---|
| 92 | |
|---|
| 93 | |
|---|
| 94 | typedef struct b_cpu_load { |
|---|
| 95 | unsigned duration; /* number of miliseconds from last measurement */ |
|---|
| 96 | unsigned idle; /* percent of ticks that CPU is idle */ |
|---|
| 97 | unsigned isr; /* percent of ticks spent in the ISR */ |
|---|
| 98 | unsigned ctxsw_rate; /* number of contextt switches per second */ |
|---|
| 99 | unsigned isr_rate; /* number of interrupts per second */ |
|---|
| 100 | unsigned isr_us; /* number of micro seconds spent in isr */ |
|---|
| 101 | } b_cpu_load; |
|---|
| 102 | |
|---|
| 103 | typedef struct b_system_globals_t |
|---|
| 104 | { |
|---|
| 105 | unsigned int b_ticks_per_second; |
|---|
| 106 | unsigned int b_cycles_per_tick; |
|---|
| 107 | b_clock b_running_clock; |
|---|
| 108 | bool b_in_interrupt; |
|---|
| 109 | unsigned int stat_isr_cnt; |
|---|
| 110 | unsigned int stat_isr_time; |
|---|
| 111 | }b_system_globals_t; |
|---|
| 112 | |
|---|
| 113 | typedef void (*b_task_func)(void *pd); |
|---|
| 114 | |
|---|
| 115 | void bos_init(void); |
|---|
| 116 | void bos_start(void); |
|---|
| 117 | bresult bos_start_task( b_task_t *handle, const b_task_params *params, b_task_func func, void *data ); |
|---|
| 118 | void bos_stop_task(b_task_t handle); |
|---|
| 119 | bresult bos_create_queue( b_queue_t *handle, b_event_t *events, int num_events ); |
|---|
| 120 | void bos_delete_queue( b_queue_t *handle ); |
|---|
| 121 | bresult bos_post_event( b_queue_t handle, b_event_t *event ); |
|---|
| 122 | b_event_t *bos_pend_event( b_queue_t handle, int timeout_ms ); |
|---|
| 123 | bresult bos_create_mutex( b_mutex_t *handle ); |
|---|
| 124 | void bos_delete_mutex( b_mutex_t *handle ); |
|---|
| 125 | bresult bos_acquire_mutex( b_mutex_t *handle, int timeout_ms ); |
|---|
| 126 | bresult bos_release_mutex( b_mutex_t *handle ); |
|---|
| 127 | void bos_sleep( unsigned int sleep_ms ); |
|---|
| 128 | unsigned int bos_getticks( void ); |
|---|
| 129 | void bos_getclock(b_clock *clock); |
|---|
| 130 | unsigned int bos_enter_critical(void); |
|---|
| 131 | void bos_exit_critical(unsigned int flags); |
|---|
| 132 | void bos_getload(b_cpu_load *load); |
|---|
| 133 | void bos_calibrate(void); |
|---|
| 134 | void bos_trace(b_trace_evt_t evt, unsigned char in, unsigned char out, unsigned int data); |
|---|
| 135 | void bos_print_taskinfo(void); |
|---|
| 136 | void gdb_handler(unsigned int regs[],unsigned int cause); |
|---|
| 137 | const void *bos_task_from_stack(const uint32_t *stack); |
|---|
| 138 | |
|---|
| 139 | unsigned int bos_ram_size(void); |
|---|
| 140 | |
|---|
| 141 | #if SUPPORT_DST_PLATFORM |
|---|
| 142 | b_task_stats *bos_get_task_info(b_task_t id);/*neverdai add 080825*/ |
|---|
| 143 | void stack_backtrace(unsigned int *r_sp, unsigned int *r_pc, unsigned int *r_ra, const char *prefix);/* cafrii 081006 add. it is defined in gdb_nub.c */ |
|---|
| 144 | #endif |
|---|
| 145 | |
|---|
| 146 | extern b_system_globals_t *g_p_dsp; |
|---|
| 147 | |
|---|
| 148 | /* g_ticks_per_second must match your os configuration */ |
|---|
| 149 | #ifdef LINUX |
|---|
| 150 | #define g_ticks_per_second 1000 |
|---|
| 151 | #else |
|---|
| 152 | #define g_ticks_per_second 200 |
|---|
| 153 | #endif |
|---|
| 154 | #define g_cycles_per_tick g_p_dsp->b_cycles_per_tick |
|---|
| 155 | #define g_running_clock g_p_dsp->b_running_clock |
|---|
| 156 | #define bos_in_interrupt() g_p_dsp->b_in_interrupt |
|---|
| 157 | #define g_stat_isr_cnt g_p_dsp->stat_isr_cnt |
|---|
| 158 | #define g_stat_isr_time g_p_dsp->stat_isr_time |
|---|
| 159 | |
|---|
| 160 | #endif /* __BOS_H__ */ |
|---|