/********************************************************************************************************************** * DISCLAIMER * This software is supplied by Renesas Electronics Corporation and is only intended for use with Renesas products. No * other uses are authorized. This software is owned by Renesas Electronics Corporation and is protected under all * applicable laws, including copyright laws. * THIS SOFTWARE IS PROVIDED "AS IS" AND RENESAS MAKES NO WARRANTIES REGARDING * THIS SOFTWARE, WHETHER EXPRESS, IMPLIED OR STATUTORY, INCLUDING BUT NOT LIMITED TO WARRANTIES OF MERCHANTABILITY, * FITNESS FOR A PARTICULAR PURPOSE AND NON-INFRINGEMENT. ALL SUCH WARRANTIES ARE EXPRESSLY DISCLAIMED. TO THE MAXIMUM * EXTENT PERMITTED NOT PROHIBITED BY LAW, NEITHER RENESAS ELECTRONICS CORPORATION NOR ANY OF ITS AFFILIATED COMPANIES * SHALL BE LIABLE FOR ANY DIRECT, INDIRECT, SPECIAL, INCIDENTAL OR CONSEQUENTIAL DAMAGES FOR ANY REASON RELATED TO * THIS SOFTWARE, EVEN IF RENESAS OR ITS AFFILIATES HAVE BEEN ADVISED OF THE POSSIBILITY OF SUCH DAMAGES. * Renesas reserves the right, without notice, to make changes to this software and to discontinue the availability of * this software. By using this software, you agree to the additional terms and conditions found by accessing the * following link: * http://www.renesas.com/disclaimer * * Copyright (C) 2020 Renesas Electronics Corporation. All rights reserved. *********************************************************************************************************************/ /***********************************************************************/ /* */ /* FILE :Main.c or Main.cpp */ /* DATE :Tue, Oct 31, 2006 */ /* DESCRIPTION :Main Program */ /* CPU TYPE : */ /* */ /* NOTE:THIS IS A TYPICAL EXAMPLE. */ /* */ /***********************************************************************/ //#include "typedefine.h" #include "r_smc_entry.h" #pragma address g_sci_tx_buf=0x00800000 #pragma address g_sci_rx_buf=0x00801000 unsigned char g_sci_tx_buf[0x1000]; unsigned char g_sci_rx_buf[0x1000]; volatile unsigned long g_sci_txi_count = 0; volatile unsigned long g_sci_tei_count = 0; volatile unsigned long g_sci_rxi_count = 0; volatile int g_dmac4_flag; void sci_tx_buf_copy(unsigned char *buf); #ifdef __cplusplus //#include // Remove the comment when you use ios //_SINT ios_base::Init::init_cnt; // Remove the comment when you use ios #endif void main(void); #ifdef __cplusplus extern "C" { void abort(void); } #endif void main(void) { unsigned long i; unsigned char dummy1, dummy2; //メモリ初期化 for (i=0; i<0x1000; i++) { g_sci_tx_buf[i] = 0x00; g_sci_rx_buf[i] = 0x00; } //割り込み優先度は0に設定 IPR(SCI1, RXI1) = 0; IPR(SCI1, TXI1) = 0; R_Config_SCI1_Start(); R_Config_DMAC4_Start(); R_Config_DMAC5_Start(); //受信側 DMAC5.DMCRA = 10; //受信10バイト R_Config_SCI1_Serial_Receive(&dummy1, 1); //RE=RIE=1に設定 //送信側 //1回目 sci_tx_buf_copy("SCI DMAC test\r\n"); //0x0080_0000~にコピー(15バイト) DMAC4.DMCRA = 15; //送信15バイト g_dmac4_flag = 1; R_Config_SCI1_Serial_Send(&dummy2, 1); //DMAC起動トリガ //2回目 //(1)メモリへのデータセット sci_tx_buf_copy("2nd time 0123456789\r\n"); //0x0080_000F~にコピー(21バイト) //(2)DMAC起動トリガを生じさせる準備(TXI割り込みが発生する様にする) while (SCI1.SSR.BIT.TEND == 0) { __nop(); //送信中の場合は送信完了まで待ってから送信を停止 } SCI1.SCR.BYTE &= ~0xA0U; //TE=TIE=0 (*1)を実行するための条件 ICU.IR[61].BIT.IR = 0; //1回目の最後のキャラクタ送信の際にDMACが起動されずに割り込みフラグが立っている状態となるので割り込みフラグをクリア //(*)送信間隔が短くて、1回目の送信の最後のキャラクタのTDR→内部レジスタ転送が終わる前に2回目の送信準備(DMAC起動)が整っている //場合は、本来一度TE=TIE=0にする必要はない //そうでない場合、一度TE=TIE=0として、TXI割り込みが発生する条件を整える必要がある //(3)DMACの設定 while (g_dmac4_flag) __nop(); //前回のDMACの転送が終わった後で設定 DMAC4.DMCRA = 21; //送信21バイト DMAC4.DMCNT.BIT.DTE = 1U; //次の処理のためにDMACを起動 //(4)TXI割り込みを発生させる SCI1.SCR.BYTE |= 0xA0U; //DMAC起動トリガ(*1) /* -送信間隔が短い場合(*)- →(2)(4)は無くて良い(1回目の最後のキャラクタ送信のTXIが2回目の送信のDMACを起動させる) -送信間隔が開く場合- 必ずしも上記でなければならないという事はありませんが、 余計に発生したTXI割り込みの処理と、2回目の送信にあたりTXI割り込みが生じる様にする必要があると思います */ while(1) { __nop(); } } #ifdef __cplusplus void abort(void) { } #endif void sci_tx_buf_copy(unsigned char *buf) { static unsigned long index = 0; while (*buf != '\0') { g_sci_tx_buf[index++] = *buf++; } }