bsp_share.h 1.9 KB

12345678910111213141516171819202122232425262728293031323334353637383940414243444546474849505152535455565758596061
  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. {
  13. unsigned short flag;
  14. unsigned short crc;
  15. unsigned int len;
  16. unsigned char data[];
  17. } __attribute__((__packed__));
  18. struct shmem_fd
  19. {
  20. int fd;
  21. int shmem_len;
  22. struct shmem_block *linux_write;
  23. struct shmem_block *linux_read;
  24. int linux_write_len, linux_read_len;
  25. int linux_write_data_len, linux_read_data_len;
  26. };
  27. extern struct shmem_fd shmem_fd;
  28. #define shmem_code_len 8 /* 8 = flag(2) + crc(2) + len(4) */
  29. #define max_shmem_wr_len(s) ((s) / 2)
  30. #define max_shmem_rd_len(s) ((s) / 2)
  31. #define max_shmem_wr_data_len(s) (max_shmem_wr_len(s) - shmem_code_len)
  32. #define max_shmem_rd_data_len(s) (max_shmem_rd_len(s) - shmem_code_len)
  33. /**
  34. * 参数 waiting 说明:
  35. * waiting 的单位为“微秒”
  36. * 如果 waiting < 0 ,则会一直等待,直到数据可读/可写
  37. * 如果 waiting == 0 ,则仅检查一次数据是否可读/可写,不可以则返回 -ETIMEOUT
  38. * 如果 waiting > 0 ,则检查一次数据是否可读/可写,等待 waiting 后,再检查一次,
  39. * 不可以则返回 -ETIMEOUT
  40. */
  41. int shmem_read_crc(struct shmem_fd *shmem_fd, void *buf, int len,
  42. int waiting, unsigned short *crc);
  43. int shmem_write_crc(struct shmem_fd *shmem_fd, void *buf, int len,
  44. int waiting, unsigned short *crc);
  45. int shmem_read(struct shmem_fd *shmem_fd, void *buf, int len, int waiting);
  46. int shmem_write(struct shmem_fd *shmem_fd, void *buf, int len, int waiting);
  47. int shmem_init(struct shmem_fd *shmem_fd);
  48. void shmem_exit(struct shmem_fd *shmem_fd);
  49. #endif // !__SHMEM_H