Skip to content

Commit

Permalink
Merge pull request #27 from efabless/gf180mcuD
Browse files Browse the repository at this point in the history
changes required to run cocotb with GF
  • Loading branch information
jeffdi committed Nov 29, 2023
2 parents 99f9632 + 17ec757 commit 0f3bc96
Show file tree
Hide file tree
Showing 13 changed files with 1,473 additions and 12 deletions.
156 changes: 156 additions & 0 deletions verilog/dv/firmware/APIs/bitbang.h
Original file line number Diff line number Diff line change
@@ -0,0 +1,156 @@

#ifndef BITBANG_C_HEADER_FILE
#define BITBANG_C_HEADER_FILE
/*
reg_mprj_xfer contain
bit 0 : busy
bit 1 : bitbang enable
bit 2 : bitbang reset active low
bit 3 : bitbang load registers
bit 4 : bitbang clock
bit 5 : serial data 1
bit 6 : serial data 2
*/

void bb_clock11(){
reg_mprj_xfer = 0x66;
reg_mprj_xfer = 0x76;
}

void bb_clock00(){
reg_mprj_xfer = 0x06;
reg_mprj_xfer = 0x16;
}

void bb_clock10(){
reg_mprj_xfer = 0x46;
reg_mprj_xfer = 0x56;
}

void bb_clock01(){
reg_mprj_xfer = 0x26;
reg_mprj_xfer = 0x36;
}

void bb_load(){
reg_mprj_xfer = 0x06;
reg_mprj_xfer = 0x0e;
reg_mprj_xfer = 0x06;
}

void bb_reset(){
reg_mprj_xfer = 0x04;
reg_mprj_xfer = 0x06;

}

// configure the GPIO in the left chain with configL and the GPIO in
// the right chain with configR
// left | right
// 18 & 19
// 17 & 20
// 16 & 21
// 15 & 22
// 14 & 23
// 13 & 24
// 12 & 25
// 11 & 26
// 10 & 27
// 9 & 28
// 8 & 29
// 7 & 30
// 6 & 31
// 5 & 32
// 4 & 33
// 3 & 34
// 2 & 35
// 1 & 36
// 0 & 37
void bb_configure2Gpios(unsigned int configL,unsigned int configR){
int num_bits,mask;
int left,right;
num_bits = get_gpio_num_bit();
mask = 0x1 << num_bits-1;
for (int i = num_bits-1; i >= 0; i--){
left = (configL & mask ) >> i;
right= (configR & mask ) >> i;
mask = mask >> 1;
if (left){
if (right)
bb_clock11();
else
bb_clock10();

}else{
if(right)
bb_clock01();
else
bb_clock00();
}
}
}

void bb_configureAllGpios(unsigned int config){
reg_mprj_io_37 = config;
reg_mprj_io_36 = config;
reg_mprj_io_35 = config;
reg_mprj_io_34 = config;
reg_mprj_io_33 = config;
reg_mprj_io_32 = config;
reg_mprj_io_31 = config;
reg_mprj_io_30 = config;
reg_mprj_io_29 = config;
reg_mprj_io_28 = config;
reg_mprj_io_27 = config;
reg_mprj_io_26 = config;
reg_mprj_io_25 = config;
reg_mprj_io_24 = config;
reg_mprj_io_23 = config;
reg_mprj_io_22 = config;
reg_mprj_io_21 = config;
reg_mprj_io_20 = config;
reg_mprj_io_19 = config;
reg_mprj_io_18 = config;
reg_mprj_io_17 = config;
reg_mprj_io_16 = config;
reg_mprj_io_15 = config;
reg_mprj_io_14 = config;
reg_mprj_io_13 = config;
reg_mprj_io_12 = config;
reg_mprj_io_11 = config;
reg_mprj_io_10 = config;
reg_mprj_io_9 = config;
reg_mprj_io_8 = config;
reg_mprj_io_7 = config;
reg_mprj_io_6 = config;
reg_mprj_io_5 = config;
reg_mprj_io_4 = config;
reg_mprj_io_3 = config;
reg_mprj_io_2 = config;
reg_mprj_io_1 = config;
reg_mprj_io_0 = config;

bb_reset();
bb_configure2Gpios(config,config);// 18 & 19
bb_configure2Gpios(config,config);// 17 & 20
bb_configure2Gpios(config,config);// 16 & 21
bb_configure2Gpios(config,config);// 15 & 22
bb_configure2Gpios(config,config);// 14 & 23
bb_configure2Gpios(config,config);// 13 & 24
bb_configure2Gpios(config,config);// 12 & 25
bb_configure2Gpios(config,config);// 11 & 26
bb_configure2Gpios(config,config);// 10 & 27
bb_configure2Gpios(config,config);// 9 & 28
bb_configure2Gpios(config,config);// 8 & 29
bb_configure2Gpios(config,config);// 7 & 30
bb_configure2Gpios(config,config);// 6 & 31
bb_configure2Gpios(config,config);// 5 & 32
bb_configure2Gpios(config,config);// 4 & 33
bb_configure2Gpios(config,config);// 3 & 34
bb_configure2Gpios(config,config);// 2 & 35
bb_configure2Gpios(config,config);// 1 & 36
bb_configure2Gpios(config,config);// 0 & 37
bb_load();
}

