APM:Libraries
StorageMode.c
Go to the documentation of this file.
1 /*
2 (c) 2017 night_ghost@ykoctpa.ru
3 
4 
5 */
6 
7 #include "StorageMode.h"
8 
9 
10 // defines of disk status
11 #include "../sd/FatFs/diskio.h"
12 
13 
15 
16 
17 const int8_t STORAGE_Inquirydata[] =
18 {
19  0x00, 0x80, 0x02, 0x02,
21  0x00, 0x00, 0x00,
22  'R', 'E', 'V', 'O', ' ', '@', 'N', 'G', // Manufacturer : 8 bytes
23  'S', 'D', ' ', 'C', 'a', 'r', 'd', ' ', // Product : 16 Bytes
24  'R', 'e', 'a', 'd', 'e', 'r', ' ', ' ', //
25  '1', '.', '0' ,'0', // Version : 4 Bytes
26 };
27 
28 int8_t STORAGE_Init(uint8_t lun)
29 {
30  return 0;
31 }
32 
33 
34 int8_t STORAGE_GetCapacity(uint8_t lun, uint32_t *block_num, uint32_t *block_size)
35 {
36  if(lun>0) return 1;
37 
38  *block_size = MAL_massBlockSize[lun];
39  *block_num = MAL_massBlockCount[lun];
40  return 0;
41 }
42 
43 int8_t STORAGE_IsReady(uint8_t lun)
44 {
46 }
47 
48 int8_t STORAGE_IsWriteProtected(uint8_t lun)
49 {
50  return usb_mass_mal_get_status(lun) & STA_PROTECT;
51 
52 }
53 
54 int8_t STORAGE_Read(
55  uint8_t lun, // logical unit number
56  uint8_t *buf, // Pointer to the buffer to save data
57  uint32_t blk_addr, // address of 1st block to be read
58  uint16_t blk_len) // nmber of blocks to be read
59 {
60  return usb_mass_mal_read_memory(lun, buf, blk_addr, blk_len);
61 }
62 
63 int8_t STORAGE_Write(uint8_t lun,
64  uint8_t *buf,
65  uint32_t blk_addr,
66  uint16_t blk_len)
67 {
68  return usb_mass_mal_write_memory(lun, buf, blk_addr, blk_len);
69 }
70 
71 inline int8_t STORAGE_GetMaxLun(void)
72 {
73  return (STORAGE_LUN_NBR - 1);
74 }
75 
76 
77 #ifdef USE_USB_OTG_FS
78 extern void systemInit(uint8_t oc);
79 
80 void OTG_FS_WKUP_IRQHandler(void)
81 {
82  if(USB_OTG_dev.cfg.low_power)
83  {
84  *(uint32_t *)(0xE000ED10) &= 0xFFFFFFF9 ; // SCB_SCR reset bits 0x6, SLEEPDEEP & SLEEPONEXIT
85  systemInit(0);
86  USB_OTG_UngateClock(&USB_OTG_dev);
87  }
88  EXTI_ClearITPendingBit(EXTI_Line18);
89 }
90 #endif
91 
92 
94 {
102  (int8_t *)STORAGE_Inquirydata,
103 };
104 
#define STA_NOINIT
Definition: diskio.h:42
void OTG_FS_WKUP_IRQHandler(void)
const USBD_STORAGE_cb_TypeDef STORAGE_fops
Definition: StorageMode.c:93
#define STA_PROTECT
Definition: diskio.h:44
int8_t STORAGE_GetCapacity(uint8_t lun, uint32_t *block_num, uint32_t *block_size)
Definition: StorageMode.c:34
int8_t STORAGE_Init(uint8_t lun)
Definition: StorageMode.c:28
USB_OTG_CORE_HANDLE USB_OTG_dev
USB_OTG_CORE_CFGS cfg
Definition: usb_core.h:298
uint16_t usb_mass_mal_get_status(uint8_t lun)
int8_t STORAGE_Write(uint8_t lun, uint8_t *buf, uint32_t blk_addr, uint16_t blk_len)
Definition: StorageMode.c:63
#define USBD_STD_INQUIRY_LENGTH
Definition: usbd_msc_mem.h:48
void USB_OTG_UngateClock(USB_OTG_CORE_HANDLE *pdev)
USB_OTG_UngateClock : active USB Core clock.
Definition: usb_core.c:1982
const USBD_STORAGE_cb_TypeDef *const USBD_STORAGE_fops
Definition: StorageMode.c:105
uint32_t MAL_massBlockCount[STORAGE_LUN_NBR]
int8_t STORAGE_IsReady(uint8_t lun)
Definition: StorageMode.c:43
int8_t STORAGE_Read(uint8_t lun, uint8_t *buf, uint32_t blk_addr, uint16_t blk_len)
Definition: StorageMode.c:54
int8_t usb_mass_mal_write_memory(uint8_t lun, uint8_t *writebuff, uint32_t memoryOffset, uint16_t transferLength)
const int8_t STORAGE_Inquirydata[]
Definition: StorageMode.c:17
#define STORAGE_LUN_NBR
#define STA_NODISK
Definition: diskio.h:43
uint32_t MAL_massBlockSize[STORAGE_LUN_NBR]
int8_t STORAGE_GetMaxLun(void)
Definition: StorageMode.c:71
void systemInit(uint8_t oc)
Setup the microcontroller system Initialize the Embedded Flash Interface, the PLL and update the Syst...
uint8_t low_power
Definition: usb_core.h:172
int8_t usb_mass_mal_read_memory(uint8_t lun, uint8_t *readbuff, uint32_t memoryOffset, uint16_t transferLength)
int8_t STORAGE_IsWriteProtected(uint8_t lun)
Definition: StorageMode.c:48