📄 sh7145sci.c
字号:
/* * TOPPERS/JSP Kernel * Toyohashi Open Platform for Embedded Real-Time Systems/ * Just Standard Profile Kernel * * Copyright (C) 2000-2003 by Embedded and Real-Time Systems Laboratory * Toyohashi Univ. of Technology, JAPAN * Copyright (C) 2001-2003 by Industrial Technology Institute, * Miyagi Prefectural Government, JAPAN * Copyright (C) 2002-2004 by Hokkaido Industrial Research Institute, JAPAN * * 惧淡螟侯涪荚は·笆布の (1)×(4) の掘凤か·Free Software Foundation * によって给山されている GNU General Public License の Version 2 に淡 * 揭されている掘凤を塔たす眷圭に嘎り·塑ソフトウェア∈塑ソフトウェア * を猖恃したものを崔むˉ笆布票じ∷を蝗脱ˇ剩澜ˇ猖恃ˇ浩芹邵∈笆布· * 网脱と钙ぶ∷することを痰浸で钓满するˉ * (1) 塑ソフトウェアをソ〖スコ〖ドの妨で网脱する眷圭には·惧淡の螟侯 * 涪山绩·この网脱掘凤および布淡の痰瘦沮惮年が·そのままの妨でソ〖 * スコ〖ド面に崔まれていることˉ * (2) 塑ソフトウェアを·ライブラリ妨及など·戮のソフトウェア倡券に蝗 * 脱できる妨で浩芹邵する眷圭には·浩芹邵に燃うドキュメント∈网脱 * 荚マニュアルなど∷に·惧淡の螟侯涪山绩·この网脱掘凤および布淡 * の痰瘦沮惮年を非很することˉ * (3) 塑ソフトウェアを·怠达に寥み哈むなど·戮のソフトウェア倡券に蝗 * 脱できない妨で浩芹邵する眷圭には·肌のいずれかの掘凤を塔たすこ * とˉ * (a) 浩芹邵に燃うドキュメント∈网脱荚マニュアルなど∷に·惧淡の螟 * 侯涪山绩·この网脱掘凤および布淡の痰瘦沮惮年を非很することˉ * (b) 浩芹邵の妨轮を·侍に年める数恕によって·TOPPERSプロジェクトに * 鼠桂することˉ * (4) 塑ソフトウェアの网脱により木儡弄または粗儡弄に栏じるいかなる禄 * 巢からも·惧淡螟侯涪荚およびTOPPERSプロジェクトを倘勒することˉ * * 塑ソフトウェアは·痰瘦沮で捏丁されているものであるˉ惧淡螟侯涪荚お * よびTOPPERSプロジェクトは·塑ソフトウェアに簇して·その努脱材墙拉も * 崔めて·いかなる瘦沮も乖わないˉまた·塑ソフトウェアの网脱により木 * 儡弄または粗儡弄に栏じたいかなる禄巢に簇しても·その勒扦を砷わないˉ * * @(#) $Id: sh7145sci.c,v 1.3 2005/07/06 00:45:07 honda Exp $ *//* * SH2柒垄シリアルコミュニケ〖ションインタフェ〖スSCI脱 词白ドライバ */#include <s_services.h>#include "sh7145sci.h"/* * シリアルI/Oポ〖ト介袋步ブロック */#ifndef GDB_STUBconst SIOPINIB siopinib_table[TNUM_PORT] = { {0xffff81b0, BRR9600, 0x0, 6}, /* SCI1 */#if TNUM_PORT >= 2 {0xffff81a0, BRR9600, 0x0, 6}, /* SCI0 */#endif /* TNUM_PORT >= 2 */};#else /* GDB_STUB */const SIOPINIB siopinib_table[TNUM_PORT] = { {0xffff81a0, BRR9600, 0x0, 6}, /* SCI0 */};#endif /* GDB_STUB *//* * シリアルI/Oポ〖ト瓷妄ブロックのエリア */static SIOPCB siopcb_table[TNUM_PORT];/* * シリアルI/Oポ〖トIDから瓷妄ブロックを艰り叫すためのマクロ */ /* ポ〖トIDからデバイス戎规を滇めるマクロ */#define INDEX_SIOP(siopid) ((UINT)((siopid) - 1))#define get_siopcb(siopid) (&(siopcb_table[INDEX_SIOP(siopid)]))/* * 矢机を减慨できるか々 */Inline BOOLsh2sci_getready (SIOPCB * siopcb){ /* レシ〖ブデ〖タレジスタフルˇフラグのチェック */ return (sil_reb_mem ((VB *) (siopcb->siopinib->reg_base + SCI_SSR)) & SSR_RDRF);}/* * 矢机を流慨できるか々 */Inline BOOLsh2sci_putready (SIOPCB * siopcb){ /* トランスミットデ〖タレジスタエンプティˇフラグのチェック */ return (sil_reb_mem ((VB *) (siopcb->siopinib->reg_base + SCI_SSR)) & SSR_TDRE);}/* * 减慨した矢机の艰叫し */Inline charsh2sci_getchar (SIOPCB * siopcb){ char data; data = sil_reb_mem ((VB *) (siopcb->siopinib->reg_base + SCI_RDR)); /* レシ〖ブデ〖タレジスタフルˇフラグのクリア */ sil_wrb_mem ((VB *) (siopcb->siopinib->reg_base + SCI_SSR), sil_reb_mem ((VB *) (siopcb->siopinib->reg_base + SCI_SSR)) & ~SSR_RDRF); return data;}/* * 流慨する矢机の今哈み */Inline voidsh2sci_putchar (SIOPCB * siopcb, char c){ sil_wrb_mem ((VB *) (siopcb->siopinib->reg_base + SCI_TDR), c); sil_wrb_mem ((VB *) (siopcb->siopinib->reg_base + SCI_SSR), sil_reb_mem ((VB *) (siopcb->siopinib->reg_base + SCI_SSR)) & ~SSR_TDRE);}/* * SIOドライバの介袋步ル〖チン */voidsh2sci_initialize (){ SIOPCB *siopcb; UINT i; /* * シリアルI/Oポ〖ト瓷妄ブロックの介袋步 */ for (siopcb = siopcb_table, i = 0; i < TNUM_PORT; siopcb++, i++) { siopcb->openflag = FALSE; siopcb->siopinib = (&siopinib_table[i]); }}/* * オ〖プンしているポ〖トがあるか々 */BOOLsh2sci_openflag (ID siopid){ return (siopcb_table[siopid - 1].openflag);}/* * シリアルI/Oポ〖トのオ〖プン */SIOPCB *sh2sci_opn_por (ID siopid, VP_INT exinf){ SIOPCB *siopcb = get_siopcb (siopid); /* 流减慨匿贿 */ sil_wrb_mem ((VB *) (siopcb->siopinib->reg_base + SCI_SCR), 0x00); /* SCIデ〖タ掐叫蜗ポ〖トの肋年 */ /* ピンアサイン */ /* sys_initializeで肋年 */ /* 流减慨フォ〖マット */ /* 拇殊票袋及 */ /* 8ビット、パリティなし */ /* ストップビットレングス¨1 */ /* クロックセレクト */ sil_wrb_mem ((VB *) (siopcb->siopinib->reg_base + SCI_SMR), siopcb->siopinib->smr); sil_wrb_mem ((VB *) (siopcb->siopinib->reg_base + SCI_BRR), (VB) siopcb->siopinib->brr); /* * ボ〖レ〖トの肋年稿、1カウント尸略たなければならない。 */ sil_dly_nse (sh2sci_DELAY); /* 猛はsh1と票じ */ /* エラ〖フラグをクリア */ sil_wrb_mem ((VB *) (siopcb->siopinib->reg_base + SCI_SSR), sil_reb_mem ((VB *) (siopcb->siopinib->reg_base + SCI_SSR)) & ~(SSR_ORER | SSR_FER | SSR_PER)); /*流减慨钓材、减慨充り哈み钓材 */ sil_wrb_mem ((VB *) (siopcb->siopinib->reg_base + SCI_SCR), (VB) (SCI_RIE | SCI_TE | SCI_RE)); siopcb->exinf = exinf; siopcb->openflag = TRUE; return (siopcb);}/* * シリアルI/Oポ〖トのクロ〖ズ */voidsh2sci_cls_por (SIOPCB * siopcb){ /* 流减慨匿贿、充哈み敦贿 */ sil_wrb_mem ((VB *) (siopcb->siopinib->reg_base + SCI_SCR), sil_reb_mem ((VB *) (siopcb->siopinib->reg_base + SCI_SCR)) & (VB) ~ (SCI_TIE | SCI_RIE | SCI_TE | SCI_RE)); siopcb->openflag = FALSE;}/* * シリアルI/Oポ〖トへの矢机流慨 */BOOLsh2sci_snd_chr (SIOPCB * siopcb, char c){ if (sh2sci_putready (siopcb)) { sh2sci_putchar (siopcb, c); return (TRUE); } return (FALSE);}/* * シリアルI/Oポ〖トからの矢机减慨 */INTsh2sci_rcv_chr (SIOPCB * siopcb){ if (sh2sci_getready (siopcb)) { return ((INT) (UB) sh2sci_getchar (siopcb)); /* (UB)でキャストするのはゼロ橙磨にするため */ } return (-1);}/* * シリアルI/Oポ〖トからのコ〖ルバックの钓材 */voidsh2sci_ena_cbr (SIOPCB * siopcb, UINT cbrtn){ switch (cbrtn) { case SIO_ERDY_SND: /* 流慨充り哈み妥滇を钓材 */ sil_wrb_mem ((VB *) (siopcb->siopinib->reg_base + SCI_SCR), sil_reb_mem ((VB *) (siopcb->siopinib->reg_base + SCI_SCR)) | SCI_TIE); break; case SIO_ERDY_RCV: /* 减慨充り哈み妥滇を钓材 */ sil_wrb_mem ((VB *) (siopcb->siopinib->reg_base + SCI_SCR), sil_reb_mem ((VB *) (siopcb->siopinib->reg_base + SCI_SCR)) | SCI_RIE); break; }}/* * シリアルI/Oポ〖トからのコ〖ルバックの敦贿 */voidsh2sci_dis_cbr (SIOPCB * siopcb, UINT cbrtn){ switch (cbrtn) { case SIO_ERDY_SND: /* 流慨充り哈み妥滇を敦贿 */ sil_wrb_mem ((VB *) (siopcb->siopinib->reg_base + SCI_SCR), sil_reb_mem ((VB *) (siopcb->siopinib->reg_base + SCI_SCR)) & ~SCI_TIE); break; case SIO_ERDY_RCV: /* 减慨充り哈み妥滇を敦贿 */ sil_wrb_mem ((VB *) (siopcb->siopinib->reg_base + SCI_SCR), sil_reb_mem ((VB *) (siopcb->siopinib->reg_base + SCI_SCR)) & ~SCI_RIE); break; }}/* * シリアルI/Oポ〖トに滦する流慨充哈み借妄 */Inline voidsh2sci_isr_siop_out (SIOPCB * siopcb){ VB scr0 = sil_reb_mem ((VB *) (siopcb->siopinib->reg_base + SCI_SCR)); if ((scr0 & SCI_TIE) != 0 && sh2sci_putready (siopcb)) { /* * 流慨奶梦コ〖ルバックル〖チンを钙び叫すˉ */ sh2sci_ierdy_snd (siopcb->exinf); }}/* * シリアルI/Oポ〖トに滦する减慨充哈み借妄 */Inline voidsh2sci_isr_siop_in (SIOPCB * siopcb){ VB scr0 = sil_reb_mem ((VB *) (siopcb->siopinib->reg_base + SCI_SCR)); if ((scr0 & SCI_RIE) != 0 && sh2sci_getready (siopcb)) { /* * 减慨奶梦コ〖ルバックル〖チンを钙び叫すˉ */ sh2sci_ierdy_rcv (siopcb->exinf); }}/* * シリアルI/Oポ〖トに滦する减慨エラ〖充哈み借妄 */Inline voidsh2sci_isr_siop_err (SIOPCB * siopcb){ sil_wrb_mem ((VB *) (siopcb->siopinib->reg_base + SCI_SSR), sil_reb_mem ((VB *) (siopcb->siopinib->reg_base + SCI_SSR)) & ~(SSR_ORER | SSR_FER | SSR_PER));}/* * SCI流慨充哈みサ〖ビスル〖チン * */voidsh2sci_isr_out (void){ if (siopcb_table[0].openflag) { sh2sci_isr_siop_out (get_siopcb (1)); }}/* * SIO减慨充哈みサ〖ビスル〖チン * */voidsh2sci_isr_in (void){ if (siopcb_table[0].openflag) { sh2sci_isr_siop_in (get_siopcb (1)); }}/* * SIO减慨エラ〖充哈みサ〖ビスル〖チン */voidsh2sci_isr_error (void){ if (siopcb_table[0].openflag) { sh2sci_isr_siop_err (get_siopcb (1)); }}/* * ポ〖リングによる矢机の流慨 */voidsh2sci_putc_pol (ID portid, char c){ while (!sh2sci_putready (&siopcb_table[portid - 1])); sh2sci_putchar (&siopcb_table[portid - 1], c);}#if TNUM_PORT >= 2/* * SIO减慨充哈みサ〖ビスル〖チン * */voidsh2sci_isr2_in (void){ if (siopcb_table[1].openflag) { sh2sci_isr_siop_in (get_siopcb (2)); }}/* * SCI流慨充哈みサ〖ビスル〖チン * */voidsh2sci_isr2_out (void){ if (siopcb_table[1].openflag) { sh2sci_isr_siop_out (get_siopcb (2)); }}/* * SIO减慨エラ〖充哈みサ〖ビスル〖チン */voidsh2sci_isr2_error (void){ if (siopcb_table[1].openflag) { sh2sci_isr_siop_err (get_siopcb (2)); }}#endif /* of #if TNUM_PORT >= 2 */
⌨️ 快捷键说明
复制代码
Ctrl + C
搜索代码
Ctrl + F
全屏模式
F11
切换主题
Ctrl + Shift + D
显示快捷键
?
增大字号
Ctrl + =
减小字号
Ctrl + -