/* * TOPPERS/ASP Kernel * Toyohashi Open Platform for Embedded Real-Time Systems/ * Advanced Standard Profile Kernel * * Copyright (C) 2000-2003 by Embedded and Real-Time Systems Laboratory * Toyohashi Univ. of Technology, JAPAN * Copyright (C) 2003-2004 by Naoki Saito * Nagoya Municipal Industrial Research Institute, JAPAN * Copyright (C) 2003-2004 by Platform Development Center * RICOH COMPANY,LTD. JAPAN * Copyright (C) 2008-2010 by Witz Corporation, JAPAN * Copyright (C) 2013 by Mitsuhiro Matsuura * * 上記著作権者は,以下の(1)~(4)の条件を満たす場合に限り,本ソフトウェ * ア(本ソフトウェアを改変したものを含む.以下同じ)を使用・複製・改 * 変・再配布(以下,利用と呼ぶ)することを無償で許諾する. * (1) 本ソフトウェアをソースコードの形で利用する場合には,上記の著作 * 権表示,この利用条件および下記の無保証規定が,そのままの形でソー * スコード中に含まれていること. * (2) 本ソフトウェアを,ライブラリ形式など,他のソフトウェア開発に使 * 用できる形で再配布する場合には,再配布に伴うドキュメント(利用 * 者マニュアルなど)に,上記の著作権表示,この利用条件および下記 * の無保証規定を掲載すること. * (3) 本ソフトウェアを,機器に組み込むなど,他のソフトウェア開発に使 * 用できない形で再配布する場合には,次のいずれかの条件を満たすこ * と. * (a) 再配布に伴うドキュメント(利用者マニュアルなど)に,上記の著 * 作権表示,この利用条件および下記の無保証規定を掲載すること. * (b) 再配布の形態を,別に定める方法によって,TOPPERSプロジェクトに * 報告すること. * (4) 本ソフトウェアの利用により直接的または間接的に生じるいかなる損 * 害からも,上記著作権者およびTOPPERSプロジェクトを免責すること. * また,本ソフトウェアのユーザまたはエンドユーザからのいかなる理 * 由に基づく請求からも,上記著作権者およびTOPPERSプロジェクトを * 免責すること. * * 本ソフトウェアは,無保証で提供されているものである.上記著作権者お * よびTOPPERSプロジェクトは,本ソフトウェアに関して,特定の使用目的 * に対する適合性も含めて,いかなる保証も行わない.また,本ソフトウェ * アの利用により直接的または間接的に生じたいかなる損害に関しても,そ * の責任を負わない. * * @(#) $Id$ */ /* * RX630 UART用シリアルI/Oモジュール */ #include "kernel_impl.h" #include #include "target_serial.h" #include "hal/serial_api.h" #include "target_syssvc.h" #include "syssvc/serial.h" /* * シリアルI/Oポート初期化ブロックの定義 */ typedef struct sio_port_initialization_block { PinName tx; PinName rx; } SIOPINIB; /* * シリアルI/Oポート管理ブロックの定義 */ struct sio_port_control_block { const SIOPINIB *p_siopinib; intptr_t exinf; bool_t openflag; serial_t serial; }; /* * シリアルI/Oポート管理ブロックのエリア */ SIOPCB siopcb_table[TNUM_PORT]; static const SIOPINIB siopinib_table[TNUM_SIOP] = { { P20, P21 }, #if TNUM_SIOP > 1 { P32, P33 }, #endif #if TNUM_SIOP > 2 { P50, P52 }, #endif #if TNUM_SIOP > 3 { P23, P25 }, #endif #if TNUM_SIOP > 4 { PC3, PC2 }, #endif #if TNUM_SIOP > 5 { PC7, PC6 }, #endif #if TNUM_SIOP > 6 { P26, P30 }, #endif }; /* * シリアルI/OポートIDから管理ブロックを取り出すためのマクロ */ #define INDEX_SIOP(siopid) ((uint_t)((siopid) - 1)) #define get_siopcb(siopid) (&(siopcb_table[INDEX_SIOP(siopid)])) #define get_siopinib(siopid) (&(siopinib_table[INDEX_SIOP(siopid)])) static void mbed_serial_irq_handler(uint32_t id, SerialIrq event); /* * SIOドライバの初期化 */ void sio_initialize(intptr_t exinf) { SIOPCB *p_siopcb; uint_t i; /* * シリアルI/Oポート管理ブロックの初期化 */ for (p_siopcb = siopcb_table, i = 0; i < TNUM_SIOP; p_siopcb++, i++) { p_siopcb->p_siopinib = &(siopinib_table[i]); p_siopcb->openflag = false; } } /* * シリアルI/Oポートのオープン */ SIOPCB * sio_opn_por(ID siopid, intptr_t exinf) { SIOPCB *p_siopcb = NULL; ER ercd; serial_t *serial; if ((siopid <= 0) || (siopid > (sizeof(siopcb_table) / sizeof(siopcb_table[0])))) return NULL; p_siopcb = get_siopcb(siopid); if (p_siopcb->openflag) return NULL; p_siopcb->openflag = true; p_siopcb->exinf = exinf; serial = &p_siopcb->serial; serial_init(serial, p_siopcb->p_siopinib->tx, p_siopcb->p_siopinib->rx); serial_baud(serial, UART_BAUDRATE); serial_format(serial, 8, ParityNone, 1); serial_irq_handler(serial, mbed_serial_irq_handler, siopid); return p_siopcb; } /* * シリアルI/Oポートのクローズ */ void sio_cls_por(SIOPCB *p_siopcb) { ER ercd; serial_t *serial = &p_siopcb->serial; /* * デバイス依存のクローズ処理. */ serial_free(serial); p_siopcb->openflag = false; } /* * シリアルI/Oポートへの文字送信 */ bool_t sio_snd_chr(SIOPCB *p_siopcb, char c) { serial_t *serial = &p_siopcb->serial; if (!serial_writable(serial)) return false; serial_putc(serial, c); return true; } /* * シリアルI/Oポートからの文字受信 */ int_t sio_rcv_chr(SIOPCB *p_siopcb) { serial_t *serial = &p_siopcb->serial; if (!serial_readable(serial)) return -1; return serial_getc(serial); } /* * シリアルI/Oポートからのコールバックの許可 */ void sio_ena_cbr(SIOPCB *p_siopcb, uint_t cbrtn) { serial_t *serial = &p_siopcb->serial; switch (cbrtn) { case SIO_RDY_SND: serial_irq_set(serial, TxIrq, true); break; case SIO_RDY_RCV: serial_irq_set(serial, RxIrq, true); break; } } /* * シリアルI/Oポートからのコールバックの禁止 */ void sio_dis_cbr(SIOPCB *p_siopcb, uint_t cbrtn) { serial_t *serial = &p_siopcb->serial; switch (cbrtn) { case SIO_RDY_SND: serial_irq_set(serial, TxIrq, false); break; case SIO_RDY_RCV: serial_irq_set(serial, RxIrq, false); break; } } /* * シリアルI/Oポートからの送信可能コールバック */ void serial_irdy_snd(SIOPCB *p_siopcb) { /* 共通部(syssvc\serial.c)にあるsio_irdy_snd関数を呼び出し*/ sio_irdy_snd(p_siopcb->exinf); } /* * シリアルI/Oポートからの受信通知コールバック */ void serial_irdy_rcv(SIOPCB *p_siopcb) { /* 共通部(syssvc\serial.c)にあるsio_irdy_rcv関数を呼び出し*/ sio_irdy_rcv(p_siopcb->exinf); } /* * SIOの割込みハンドラ */ void mbed_serial_irq_handler(uint32_t siopid, SerialIrq event) { SIOPCB *p_siopcb; if ((siopid <= 0) || (siopid > (sizeof(siopcb_table) / sizeof(siopcb_table[0])))) return; p_siopcb = get_siopcb(siopid); if (!p_siopcb->openflag) return; switch (event) { case TxIrq: serial_irdy_snd(p_siopcb); break; case RxIrq: serial_irdy_rcv(p_siopcb); break; } }