Xilinx HLS #1: Smartcard Reader (Vivado High Level Synthesis)

Video Statistics and Information

Video
Captions Word Cloud
Reddit Comments
Captions
so this is gonna be a pretty quick introduction to the high-level synthesis options and divide of the new zhiling suite so to start we create a new project and here I'm gonna actually be making a smartcard example writer so it's something that has to progress through a specific statement change so we create a project created somewhere we just make a new file and go back to the directory we want them all to be in so here I'm just making a new directory within this and in this case I'll call it smart kerah dot C so you can just see that off screen a bit and once we have this we can return back to the creative project wizard and give it the name of the top-level function so this is the function that will be the main block in your device we can at this point also create a new file that will become the sea level test bench and as part of this you can use that to verify the RTL files so you can change the solution name to from the default and finally you select apart so a bit of a scam here I'm not actually going to be using any specific part I'm just using this to generate the very log source code that I want to then integrate into another part of my project so I just select any part here and hit OK you'll notice the default license only includes some of the newer parts too so there's a good chance if you're using something a bit older it won't even officially be supported so this is the view that it looks like here and you can see we can go up to the source window here and open that smart code C file and to make it a little easier to see I'm just going to double click to make the code editor full screen there oops wrong one sorry full screen so now we need the file that we're going to generate so in this case I know for example that I will have a number of inputs that'll give to this function and the objective of the function is to set them over a ul so to start with I include what's called this ap CH file and I'm also going to include another header file I'm going to need called ap utility you really have to look at the user guide it goes through a lot of the details of the API the AP siient dot h in particular gives us integers of any size so you're not just limited you know you went 8 or 16 or 32 you can give a you int 5 obviously for our hardware design that's very advantageous because we want to minimize the amount of waste so the wasted bits so to start with I create a return the output is gonna be a 16-bit integer and you're gonna multiple outputs as I'll show in a minute here and I'm just gonna go ahead and generate the various inputs that I'm passing to it so in this case this CLA Insp 1 P 2 Len command and the command are actually going to be input bytes that will then be processed by this function and these are all static so they're set once at the beginning of the sort of call and then they're processed here you can see the un5 and you went 128 so these are some you know otter sizes you wouldn't normally have the Len response and the response are actually going to be output so you can see you're using a pointer here again though these will be a single one so the response is just at the end of the processing is done the UART interface is something that's streaming so the function will be called and then it's expecting that it's going to be outputting multiple bytes to the UART and then the UART is going to be putting bytes so there's going to be some dependencies so we can see I've sort of started to create that and I'll put a comment there that those are to you are streaming to and from the US so as we'll see a lot of the trouble and a lot of the important stuff will come around to get that streaming interface to work properly anyway so is a first example what we're gonna go through is we're going to say okay well the objective is that the UART outputs those input bytes in sequence so if you know the smartcard protocol it sends the CLA by the I and s by the p1 p2 bytes and the length of either the command or the response I'm simplifying here a little bit so the expected sort of working of this function is that it'll go through and output each of those bytes to the you air but if this is just straight C what you know is that the compiler will optimize all that way because only the final one matters so we have to put a note that the pointers are volatile and this tells the compiler in normal C code and also it's incredibly important in this case to say don't optimize that away do every one of these rights I'm also going to use them like arrays in this case there's two ways to use them the user guide goes into more detail and this will put it into what's called a FIFO mode so I'm you know saying I'm going to write to the first byte in second by etc if the high-level synthesis can detect that I'm accessing this output in a sequential manner manner it will allow me to use it exactly like a FIFO which is handy because the real you are at interface will run like a FIFO because you'll write a bunch of bytes and it'll take some time before we get those bytes physically going over the wire the next thing I need to do now after you send those that header bytes those five bytes the smart card is going to return with this acknowledgment byte so we want to write five byte and then read this single acknowledgement or procedure but one other issue you're going to run into that's extremely critical here is that the high level synthesis is going to try to optimize stuff away and in particular it's going to say okay you're doing five rates and one read it thinks it can try to do that read early on so you have to insert these ap weight function calls here and this is going to tell it that it cannot do that optimization it has to do those five steps and wait before executing the next step what will happen otherwise is you might get a stall condition because it'll try to read from the input FIFO and the input file will have no data and the procedure will stall until that FIFO gets data but it'll never get data because those five bytes are being written out so it's sort of important you go through and understand where these ap white right wait so I might be required so we can keep going and after I read the byte I'm also gonna put an AP wait because I need to read that byte in before I send more data out so if I don't have this ap wait it may in fact start to try outputting data before it's received this acknowledgment byte which I don't want so to output the payload you can see the the payload or I've called the command is 128 bit integer on the input and I'm just gonna use a while loop that goes through however many bytes there are in this case what I'm gonna use is the upper sort of starting at bit 127 two-bit 120 and I'm gonna use this ap and get range macro again there's a number of them defined so you can sort of look through them all and it's gonna use another variable to index it and we can see this loop count variable so it's just starting at 127 to 120 get to byte puts it out it then gets the next range of 8 bits etc and once it's outputted that it'll finally expect a response from the smartcard which will be the two status bytes but in this case I'm also going to add some additional code that will send a possible receive extra response bytes so in this case I have to tell the smart card I want to read something from it so I'll send it one more bite I'll use an app weight because then I have to read so I don't want it to try to streamline the right where I say tell this marker how much it's supposed to send me and try to streamline that into where I'm actually reading in the data from the smart card because I'll get into this lock condition once again so to do this I'm again going to use a while loop and you notice the response is 128-bit output you have to be familiar with limitations of for example very log you can't have 2d arrays on the ports so this is one of the reasons I'm using the response as a hundred and twenty eight bit integer so in this case the response is read in just eight bits at a time and in this case I'm using a bit shift something you'd normally use in C instead of the macro either way this effectively gets translated to the same idea by the high level synthesis so it's very easy using your normal C coding and your normal expectations of twiddling with bits to get it translated into the high level synthesis so finally I read those two status bytes as I mentioned and we'll need a intermediate variable again it's it's quite clean in how you can define an intermediate variable and it will generate as needed any other sort of outputs you might require so here I read one byte of it and using the typical sort of C shifting an orange I read the second byte of it - I've used the wrong name underlies it in red so we just fixed that error so you might notice also this ap weight here is actually not needed because the previous functions here were reading in it's you write in and then you're done so you don't need the AP weight we need the AP weight because between you are out and you are in without that it's going to try and optimize those two together so that we then return the function and go back to the GUI so from there you can run the C synthesis and see if it gives you any errors and in this case it pops up saying there were some problems and what we see is this unsupported memory access on the smart card out so it hasn't like something we've done in this case again see the user guide to get the full details of the various methods but you can specify actually what sort of interface you want that you are it out to be in this case I want the FIFO type interface so what we do is we use special directives to tell it that that particular those you are at out you order you are out and you are in make them FIFO so we have various options you can go through you can have this handshaking protocols and I also tell it a depth which is used for some of the KO sim options that you can read about so once that's fixed you can try running synthesis again and we'll see if that fixed the problem so we just hit that arrow there we go so that it worked and you can just look at the various output options so the very log code for example is right here and you can see everything so of particular interest to us is this interface at the top to look at what sort of ports it's created so we'll come back to that in a minute when we look at some of the other options the next thing you might want to do is actually test the code so before testing the very log you can test it and see as a higher level test bench and this can be a little easier because you can obviously use any of this sort of standard C type libraries as part of your test bench so to do this we create a header file and you just put it anywhere here and I'll just copy the API I'm expecting to be using in the test bench so I'll include that and I also will once again include the AP CH so in this file we just have your standard in Maine and it's actually gonna be compiled by there's a special compiler that you know can deal with those integers of lots of different sizes so I'm gonna create some example variables some command and responses and the UART out and you are it in I'm actually generating as arrays so they'll be prefilled with what for the input for example what the total inputs are going to be I'm not really gonna deal with how the timing works out in this high level simulation at least for this simple one so I know for example that I'm expecting certain responses so in this case I'm just gonna fill them in with what I want to test ideally you can test a number of vectors obviously this is a very very simple test punch example so now when we need to create a large integer like the command 128 bits we use this special APN string to bits X and this lets us generate hex vectors of larger-than-normal see constants would allow you to do so once you have all your test vectors set up I'll call the function as if it's a just standard C function with some of the inputs there and again you can check your header file if needed and for the FIFO this is where I just passed them the UART out and UART in type buffers for the response again if it's a pointer obviously you should be passing the variable by reference so for the output ideally again you would do some sort of verification that the open is what you expected I'm just gonna print it to show you this working so I know they're supposed to be sixteen bytes in the UART output FIFO buffer from that will correspond with the command I passed and also five bytes of header so in my real application this output FIFO is going to be passed to the UART in this test application it's not and it's simply passed to the a printf here you can use you can sort of take the generated RTL and then put it in another test bench a real test bench if you want to call it that to also check timing or if you have a sort of better test bench that includes everything else so there we go so once we have this you can we need that variable too you can run the C simulation so there's a little button there we just click that and hit OK and see if there's any errors and in this case we came up with some sort of error so you just go over to the console and what you see is that the header file was not found so this was very straightforward to fix and we'll just move the header file into the expected directory the C test benches you're using here you may find them a little more limited in terms of how the streaming data works this is one of the limitations of writing and see if you use C++ there's an improvement on this because there's a stream class so you won't have sort of all of these limitations where for example I'm putting all of the input in the FIFO at once and not simulating how there's this dependency that the smart card needs to see those header bytes before it writes the output so if I run it it's just dump the year at output and it's actually exactly what I expected so let's give it more or less worked so now we can again look at the generated ver log code and what we noticed for one thing is this response out actually has a valid signal so it's using this AP valid it will put by default and you can check the user guide to see it and what that means is that the response out will only be valid when that flag goes hi what I might want instead is that it's just valid at sort of the output of the entire function so I'm gonna change the type to you can change it to say AP none so there's no handshaking signals and you can register it as well if you want and you have the option of including these directives in a special directive file or as I've done right here writing into the source code so this is where you can easily see them with the pragmas I find it for simple stuff a little easier to include in the source files because they're all right there and it's easier to sort of not forget what you've put so there we see that so in this case the UART out as I said have these FIFO interface so it has a typical FIFO full or empty and write and read you have other options here you might want for example to not have a fight for interface and just have handshaking signals to say there's a byte available read the byte or the outputs valid and are you done writing in this case I'm gonna use a different outputting called the a PHS AP handshake and to use this I delete that pointer incrementing so that these plus pluses in the UART out because I those are only for the FIFO mode and I modified the directive to support a PHS and what you'll see is that when I regenerate the files instead of having this standard you know FIFO full FIFO right or fight for amplify for read type signals what you have instead is these handshaking signals that say it will put valid and output red so again there's lots of good timing diagrams in the user guide from Xilinx but I hope this very quick tutorial has helped you sort of understand how to get started just a little bit with the vivid ooh high level synthesis thanks for watching
Info
Channel: Colin O'Flynn
Views: 7,103
Rating: 4.7948718 out of 5
Keywords: verilog, fpga, xilinx
Id: yHUTok7Y6CQ
Channel Id: undefined
Length: 20min 56sec (1256 seconds)
Published: Fri Jan 11 2013
Related Videos
Note
Please note that this website is currently a work in progress! Lots of interesting data and statistics to come.