 Okay, let's continue with code processing, I would start with Cortex-M4 project, so this is this main.c file just to remind you if I would select this link with editor, then I can switch quite easily between sources of both projects and I got better visibility. Okay, so Cortex-M4 at the beginning, so we'll start with some definitions. We need to define the hardware semaphore ID which we'll use. It will be the same for both cores. I would use hardware semaphore ID 9. Then we can specify as well the process ID which would be used to take the semaphore. This process ID is not necessary if we are operating between both cores and there would be single processes in one core and the second one. This process ID is important if you've got multiple processes within one core or between both cores. In this case, it is important to indicate which process has taken the semaphore and has right to release it. In our case, I would just specify it to demonstrate how we can use it, but it is not necessary. Okay, define hardware semaphore process and I would use number 4. Okay, then I would declare the simple variable which would be used to indicate whether there was an interrupt triggered by hardware semaphore. So this flag would be set within hardware semaphore interrupt which would unblock the process taking of the hardware semaphore from while one loop. Okay, so those are the variables we'll use at the moment. Then within main function, we can see that we are activating the GPIOs, USART, and then we are booting CPU 2, so our Cortex-M0+. Within this section or just before it, we can activate interrupts for hardware semaphore for selected semaphores because we can use more than one semaphore and we can specify which of those would generate an interrupt. We've got only one semaphore, but we would like to have interrupts coming from this semaphore as well. This is why I would use hardware abstraction layer library function, so HAL underscore hardware semaphore underscore and now if I would press control space, I can see all of the functions available for this module. The function we would like to use is this first one, activate notification. It is requiring the argument it is the semaphore mask and so it is specifying which semaphores will activate the interrupt. Okay, so just to set this mask, I can use the macro hardware abstraction layer underscore hardware semaphore underscore control space semaphore id to mask and now we can put our hardware semaphore id as an argument. Okay, after this operation, our semaphore hardware semaphore number 9 will generate the interrupts once it will be released. Okay, let's continue with next operation, so now we will process the code to a while one loop. So within this while one loop, we would like to periodically send some data over USART2. This USART2 is already configured within this Cortex M4 and we should remember that we've got one USART2 and two cores, so this hardware semaphore number 9 will guard the unique access to this USART2. So at the beginning, we would like to take the semaphore if it will be successful operation, we would like to send the data over USART2. If not, we would like to wait for availability of this hardware semaphore to send our data. I would start from trial of taking the semaphore, so for this we are using hl underscore hardware semaphore underscore and it would be take function and now semaphore id in our case it will be hardware semaphore and it will be our definition. So it's id, yes, and the process id it was hardware semaphore process. Okay, so this is the function and we will continue only in a case if the return value of this function will be hl okay. Hl okay means that it was possible to take this semaphore, so after this function the semaphore 9 would be filled in with the core id of Cortex M4 as we are within the Cortex M4 part, the process id would be filled with number 4 and log bit would be set. So in such a case we will clear our status flag, it will be rather for next iterations of this operation then what we need to do is to disable the interrupt or semaphore disable the interrupt just in case that we will not take the semaphore for the second time just after release it. So those two lines would be important in next iterations not the first one but next iterations of this loop and now the main operation we would like to do within this if loop it would be sending the data, sending the data over the UART, so hl underscore UART underscore control space and we would like to send something so it will be T transmit, transmit so we've got only one UART so this would be this handler and the data would send some string so as it is Cortex M4 so I would use cm4 and carriage return and newline, then the number of the data 6 and timeout so how much time we would like to try to perform this operation so 200 milliseconds after this, just after this operation we would release the hardware semaphore for this we've got hardware semaphore release function it is a very similar one it has exactly the same arguments so semaphore id and semaphore process it is important to use the same arguments because the semaphore must be released by the same process which took it so we need to have the same argument so the semaphore id a core id and process id to release the semaphore I described it already more in details in the theoretical slides okay so this is the situation when it was possible to take the semaphore now let's perform some additional coding when it will be not possible to take the semaphore so the semaphore has been already taken by the other core what we need to do in the in such a case so the first thing would be to enable the interrupts for the semaphore to have information about semaphore release after this we can wait in the loop waiting for the semaphore status setting so as we discussed already the semaphore status has been cleared and it's cleared at the beginning and within our interrupt from from hardware semaphore which is triggered once the semaphore is released this semaphore underscore status variable is set so once this variable would be set it will be possible for us to go out of this else condition and try once again to take the semaphore okay after this just not to make too quick message flow on the terminal we will just delay the process using standard how delay function with 1000 milliseconds as an argument okay so concerning a while one loop this is the complete coding what we need to do now is to implement this hardware semaphore interrupt callback the place for this the ideal place for this is user code for oven main dot c file how we can find the name of this of this callback we can go to this it is it dot c file so the interrupt file and at the end we should see this hardware semaphore irq handler which is generated automatically by qbemix or qbide tools as this interrupt has been enabled if i would go to the definition of this function so not header but the definition so i would just copy and try to open hardware semaphore over here so we can see that in case of hardware semaphore we will have this free callback this free callback is declared as a week so we can copy it to our code over here and we can implement it what we need to do here is to set our variable to one so this is the simplest method of course it could be it would be good to to check whether this semaphore mask is in line with our settings so we may guard it by this sem mask which is an argument and we can verify whether it is in line with our settings so this is hull underscore hardware semaphore underscore semaphore id and our hardware semaphore id over here and in case it would be not zero so there would be something in fact our semaphore id would be set there the semaphore status would be set so this is all coding concerning cortex m4 now we will continue with cortex m0 plus code modifications okay before we will continue with cortex m0 plus i can just save this main.c file from cortex m4 and i will switch to main.c file from cortex m0 plus okay the beginning would be very similar so we need to define exactly the same semaphore id and process id to be able to take the the same semaphore using using different core please remember that the hardware semaphore registers are common for both cores so we are operating on them on one core the second core but we should remember that there is one common set of registers which are accessible by both cores and next point is a private variable we will use exactly the same id bit one but it will be the same naming but it is it is a different variable because it is global variable from cortex m0 plus memory area status and we will clear it then we will go directly into main function and what we need to do within this user code begin please have a look that here is much more simpler we are activating only hull in it there is no clock configuration because it is already done within cortex m4 and cortex m4 in this activating the cortex m0 plus so what we need to do here is activate the hardware semaphore sorry some activate the interrupts like it was done it has been done within a cortex m4 so to be atrial hardware semaphore hardware semaphore id semaphore id sorry sem id to mask and our hardware semaphore underscore id not id but id and i need a second bracket and that's it okay the second point is very important due to the fact that above cores will use usart2 but usart2 is already initialized by cortex m4 and as we are using hardware abstraction layer and hardware abstraction layer is using handlers so the structures which are filled within the parameters of the of the of the peripheral we need to specify some basic settings for the handler within cortex m0 plus code as well as we can see above in the code there is already the handler definition and what we need to do within this user code to section so before main while one loop we need to field the basic settings of this of this handler of this structure and it should be instance and the instance should be set to usart2 and the next point would be to set the x and rx to non busy initial state to allow us to send some data to the user using hardware abstraction layer functions to do this we will use uart it would be this argument if you would check for example uart init function which is used when cortex m4 core you will see exactly this function check idle state run there after the initialization it is giving you then access to the uart and it is allowing you to send and receive the data after proper initialization okay after this process we may continue with our main while one loop so it will be exactly the same coding like oven cortex m4 so I would just copy the content of it from this place the only difference would be that it will be cortex m0 plus and I need to change it to 7 because I add one sign okay so we've got the while one loop programmed and the same story would be with this callback so I would come back to main.cfm from cortex m4 and I would just copy this part after this operation I would save it so the coding process is done now I can build the complete project just to have the more automatic build process I would highlight my cortex m0 plus project I would click write button on mouse and select the properties and within properties I would go to project references and I would select this cortex m4 apart when I will do it prior the build of cortex m0 plus cortex m4 code would be built automatically so now I can press keeping this cortex m0 plus project highlighted I can press this hammer to build the project in fact both projects we can see some errors so let's try to fix them most probably there is no n at the end and the same story would be in discount okay now it should be okay so let's come back and try once again okay now we can see some warnings but those are not let's say the blocking ones so we can continue with of the investigations in next part we will run a debug session and check whether everything is working correctly in this video