]> rtime.felk.cvut.cz Git - fpga/rpi-motor-control-pxmc.git/blob - src/app/rpi-pmsm-test1/appl_main.c
RPi PXMC Test: stop FPGA clock when application is terminated to activate FPGA failsa...
[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 #include "rpi_gpio.h"
8 #include "rpi_gpclk.h"
9
10 void appl_stop(void)
11 {
12   pxmc_done();
13   fprintf(stderr, "Application abnormal termination\n");
14   sleep(1);
15   /* stop clock pin driving FPGA to ensure failase state */
16   rpi_gpio_direction_output(4, 0);
17 }
18
19 /***********************************/
20 int main(int argc, char *argv[])
21 {
22   appl_setup_environment(argv[0]);
23
24   /* initialize 50 Mhz clock output on gpio 4 */
25   if (rpi_peripheral_registers_map() < 0) {
26     fprintf(stderr, "%s: rpi_peripheral_registers_map failed\n", argv[0]);
27     return -1;
28   }
29
30   if (rpi_gpclk_setup(0, RPI_GPCLK_PLLD_500_MHZ, 10, 0) < 0) {
31     fprintf(stderr, "%s: rpi_gpclk_setup failed\n", argv[0]);
32     return -1;
33   }
34
35   if (rpi_gpio_alt_fnc(4 /*gpio*/, 0/*alt_fnc*/) < 0) {
36     fprintf(stderr, "%s: rpi_gpio_alt_fnc failed\n", argv[0]);
37     return -1;
38   }
39
40   pxmc_initialize();
41
42   do {
43     cmdproc_poll();
44   } while(1);
45
46   return 0;
47 }
48