#endif // BITBANG_C_HEADER_FILE
105 changes: 105 additions & 0 deletions verilog/dv/firmware/APIs/firmware_apis.h
Original file line number Diff line number Diff line change
@@ -0,0 +1,105 @@
/**
\file
*/
#ifndef FIRMWARE_APIS_C_HEADER_FILE
#define FIRMWARE_APIS_C_HEADER_FILE

#include <defs.h>
#include <stub.c>
#include <uart.h>
#include <irq_vex.h>

#include <gpios.h>
#include <timer0.h>
#include <mgmt_gpio.h>
#include <la.h>
#include <uart_api.h>
#include <irq_api.h>
#include <spi_master.h>
#include <user_space.h>

#ifndef DOXYGEN_SHOULD_SKIP_THIS
void enable_debug(){
User_enableIF();
flash_phy_clk_divisor_write(0);
// set_debug_reg1(0);
// set_debug_reg2(0);

}
#endif /* DOXYGEN_SHOULD_SKIP_THIS */
/**
* Enable or disable the housekeeping SPI
* This function writes to the housekeeping disenable register inside the housekeeping
* \note
* When this register asserted housekeeping SPI can't be used and GPIOs[3] which is CSB can be used as any other Caravel GPIOs
*
* \warning
* By default the housekeeping SPI is enabled to use GPIOs[3] freely it should be disabled.
*
* @param is_enable when 1 (true) housekeeping is active, 0 (false) housekeeping is disabled
*/
void enableHkSpi(bool is_enable){reg_hkspi_disable = !is_enable;}
// debug regs
#ifndef DOXYGEN_SHOULD_SKIP_THIS
void set_debug_reg1(unsigned int data){reg_debug_1 = data;}
void set_debug_reg2(unsigned int data){reg_debug_2 = data;}
unsigned int get_debug_reg1(){return reg_debug_1;}
unsigned int get_debug_reg2(){return reg_debug_2;}
void wait_debug_reg1(unsigned int data){while (get_debug_reg1() != data);}
void wait_debug_reg2(unsigned int data){while (get_debug_reg2() != data);}
#endif /* DOXYGEN_SHOULD_SKIP_THIS */

// user project registers
#ifndef DOXYGEN_SHOULD_SKIP_THIS
#define reg_mprj_userl (*(volatile unsigned int*)0x300FFFF0)
#define reg_mprj_userh (*(volatile unsigned int*)0x300FFFF4)
#define reg_oeb_userl (*(volatile unsigned int*)0x300FFFEC)
#define reg_oeb_userh (*(volatile unsigned int*)0x300FFFE8)

// gpio_user
void set_gpio_user_l(unsigned int data){reg_mprj_userl = data;}
void set_gpio_user_h(unsigned int data){reg_mprj_userh = data;}
unsigned int get_gpio_user_h(){
return reg_mprj_userh;
}
unsigned int get_gpio_user_l(){return reg_mprj_userl;}
void wait_gpio_user_l(unsigned int data){while (reg_mprj_userl != data);}
void wait_gpio_user_h(unsigned int data){
while (get_gpio_user_h() != data);
}

void output_enable_all_gpio_user(char is_enable){
if (is_enable){
reg_oeb_userl = 0x0;
reg_oeb_userh = 0x0;
}else{
reg_oeb_userl = 0xFFFFFFFF;
reg_oeb_userh = 0x3F;
}

}
#endif /* DOXYGEN_SHOULD_SKIP_THIS */

//
/**
* Insert delay
*
* @param num number of delays steps. step is increment local variable and check it's value
*
*
*/
void dummyDelay(int num){
for (int i=0;i < num;i++){
continue;
}
}



// debug
#ifndef DOXYGEN_SHOULD_SKIP_THIS
void mgmt_debug_enable(){reg_wb_enable = reg_wb_enable | 0x10;}
#endif /* DOXYGEN_SHOULD_SKIP_THIS */


#endif // FIRMWARE_APIS_C_HEADER_FILE
Loading

0 comments on commit 0f3bc96

Please sign in to comment.