due-pp-lib.h 4.1 KB

123456789101112131415161718192021222324252627282930313233343536373839404142434445464748495051525354555657585960616263646566676869707172737475767778798081828384858687888990919293949596979899100101102103
  1. //2023.10.07 +int due_download_prog_save_to_file(int fd,due_prog_t *program);
  2. //10.18 +int due_download_prog_save_to_file_command/data
  3. /*
  4. Copyright 2018, Carl Michal
  5. This file is part of due-pp-lib.
  6. due-pp-lib is free software: you can redistribute it and/or modify
  7. it under the terms of the GNU General Public License as published by
  8. the Free Software Foundation, either version 3 of the License, or (at
  9. your option) any later version.
  10. This program is distributed in the hope that it will be useful, but
  11. WITHOUT ANY WARRANTY; without even the implied warranty of
  12. MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the GNU
  13. General Public License for more details.
  14. You should have received a copy of the GNU General Public License
  15. along with this program. If not, see <http://www.gnu.org/licenses/>.
  16. */
  17. //#include "stdio.h" //FILE
  18. // MAXDATA is in 4-byte words
  19. #define MAXDATA 23003
  20. #define MAXSUB 4000
  21. #define DEFAULT_PORT 0
  22. #define ALT_PORT 1
  23. #define DAC_PORT 2
  24. //#define NUM_OPCODES 14
  25. // branch and exit assigned to 15?
  26. // this isn't a great system since the minimums don't necessarily line up
  27. // with opcodes. Here the NUM_OPCODES element is for an ordinary event,
  28. // and NUM_OPCODES+1 is for CALL_SUB. EXT_TRIG and TRIG_MAX
  29. // have restrictions on both the event themselves and the preceding.
  30. // Some of these are for the events preceding. Take the bigger of the two and
  31. // use for both.
  32. //int min_ticks[NUM_OPCODES+2] = {20,20,20,25,0,25,20,25,25,25,25,25,25,20,10,25};
  33. typedef struct due_prog_type{
  34. unsigned int dpos,
  35. events, // not really important!
  36. queued_events,
  37. queue_pos,
  38. loop_level,
  39. state,
  40. last_ticks,
  41. in_sub_num;
  42. char in_sub,
  43. error,
  44. active_port, // 0 = default, 1=alternate, 2=dacs
  45. auto_shift; // do we bit shift the outputs automatically?
  46. unsigned int data[MAXDATA]; // the program itself
  47. int sub_table[MAXSUB];//={[0 ... 3999] = 0 }; // holds the start address for the beginning of each subroutine.
  48. char sub_entry_port[MAXSUB];
  49. } due_prog_t;
  50. // public functions:
  51. int due_init_program(due_prog_t *program, char auto_shift);
  52. int due_add_event(due_prog_t *program, unsigned int outputs, unsigned int ticks);
  53. int due_start_loop(due_prog_t *program, unsigned int loops,unsigned int outputs, unsigned int ticks) ;
  54. int due_end_loop(due_prog_t *program, unsigned int outputs, unsigned int ticks) ;
  55. int due_exit_program(due_prog_t *program);
  56. int due_swap_to_alt(due_prog_t *program, unsigned int outputs, unsigned int ticks);
  57. int due_swap_to_default(due_prog_t *program, unsigned int outputs, unsigned int ticks);
  58. int due_swap_to_dacs(due_prog_t *program, unsigned int dac0, unsigned int dac1, unsigned int ticks);
  59. int due_finalize_program(due_prog_t *program);
  60. int due_call_sub(due_prog_t *program, unsigned int subroutine_id, unsigned int outputs,unsigned int ticks);
  61. int due_start_sub(due_prog_t *program, unsigned int subroutine_id);
  62. int due_return_from_sub(due_prog_t *program, unsigned int outputs, unsigned int ticks);
  63. int due_wait_for_trigger(due_prog_t *program, unsigned int outputs,unsigned int ticks);
  64. int due_wait_for_trigger_max(due_prog_t *program, unsigned int outputs, unsigned int ticks);
  65. int due_write_dacs(due_prog_t *program, unsigned int dac0, unsigned int dac1,unsigned int outputs,unsigned int ticks);
  66. int due_write_alt(due_prog_t *program, unsigned int outputs_alt, unsigned int outputs,unsigned int ticks);
  67. int due_write_default(due_prog_t *program, unsigned int outputs_def,unsigned int outputs,unsigned int ticks);
  68. int due_dump_program(due_prog_t *program);
  69. int due_open_prog(char *device);
  70. void due_close_prog(int fd);
  71. int due_download_prog(int fd,due_prog_t *program);
  72. int due_download_prog_save_to_file(int fd,due_prog_t *program);
  73. int due_download_prog_save_to_file_command(int fd,due_prog_t *program);
  74. //int due_download_prog_save_to_file_data(int fd,due_prog_t *program);
  75. int due_run_program(int fd, char start_command);
  76. int due_wait_for_completion(int fd, int timeout);
  77. int due_interrupt_program(int fd);
  78. int due_get_status(int fd);
  79. int due_write_dacs_now(int fd, unsigned int dac0,unsigned int dac1);
  80. int due_write_alt_now(int fd, unsigned int outputs);
  81. int due_read_analog(int fd, unsigned char pin);