bsp_share.h 2.0 KB

123456789101112131415161718192021222324252627282930313233343536373839404142434445464748495051525354555657585960
  1. #ifndef __SHMEM_H
  2. //T536 共享内存地址
  3. //1. linux核->裸核空间定义如下:
  4. #define SHM_ADDR_D_FREQ_TR 0x00000000 //频率跟踪
  5. #define SHM_ADDR_D_RFV_1 0x00000040 //第一片AD7616参考电压范围
  6. #define SHM_ADDR_D_RFV_2 0x00000080 //第二片AD7616参考电压范围
  7. #define SHM_ADDR_D_RFV_3 0x000000C0 //第三片AD7616参考电压范围
  8. #define SHM_ADDR_D_RFV_4 0x00000100 //第四片AD7616参考电压范围
  9. #define SHM_ADDR_D_TIME 0x00001000 //系统时间 linux向裸核校时
  10. #define SHM_ADDR_D_HB 0x00001040 //心跳
  11. struct shmem_block {
  12. unsigned short flag;
  13. unsigned short crc;
  14. unsigned int len;
  15. unsigned char data[];
  16. } __attribute__((__packed__));
  17. struct shmem_fd {
  18. int fd;
  19. int shmem_len;
  20. struct shmem_block *linux_write;
  21. struct shmem_block *linux_read;
  22. int linux_write_len, linux_read_len;
  23. int linux_write_data_len, linux_read_data_len;
  24. };
  25. extern struct shmem_fd shmem_fd;
  26. #define shmem_code_len 8 /* 8 = flag(2) + crc(2) + len(4) */
  27. #define max_shmem_wr_len(s) ((s) / 2)
  28. #define max_shmem_rd_len(s) ((s) / 2)
  29. #define max_shmem_wr_data_len(s) (max_shmem_wr_len(s) - shmem_code_len)
  30. #define max_shmem_rd_data_len(s) (max_shmem_rd_len(s) - shmem_code_len)
  31. /**
  32. * 参数 waiting 说明:
  33. * waiting 的单位为“微秒”
  34. * 如果 waiting < 0 ,则会一直等待,直到数据可读/可写
  35. * 如果 waiting == 0 ,则仅检查一次数据是否可读/可写,不可以则返回 -ETIMEOUT
  36. * 如果 waiting > 0 ,则检查一次数据是否可读/可写,等待 waiting 后,再检查一次,
  37. * 不可以则返回 -ETIMEOUT
  38. */
  39. int shmem_read_crc(struct shmem_fd *shmem_fd, void *buf, int len,
  40. int waiting, unsigned short *crc);
  41. int shmem_write_crc(struct shmem_fd *shmem_fd, void *buf, int len,
  42. int waiting, unsigned short *crc);
  43. int shmem_read(struct shmem_fd *shmem_fd, void *buf, int len, int waiting);
  44. int shmem_write(struct shmem_fd *shmem_fd, void *buf, int len, int waiting);
  45. int shmem_init(struct shmem_fd *shmem_fd);
  46. void shmem_exit(struct shmem_fd *shmem_fd);
  47. #endif // !__SHMEM_H