]> rtime.felk.cvut.cz Git - fpga/rpi-motor-control-pxmc.git/blob - src/app/rpi-pmsm-test1/appl_main.c
RPi PXMC Test: extend application to work on Ti AM437x and Xilinx Zynq.
[fpga/rpi-motor-control-pxmc.git] / src / app / rpi-pmsm-test1 / appl_main.c
1 #include <system_def.h>
2 #include <stdio.h>
3 #include <string.h>
4
5 #include "appl_defs.h"
6 #include "appl_utils.h"
7
8 #ifdef APPL_WITH_ZYNQ_DRV
9 #include "zynq_3pmdrv1_mc.h"
10 #else
11 #include "rpi_gpio.h"
12 #include "rpi_gpclk.h"
13 #endif
14
15 void appl_stop(void)
16 {
17   pxmc_done();
18   fprintf(stderr, "Application abnormal termination\n");
19   sleep(1);
20   /* stop clock pin driving FPGA to ensure failase state */
21  #ifndef APPL_WITH_ZYNQ_DRV
22   rpi_gpio_direction_output(4, 0);
23  #endif
24 }
25
26 /***********************************/
27 int main(int argc, char *argv[])
28 {
29   appl_setup_environment(argv[0]);
30
31 #ifdef APPL_RPI_PMSM_SETUP_CLKOUT
32
33   /* initialize 50 Mhz clock output on gpio 4 */
34   if (rpi_peripheral_registers_map() < 0) {
35     fprintf(stderr, "%s: rpi_peripheral_registers_map failed\n", argv[0]);
36     return -1;
37   }
38
39   if (rpi_gpclk_setup(0, RPI_GPCLK_PLLD_500_MHZ, 10, 0) < 0) {
40     fprintf(stderr, "%s: rpi_gpclk_setup failed\n", argv[0]);
41     return -1;
42   }
43
44   if (rpi_gpio_alt_fnc(4 /*gpio*/, 0/*alt_fnc*/) < 0) {
45     fprintf(stderr, "%s: rpi_gpio_alt_fnc failed\n", argv[0]);
46     return -1;
47   }
48
49 #endif /* APPL_RPI_PMSM_SETUP_CLKOUT */
50
51   pxmc_initialize();
52
53   do {
54     cmdproc_poll();
55   } while(1);
56
57   return 0;
58 }
59