Skip to content
New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

Add tests for sram test chip #64

Merged
merged 4 commits into from
Dec 30, 2024
Merged
Show file tree
Hide file tree
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
2 changes: 2 additions & 0 deletions silicon_tests/common/common.h
Original file line number Diff line number Diff line change
Expand Up @@ -22,6 +22,8 @@
#include <uart_api.h>
#include <spi_master.h>
#include <packet.h>
#include <user_space.h>
#include <rand.h>

/**
* Enable communication between firmware and user project
Expand Down
23 changes: 23 additions & 0 deletions silicon_tests/common/rand.h
Original file line number Diff line number Diff line change
@@ -0,0 +1,23 @@
unsigned int rand_num_gen(unsigned int * seed) {
// Static LFSR state to maintain across function calls
unsigned int lfsr = * seed; // Initial non-zero seed
static int initialized = 0; // To initialize LFSR on the first call
unsigned int feedback;

// Initialize LFSR only once
if (!initialized) {
initialized = 1;
}

// Save the current LFSR value to return
unsigned int random_value = lfsr;

// Compute feedback using a maximal-length polynomial x^32 + x^22 + x^2 + x^1 + 1
feedback = ((lfsr >> 0) ^ (lfsr >> 1) ^ (lfsr >> 21) ^ (lfsr >> 31)) & 1;

// Shift LFSR and insert feedback bit
lfsr = (lfsr >> 1) | (feedback << 31);

*seed = lfsr;
return random_value;
}
178 changes: 178 additions & 0 deletions silicon_tests/common/user_space.h
Original file line number Diff line number Diff line change
@@ -0,0 +1,178 @@
/**
\file
*/

#ifndef CUSTOM_USER_ADDR_SPACE_C_HEADER_FILE
#define CUSTOM_USER_ADDR_SPACE_C_HEADER_FILE
#define USER_SPACE_ADDR 0x30000000


inline void USER_writeWord(volatile int data,int offset) __attribute__((always_inline));
inline volatile int USER_readWord(int offset) __attribute__((always_inline));
inline void USER_writeHalfWord(volatile short data,volatile int offset,bool is_first_word) __attribute__((always_inline));
inline volatile short USER_readHalfWord(volatile int offset,bool is_first_word) __attribute__((always_inline));
inline void USER_writeByte(volatile char data,volatile int offset,volatile char byte_num) __attribute__((always_inline));
inline volatile char USER_readByte( volatile int offset,volatile char byte_num) __attribute__((always_inline));

/**
* Enable communication between firmware and user project through wishbone
* \warning
* This necessary when reading or writing are needed between wishbone and user project
* if interface isn't enabled no ack would be receive and the writing or reading command will be stuck
*/
void User_enableIF(){
reg_wb_enable =1; // for enable writing to reg_debug_1 and reg_debug_2
}


/**
* Write word (4 bytes) at user address space 32 bit register
*
* @param data world data to write
* @param offset the offset of the register to write. Origin at the user project address
*
* \note
* Since offset is a word (4 bytes) and address space represent bytes, offset = address /4
* \n For example if project caravel space are 26 address bit offset = wb_addr_i[25:0]/4
*
* <table>
<caption id="multi_row"> world memory (4 bytes offset)</caption>
<tr><th>address<th>offset <th>byte0<th>byte1<th>byte2<th>byte3
<tr><td>0x0<td>0<td style="background-color:#FED64E">0<td style="background-color:#FED64E">1<td style="background-color:#FED64E">2<td style="background-color:#FED64E">3
<tr><td>0x4<td>1<td style="background-color:#EDBB99">4<td style="background-color:#EDBB99">5<td style="background-color:#EDBB99">6<td style="background-color:#EDBB99">7
<tr><td>0x8<td>2<td style="background-color:#FED64E">8<td style="background-color:#FED64E" >9<td style="background-color:#FED64E">10<td style="background-color:#FED64E">11
<tr><td>0xC<td>3<td style="background-color:#EDBB99">12<td style="background-color:#EDBB99">13<td style="background-color:#EDBB99">14<td style="background-color:#EDBB99">15 </table>

*/


