source: svn/trunk/newcon3bcm2_21bu/dta/src/bos.h

Last change on this file was 2, checked in by phkim, 11 years ago

1.phkim

  1. revision copy newcon3sk r27
  • Property svn:executable set to *
File size: 5.1 KB
Line 
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)
39typedef 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
49typedef struct b_timeval
50{
51           unsigned int         tv_sec;         /* seconds */
52           unsigned int                 tv_usec;                /* microseconds */
53}b_timeval;
54
55typedef 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
63typedef 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
75extern struct b_task_stats g_os_task_stats[];
76
77typedef unsigned int b_task_t;
78typedef unsigned int b_queue_t;
79typedef unsigned int b_event_t;
80typedef 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
87typedef struct b_clock {
88        uint32_t clock_hi;
89        uint32_t clock_low;
90        unsigned clock_freq;
91} b_clock;
92
93
94typedef 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
103typedef 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
113typedef void (*b_task_func)(void *pd);
114
115void bos_init(void);
116void bos_start(void);
117bresult bos_start_task( b_task_t *handle, const b_task_params *params, b_task_func func,  void *data );
118void bos_stop_task(b_task_t handle);
119bresult bos_create_queue(  b_queue_t *handle, b_event_t *events, int num_events );
120void bos_delete_queue(  b_queue_t *handle );
121bresult bos_post_event( b_queue_t handle, b_event_t *event );
122b_event_t *bos_pend_event( b_queue_t handle, int timeout_ms );
123bresult bos_create_mutex( b_mutex_t *handle );
124void bos_delete_mutex( b_mutex_t *handle );
125bresult bos_acquire_mutex( b_mutex_t *handle, int timeout_ms  );
126bresult bos_release_mutex( b_mutex_t *handle );
127void bos_sleep( unsigned int sleep_ms );
128unsigned int bos_getticks( void );
129void bos_getclock(b_clock *clock);
130unsigned int bos_enter_critical(void);
131void bos_exit_critical(unsigned int flags);
132void bos_getload(b_cpu_load *load);
133void bos_calibrate(void);
134void bos_trace(b_trace_evt_t evt, unsigned char in, unsigned char out, unsigned int data);
135void bos_print_taskinfo(void);
136void gdb_handler(unsigned int regs[],unsigned int cause);
137const void *bos_task_from_stack(const uint32_t *stack);
138
139unsigned int bos_ram_size(void);
140
141#if SUPPORT_DST_PLATFORM
142b_task_stats *bos_get_task_info(b_task_t id);/*neverdai add 080825*/
143void 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
146extern 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__ */
Note: See TracBrowser for help on using the repository browser.