FPGA:MicroBlaze LED


前回のHelloのプリントと同じ要領でVitisの「File → New → Application Project」からplatform projectを作っていく。テンプレートでhelloを選ぶところまでは同じ。

今回は、#include "xparameters.h"としてxparameters.hをまず読み込む。このファイルは どのメモリアドレスに IP コアを割り当てたかなどの情報を持っている。

#define LED *((volatile unsigned int*) (XPAR_GPIO_0_BASEADDR + 0x00))

#define LED_ctrl *((volatile unsigned int*) (XPAR_GPIO_0_BASEADDR + 0x04))

XPAR_GPIO_0_BASEADDRが、GPIOの先頭アドレスを示すとの事で、先頭から4ビット離れたところが、コントロールビットなるとの事だが、ここがわからない。

XPAR_GPIO_0_BASEADDRを選択してOpen Declarationで定義に飛んでみると確かにXPAR_GPIO_0_BASEADDR が定義されている。

/* Canonical definitions for peripheral AXI_GPIO_0 */
#define XPAR_GPIO_0_BASEADDR 0x40000000
#define XPAR_GPIO_0_HIGHADDR 0x4000FFFF
#define XPAR_GPIO_0_DEVICE_ID XPAR_AXI_GPIO_0_DEVICE_ID
#define XPAR_GPIO_0_INTERRUPT_PRESENT 0
#define XPAR_GPIO_0_IS_DUAL 0


ハードウェア構成のときに”AXI GPIO”というIPをブロックダイアグラムに追加しました。この数値は”AXI GPIO”における各レジスタのベースアドレス0x40000000になっている
(後で確認してみる)
しかし4ビット目がコントロールだというのは???

https://www.xilinx.com/support/documentation/ip_documentation/axi_gpio/v2_0/pg144-axi-gpio.pdf
というファイルがあるので中身を熟読するしかないようで、ざっと見ると記載があって
4ビット目は3-state control registerであると。そうだとして、何を設定するの?
もう少し読み進めると、
0だとアウトプットして設定されて、1だとインプットに設定されるという事がわかる。
ArduinoのマイコンとかMSP432とかSTM32とかでGPIOをアウトプットとインプットに指定するのと同じ要領と解釈すると理解できる。

続いて、    case 0: LED = 0x4; break;
    case 1: LED = 0x2; break;
    case 2: LED = 0x1; break;
    case 3: LED = 0x7; break;
    case 4: LED = 0x0; break;

0x4だから0B100(R) 次が0x2だから0B010(G) 0x1は0B001(B) 0x7は111(RGB=white)で最後がゼロなので指定なしで消灯

このLEDの例は、WEB上にも例題として記述を見つける事ができるので理解はできるが、他のペリフェラルを使うとなると勉強がまだまだ必要

以下記載したソース

/******************************************************************************
*
* Copyright (C) 2009 - 2014 Xilinx, Inc.  All rights reserved.
*
* Permission is hereby granted, free of charge, to any person obtaining a copy
* of this software and associated documentation files (the "Software"), to deal
* in the Software without restriction, including without limitation the rights
* to use, copy, modify, merge, publish, distribute, sublicense, and/or sell
* copies of the Software, and to permit persons to whom the Software is
* furnished to do so, subject to the following conditions:
*
* The above copyright notice and this permission notice shall be included in
* all copies or substantial portions of the Software.
*
* Use of the Software is limited solely to applications:
* (a) running on a Xilinx device, or
* (b) that interact with a Xilinx device through a bus or interconnect.
*
* THE SOFTWARE IS PROVIDED "AS IS", WITHOUT WARRANTY OF ANY KIND, EXPRESS OR
* IMPLIED, INCLUDING BUT NOT LIMITED TO THE WARRANTIES OF MERCHANTABILITY,
* FITNESS FOR A PARTICULAR PURPOSE AND NONINFRINGEMENT. IN NO EVENT SHALL
* XILINX  BE LIABLE FOR ANY CLAIM, DAMAGES OR OTHER LIABILITY,
* WHETHER IN AN ACTION OF CONTRACT, TORT OR OTHERWISE, ARISING FROM, OUT OF
* OR IN CONNECTION WITH THE SOFTWARE OR THE USE OR OTHER DEALINGS IN THE
* SOFTWARE.
*
* Except as contained in this notice, the name of the Xilinx shall not be used
* in advertising or otherwise to promote the sale, use or other dealings in
* this Software without prior written authorization from Xilinx.
*
******************************************************************************/

/*
 * helloworld.c: simple test application
 *
 * This application configures UART 16550 to baud rate 9600.
 * PS7 UART (Zynq) is not initialized by this application, since
 * bootrom/bsp configures it to baud rate 115200
 *
 * ------------------------------------------------
 * | UART TYPE   BAUD RATE                        |
 * ------------------------------------------------
 *   uartns550   9600
 *   uartlite    Configurable only in HW design
 *   ps7_uart    115200 (configured by bootrom/bsp)
 */

#include <stdio.h>
#include "platform.h"
#include "xparameters.h"

#define LED *((volatile unsigned int*) (XPAR_GPIO_0_BASEADDR + 0x00))
#define LED_ctrl *((volatile unsigned int*) (XPAR_GPIO_0_BASEADDR + 0x04))

int main()
{
int i,j;
LED_ctrl = 0x0;

    xil_printf("Hello World\n\r");
    while(1){
    for (i=0;i<5;i++){
    xil_printf("i=%d\r\n",i);
    switch(i){
    case 0: LED = 0x4; break;
    case 1: LED = 0x2; break;
    case 2: LED = 0x1; break;
    case 3: LED = 0x7; break;
    case 4: LED = 0x0; break;
    default: LED=0x0;
    }
    for (j=0; j<4000000; j++);
    }
    }

    return 0;
}





コメント

このブログの人気の投稿

Attiny85とAQM0802A(LCD)のI2C接続

CH9329で日本語キーボード109で正しく表示する方法