inline void USER_writeWord(volatile int data,int offset){
*(((volatile int *) USER_SPACE_ADDR)+offset) = data;

}
/**
* Read word (4 bytes) at user address space 32 bit register
*
* @param offset the offset of the register to write. Origin at the user project address
*
* \note
* Since offset is a word (4 bytes) and address space represent bytes, offset = address /4
* \n For example if project caravel space are 26 address bit offset = wb_addr_i[25:0]/4
*
* <table>
<caption id="multi_row"> world memory (4 bytes offset)</caption>
<tr><th>address<th>offset <th>byte0<th>byte1<th>byte2<th>byte3
<tr><td>0x0<td>0<td style="background-color:#FED64E">0<td style="background-color:#FED64E">1<td style="background-color:#FED64E">2<td style="background-color:#FED64E">3
<tr><td>0x4<td>1<td style="background-color:#EDBB99">4<td style="background-color:#EDBB99">5<td style="background-color:#EDBB99">6<td style="background-color:#EDBB99">7
<tr><td>0x8<td>2<td style="background-color:#FED64E">8<td style="background-color:#FED64E" >9<td style="background-color:#FED64E">10<td style="background-color:#FED64E">11
<tr><td>0xC<td>3<td style="background-color:#EDBB99">12<td style="background-color:#EDBB99">13<td style="background-color:#EDBB99">14<td style="background-color:#EDBB99">15 </table>

*/
inline volatile int USER_readWord(int offset){
return *(((volatile int *) USER_SPACE_ADDR)+offset);
}
/**
* Write half word (2 bytes) at user address space 32 bit register
*
* @param data half world data to write
* @param offset the offset of the register to write. Origin at the user project address
* @param is_first_word the offset of the register to write. Origin at the user project address
*
* \note
* Since offset is a word (4 bytes) and address space represent bytes, offset = address /4
* \n For example if project caravel space are 26 address bit offset = wb_addr_i[25:0]/4
*
* <table>
<caption id="multi_row"> world memory (2byte offset)</caption>
<tr><th>is first word<th>-<th> 1<th> 1 <th>0<th>0
<tr><th>address<th>offset <th>byte0<th>byte1<th>byte2<th>byte3
<tr><td>0x0<td>0<td style="background-color:#FEF5E7">0<td style="background-color:#FEF5E7">1<td style="background-color:#FED64E">2<td style="background-color:#FED64E">3
<tr><td>0x4<td>1<td style="background-color:#FAD7A0">4<td style="background-color:#FAD7A0">5<td style="background-color:#EDBB99">6<td style="background-color:#EDBB99">7
<tr><td>0x8<td>2<td style="background-color:#FEF5E7">8<td style="background-color:#FEF5E7" >9<td style="background-color:#FED64E">10<td style="background-color:#FED64E">11
<tr><td>0xC<td>3<td style="background-color:#FAD7A0">12<td style="background-color:#FAD7A0">13<td style="background-color:#EDBB99">14<td style="background-color:#EDBB99">15 </table>

*/
inline void USER_writeHalfWord(volatile short data,volatile int offset,bool is_first_word){
volatile int half_word_offset = offset *2 + is_first_word;
*(((volatile short *) USER_SPACE_ADDR)+half_word_offset) = data;

}
/**
* Read half word (2 bytes) at user address space 32 bit register
*
* @param offset the offset of the register to write. Origin at the user project address
* @param is_first_word the offset of the register to write. Origin at the user project address
*
* \note
* Since offset is a word (4 bytes) and address space represent bytes, offset = address /4
* \n For example if project caravel space are 26 address bit offset = wb_addr_i[25:0]/4
*
* <table>
<caption id="multi_row"> world memory (2byte offset)</caption>
<tr><th>is first word<th>-<th> 1<th> 1 <th>0<th>0
<tr><th>address<th>offset <th>byte0<th>byte1<th>byte2<th>byte3
<tr><td>0x0<td>0<td style="background-color:#FEF5E7">0<td style="background-color:#FEF5E7">1<td style="background-color:#FED64E">2<td style="background-color:#FED64E">3
<tr><td>0x4<td>1<td style="background-color:#FAD7A0">4<td style="background-color:#FAD7A0">5<td style="background-color:#EDBB99">6<td style="background-color:#EDBB99">7
<tr><td>0x8<td>2<td style="background-color:#FEF5E7">8<td style="background-color:#FEF5E7" >9<td style="background-color:#FED64E">10<td style="background-color:#FED64E">11
<tr><td>0xC<td>3<td style="background-color:#FAD7A0">12<td style="background-color:#FAD7A0">13<td style="background-color:#EDBB99">14<td style="background-color:#EDBB99">15 </table>

*/
inline volatile short USER_readHalfWord(volatile int offset,bool is_first_word){
volatile int half_word_offset = offset *2 + is_first_word;
return *(((volatile short *) USER_SPACE_ADDR)+half_word_offset);
}
/**
* Write byte at user address space 32 bit register
*
* @param data byte data to write
* @param offset the offset of the register to write. Origin at the user project address
* @param byte_num number of the in the 4 bytes register (32 bits)
*
* \note
* Since offset is a word (4 bytes) and address space represent bytes, offset = address /4
* \n For example if project caravel space are 26 address bit offset = wb_addr_i[25:0]/4
*
* <table>
<caption id="multi_row"> world memory (2byte offset)</caption>
<tr><th >byte_num<th>-<th> 0 <th >1<th >2<th >3
<tr><th>address<th>offset <th>byte0<th>byte1<th>byte2<th>byte3
<tr><td>0x0<td>0<td style="background-color:#FEF5E7">0<td style="background-color:#FAD7A0">1<td style="background-color:#FED64E">2<td style="background-color:#EDBB99">3
<tr><td>0x4<td>1<td style="background-color:#FED64E">4<td style="background-color:#EDBB99">5<td style="background-color:#FEF5E7">6<td style="background-color:#FAD7A0">7
<tr><td>0x8<td>2<td style="background-color:#FEF5E7">8<td style="background-color:#FAD7A0" >9<td style="background-color:#FED64E">10<td style="background-color:#EDBB99">11
<tr><td>0xC<td>3<td style="background-color:#FED64E">12<td style="background-color:#EDBB99">13<td style="background-color:#FEF5E7">14<td style="background-color:#FAD7A0">15 </table>

*/
inline void USER_writeByte(volatile char data,volatile int offset,volatile char byte_num){
if (byte_num > 3)
byte_num =0;
volatile int byte_offset = offset *4 + byte_num;
*(((volatile char *) USER_SPACE_ADDR)+byte_offset) = data;
}
/**
* Read byte at user address space 32 bit register
*
* @param offset the offset of the register to write. Origin at the user project address
* @param byte_num number of the in the 4 bytes register (32 bits)
*
* \note
* Since offset is a word (4 bytes) and address space represent bytes, offset = address /4
* \n For example if project caravel space are 26 address bit offset = wb_addr_i[25:0]/4
*
* <table>
<caption id="multi_row"> world memory (2byte offset)</caption>
<tr><th >byte_num<th>-<th> 0 <th >1<th >2<th >3
<tr><th>address<th>offset <th>byte0<th>byte1<th>byte2<th>byte3
<tr><td>0x0<td>0<td style="background-color:#FEF5E7">0<td style="background-color:#FAD7A0">1<td style="background-color:#FED64E">2<td style="background-color:#EDBB99">3
<tr><td>0x4<td>1<td style="background-color:#FED64E">4<td style="background-color:#EDBB99">5<td style="background-color:#FEF5E7">6<td style="background-color:#FAD7A0">7
<tr><td>0x8<td>2<td style="background-color:#FEF5E7">8<td style="background-color:#FAD7A0" >9<td style="background-color:#FED64E">10<td style="background-color:#EDBB99">11
<tr><td>0xC<td>3<td style="background-color:#FED64E">12<td style="background-color:#EDBB99">13<td style="background-color:#FEF5E7">14<td style="background-color:#FAD7A0">15 </table>

*/
volatile char USER_readByte( volatile int offset,volatile char byte_num){
if (byte_num > 3)
byte_num =0;
volatile int byte_offset = offset *4 + byte_num;
return *(((volatile char *) USER_SPACE_ADDR)+byte_offset);
}

#endif // CUSTOM_USER_ADDR_SPACE_C_HEADER_FILE
5 changes: 5 additions & 0 deletions silicon_tests/sram_tc/ram1k_smoke_test/Makefile
Original file line number Diff line number Diff line change
@@ -0,0 +1,5 @@
.SUFFIXES:
TESTNAME = ram1k_smoke_test


include ../../common/common_makefile.mk
Loading