/*************************************************************** ** ** Broadcom Corp. Confidential ** Copyright 1998-2000 Broadcom Corp. All Rights Reserved. ** ** THIS SOFTWARE MAY ONLY BE USED SUBJECT TO AN EXECUTED ** SOFTWARE LICENSE AGREEMENT BETWEEN THE USER AND BROADCOM. ** YOU HAVE NO RIGHT TO USE OR EXPLOIT THIS MATERIAL EXCEPT ** SUBJECT TO THE TERMS OF SUCH AN AGREEMENT. ** ** File: bos.h ** Description: Encapsulate OS functions. ** ** Created: Mon Sep 25 18:12:35 PDT 2006 by Jeff Fisher ** ****************************************************************/ #ifndef __BOS_H__ #define __BOS_H__ #include "bstd.h" #define bresult BERR_Code #define berr_invalid_parameter BERR_INVALID_PARAMETER #define berr_out_of_memory BERR_OUT_OF_DEVICE_MEMORY #define berr_external_error BERR_OS_ERROR #define berr_timeout BERR_TIMEOUT #define b_ok BERR_SUCCESS #define berr_not_supported BERR_NOT_SUPPORTED #define berr_not_available BERR_NOT_INITIALIZED #define TICKS_TO_MS(ticks) ((ticks) * 1000/g_ticks_per_second) #define MS_TO_TICKS(x) (((x) * g_ticks_per_second)/ 1000) #define MEM_SIZE_8M (0x0800000) #define MEM_SIZE_16M (0x1000000) #define MEM_SIZE_32M (0x2000000) #define MEM_SIZE_64M (0x4000000) #define BOS_PEND_FOREVER (-1) typedef enum b_trace_evt_t { eTRACE_THREAD_CREATE, eTRACE_SCHED, eTRACE_TICK, eTRACE_INT, eTRACE_INT_TRACE, eTRACE_USER, }b_trace_evt_t; typedef struct b_timeval { unsigned int tv_sec; /* seconds */ unsigned int tv_usec; /* microseconds */ }b_timeval; typedef struct b_task_params { uint16_t priority; /* 0 is highest, 63 lowest */ uint16_t stack_size; /* stack size in words */ unsigned int *stack; /* buffer to be used for thread stack */ const char *name; /* thread name */ } b_task_params; typedef struct b_task_stats { unsigned clock_cnt; /* number of CPU clocks spent in the task */ unsigned instr_cnt; /* perf count 3 (instructions) */ uint16_t active_cnt; /* number of context switches into a task */ uint16_t stack_size; b_timeval last_time; const uint32_t *stack; /* pointer to the stack array, it points past the last usable entry in the stack */ uint16_t stack_left; uint8_t stack_fast_scan; char name[16]; /* task name */ } b_task_stats; extern struct b_task_stats g_os_task_stats[]; typedef unsigned int b_task_t; typedef unsigned int b_queue_t; typedef unsigned int b_event_t; typedef struct b_mutex_t { b_queue_t queue; b_event_t event_queue; b_event_t event; }b_mutex_t; typedef struct b_clock { uint32_t clock_hi; uint32_t clock_low; unsigned clock_freq; } b_clock; typedef struct b_cpu_load { unsigned duration; /* number of miliseconds from last measurement */ unsigned idle; /* percent of ticks that CPU is idle */ unsigned isr; /* percent of ticks spent in the ISR */ unsigned ctxsw_rate; /* number of contextt switches per second */ unsigned isr_rate; /* number of interrupts per second */ unsigned isr_us; /* number of micro seconds spent in isr */ } b_cpu_load; typedef struct b_system_globals_t { unsigned int b_ticks_per_second; unsigned int b_cycles_per_tick; b_clock b_running_clock; bool b_in_interrupt; unsigned int stat_isr_cnt; unsigned int stat_isr_time; }b_system_globals_t; typedef void (*b_task_func)(void *pd); void bos_init(void); void bos_start(void); bresult bos_start_task( b_task_t *handle, const b_task_params *params, b_task_func func, void *data ); void bos_stop_task(b_task_t handle); bresult bos_create_queue( b_queue_t *handle, b_event_t *events, int num_events ); void bos_delete_queue( b_queue_t *handle ); bresult bos_post_event( b_queue_t handle, b_event_t *event ); b_event_t *bos_pend_event( b_queue_t handle, int timeout_ms ); bresult bos_create_mutex( b_mutex_t *handle ); void bos_delete_mutex( b_mutex_t *handle ); bresult bos_acquire_mutex( b_mutex_t *handle, int timeout_ms ); bresult bos_release_mutex( b_mutex_t *handle ); void bos_sleep( unsigned int sleep_ms ); unsigned int bos_getticks( void ); void bos_getclock(b_clock *clock); unsigned int bos_enter_critical(void); void bos_exit_critical(unsigned int flags); void bos_getload(b_cpu_load *load); void bos_calibrate(void); void bos_trace(b_trace_evt_t evt, unsigned char in, unsigned char out, unsigned int data); void bos_print_taskinfo(void); void gdb_handler(unsigned int regs[],unsigned int cause); const void *bos_task_from_stack(const uint32_t *stack); unsigned int bos_ram_size(void); #if SUPPORT_DST_PLATFORM b_task_stats *bos_get_task_info(b_task_t id);/*neverdai add 080825*/ 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 */ #endif extern b_system_globals_t *g_p_dsp; /* g_ticks_per_second must match your os configuration */ #ifdef LINUX #define g_ticks_per_second 1000 #else #define g_ticks_per_second 200 #endif #define g_cycles_per_tick g_p_dsp->b_cycles_per_tick #define g_running_clock g_p_dsp->b_running_clock #define bos_in_interrupt() g_p_dsp->b_in_interrupt #define g_stat_isr_cnt g_p_dsp->stat_isr_cnt #define g_stat_isr_time g_p_dsp->stat_isr_time #endif /* __BOS_H__ */