Advertisement
Guest User

main.c

a guest
Apr 5th, 2020
142
0
Never
Not a member of Pastebin yet? Sign Up, it unlocks many cool features!
C 2.50 KB | None | 0 0
  1. #include "xparameters.h"
  2. #include "xgpio.h"
  3. #include "cordic_ip.h"
  4.  
  5. /**************************** user definitions ********************************/
  6. #define CHANNEL 1
  7.  
  8. //Cordic processor base addres redefinition
  9. #define CORDIC_BASE_ADDR XPAR_CORDIC_IP_0_S00_AXI_BASEADDR
  10.  
  11. //Cordic processor registers' offset redefinition
  12. #define CONTROL_REG_OFFSET CORDIC_IP_S00_AXI_SLV_REG0_OFFSET
  13. #define ANGLE_REG_OFFSET CORDIC_IP_S00_AXI_SLV_REG1_OFFSET
  14. #define STATUS_REG_OFFSET CORDIC_IP_S00_AXI_SLV_REG2_OFFSET
  15. #define RESULT_REG_OFFSET CORDIC_IP_S00_AXI_SLV_REG3_OFFSET
  16. #define RESULT_REG_SIN(param) ((u32)param & (u32)(0x00000FFF))
  17. #define RESULT_REG_COS(param) (((u32)param & (u32)(0x0FFF0000)) >> 16 )
  18.  
  19. /***************************** Main function *********************************/
  20.  
  21. int main(){
  22. int status;
  23. XGpio angleGpio, sinGpio, cosGpio;
  24. u32 data;
  25. u32 result, sin, cos;
  26.  
  27. /* Initialize driver for the input angle GPIOe */
  28.         status = XGpio_Initialize(&angleGpio, XPAR_AXI_GPIO_ANGLE_DEVICE_ID);
  29.         if (status != XST_SUCCESS) {
  30.                goto FAILURE;
  31.         }
  32.         XGpio_SetDataDirection(&angleGpio, CHANNEL, 0xFFF);
  33.        
  34. /* Initialize driver for the output sin GPIO */
  35.         status = XGpio_Initialize(&sinGpio, XPAR_AXI_GPIO_SIN_DEVICE_ID);
  36.         if (status != XST_SUCCESS) {
  37.                goto FAILURE;
  38.         }
  39.         XGpio_SetDataDirection(&sinGpio, CHANNEL, 0x000);
  40.        
  41. /* Initialize driver for the output sin GPIO */
  42.         status = XGpio_Initialize(&cosGpio, XPAR_AXI_GPIO_COS_DEVICE_ID);
  43.         if (status != XST_SUCCESS) {
  44.                goto FAILURE;
  45.         }
  46.         XGpio_SetDataDirection(&cosGpio, CHANNEL, 0x000);
  47.        
  48. //Read angle binary data from angle GPIO. fxp(12:10) format
  49.         data = XGpio_DiscreteRead(&angleGpio, CHANNEL);
  50.        
  51.        
  52. //Send data to data register of cordic processor
  53.         CORDIC_IP_mWriteReg(CORDIC_BASE_ADDR, ANGLE_REG_OFFSET, data);
  54.        
  55. //Start cordic processor - pulse start bit in control register
  56.         CORDIC_IP_mWriteReg(CORDIC_BASE_ADDR, CONTROL_REG_OFFSET, 1);
  57.         CORDIC_IP_mWriteReg(CORDIC_BASE_ADDR, CONTROL_REG_OFFSET, 0);
  58.        
  59. //Wait for ready bit in status register
  60.         while( (CORDIC_IP_mReadReg(CORDIC_BASE_ADDR, STATUS_REG_OFFSET) & 0x01) == 0);
  61.        
  62. //Get results
  63.         result = CORDIC_IP_mReadReg(CORDIC_BASE_ADDR, RESULT_REG_OFFSET);
  64.        
  65. //Extract sin and cos from 32-bit register data
  66.         sin = RESULT_REG_SIN( result );
  67.         cos = RESULT_REG_COS( result );
  68.        
  69. //Send to GPIO
  70.         XGpio_DiscreteWrite(&sinGpio, CHANNEL, sin);
  71.         XGpio_DiscreteWrite(&cosGpio, CHANNEL, cos);
  72.        
  73. /* Failure or end trap */
  74. FAILURE:
  75.         while(1);
  76.        
  77. }
Advertisement
Add Comment
Please, Sign In to add comment
Advertisement