pico-ice
RaspberryPi Pico with an iCE40 FPGA
Loading...
Searching...
No Matches
ice_sram.h
1/*
2 * MIT License
3 *
4 * Copyright (c) 2023 tinyVision.ai
5 *
6 * Permission is hereby granted, free of charge, to any person obtaining a copy
7 * of this software and associated documentation files (the "Software"), to deal
8 * in the Software without restriction, including without limitation the rights
9 * to use, copy, modify, merge, publish, distribute, sublicense, and/or sell
10 * copies of the Software, and to permit persons to whom the Software is
11 * furnished to do so, subject to the following conditions:
12 *
13 * The above copyright notice and this permission notice shall be included in all
14 * copies or substantial portions of the Software.
15 *
16 * THE SOFTWARE IS PROVIDED "AS IS", WITHOUT WARRANTY OF ANY KIND, EXPRESS OR
17 * IMPLIED, INCLUDING BUT NOT LIMITED TO THE WARRANTIES OF MERCHANTABILITY,
18 * FITNESS FOR A PARTICULAR PURPOSE AND NONINFRINGEMENT. IN NO EVENT SHALL THE
19 * AUTHORS OR COPYRIGHT HOLDERS BE LIABLE FOR ANY CLAIM, DAMAGES OR OTHER
20 * LIABILITY, WHETHER IN AN ACTION OF CONTRACT, TORT OR OTHERWISE, ARISING FROM,
21 * OUT OF OR IN CONNECTION WITH THE SOFTWARE OR THE USE OR OTHER DEALINGS IN THE
22 * SOFTWARE.
23 */
24
34#pragma once
35#include <stdint.h>
36#include <stddef.h>
37#include "boards/pico_ice.h"
38
39// This module is not thread safe.
40
41#define ICE_SRAM_STATUS_BUSY_MASK 0x01
42
43// Long transfers to/from the SRAM should be avoided as CS should not be
44// asserted for more than 8us. Holding CS for too long can result in data loss.
45#define ICE_SRAM_TRANSFER_SIZE 32
46
47#ifdef __cplusplus
48extern "C" {
49#endif
50
54void ice_sram_init(void);
55
59void ice_sram_reset(void);
60
72void ice_sram_get_id(uint8_t id[8]);
73
84void ice_sram_write_async(uint32_t addr, const uint8_t *data, size_t data_size, void (*callback)(volatile void *), void *context);
85
92void ice_sram_write_blocking(uint32_t addr, const uint8_t *data, size_t data_size);
93
106void ice_sram_read_async(uint32_t addr, uint8_t *data, size_t data_size, void (*callback)(volatile void *), void *context);
107
114void ice_sram_read_blocking(uint32_t addr, uint8_t *data, size_t data_size);
115
116#ifdef __cplusplus
117}
118#endif
119
void ice_sram_get_id(uint8_t id[8])
Obtain the chip ID from the SRAM chip.
void ice_sram_write_async(uint32_t addr, const uint8_t *data, size_t data_size, void(*callback)(volatile void *), void *context)
Calling this function when any SPI transfer is in progress on this bus waits for it then starts.
void ice_sram_read_async(uint32_t addr, uint8_t *data, size_t data_size, void(*callback)(volatile void *), void *context)
Read a buffer from the flash chip in the background, with a callback called once done.
void ice_sram_read_blocking(uint32_t addr, uint8_t *data, size_t data_size)
Read a buffer from the flash chip and wait until completion.
void ice_sram_reset(void)
Send a reset command to the SRAM chipo.
void ice_sram_init(void)
Send an initialization command to the SRAM chip.
void ice_sram_write_blocking(uint32_t addr, const uint8_t *data, size_t data_size)
Write a buffer to the flash chip and wait until completion.