<commit_before>/*
 * Copyright 2022 Google LLC
 *
 * Licensed under the Apache License, Version 2.0 (the "License");
 * you may not use this file except in compliance with the License.
 * You may obtain a copy of the License at
 *
 *     http://www.apache.org/licenses/LICENSE-2.0
 *
 * Unless required by applicable law or agreed to in writing, software
 * distributed under the License is distributed on an "AS IS" BASIS,
 * WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied.
 * See the License for the specific language governing permissions and
 * limitations under the License.
 */

#include "libs/msc_ums/msc_ums.h"

#include "third_party/freertos_kernel/include/FreeRTOS.h"
#include "third_party/freertos_kernel/include/task.h"
#include "third_party/nxp/rt1176-sdk/components/flash/nand/fsl_nand_flash.h"

extern "C" nand_handle_t *BOARD_GetNANDHandle(void);

#define DATA_IN (0)
#define DATA_OUT (1)
#define USB_MSC_INTERFACE_COUNT (1U)
#define USB_MSC_INTERFACE_ALTERNATE_COUNT (1U)
#define USB_MSC_CONFIGURE_INDEX (1U)
#define USB_DEVICE_MSC_WRITE_BUFF_SIZE (512 * 32U)
#define USB_DEVICE_MSC_READ_BUFF_SIZE (512 * 32U)
#define LOGICAL_UNIT_SUPPORTED (1)

