?? timer.c
字號:
/* * dspapps/dsp/task_testB/timer.c * * DSP timer module * * Copyright (C) 2003 Nokia Corporation * * Written by Toshihiro Kobayashi <toshihiro.kobayashi@nokia.com> * * This program is free software; you can redistribute it and/or modify * it under the terms of the GNU General Public License as published by * the Free Software Foundation; either version 2 of the License, or * (at your option) any later version. * * This program is distributed in the hope that it will be useful, * but WITHOUT ANY WARRANTY; without even the implied warranty of * MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the * GNU General Public License for more details. * * You should have received a copy of the GNU General Public License * along with this program; if not, write to the Free Software * Foundation, Inc., 59 Temple Place, Suite 330, Boston, MA 02111-1307 USA * * $Id: timer.c * $Revision: 2.0 * $Date: 2003/11/11 * */#include <std.h>#include <hwi.h>#include <tsk.h>#include <mem.h>#include "omap1510.h"#include "list.h"#include "tokliBIOSlib.h"#define __timer1_start() \ do {\ outw(inw(_CNTL_TIMER1) | _CNTL_TIMERn_BIT_ST,\ _CNTL_TIMER1);\ } while(0)#define __timer1_stop() \ do {\ outw(inw(_CNTL_TIMER1) & ~_CNTL_TIMERn_BIT_ST,\ _CNTL_TIMER1);\ } while(0)#ifndef TQ_USE_MALLOCstatic struct procq tq_1s_pool[TQ_MAX];#endifLIST_HEAD(tq_1s);/* * Timer1 is configured in DSP/BIOS configuration, * but we want to set it not to be changed by DSP domain clock * frequency. * Therefore, we need set it up again here. */Void init_timer(Void){ LgUns ldval; __timer1_stop(); // 12MHz for timer clock outw(inw(_DSP_CKCTL) & ~_DSP_CKCTL_BIT_TIMXO, _DSP_CKCTL);// // enable timer clock// outw(inw(_DSP_IDLECT2) | _DSP_IDLECT2_BIT_EN_TIMCK,// _DSP_IDLECT2); // Autoload mode, PTV=0 ldval = 12000000L/2/100; // 1/100 s outw(ldval>>16, _LOAD_TIM_HI1); outw(ldval&0xffff, _LOAD_TIM_LO1); outw(_CNTL_TIMERn_BIT_AR | _CNTL_TIMERn_BIT_PTV(0) | _CNTL_TIMERn_BIT_CLOCK_ENABLE, _CNTL_TIMER1); __timer1_start();}Void timer1_start(Void){ __timer1_start();}Void timer1_stop(Void){ __timer1_stop();}Void init_tq(Void){#ifndef TQ_USE_MALLOC Int i; for(i=0; i<TQ_MAX; i++) { tq_1s_pool[i].tid = MBCMD_TID_FREE; }#endif /* TQ_USE_MALLOC */}Void *register_tq_1s(struct dsptask *task, Uns (*f)(struct dsptask *task)){ struct procq *new; Uns intm_saved;#ifdef TQ_USE_MALLOC new = MEM_alloc(MEM->MALLOCSEG, sizeof(struct procq), 2); if(new == MEM_ILLEGAL) return MEM_ILLEGAL; new->func = f; new->tid = task->tid; intm_saved = HWI_disable(); list_add_tail((struct list_head *)new, &tq_1s); HWI_restore(intm_saved);#else /* TQ_USE_MALLOC */ Int i; intm_saved = HWI_disable(); for(i=0; i<TQ_MAX; i++) { if(tq_1s_pool[i].tid == MBCMD_TID_FREE) { new = &tq_1s_pool[i]; goto add; } } HWI_restore(intm_saved); return MEM_ILLEGAL;add: new->func = f; new->tid = task->tid; list_add_tail((struct list_head *)new, &tq_1s); HWI_restore(intm_saved);#endif /* TQ_USE_MALLOC */ return new;}Void unregister_tq_1s(struct dsptask *task, Void *id){ struct list_head *p; Uns intm_saved; intm_saved = HWI_disable(); list_for_each(p, &tq_1s) { if(p == id) { list_del(p); break; } } HWI_restore(intm_saved);#ifdef TQ_USE_MALLOC MEM_free(MEM->MALLOCSEG, id, sizeof(struct procq));#else ((struct procq*)id)->tid = MBCMD_TID_FREE;#endif}/* * PRD functions */Void prd_10ms(Void){ TSK_yield();}Void prd_1s(Void){ struct list_head *p, *next; Uns eid;#ifdef DEBUG_WAKEUP_CNT LgUns wakeup_cnt;#endif /* DEBUG_WAKEUP_CNT */ /* * Do not use list_for_each(). * We must hold p->next before calling func() * in order to allow the queue to suicide * (i.e. call unregister() itself in func().) */ for(p = tq_1s.next; p != &tq_1s; p = next) { struct procq *pq = (struct procq *)p; Uns tid = pq->tid; next = p->next; eid = pq->func(dsptask[tid]); /* * after func(), we shold not to access p or pq * because it can be deleted! */ if(eid) { sys_cmderr(eid, mbcmd(0,tid)); } }#ifdef DEBUG_WAKEUP_CNT if((wakeup_cnt = get_wakeup_cnt()) > 0) { mbsend(mbcmd(MBCMD_ERR, MBCMD_EID_DEBUG), wakeup_cnt>>16); mbsend(mbcmd(MBCMD_ERR, MBCMD_EID_DEBUG), wakeup_cnt&0xffff); clear_wakeup_cnt(); }#endif /* DEBUG_WAKEUP_CNT */}
?? 快捷鍵說明
復制代碼
Ctrl + C
搜索代碼
Ctrl + F
全屏模式
F11
切換主題
Ctrl + Shift + D
顯示快捷鍵
?
增大字號
Ctrl + =
減小字號
Ctrl + -