main.c 3.2 KB

123456789101112131415161718192021222324252627282930313233343536373839404142434445464748495051525354555657585960616263646566676869707172737475767778798081828384858687888990919293949596979899100101102103104105106107108109110111112113114115116117118119120121122123124125126127128129130131132133134135136
  1. /*********************************Copyright (c)*********************************************
  2. **
  3. **
  4. **
  5. **-------------------------------file info-------------------------------------------------
  6. ** Vrsions: V1.0
  7. ** Filename: main.c
  8. ** Creator: shanlong.li
  9. ** Date: 2021/08/30
  10. ** Description: share memory and mailbox
  11. **
  12. **-------------------------------history----------------------------------------------
  13. ** Name: shanlong.li
  14. ** Versions: V1.0
  15. ** Date: 2021/08/30
  16. ** Description:
  17. **
  18. ** ----------------------------------------------------------------------------------------
  19. ******************************************************************************************/
  20. #include <stdio.h>
  21. #include <string.h>
  22. #include "e24_host_shm.h"
  23. int comm_local_buffer(void)
  24. {
  25. enum e24_status status;
  26. struct e24_device *device;
  27. struct e24_event *evt;
  28. char in_data[BUF_LEN],out_data[BUF_LEN];
  29. int i;
  30. device = e24_open_device(0,&status);
  31. if(status == E24_STATUS_FAILURE) {
  32. printf("open device fail\n");
  33. return 0;
  34. }
  35. evt = e24_event_init(device,&status);
  36. if(status == E24_STATUS_FAILURE) {
  37. printf("event init fail\n");
  38. goto _derro;
  39. }
  40. printf("input data:\n");
  41. for(i = 0;i< BUF_LEN; i++) {
  42. in_data[i] = 27;
  43. printf("%d,",in_data[i]);
  44. }
  45. printf("\n");
  46. memset(out_data,0x0,BUF_LEN);
  47. e24_run_command(evt,(void*)in_data,BUF_LEN,(void*)out_data,BUF_LEN,&status);
  48. printf("output data:\n");
  49. for(i = 0;i< BUF_LEN; i++) {
  50. printf("%d,",out_data[i]);
  51. }
  52. printf("\n");
  53. _error:
  54. e24_release_buffer(device,NULL);
  55. e24_event_release(evt);
  56. _derro:
  57. e24_release_device(device);
  58. return 0;
  59. }
  60. int comm_alloc_buffer(void) {
  61. enum e24_status status = -1;
  62. struct e24_device *device;
  63. struct e24_event *evt;
  64. struct e24_ioctl_alloc alloc_out_buf = {.size = BUF_LEN,};
  65. struct e24_ioctl_alloc alloc_in_buf = {.size = BUF_LEN,};
  66. int i;
  67. device = e24_open_device(0,&status);
  68. if(status == E24_STATUS_FAILURE) {
  69. printf("open device fail\n");
  70. return 0;
  71. }
  72. evt = e24_event_init(device,&status);
  73. if(status == E24_STATUS_FAILURE) {
  74. printf("event init fail\n");
  75. goto _derror;
  76. }
  77. e24_alloc_buffer(device,&alloc_in_buf,&status);
  78. if(status == E24_STATUS_FAILURE) {
  79. printf("alloc in buffer failed\n");
  80. goto _berror;
  81. }
  82. e24_alloc_buffer(device,&alloc_out_buf,&status);
  83. if(status == E24_STATUS_FAILURE) {
  84. printf("alloc out buffer failed\n");
  85. goto _error;
  86. }
  87. printf("input data:\n");
  88. for(i = 0;i< BUF_LEN; i++) {
  89. ((char*)alloc_in_buf.addr)[i] = 7;
  90. printf("%d,",((char*)alloc_in_buf.addr)[i]);
  91. }
  92. printf("\n");
  93. memset((char *)alloc_out_buf.addr,0x0,BUF_LEN);
  94. e24_run_command(evt,(void*)alloc_in_buf.addr,BUF_LEN,(void*)alloc_out_buf.addr,BUF_LEN,&status);
  95. printf("output data:\n");
  96. for(i = 0;i< BUF_LEN; i++) {
  97. printf("%d,",((char *)alloc_out_buf.addr)[i]);
  98. }
  99. printf("\n");
  100. e24_release_buffer(device,&alloc_out_buf);
  101. _error:
  102. e24_release_buffer(device,&alloc_in_buf);
  103. _berror:
  104. e24_event_release(evt);
  105. _derror:
  106. e24_release_device(device);
  107. return 0;
  108. }
  109. int main(int argc,char **argv) {
  110. printf("buffer alloced from share memory:\n");
  111. comm_alloc_buffer();
  112. printf("local buffer:\n");
  113. comm_local_buffer();
  114. return 0;
  115. }