Ignore:
Timestamp:
Apr 5, 2019, 9:26:53 PM (5 years ago)
Author:
coas-nagasima
Message:

mbed関連を更新
シリアルドライバをmbedのHALを使うよう変更
ファイルディスクリプタの処理を更新

File:
1 edited

Legend:

Unmodified
Added
Removed
  • asp3_tinet_ecnl_rx/trunk/asp3_dcre/target/gr_sakura_gcc/target_serial.c

    r337 r374  
    33 *      Toyohashi Open Platform for Embedded Real-Time Systems/
    44 *      Advanced Standard Profile Kernel
    5  * 
     5 *
    66 *  Copyright (C) 2000-2003 by Embedded and Real-Time Systems Laboratory
    77 *                              Toyohashi Univ. of Technology, JAPAN
     
    1212 *  Copyright (C) 2008-2010 by Witz Corporation, JAPAN
    1313 *  Copyright (C) 2013      by Mitsuhiro Matsuura
    14  * 
     14 *
    1515 *  上記著作権者は,以下の(1)~(4)の条件を満たす場合に限り,本ソフトウェ
    1616 *  ア(本ソフトウェアを改変したものを含む.以下同じ)を使用・複製・改
     
    3535 *      由に基づく請求からも,上記著作権者およびTOPPERSプロジェクトを
    3636 *      免責すること.
    37  * 
     37 *
    3838 *  本ソフトウェアは,無保証で提供されているものである.上記著作権者お
    3939 *  よびTOPPERSプロジェクトは,本ソフトウェアに関して,特定の使用目的
     
    4141 *  アの利用により直接的または間接的に生じたいかなる損害に関しても,そ
    4242 *  の責任を負わない.
    43  * 
     43 *
    4444 *  @(#) $Id$
    4545 */
     
    5151#include <sil.h>
    5252#include "target_serial.h"
     53#include "hal/serial_api.h"
     54#include "target_syssvc.h"
     55#include "syssvc/serial.h"
     56
     57/*
     58 *  シリアルI/Oポート初期化ブロックの定義
     59 */
     60typedef struct sio_port_initialization_block {
     61        PinName tx;
     62        PinName rx;
     63} SIOPINIB;
     64
     65/*
     66 *  シリアルI/Oポート管理ブロックの定義
     67 */
     68struct sio_port_control_block {
     69        const SIOPINIB *p_siopinib;
     70        intptr_t exinf;
     71        bool_t openflag;
     72        serial_t serial;
     73};
     74
     75/*
     76 *  シリアルI/Oポート管理ブロックのエリア
     77 */
     78SIOPCB siopcb_table[TNUM_PORT];
     79
     80static const SIOPINIB siopinib_table[TNUM_SIOP] =
     81{
     82        { P20, P21 },
     83#if TNUM_SIOP > 1
     84        { P32, P33 },
     85#endif
     86#if TNUM_SIOP > 2
     87        { P50, P52 },
     88#endif
     89#if TNUM_SIOP > 3
     90        { P23, P25 },
     91#endif
     92#if TNUM_SIOP > 4
     93        { PC3, PC2 },
     94#endif
     95#if TNUM_SIOP > 5
     96        { PC7, PC6 },
     97#endif
     98#if TNUM_SIOP > 6
     99        { P26, P30 },
     100#endif
     101};
     102
     103/*
     104 *  シリアルI/OポートIDから管理ブロックを取り出すためのマクロ
     105 */
     106#define INDEX_SIOP(siopid)       ((uint_t)((siopid) - 1))
     107#define get_siopcb(siopid)       (&(siopcb_table[INDEX_SIOP(siopid)]))
     108#define get_siopinib(siopid) (&(siopinib_table[INDEX_SIOP(siopid)]))
     109
     110static void mbed_serial_irq_handler(uint32_t id, SerialIrq event);
    53111
    54112/*
     
    58116sio_initialize(intptr_t exinf)
    59117{
    60         rx630_uart_initialize();
     118        SIOPCB  *p_siopcb;
     119        uint_t  i;
     120
     121        /*
     122         *  シリアルI/Oポート管理ブロックの初期化
     123         */
     124        for (p_siopcb = siopcb_table, i = 0; i < TNUM_SIOP; p_siopcb++, i++) {
     125                p_siopcb->p_siopinib = &(siopinib_table[i]);
     126                p_siopcb->openflag = false;
     127        }
    61128}
    62129
     
    69136        SIOPCB  *p_siopcb = NULL;
    70137        ER      ercd;
    71         INTNO   intno_sio_tx, intno_sio_rx;
    72        
    73         /*
    74          *  シリアルI/O割込みをマスクする.
    75          *  (dis_int関数は、"\kernel\interrupt.c"に記述)
    76          */
    77         p_siopcb = rx630_uart_get_siopcb(siopid);
    78         intno_sio_tx = rx630_uart_intno_tx(p_siopcb);
    79         intno_sio_rx = rx630_uart_intno_rx(p_siopcb);
    80         ercd = dis_int(intno_sio_tx);
    81         assert(ercd == E_OK);
    82         ercd = dis_int(intno_sio_rx);
    83         assert(ercd == E_OK);
    84        
    85         p_siopcb =
    86                 rx630_uart_opn_por(siopid , exinf , UART_BAUDRATE , UART_CLKSRC);
    87 
    88         /*
    89          *  シリアルI/O割込みをマスク解除する.
    90          *  (ena_int関数は、"\kernel\interrupt.c"に記述)
    91          */
    92         ercd = ena_int(intno_sio_tx);
    93         assert(ercd == E_OK);
    94         ercd = ena_int(intno_sio_rx);
    95         assert(ercd == E_OK);
    96 
    97         return(p_siopcb);
     138        serial_t *serial;
     139
     140        if ((siopid <= 0) || (siopid > (sizeof(siopcb_table) / sizeof(siopcb_table[0]))))
     141                return NULL;
     142        p_siopcb = get_siopcb(siopid);
     143
     144        if (p_siopcb->openflag)
     145                return NULL;
     146        p_siopcb->openflag = true;
     147        p_siopcb->exinf = exinf;
     148
     149        serial = &p_siopcb->serial;
     150        serial_init(serial, p_siopcb->p_siopinib->tx, p_siopcb->p_siopinib->rx);
     151        serial_baud(serial, UART_BAUDRATE);
     152        serial_format(serial, 8, ParityNone, 1);
     153
     154        serial_irq_handler(serial, mbed_serial_irq_handler, siopid);
     155
     156        return p_siopcb;
    98157}
    99158
     
    105164{
    106165        ER        ercd;
    107         INTNO   intno_sio_tx, intno_sio_rx;
     166        serial_t *serial = &p_siopcb->serial;
    108167
    109168        /*
    110169         *  デバイス依存のクローズ処理.
    111170         */
    112         rx630_uart_cls_por(p_siopcb);
    113        
    114         /*
    115          *  シリアルI/O割込みをマスクする.
    116          */
    117         intno_sio_tx = rx630_uart_intno_tx(p_siopcb);
    118         intno_sio_rx = rx630_uart_intno_rx(p_siopcb);
    119         ercd = dis_int(intno_sio_tx);
    120         assert(ercd == E_OK);
    121         ercd = dis_int(intno_sio_rx);
    122         assert(ercd == E_OK);
     171        serial_free(serial);
     172        p_siopcb->openflag = false;
     173}
     174
     175/*
     176 *  シリアルI/Oポートへの文字送信
     177 */
     178bool_t
     179sio_snd_chr(SIOPCB *p_siopcb, char c)
     180{
     181        serial_t *serial = &p_siopcb->serial;
     182        if (!serial_writable(serial))
     183                return false;
     184        serial_putc(serial, c);
     185        return true;
     186}
     187
     188/*
     189 *  シリアルI/Oポートからの文字受信
     190 */
     191int_t
     192sio_rcv_chr(SIOPCB *p_siopcb)
     193{
     194        serial_t *serial = &p_siopcb->serial;
     195        if (!serial_readable(serial))
     196                return -1;
     197        return serial_getc(serial);
     198}
     199
     200/*
     201 *  シリアルI/Oポートからのコールバックの許可
     202 */
     203void
     204sio_ena_cbr(SIOPCB *p_siopcb, uint_t cbrtn)
     205{
     206        serial_t *serial = &p_siopcb->serial;
     207        switch (cbrtn) {
     208        case SIO_RDY_SND:
     209                serial_irq_set(serial, TxIrq, true);
     210                break;
     211        case SIO_RDY_RCV:
     212                serial_irq_set(serial, RxIrq, true);
     213                break;
     214        }
     215}
     216
     217/*
     218 *  シリアルI/Oポートからのコールバックの禁止
     219 */
     220void
     221sio_dis_cbr(SIOPCB *p_siopcb, uint_t cbrtn)
     222{
     223        serial_t *serial = &p_siopcb->serial;
     224        switch (cbrtn) {
     225        case SIO_RDY_SND:
     226                serial_irq_set(serial, TxIrq, false);
     227                break;
     228        case SIO_RDY_RCV:
     229                serial_irq_set(serial, RxIrq, false);
     230                break;
     231        }
     232}
     233
     234/*
     235 *  シリアルI/Oポートからの送信可能コールバック
     236 */
     237void
     238serial_irdy_snd(SIOPCB  *p_siopcb)
     239{
     240        /* 共通部(syssvc\serial.c)にあるsio_irdy_snd関数を呼び出し*/
     241        sio_irdy_snd(p_siopcb->exinf);
     242}
     243
     244/*
     245 *  シリアルI/Oポートからの受信通知コールバック
     246 */
     247void
     248serial_irdy_rcv(SIOPCB  *p_siopcb)
     249{
     250        /* 共通部(syssvc\serial.c)にあるsio_irdy_rcv関数を呼び出し*/
     251        sio_irdy_rcv(p_siopcb->exinf);
    123252}
    124253
     
    126255 *  SIOの割込みハンドラ
    127256 */
    128 void sio_tx_isr(intptr_t exinf)
    129 {
    130         rx630_uart_tx_isr(exinf);
    131 }
    132 
    133 /*
    134  *  SIOの割込みハンドラ
    135  */
    136 void sio_rx_isr(intptr_t exinf)
    137 {
    138         rx630_uart_rx_isr(exinf);
    139 }
    140 
    141 /*
    142  *  シリアルI/Oポートへの文字送信
    143  */
    144 bool_t
    145 sio_snd_chr(SIOPCB *siopcb, char c)
    146 {
    147         return(rx630_uart_snd_chr(siopcb, c));
    148 }
    149 
    150 /*
    151  *  シリアルI/Oポートからの文字受信
    152  */
    153 int_t
    154 sio_rcv_chr(SIOPCB *siopcb)
    155 {
    156         return(rx630_uart_rcv_chr(siopcb));
    157 }
    158 
    159 /*
    160  *  シリアルI/Oポートからのコールバックの許可
    161  */
    162 void
    163 sio_ena_cbr(SIOPCB *siopcb, uint_t cbrtn)
    164 {
    165         rx630_uart_ena_cbr(siopcb, cbrtn);
    166 }
    167 
    168 /*
    169  *  シリアルI/Oポートからのコールバックの禁止
    170  */
    171 void
    172 sio_dis_cbr(SIOPCB *siopcb, uint_t cbrtn)
    173 {
    174         rx630_uart_dis_cbr(siopcb, cbrtn);
    175 }
    176 
    177 /*
    178  *  シリアルI/Oポートからの送信可能コールバック
    179  */
    180 void
    181 rx630_uart_irdy_snd(intptr_t exinf)
    182 {
    183         /* 共通部(syssvc\serial.c)にあるsio_irdy_snd関数を呼び出し*/
    184         sio_irdy_snd(exinf);
    185 }
    186 
    187 /*
    188  *  シリアルI/Oポートからの受信通知コールバック
    189  */
    190 void
    191 rx630_uart_irdy_rcv(intptr_t exinf)
    192 {
    193         /* 共通部(syssvc\serial.c)にあるsio_irdy_rcv関数を呼び出し*/
    194         sio_irdy_rcv(exinf);
    195 }
    196 
     257void
     258mbed_serial_irq_handler(uint32_t siopid, SerialIrq event)
     259{
     260        SIOPCB  *p_siopcb;
     261
     262        if ((siopid <= 0) || (siopid > (sizeof(siopcb_table) / sizeof(siopcb_table[0]))))
     263                return;
     264        p_siopcb = get_siopcb(siopid);
     265
     266        if (!p_siopcb->openflag)
     267                return;
     268
     269        switch (event) {
     270        case TxIrq:
     271                serial_irdy_snd(p_siopcb);
     272                break;
     273        case RxIrq:
     274                serial_irdy_rcv(p_siopcb);
     275                break;
     276        }
     277}
Note: See TracChangeset for help on using the changeset viewer.