+
+
+#include <t_services.h>
+#include "kernel_id.h"
+#include "test.h"
+#include <cdefBF533.h>
+
+/*
+ * 並行実行されるタスクへのメッセージ領域
+ */
+char message[3];
+
+/*
+ * ループ回数
+ */
+UW task_loop; /* タスク内でのループ回数 */
+UW tex_loop; /* 例外処理ルーチン内でのループ回数 */
+
+/*
+ * 並行実行されるタスク
+ */
+void task(VP_INT exinf)
+{
+ INT n = 0;
+ INT tskno = (INT) exinf;
+
+ syslog(LOG_NOTICE, "task%d is running (%03d). %s",
+ tskno, ++n);
+
+}
+
+/*
+ * 並行して実行されるタスク用のタスク例外処理ルーチン
+ */
+void tex_routine(TEXPTN texptn, VP_INT exinf)
+{
+ INT tskno = (INT) exinf;
+
+ syslog(LOG_NOTICE, "task%d receives exception 0x%04x. ",
+ tskno, texptn);
+
+ }
+
+/*
+ * CPU例外ハンドラ
+ */
+#ifdef CPUEXC1
+
+void
+cpuexc_handler(VP p_excinf)
+{
+
+ syslog(LOG_NOTICE, "CPU exception handler (p_excinf = %08p).",
+ p_excinf);
+
+}
+
+#endif /* CPUEXC1 */
+
+/*
+ * 周期ハンドラ
+ *
+ * HIGH_PRIORITY,MID_PRIORITY,LOW_PRIORITY の各優先度のレディキュー
+ * を回転させる.
+ */
+void cyclic_handler(VP_INT exinf)
+{
+
+}
+
+/*
+ * メインタスク
+ */
+void main_task(VP_INT exinf)
+{
+ unsigned short dummy;
+
+ vmsk_log(LOG_UPTO(LOG_INFO), LOG_UPTO(LOG_EMERG));
+ syslog(LOG_NOTICE, "Sample program starts (exinf = %d).", (INT) exinf);
+
+ syscall(serial_ctl_por(TASK_PORTID,
+ (IOCTL_CRLF | IOCTL_FCSND | IOCTL_FCRCV)));
+
+ /*
+ * タスクの起動
+ act_tsk(TASK1);
+ act_tsk(TASK2);
+ act_tsk(TASK3);
+ */
+
+ *pSPORT0_TCR1 =
+ 0 << 14 | // TCKFE, 0:sample at down edge, 1:sample at up edge
+ 0 << 13 | // LATFS, 0:early frame sync, 1:late frame sync
+ 0 << 12 | // LTFS, 0:Active high TFS, 1:Active low TFS
+ 0 << 11 | // DITFS, 0:data dependent TFS generation, 1:data independent TFS generation
+ 0 << 10 | // TFSR, 0:TFS is not required every word, 1:TFS is required every word
+ 0 << 9 | // ITFS, 0:external TFS, 1:internal TFS
+ 0 << 4 | // TLSBIT, 0:MSB first transmission, 1:LSB first transmission
+ 0 << 2 | // TDTYPE 0:normal, 1:reserved, 2:u-law, 3:a-law
+ 0 << 1 | // ITCLK, 0:external clock generation, 1:internal clock generation
+ 0 << 0 ; // TSPEN 0:Tx disable, 1:Tx enable
+
+ *pSPORT0_TCR2 =
+ 0 << 10 | // TRFST, 0:left streo ch first, 1:right stereo ch first
+ 0 << 9 | // TSFESE, 0:normal frame sync, 1:LR frame clock
+ 0 << 8 | // TXSE, 0:secondary ch disable, 1:secondary ch enable
+ 0 << 0 ; // SLEN 0-1:not allowed,2-31:Serial word length - 1
+
+
+ *pSPORT0_RCR1 =
+ 0 << 14 | // RCKFE, 0:sample at down edge, 1:sample at up edge
+ 0 << 13 | // LARFS, 0:early frame sync, 1:late frame sync
+ 0 << 12 | // LRFS, 0:Active high RFS, 1:Active low RFS
+ 1 << 10 | // RFSR, 0:RFS is not required every word, 1:RFS is required every word
+ 0 << 9 | // IRFS, 0:external RFS, 1:internal RFS
+ 0 << 4 | // RLSBIT, 0:MSB first transmission, 1:LSB first transmission
+ 0 << 2 | // RDTYPE 0:zero fill, 1:sign extend, 2:u-law, 3:a-law
+ 0 << 1 | // IRCLK, 0:external clock generation, 1:internal clock generation
+ 0 << 0 ; // RSPEN 0:Rx disable, 1:Rx enable
+
+ *pSPORT0_RCR2 =
+ 0 << 10 | // RRFST, 0:left streo ch first, 1:right stereo ch first
+ 0 << 9 | // RSFESE, 0:normal frame sync, 1:LR frame clock
+ 1 << 8 | // RXSE, 0:secondary ch disable, 1:secondary ch enable
+ 29 << 0 ; // SLEN 0-1:not allowed,2-31:Serial word length - 1
+ ssync();
+
+ /*
+ syslog( LOG_NOTICE, "SPORT0_Disable " );
+ syslog( LOG_NOTICE, "SPORT0_RCR1 : %08x", *pSPORT0_RCR1 );
+ syslog( LOG_NOTICE, "SPORT0_RCR2 : %08x", *pSPORT0_RCR2 );
+
+ syslog( LOG_NOTICE, "SPORT0_STAT : %08x", *pSPORT0_STAT );
+*/
+
+ int count = 0, event = 0;
+
+
+ // RX FIFOが空になるまで読み捨てる
+ while( *pSPORT0_STAT & RXNE)
+ dummy = *pSPORT0_RX32;
+/*
+ *pSPORT0_RCR1 &= ~RSPEN; // RX SPORT disable
+ syslog( LOG_NOTICE, "FIFO Cleared. FIFO must be empty");
+ syslog( LOG_NOTICE, "SPORT0_STAT : %08x", *pSPORT0_STAT );
+*/
+ /*
+ * メインループ
+ */
+ do {
+ long int rx[4];
+
+ // RX受信を開始する
+ *pSPORT0_RCR1 |= RSPEN; // RX SPORT Enable
+ ssync();
+ /*
+ syslog( LOG_NOTICE, "SPORT0_Enabled" );
+ syslog( LOG_NOTICE, "SPORT0_RCR1 : %08x", *pSPORT0_RCR1 );
+ syslog( LOG_NOTICE, "SPORT0_RCR2 : %08x", *pSPORT0_RCR2 );
+*/
+ // 3mS スリープ
+ tslp_tsk(3);
+
+ // FIFOにデータがたまったはずである。
+ /*
+ syslog( LOG_NOTICE, "SPORT0_Disabled. FIFO must be full " );
+ syslog( LOG_NOTICE, "SPORT0_RCR1 : %08x", *pSPORT0_RCR1 );
+ syslog( LOG_NOTICE, "SPORT0_RCR2 : %08x", *pSPORT0_RCR2 );
+
+ syslog( LOG_NOTICE, "SPORT0_STAT : %08x", *pSPORT0_STAT );
+*/
+ // FIFOデータを読みだして下位2bitのみ表示する
+ rx[0] = *pSPORT0_RX32 & 0x3; // 下位2bitのみ抽出
+ rx[1] = *pSPORT0_RX32 & 0x3; // 下位2bitのみ抽出
+ rx[2] = *pSPORT0_RX32 & 0x3; // 下位2bitのみ抽出
+ rx[3] = *pSPORT0_RX32 & 0x3; // 下位2bitのみ抽出
+ *pSPORT0_RCR1 &= ~RSPEN; // RX SPORT disable
+ // syslog( LOG_NOTICE, "FIFO Read. FIFO must be empty");
+ if (rx[0] !=0)
+ {
+ event ++;
+ syslog( LOG_NOTICE, "RX word : %d,%d,%d,%d", rx[0], rx[1], rx[2], rx[3] );
+ }
+ count++;
+ if (!( count % 1000 ))
+ syslog( LOG_NOTICE, "trial : %d, event : %d", count, event);
+ // syslog( LOG_NOTICE, "SPORT0_RCR1 : %08x", *pSPORT0_RCR1 );
+ // syslog( LOG_NOTICE, "SPORT0_RCR2 : %08x", *pSPORT0_RCR2 );
+ // syslog( LOG_NOTICE, "SPORT0_STAT : %08x", *pSPORT0_STAT );
+
+ // RX受信を終了する。FIFOにはデータがたまっているはずである。
+ *pSPORT0_RCR1 &= ~RSPEN; // RX SPORT disable
+ ssync();
+ /*
+ syslog( LOG_NOTICE, "SPORT0 dsiabled");
+ syslog( LOG_NOTICE, "SPORT0_RCR1 : %08x", *pSPORT0_RCR1 );
+ syslog( LOG_NOTICE, "SPORT0_RCR2 : %08x", *pSPORT0_RCR2 );
+ syslog( LOG_NOTICE, "SPORT0_STAT : %08x", *pSPORT0_STAT );
+*/
+ // 1秒スリープ
+ tslp_tsk(10);
+
+ // RX FIFOが空になるまで読み捨てる
+ while( *pSPORT0_STAT & RXNE)
+ dummy = *pSPORT0_RX32;
+
+
+ } while (1);
+
+ syslog(LOG_NOTICE, "Sample program ends.");
+ kernel_exit();
+}