namespace coralmicro {
namespace {
constexpr int kPagesPerBlock = 64;
constexpr int kMaxPagesPerTransfer = 16;
constexpr int kFilesystemBaseBlock = 12;
constexpr size_t kPageSize = 2048;
}  // namespace

USB_DMA_NONINIT_DATA_ALIGN(USB_DATA_ALIGN_SIZE)
uint32_t g_mscReadRequestBuffer[(USB_DEVICE_MSC_READ_BUFF_SIZE * 2) >> 2];

USB_DMA_NONINIT_DATA_ALIGN(USB_DATA_ALIGN_SIZE)
uint32_t g_mscWriteRequestBuffer[(USB_DEVICE_MSC_WRITE_BUFF_SIZE * 2) >> 2];
usb_device_inquiry_data_fromat_struct_t g_InquiryInfo = {
    (USB_DEVICE_MSC_UFI_PERIPHERAL_QUALIFIER
     << USB_DEVICE_MSC_UFI_PERIPHERAL_QUALIFIER_SHIFT) |
        USB_DEVICE_MSC_UFI_PERIPHERAL_DEVICE_TYPE,
    (uint8_t)(USB_DEVICE_MSC_UFI_REMOVABLE_MEDIUM_BIT
              << USB_DEVICE_MSC_UFI_REMOVABLE_MEDIUM_BIT_SHIFT),
    USB_DEVICE_MSC_UFI_VERSIONS,
    0x02,
    USB_DEVICE_MSC_UFI_ADDITIONAL_LENGTH,
    {0x00, 0x00, 0x00},
    {'C', 'O', 'R', 'A', 'L'},
    {'M', 'A', 'S', 'S', ' ', 'S', 'T', 'O', 'R', 'A', 'G', 'E'},
    {'0', '0', '0', '1'}};
usb_device_mode_parameters_header_struct_t g_ModeParametersHeader = {
    /*refer to ufi spec mode parameter header*/
    0x0000, /*!< Mode Data Length*/
    0x00,   /*!<Default medium type (current mounted medium type)*/
    0x00,   /*!MODE SENSE command, a Write Protected bit of zero indicates the
               medium is write enabled*/
    {0x00, 0x00, 0x00, 0x00} /*!<This bit should be set to zero*/
};
typedef struct _usb_msc_struct {
  usb_device_handle deviceHandle;<commit_msg>msc_ums: Store request buffers in cacheable memory<commit_after>/*
 * Copyright 2022 Google LLC
 *
 * Licensed under the Apache License, Version 2.0 (the "License");
 * you may not use this file except in compliance with the License.
 * You may obtain a copy of the License at
 *
 *     http://www.apache.org/licenses/LICENSE-2.0
 *
 * Unless required by applicable law or agreed to in writing, software
 * distributed under the License is distributed on an "AS IS" BASIS,
 * WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied.
 * See the License for the specific language governing permissions and
 * limitations under the License.
 */

#include "libs/msc_ums/msc_ums.h"

#include "third_party/freertos_kernel/include/FreeRTOS.h"
#include "third_party/freertos_kernel/include/task.h"
#include "third_party/nxp/rt1176-sdk/components/flash/nand/fsl_nand_flash.h"

extern "C" nand_handle_t *BOARD_GetNANDHandle(void);

#define DATA_IN (0)
#define DATA_OUT (1)
#define USB_MSC_INTERFACE_COUNT (1U)
#define USB_MSC_INTERFACE_ALTERNATE_COUNT (1U)
#define USB_MSC_CONFIGURE_INDEX (1U)
#define USB_DEVICE_MSC_WRITE_BUFF_SIZE (512 * 32U)
#define USB_DEVICE_MSC_READ_BUFF_SIZE (512 * 32U)
#define LOGICAL_UNIT_SUPPORTED (1)

namespace coralmicro {
namespace {
constexpr int kPagesPerBlock = 64;
constexpr int kMaxPagesPerTransfer = 16;
constexpr int kFilesystemBaseBlock = 12;
constexpr size_t kPageSize = 2048;
}  // namespace

// TODO(ljonas): Cache management.

//USB_DMA_NONINIT_DATA_ALIGN(USB_DATA_ALIGN_SIZE)
uint32_t g_mscReadRequestBuffer[(USB_DEVICE_MSC_READ_BUFF_SIZE * 2) >> 2];

// USB_DMA_NONINIT_DATA_ALIGN(USB_DATA_ALIGN_SIZE)
uint32_t g_mscWriteRequestBuffer[(USB_DEVICE_MSC_WRITE_BUFF_SIZE * 2) >> 2];
usb_device_inquiry_data_fromat_struct_t g_InquiryInfo = {
    (USB_DEVICE_MSC_UFI_PERIPHERAL_QUALIFIER
     << USB_DEVICE_MSC_UFI_PERIPHERAL_QUALIFIER_SHIFT) |
        USB_DEVICE_MSC_UFI_PERIPHERAL_DEVICE_TYPE,
    (uint8_t)(USB_DEVICE_MSC_UFI_REMOVABLE_MEDIUM_BIT
              << USB_DEVICE_MSC_UFI_REMOVABLE_MEDIUM_BIT_SHIFT),
    USB_DEVICE_MSC_UFI_VERSIONS,
    0x02,
    USB_DEVICE_MSC_UFI_ADDITIONAL_LENGTH,
    {0x00, 0x00, 0x00},
    {'C', 'O', 'R', 'A', 'L'},
    {'M', 'A', 'S', 'S', ' ', 'S', 'T', 'O', 'R', 'A', 'G', 'E'},
    {'0', '0', '0', '1'}};
usb_device_mode_parameters_header_struct_t g_ModeParametersHeader = {
    /*refer to ufi spec mode parameter header*/
    0x0000, /*!< Mode Data Length*/
    0x00,   /*!<Default medium type (current mounted medium type)*/
    0x00,   /*!MODE SENSE command, a Write Protected bit of zero indicates the
               medium is write enabled*/
    {0x00, 0x00, 0x00, 0x00} /*!<This bit should be set to zero*/
};
typedef struct _usb_msc_struct {
  usb_device_handle deviceHandle;
{'fraction_non_alphanumeric': 0.10340409956076135, 'fraction_numerical': 0.0314787701317716, 'mean_word_length': 4.927331887201736, 'pattern_counts': {'":': 0, '<': 17, '<?xml version=': 0, '>': 11, 'https://': 0, 'lorem ipsum': 0, 'www.': 2, 'xml': 0}, 'pii_count': 0, 'substrings_counts': 0, 'word_list_counts': {'cursed_substrings.json': 2, 'profanity_word_list.json': 0, 'sexual_word_list.json': 0, 'zh_pornsignals.json': 0}}
{'dir': 'git-commits-cleaned', 'id': '3707464', 'n_tokens_mistral': 2086, 'n_tokens_neox': 1952, 'n_words': 482}