Forum: FPGA, VHDL & Co. Lattice Mico32: Custom Component


von Keller T. (fabito)


Lesenswert?

Hallo zusammen,

Für Lattice Mico32 habe ich eine benutzerdefinierte Komponent für UART 
Opencore erstellt.

Nur es ist mir noch nicht gelungen Zugriff auf Register zu haben?

Hat vielleich jemand hier eine Idee warum ?

So sehen meine Treiber Dateien aus:
1
#include "OpencoreUart.h"
2
#include "LookupServices.h"
3
4
/******************************************************************************
5
 * Initializes a opencoreuart                                                         *
6
 ******************************************************************************/
7
void init_Opencoreuart( OpencoreuartCtx_t * ctx )
8
{
9
    ctx->lookupReg.name = ctx->name;
10
    ctx->lookupReg.deviceType = "OpencoreuartDevice";
11
    ctx->lookupReg.priv = ctx;
12
13
    MicoRegisterDevice( &(ctx->lookupReg) );
14
    /* all done */
15
    return;
16
}

----------------------------------------------
1
#ifndef _OpencoreUart_HEADER_FILE_
2
#define _OpencoreUart_HEADER_FILE_
3
4
#include <stddef.h>
5
#include "DDStructs.h"
6
7
/***********************************************************************
8
 *                                                                     *
9
 * UART PHYSICAL DEVICE SPECIFIC INFORMATION                           *
10
 *                                                                     *
11
 ***********************************************************************/
12
13
/* REGISTER OFFSETS FROM BASE ADDRESS */
14
#define OPENCOREUART_RXTX            0x00   //Receiver Buffer and Transmitter Holding Register (THR)
15
#define OPENCOREUART_IER             0x01   //Interrupt Enable Register
16
#define OPENCOREUART_IIR             0x02   //Interrupt Identification and FIFO Control Register
17
#define OPENCOREUART_LCR             0x03   //Line control Register
18
#define OPENCOREUART_MCR             0x04   //Modem control Register
19
#define OPENCOREUART_LSR             0x05   //Line status Register
20
#define OPENCOREUART_MSR             0x06   //Modem status Register
21
22
/*
23
The registers can be accessed when the 7th (DLAB) bit of the Line Control Register is set to ‘1’. At
24
this time the above registers at addresses 0-1 can’t be accessed.
25
*/
26
#define OPENCOREUART_DIVL            0x00   //Divisor Latch Byte 1 (LSB)
27
#define OPENCOREUART_DIVH            0x01   //Divisor Latch Byte 1 (MSB)
28
29
30
31
#ifdef __cplusplus
32
extern "C"{
33
#endif /* __cplusplus */
34
35
/* device initialization function */
36
void init_Opencoreuart( OpencoreuartCtx_t * ctx );
37
38
39
/*
40
* GPIO REGISTER MAPPING
41
*/
42
typedef struct st_Opencoreuart_t{
43
  
44
  /* Receiver oder Transmit FIFO oder Divisor Latch Byte 1 (LSB) */  //REG-0//
45
  volatile unsigned char rxtx;
46
  
47
  /* Interrupt Enable Register oder Divisor Latch Byte 1 (MSB)  */   //REG-1//
48
  volatile unsigned char ier;
49
  
50
  /* Interrupt Identification oder FIFO Control*/                    //REG-2//
51
  volatile unsigned char iir;
52
  
53
  /* Line Control Register */                                        //REG-3//
54
  volatile unsigned char lcr;
55
  
56
  /* Modem Control Register */                                     //REG-4//                               
57
  volatile unsigned char mcr;
58
  
59
  /* Line Status Register */                                         //REG-5//
60
  volatile unsigned char lsr;
61
  
62
   /* Modem Status Register*/                                           //REG-6//
63
  volatile unsigned char msr;
64
65
}Opencoreuart_t;
66
67
68
/***********************************************************************
69
 *                                                                     *
70
 * USER MACROS FOR READ/WRITE OPENCOREUART REGISTERS                                                      *
71
 *                                                                     *
72
 ***********************************************************************/
73
74
#define OPENCOREUART_WR_LCR(X,Y)     ((volatile Opencoreuart_t *)((X)->base))->lcr=(Y)
75
//#define MICO_GPIO_WRITE_DATA(X,Y) ((volatile MicoGPIO_t *)((X)->base))->data=(Y)
76
77
78
#ifdef __cplusplus
79
}
80
#endif /* __cplusplus */
81
#endif//_OpencoreUart_HEADER_FILE_

1
#include <stddef.h>
2
#include "MicoUtils.h"
3
#include "DDStructs.h"
4
#include "MicoMacros.h"
5
#include "OpencoreUart.h"
6
#include "MicoGPIO.h"
7
#include "LookupServices.h"
8
#include "string.h"
9
#include<stdio.h>
10
11
12
13
//const char *const OPENCOREUART_INSTANCE_NAME = "opencoreuart";
14
15
/*************************
16
 * USER-MAIN ENTRY POINT *
17
 *************************/
18
int main(void){
19
20
/* Fetch GPIO instance named "LED" */
21
22
23
volatile Opencoreuart_t *myUart;
24
OpencoreuartCtx_t *pUart = (OpencoreuartCtx_t *)MicoGetDevice("opencoreuart");
25
26
if(pUart == 0) {
27
/* failed to find a component named "leds" */
28
return(-1);
29
}
30
/* get access to the GPIO registers */
31
myUart = (volatile Opencoreuart_t *)(pUart->base);
32
/* write 0x80 to programmable I/O pins 7 through 0 via the data
33
register. */
34
myUart->lcr = 0xff;

von Duke Scarring (Gast)


Lesenswert?

Ngii Rayan schrieb:
> Nur es ist mir noch nicht gelungen Zugriff auf Register zu haben?
>
> Hat vielleich jemand hier eine Idee warum ?

Die Hardware hast Du mit eingebunden?
Und die Basisadresse stimmt auch?

Hast Du alles (Hardware + Software) mal simuliert?

Duke

Bitte melde dich an um einen Beitrag zu schreiben. Anmeldung ist kostenlos und dauert nur eine Minute.
Bestehender Account
Schon ein Account bei Google/GoogleMail? Keine Anmeldung erforderlich!
Mit Google-Account einloggen
Noch kein Account? Hier anmelden.