1 /* 2 * Copyright 2022, Cypress Semiconductor Corporation (an Infineon company) 3 * SPDX-License-Identifier: Apache-2.0 4 * 5 * Licensed under the Apache License, Version 2.0 (the "License"); 6 * you may not use this file except in compliance with the License. 7 * You may obtain a copy of the License at 8 * 9 * http://www.apache.org/licenses/LICENSE-2.0 10 * 11 * Unless required by applicable law or agreed to in writing, software 12 * distributed under the License is distributed on an "AS IS" BASIS, 13 * WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied. 14 * See the License for the specific language governing permissions and 15 * limitations under the License. 16 */ 17 18 /** @file 19 * The whd Thread allows thread safe access to the whd hardware bus 20 * This is an whd internal file and should not be used by functions outside whd. 21 * 22 * This file provides prototypes for functions which allow multiple threads to use the whd hardware bus (SDIO or SPI) 23 * This is achieved by having a single thread (the "whd Thread") which queues messages to be sent, sending 24 * them sequentially, as well as receiving messages as they arrive. 25 * 26 * Messages to be sent come from the @ref whd_sdpcm_send_common function in whd_sdpcm.c . The messages already 27 * contain SDPCM headers, but not any bus headers (GSPI), and are passed via a queue 28 * This function can be called from any thread. 29 * 30 * Messages are received by way of a callback supplied by in whd_sdpcm.c - whd_sdpcm_process_rx_packet 31 * Received messages are delivered in the context of the whd Thread, so the callback function needs to avoid blocking. 32 * 33 */ 34 #include "cyabs_rtos.h" 35 #include "whd.h" 36 37 #ifndef INCLUDED_WHD_THREAD_H_ 38 #define INCLUDED_WHD_THREAD_H_ 39 40 #ifdef __cplusplus 41 extern "C" 42 { 43 #endif 44 45 /****************************************************** 46 * Constants 47 ******************************************************/ 48 #define WHD_THREAD_RX_BOUND (20) 49 #define WHD_MAX_BUS_FAIL (10) 50 51 typedef struct whd_thread_info 52 { 53 54 volatile whd_bool_t thread_quit_flag; 55 volatile whd_bool_t whd_inited; 56 cy_thread_t whd_thread; 57 cy_semaphore_t transceive_semaphore; 58 volatile whd_bool_t bus_interrupt; 59 void *thread_stack_start; 60 uint32_t thread_stack_size; 61 cy_thread_priority_t thread_priority; 62 63 } whd_thread_info_t; 64 65 void whd_thread_info_init(whd_driver_t whd_driver, whd_init_config_t *whd_init_config); 66 67 /** Initialises the whd Thread 68 * 69 * Initialises the whd thread, and its flags/semaphores, 70 * then starts it running 71 * 72 * @return whd result code 73 */ 74 extern whd_result_t whd_thread_init(whd_driver_t whd_driver); 75 76 77 /** Terminates the whd Thread 78 * 79 * Sets a flag then wakes the whd Thread to force it to terminate. 80 * 81 */ 82 extern void whd_thread_quit(whd_driver_t whd_driver); 83 84 85 extern void whd_thread_notify(whd_driver_t whd_driver); 86 extern void whd_thread_notify_irq(whd_driver_t whd_driver); 87 88 #ifdef __cplusplus 89 } /* extern "C" */ 90 #endif 91 92 #endif /* ifndef INCLUDED_WHD_THREAD_H_ */ 93