0
0

Delete article

Deleted articles cannot be recovered.

Draft of this article would be also deleted.

Are you sure you want to delete this article?

More than 3 years have passed since last update.

TWELITE で Lチカの続き(シリアルUART出力)

Last updated at Posted at 2020-08-20

「TWELITE で Lチカ」
https://qiita.com/nanbuwks/items/b9b5c16838d5d4626639

ではスクラッチビルドでミニマムプログラムを作成しました。
今回はその続きで、TWELITE からシリアルUART出力を行います。

無線通信などは行わず、先のLチカプログラムにシリアルUART出力に必要な最低限の記述のみ加えます。

「tsSerialPortSetup」「SERIAL_vInit()」を見て、シリアルポートをセットアップします。
https://sdk.twelite.info/hw-api-rifurensu/perifuraru/uart/serial-raiburari/tsserialportsetup
https://sdk.twelite.info/hw-api-rifurensu/perifuraru/uart/serial-raiburari/serial_vinit


#include <AppHardwareApi.h>
#include "utils.h"
#include "ToCoNet.h"
#include "ToCoNet_mod_prototype.h"
#include "serial.h" 
#include "fprintf.h"
#define LED 12

tsFILE sSerial0Stream;
static tsSerialPortSetup sSerial0;


static void vProcessEvCore(tsEvent *pEv, teEvent eEvent, uint32 u32evarg)
{
    static int counter=0;
    if (eEvent == E_EVENT_TICK_TIMER) {      // 4ms timer
        counter++;
        if (  0 == counter % 500 ) {
            vPortSetHi(LED);
            vfPrintf(&sSerial0Stream, "LED High\n\r");
        }
        if ( 250 == counter % 500 ) {
            vPortSetLo(LED);
            vfPrintf(&sSerial0Stream, "LED Low\n\r");
        }
    }
}


void cbAppColdStart(bool_t bStart)
{
    if (!bStart) {
    } else {
        vPortAsOutput(LED);  // GPIO set
        ToCoNet_Event_Register_State_Machine(vProcessEvCore); // add Event handler
        // serial init

        static uint8 au8SerialBuffTx[32];
        static uint8 au8SerialBuffRx[16];

        sSerial0.pu8SerialRxQueueBuffer = au8SerialBuffRx;
        sSerial0.pu8SerialTxQueueBuffer = au8SerialBuffTx;
        sSerial0.u32BaudRate = 115200;
        sSerial0.u16AHI_UART_RTS_LOW = 0xffff;
        sSerial0.u16AHI_UART_RTS_HIGH = 0xffff;
        sSerial0.u16SerialRxQueueSize = sizeof(au8SerialBuffRx);
        sSerial0.u16SerialTxQueueSize = sizeof(au8SerialBuffTx);
        sSerial0.u8SerialPort = E_AHI_UART_0;
        sSerial0.u8RX_FIFO_LEVEL = E_AHI_UART_FIFO_LEVEL_1;
        SERIAL_vInit(&sSerial0);

        sSerial0Stream.bPutChar = SERIAL_bTxChar;
        sSerial0Stream.u8Device = E_AHI_UART_0;

        vfPrintf(&sSerial0Stream, "Hello World!\n\r");
    }
}

void cbAppWarmStart(bool_t bStart) { return; }
void cbToCoNet_vRxEvent(tsRxDataApp *psRx) { return; }
void cbToCoNet_vTxEvent(uint8 u8CbId, uint8 bStatus) { return; }
void cbToCoNet_vNwkEvent(teEvent eEvent, uint32 u32arg) { return; }
void cbToCoNet_vHwEvent(uint32 u32DeviceId, uint32 u32ItemBitmap) {	return; }
uint8 cbToCoNet_u8HwInt(uint32 u32DeviceId, uint32 u32ItemBitmap) {	return FALSE; }
void cbToCoNet_vMain(void) { return; }


実行結果


Hello World!
LED Low
LED High
LED Low
LED High
LED Low
・
・
・
0
0
0

Register as a new user and use Qiita more conveniently

  1. You get articles that match your needs
  2. You can efficiently read back useful information
  3. You can use dark theme
What you can do with signing up
0
0

Delete article

Deleted articles cannot be recovered.

Draft of this article would be also deleted.

Are you sure you want to delete this article?