├── MAINTAINERS.txt ├── change_list.txt ├── copyright.txt ├── extension ├── include │ ├── device │ │ └── device_interface.h │ ├── fifo.h │ ├── fifo_lock.h │ ├── lib_string.h │ ├── mm │ │ ├── heap_1_config.h │ │ ├── heap_2_config.h │ │ ├── heap_3_config.h │ │ ├── heap_4_config.h │ │ ├── heap_5_config.h │ │ ├── raw_malloc.h │ │ ├── raw_page.h │ │ ├── raw_tlsf.h │ │ └── slab │ │ │ ├── arch.h │ │ │ ├── buddy.h │ │ │ ├── config.h │ │ │ ├── frame.h │ │ │ ├── list.h │ │ │ ├── misc.h │ │ │ ├── slab.h │ │ │ └── spinlock.h │ ├── posix │ │ ├── errno.h │ │ ├── mqueue.h │ │ ├── pthread.h │ │ └── semphore.h │ ├── protothread │ │ ├── cc.h │ │ ├── clock.h │ │ ├── etimer.h │ │ ├── lc-switch.h │ │ ├── process.h │ │ ├── protothread.h │ │ ├── pt.h │ │ ├── stimer.h │ │ └── timer.h │ ├── raw_ff.h │ ├── raw_mlock.h │ ├── raw_work_queue.h │ ├── rb_tree.h │ ├── rf │ │ ├── active_memory.h │ │ ├── active_object.h │ │ ├── active_queue_broadcast.h │ │ ├── active_time_event.h │ │ └── rf_config.h │ ├── rsh.h │ └── simple_printf.h ├── lib │ ├── fifo.c │ ├── fifo_lock.c │ ├── raw_mlock.c │ ├── raw_work_queue.c │ ├── rb_tree.c │ ├── simple_printf.c │ └── string.c ├── mm │ ├── heap_1.c │ ├── heap_2.c │ ├── heap_3.c │ ├── heap_4.c │ ├── heap_5.c │ ├── raw_malloc.c │ ├── raw_page.c │ ├── raw_tlsf.c │ └── slab │ │ ├── raw_buddy.c │ │ ├── raw_frame.c │ │ └── raw_slab.c ├── posix │ ├── pthread.c │ ├── pthread_cond.c │ ├── pthread_mutex.c │ ├── pthread_rwlock.c │ ├── semphore.c │ └── time.c ├── protothread │ ├── clock_port.c │ ├── etimer.c │ ├── process.c │ ├── stimer.c │ └── timer.c ├── rf │ ├── active_memory.c │ ├── active_object.c │ ├── active_queue_broadcast.c │ └── active_time_event.c └── shell │ └── rsh.c ├── include ├── raw_api.h ├── raw_block.h ├── raw_byte.h ├── raw_config.h ├── raw_critical.h ├── raw_event.h ├── raw_idle_event.h ├── raw_internal.h ├── raw_internal_type.h ├── raw_list.h ├── raw_mutex.h ├── raw_obj.h ├── raw_queue.h ├── raw_queue_buffer.h ├── raw_queue_size.h ├── raw_sem.h ├── raw_stat.h ├── raw_stm.h ├── raw_system.h ├── raw_task.h ├── raw_task_queue_size.h ├── raw_task_sem.h ├── raw_timer.h └── raw_trace.h ├── raw-os.c ├── raw_block.c ├── raw_byte.c ├── raw_event.c ├── raw_idle.c ├── raw_idle_event.c ├── raw_mutex.c ├── raw_obj.c ├── raw_pend.c ├── raw_queue.c ├── raw_queue_buffer.c ├── raw_queue_size.c ├── raw_sched.c ├── raw_sem.c ├── raw_stat.c ├── raw_stm.c ├── raw_system.c ├── raw_task.c ├── raw_task_queue_size.c ├── raw_task_sem.c ├── raw_tick.c └── raw_timer.c /MAINTAINERS.txt: -------------------------------------------------------------------------------- 1 | raw-os kernel 2 | Author:Lingjun Chen(jorya_txj) 3 | Web:www.raw-os.org 4 | EMAIL:57026783@qq.com -------------------------------------------------------------------------------- /change_list.txt: -------------------------------------------------------------------------------- 1 | update to raw os 1.x 2 | 3 | 4 | 5 | -------------------------------------------------------------------------------- /extension/include/device/device_interface.h: -------------------------------------------------------------------------------- 1 | #ifndef DEVICE_INTERFACE_H 2 | #define DEVICE_INTERFACE_H 3 | 4 | 5 | 6 | /* The peripherals the IO library can interface to. */ 7 | typedef enum 8 | { 9 | eUART_TYPE = 0, 10 | eSSP_TYPE, 11 | eI2C_TYPE 12 | } Peripheral_Types_t; 13 | 14 | /* The structure that defines the peripherals that are available for use on 15 | any particular supported board. */ 16 | typedef struct xAVAILABLE_DEVICES 17 | { 18 | const char * const pcPath; /* Text name of the peripheral. For example, "/UART0/", or "/SPI2/". */ 19 | const Peripheral_Types_t xPeripheralType; /* The type of the peripheral, as defined by the Peripheral_Types_t enum. */ 20 | const void *pvBaseAddress; /* The base address of the peripheral in the microcontroller memory map. */ 21 | } Available_Peripherals_t; 22 | 23 | 24 | /* The base transfer control structure, that points to the actual, IO method 25 | specific structure. */ 26 | typedef struct xTRANSFER_CONTROL 27 | { 28 | void *pvTransferState; /* Pointer to a structure that has the correct members in accordance with the ucType member. */ 29 | unsigned char ucType; /* The value of the ioctl command used to set up the type of IO method. */ 30 | } Transfer_Control_t; 31 | 32 | 33 | /* Peripheral handles are void * for data hiding purposes. */ 34 | typedef const void * Peripheral_Descriptor_t; 35 | 36 | /* Types that define valid read(), write() and ioctl() functions. */ 37 | typedef unsigned int ( *Peripheral_write_Function_t )( Peripheral_Descriptor_t const pxPeripheral, const void *pvBuffer, const unsigned int xBytes ); 38 | typedef unsigned int ( *Peripheral_read_Function_t )( Peripheral_Descriptor_t const pxPeripheral, void * const pvBuffer, const unsigned int xBytes ); 39 | typedef unsigned int ( *Peripheral_ioctl_Function_t )( Peripheral_Descriptor_t const pxPeripheral, unsigned int ulRequest, void *pvValue ); 40 | 41 | /* Structure containing control information for an open peripheral. */ 42 | typedef struct xPERIPHREAL_CONTROL 43 | { 44 | Peripheral_write_Function_t write; /* The function used to write to the peripheral. */ 45 | Peripheral_read_Function_t read; /* The function used to read from the peripheral. */ 46 | Peripheral_ioctl_Function_t ioctl; /* The function used for ioctl access to the peripheral. */ 47 | Transfer_Control_t *pxTxControl; /* Pointer to the transfer control structure used to manage transmissions through the peripheral. */ 48 | Transfer_Control_t *pxRxControl; /* Pointer to the transfer control structure used to manage receptions from the peripheral. */ 49 | const Available_Peripherals_t *pxDevice; /* Pointer to the structure that defines the name and base address of the open peripheral. */ 50 | char cPeripheralNumber; /* Where more than one peripheral of the same kind is available, this holds the number of the peripheral this structure is used to control. */ 51 | } Peripheral_Control_t; 52 | 53 | 54 | /* 55 | * Commands that can be sent to peripherals using the ioctl() function. 56 | */ 57 | 58 | /* Set transfer mode ioctl() requests. */ 59 | #define ioctlUSE_POLLED_TX 0 60 | #define ioctlUSE_POLLED_RX 1 61 | #define ioctlUSE_ZERO_COPY_TX 2 62 | #define ioctlUSE_CHARACTER_QUEUE_TX 3 63 | #define ioctlUSE_CHARACTER_QUEUE_RX 4 64 | #define ioctlUSE_CIRCULAR_BUFFER_RX 5 65 | 66 | /* Transfer mode related ioctl() requests. */ 67 | #define ioctlOBTAIN_WRITE_MUTEX 10 68 | #define ioctlWAIT_PREVIOUS_WRITE_COMPLETE 11 69 | #define ioctlRELEASE_WRITE_MUTEX 12 70 | #define ioctlSET_TX_TIMEOUT 13 71 | #define ioctlSET_RX_TIMEOUT 14 72 | #define ioctlCLEAR_RX_BUFFER 15 73 | 74 | /* Generic peripheral ioctl requests. */ 75 | #define ioctlSET_SPEED 100 76 | #define ioctlSET_INTERRUPT_PRIORITY 102 77 | 78 | /* SPI specific ioctl requests. */ 79 | #define ioctlSET_SPI_DATA_BITS 200 80 | #define ioctlSET_SPI_CLOCK_PHASE 201 81 | #define ioctlSET_SPI_CLOCK_POLARITY 202 82 | #define ioctlSET_SPI_MODE 203 83 | #define ioctlSET_SSP_FRAME_FORMAT 204 84 | 85 | /* I2C specific ioctl requests. */ 86 | #define ioctlSET_I2C_SLAVE_ADDRESS 300 87 | 88 | /* Private ioctl requests. */ 89 | #define ioctlUSE_INTERRUPTS 101 90 | 91 | /* 92 | * Peripheral control structure access macros. 93 | */ 94 | #define diGET_PERIPHERAL_BASE_ADDRESS( pxPeripheralControl ) ( ( pxPeripheralControl )->pxDevice->pvBaseAddress ) 95 | #define diGET_PERIPHERAL_NUMBER( pxPeripheralControl ) ( ( pxPeripheralControl )->cPeripheralNumber ) 96 | #define diGET_TX_TRANSFER_TYPE( pxPeripheralControl ) ( ( pxPeripheralControl )->pxTxControl->ucType ) 97 | #define diGET_RX_TRANSFER_TYPE( pxPeripheralControl ) ( ( pxPeripheralControl )->pxRxControl->ucType ) 98 | #define diGET_TX_TRANSFER_STRUCT( pxPeripheralControl ) ( ( pxPeripheralControl )->pxTxControl ) 99 | #define diGET_RX_TRANSFER_STRUCT( pxPeripheralControl ) ( ( pxPeripheralControl )->pxRxControl ) 100 | #define diGET_TX_TRANSFER_STATE( pxPeripheralControl ) ( ( pxPeripheralControl )->pxTxControl->pvTransferState ) 101 | #define diGET_RX_TRANSFER_STATE( pxPeripheralControl ) ( ( pxPeripheralControl )->pxRxControl->pvTransferState ) 102 | #define diGET_TRANSFER_TYPE_FROM_CONTROL_STRUCT( pxTransferControl ) pxTransferControl->ucType 103 | 104 | /* 105 | * Function prototypes. 106 | */ 107 | Peripheral_Descriptor_t raw_open( const char *pcPath, const unsigned int ulFlags ); 108 | char raw_ioctl( Peripheral_Descriptor_t const xPeripheral, unsigned int ulRequest, void *pvValue ); 109 | 110 | /* 111 | * Macros for the functions that are really macros to keep the call depth down 112 | * and the efficiency up. 113 | */ 114 | #define raw_write( xPeripheral, pvBuffer, xBytes ) ( ( Peripheral_Control_t * ) xPeripheral )->write( ( ( Peripheral_Control_t * ) xPeripheral ), ( pvBuffer ), ( xBytes ) ) 115 | #define raw_read( xPeripheral, pvBuffer, xBytes ) ( ( Peripheral_Control_t * ) xPeripheral )->read( ( ( Peripheral_Control_t * ) xPeripheral ), ( pvBuffer ), ( xBytes ) ) 116 | 117 | 118 | #endif 119 | 120 | 121 | 122 | 123 | -------------------------------------------------------------------------------- /extension/include/fifo.h: -------------------------------------------------------------------------------- 1 | #ifndef FIFO_H 2 | #define FIFO_H 3 | 4 | #define CONFIG_FIFO_DYNAMIC_ALLOC 0 5 | 6 | struct raw_fifo { 7 | 8 | RAW_U32 in; 9 | RAW_U32 out; 10 | RAW_U32 mask; 11 | void *data; 12 | RAW_U32 free_bytes; 13 | RAW_U32 size; 14 | 15 | }; 16 | 17 | 18 | 19 | #define fifo_min(x, y) ((x) > (y)?(y):(x)) 20 | #define fifo_max(x, y) ((x) > (y)?(x):(y)) 21 | 22 | RAW_S8 fifo_init(struct raw_fifo *fifo, void *buffer, RAW_U32 size); 23 | 24 | 25 | RAW_U32 fifo_in(struct raw_fifo *fifo, 26 | const void *buf, unsigned int len); 27 | 28 | RAW_U32 fifo_out(struct raw_fifo *fifo, 29 | void *buf, RAW_U32 len); 30 | 31 | RAW_U32 fifo_out_peek(struct raw_fifo *fifo, 32 | void *buf, RAW_U32 len); 33 | 34 | 35 | RAW_U32 fifo_out_all(struct raw_fifo *fifo, void *buf); 36 | 37 | 38 | #endif 39 | 40 | -------------------------------------------------------------------------------- /extension/include/fifo_lock.h: -------------------------------------------------------------------------------- 1 | #ifndef FIFO_H 2 | #define FIFO_H 3 | 4 | #define CONFIG_FIFO_DYNAMIC_ALLOC 0 5 | 6 | struct raw_fifo_lock { 7 | 8 | RAW_U32 in; 9 | RAW_U32 out; 10 | RAW_U32 mask; 11 | void *data; 12 | RAW_U32 free_bytes; 13 | RAW_U32 size; 14 | 15 | }; 16 | 17 | 18 | 19 | #define fifo_lock_min(x, y) ((x) > (y)?(y):(x)) 20 | #define fifo_lock_max(x, y) ((x) > (y)?(x):(y)) 21 | 22 | RAW_S8 fifo_lock_init(struct raw_fifo_lock *fifo, void *buffer, RAW_U32 size); 23 | 24 | 25 | RAW_U32 fifo_lock_in(struct raw_fifo_lock *fifo, 26 | const void *buf, RAW_U32 len, void (*user_lock)(void), void (*user_unlock)(void)); 27 | 28 | 29 | RAW_U32 fifo_lock_out(struct raw_fifo_lock *fifo, void *buf, RAW_U32 len, 30 | void (*user_lock)(void), void (*user_unlock)(void)); 31 | 32 | 33 | 34 | RAW_U32 fifo_lock_out_peek(struct raw_fifo_lock *fifo, 35 | void *buf, RAW_U32 len, void (*user_lock)(void), void (*user_unlock)(void)); 36 | 37 | 38 | 39 | RAW_U32 fifo_lock_out_all(struct raw_fifo_lock *fifo, void *buf, 40 | void (*user_lock)(void), void (*user_unlock)(void)); 41 | 42 | 43 | 44 | #endif 45 | 46 | -------------------------------------------------------------------------------- /extension/include/lib_string.h: -------------------------------------------------------------------------------- 1 | /* 2 | raw os - Copyright (C) Lingjun Chen(jorya_txj). 3 | 4 | This file is part of raw os. 5 | 6 | raw os is free software; you can redistribute it it under the terms of the 7 | GNU General Public License as published by the Free Software Foundation; 8 | either version 3 of the License, or (at your option) any later version. 9 | 10 | raw os is distributed in the hope that it will be useful, but WITHOUT ANY WARRANTY; 11 | without even the implied warranty of MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. 12 | See the GNU General Public License for more details. 13 | 14 | You should have received a copy of the GNU Lesser General Public License 15 | along with this program. if not, write email to jorya.txj@gmail.com 16 | --- 17 | 18 | A special exception to the LGPL can be applied should you wish to distribute 19 | a combined work that includes raw os, without being obliged to provide 20 | the source code for any proprietary components. See the file exception.txt 21 | for full details of how and when the exception can be applied. 22 | */ 23 | 24 | #ifndef LIB_STRING_H 25 | #define LIB_STRING_H 26 | 27 | #ifdef __cplusplus 28 | extern "C" { 29 | #endif 30 | 31 | void *raw_memmove(void *dest, const void *src, RAW_U32 count); 32 | int raw_memcmp(const void *cs, const void *ct, RAW_U32 count); 33 | char *raw_strcpy(char *dest, const char *src); 34 | char *raw_strncpy(char *dest, const char *src, RAW_U32 count); 35 | char *raw_strcat(char *dest, const char *src); 36 | char *raw_strncat(char *dest, const char *src, RAW_U32 count); 37 | RAW_U32 raw_strlen(const char *s); 38 | int raw_strncmp(const char *cs, const char *ct, RAW_U32 count); 39 | int raw_strcmp(const char *cs, const char *ct); 40 | long int raw_strtol(const char *nptr, char **endptr, int base); 41 | const unsigned char *search_conf(const unsigned char *cp, const unsigned char *name); 42 | 43 | #ifdef __cplusplus 44 | } 45 | #endif 46 | 47 | 48 | #endif 49 | -------------------------------------------------------------------------------- /extension/include/mm/heap_1_config.h: -------------------------------------------------------------------------------- 1 | 2 | #ifndef HEAP_1_CONFIG_H 3 | #define HEAP_1_CONFIG_H 4 | 5 | 6 | #define portBYTE_ALIGNMENT 4 7 | 8 | #define configTOTAL_HEAP_SIZE 4096 9 | 10 | #if (portBYTE_ALIGNMENT == 8) 11 | #define portBYTE_ALIGNMENT_MASK ( 0x0007 ) 12 | #endif 13 | 14 | #if (portBYTE_ALIGNMENT == 4) 15 | #define portBYTE_ALIGNMENT_MASK ( 0x0003 ) 16 | #endif 17 | 18 | #if (portBYTE_ALIGNMENT == 2) 19 | #define portBYTE_ALIGNMENT_MASK ( 0x0001 ) 20 | #endif 21 | 22 | #if (portBYTE_ALIGNMENT == 1) 23 | #define portBYTE_ALIGNMENT_MASK ( 0x0000 ) 24 | #endif 25 | 26 | #ifndef portPOINTER_SIZE_TYPE 27 | #define portPOINTER_SIZE_TYPE unsigned long 28 | #endif 29 | 30 | 31 | void *mem_1_alloc(size_t xWantedSize); 32 | void mem_1_free(void *pv); 33 | void mem_1_init(void); 34 | size_t mem_1_free_get(void); 35 | 36 | #endif 37 | 38 | 39 | -------------------------------------------------------------------------------- /extension/include/mm/heap_2_config.h: -------------------------------------------------------------------------------- 1 | 2 | #ifndef HEAP_2_CONFIG_H 3 | #define HEAP_2_CONFIG_H 4 | 5 | 6 | #define portBYTE_ALIGNMENT 4 7 | 8 | #define configTOTAL_HEAP_SIZE 4096 9 | 10 | #if (portBYTE_ALIGNMENT == 8) 11 | #define portBYTE_ALIGNMENT_MASK ( 0x0007 ) 12 | #endif 13 | 14 | #if (portBYTE_ALIGNMENT == 4) 15 | #define portBYTE_ALIGNMENT_MASK ( 0x0003 ) 16 | #endif 17 | 18 | #if (portBYTE_ALIGNMENT == 2) 19 | #define portBYTE_ALIGNMENT_MASK ( 0x0001 ) 20 | #endif 21 | 22 | #if (portBYTE_ALIGNMENT == 1) 23 | #define portBYTE_ALIGNMENT_MASK ( 0x0000 ) 24 | #endif 25 | 26 | #ifndef portPOINTER_SIZE_TYPE 27 | #define portPOINTER_SIZE_TYPE unsigned long 28 | #endif 29 | 30 | 31 | void *mem_2_malloc(size_t xWantedSize); 32 | void mem_2_free(void *pv); 33 | size_t mem_2_free_get(void); 34 | 35 | 36 | 37 | #endif 38 | 39 | 40 | -------------------------------------------------------------------------------- /extension/include/mm/heap_3_config.h: -------------------------------------------------------------------------------- 1 | 2 | #ifndef HEAP_3_CONFIG_H 3 | #define HEAP_3_CONFIG_H 4 | 5 | void *mem_3_malloc(size_t xWantedSize); 6 | 7 | void mem_3_free(void *pv); 8 | 9 | #endif 10 | 11 | 12 | -------------------------------------------------------------------------------- /extension/include/mm/heap_4_config.h: -------------------------------------------------------------------------------- 1 | 2 | #ifndef HEAP_4_CONFIG_H 3 | #define HEAP_4_CONFIG_H 4 | 5 | 6 | #define configAPPLICATION_ALLOCATED_HEAP 0 7 | 8 | #define portBYTE_ALIGNMENT 4 9 | 10 | #define configTOTAL_HEAP_SIZE 4096 11 | 12 | #if (portBYTE_ALIGNMENT == 8) 13 | #define portBYTE_ALIGNMENT_MASK ( 0x0007 ) 14 | #endif 15 | 16 | #if (portBYTE_ALIGNMENT == 4) 17 | #define portBYTE_ALIGNMENT_MASK ( 0x0003 ) 18 | #endif 19 | 20 | #if (portBYTE_ALIGNMENT == 2) 21 | #define portBYTE_ALIGNMENT_MASK ( 0x0001 ) 22 | #endif 23 | 24 | #if (portBYTE_ALIGNMENT == 1) 25 | #define portBYTE_ALIGNMENT_MASK ( 0x0000 ) 26 | #endif 27 | 28 | #ifndef portPOINTER_SIZE_TYPE 29 | #define portPOINTER_SIZE_TYPE unsigned long 30 | #endif 31 | 32 | void *mem_4_malloc(size_t xWantedSize); 33 | void mem_4_free(void *pv); 34 | size_t mem_4_free_get(void); 35 | size_t mem_4_ever_free_heap(void); 36 | 37 | 38 | #endif 39 | 40 | 41 | -------------------------------------------------------------------------------- /extension/include/mm/heap_5_config.h: -------------------------------------------------------------------------------- 1 | 2 | #ifndef HEAP_4_CONFIG_H 3 | #define HEAP_4_CONFIG_H 4 | 5 | 6 | #define portBYTE_ALIGNMENT 4 7 | 8 | #define configTOTAL_HEAP_SIZE 4096 9 | 10 | #if (portBYTE_ALIGNMENT == 8) 11 | #define portBYTE_ALIGNMENT_MASK ( 0x0007 ) 12 | #endif 13 | 14 | #if (portBYTE_ALIGNMENT == 4) 15 | #define portBYTE_ALIGNMENT_MASK ( 0x0003 ) 16 | #endif 17 | 18 | #if (portBYTE_ALIGNMENT == 2) 19 | #define portBYTE_ALIGNMENT_MASK ( 0x0001 ) 20 | #endif 21 | 22 | #if (portBYTE_ALIGNMENT == 1) 23 | #define portBYTE_ALIGNMENT_MASK ( 0x0000 ) 24 | #endif 25 | 26 | #ifndef portPOINTER_SIZE_TYPE 27 | #define portPOINTER_SIZE_TYPE unsigned long 28 | #endif 29 | 30 | 31 | /* Used by heap_5.c. */ 32 | typedef struct HeapRegion 33 | { 34 | RAW_U8 *pucStartAddress; 35 | size_t xSizeInBytes; 36 | } HeapRegion_t; 37 | 38 | 39 | void *mem_5_malloc(size_t xWantedSize); 40 | void mem_5_free(void *pv); 41 | size_t mem_5_free_get(void); 42 | 43 | void mem_5_heap_regions(const HeapRegion_t * const pxHeapRegions); 44 | size_t mem_5_ever_free_heap(void); 45 | 46 | #endif 47 | 48 | 49 | -------------------------------------------------------------------------------- /extension/include/mm/raw_malloc.h: -------------------------------------------------------------------------------- 1 | /* 2 | raw os - Copyright (C) Lingjun Chen(jorya_txj). 3 | 4 | This file is part of raw os. 5 | 6 | raw os is free software; you can redistribute it it under the terms of the 7 | GNU General Public License as published by the Free Software Foundation; 8 | either version 3 of the License, or (at your option) any later version. 9 | 10 | raw os is distributed in the hope that it will be useful, but WITHOUT ANY WARRANTY; 11 | without even the implied warranty of MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. 12 | See the GNU General Public License for more details. 13 | 14 | You should have received a copy of the GNU Lesser General Public License 15 | along with this program. if not, write email to jorya.txj@gmail.com 16 | --- 17 | 18 | A special exception to the LGPL can be applied should you wish to distribute 19 | a combined work that includes raw os, without being obliged to provide 20 | the source code for any proprietary components. See the file exception.txt 21 | for full details of how and when the exception can be applied. 22 | */ 23 | 24 | 25 | /* 2012-7 Created by jorya_txj 26 | * xxxxxx please added here 27 | */ 28 | 29 | #ifndef RAW_MALLOC_H 30 | #define RAW_MALLOC_H 31 | 32 | #ifdef __cplusplus 33 | extern "C" { 34 | #endif 35 | 36 | /* 37 | * Memory allocation control information 38 | * In the address, the &areaque position must be aligned in 39 | * 8 byte units. (The lower three bits must be 0) 40 | * The 'nouse' area is used to adjust the address. 41 | * It is not possible to write to 'nouse'. 42 | */ 43 | typedef struct MemoryAllocateControlBlock { 44 | 45 | RAW_U64 align; /* Area used for 8 bytes alignment */ 46 | 47 | /* Area queue connects the various partitioned areas of the 48 | * allocated page. 49 | * Addresses are arranged in ascending order within each page, 50 | * and in no particular order between pages. */ 51 | LIST areaque; 52 | /* Free queue connects unused areas within the allocated 53 | * page. Arranged in order of free area size, starting with 54 | * the smallest. */ 55 | LIST freeque; 56 | 57 | RAW_U32 pagesz; /* Page size (number of bytes) */ 58 | RAW_S32 testmode; /* Test mode */ 59 | RAW_MUTEX mem_lock; 60 | /* Memory allocate/release function */ 61 | void *(*getblk)( RAW_S32 nblk); 62 | RAW_S32 (*relblk)( void *ptr ); 63 | 64 | } MACB; 65 | 66 | void raw_malloc_init(void); 67 | void *raw_malloc(RAW_U32 size); 68 | void raw_free(void *ptr); 69 | void *raw_calloc(RAW_U32 nmemb, RAW_U32 size); 70 | void *raw_realloc(void *ptr, RAW_U32 size); 71 | RAW_U16 check_malloc_test(void *ptr, int mode); 72 | 73 | 74 | 75 | /* 76 | * Option setting: minimum fragment size 77 | * must be size 'sizeof(LIST) * 2' or more. 78 | */ 79 | extern RAW_U32 _mem_minfragment; 80 | /* 81 | * Correction to align the &areaque position with the 8 byte boundary 82 | */ 83 | #define AlignMACB(macb) ( (MACB*)((RAW_U32)macb & ~0x00000007U) ) 84 | 85 | 86 | /* 87 | * Minimum fragmentation unit 88 | * Since memory is allocated in ROUNDSZ units, 89 | * the lower three bits of the address must be 0. 90 | * These low three bits are used in the flag in the area queue. 91 | */ 92 | #define ROUNDSZ_ALIGN 0x8U 93 | #define ROUND_MALLOC(sz) (((RAW_U32)(sz) + (ROUNDSZ_ALIGN - 1)) & ~(ROUNDSZ_ALIGN - 1)) 94 | 95 | /* Minimum fragment size */ 96 | #define MIN_FRAGMENT ( _mem_minfragment ) 97 | 98 | /* 99 | * Flag that uses the lower bits of the area queue prev 100 | */ 101 | #define AREA_USE 0x00000001U /* In use */ 102 | #define AREA_TOP 0x00000002U /* Top of page */ 103 | #define AREA_END 0x00000004U /* End of page */ 104 | #define AREA_MASK 0x00000007U 105 | 106 | #define setAreaFlag(q, f) ( (q)->previous = (LIST *)((RAW_U32)(q)->previous | (RAW_U32)(f)) ) 107 | #define clrAreaFlag(q, f) ( (q)->previous = (LIST *)((RAW_U32)(q)->previous & ~(RAW_U32)(f)) ) 108 | #define chkAreaFlag(q, f) ( ((RAW_U32)(q)->previous & (RAW_U32)(f)) != 0 ) 109 | 110 | #define Mask(x) ( (LIST *)((RAW_U32)(x) & ~AREA_MASK) ) 111 | #define Assign(x, y) ( (x) = (LIST *)(((RAW_U32)(x) & AREA_MASK) | (RAW_U32)(y)) ) 112 | 113 | /* 114 | * Area size 115 | */ 116 | #define AreaSize(aq) ( (RAW_S8 *)(aq)->next - (RAW_S8 *)((aq) + 1) ) 117 | #define FreeSize(fq) ( (RAW_S8 *)((fq) - 1)->next - (RAW_S8 *)(fq) ) 118 | 119 | 120 | #ifdef __cplusplus 121 | } 122 | #endif 123 | 124 | 125 | #endif 126 | 127 | 128 | -------------------------------------------------------------------------------- /extension/include/mm/raw_page.h: -------------------------------------------------------------------------------- 1 | /* 2 | raw os - Copyright (C) Lingjun Chen(jorya_txj). 3 | 4 | This file is part of raw os. 5 | 6 | raw os is free software; you can redistribute it it under the terms of the 7 | GNU General Public License as published by the Free Software Foundation; 8 | either version 3 of the License, or (at your option) any later version. 9 | 10 | raw os is distributed in the hope that it will be useful, but WITHOUT ANY WARRANTY; 11 | without even the implied warranty of MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. 12 | See the GNU General Public License for more details. 13 | 14 | You should have received a copy of the GNU Lesser General Public License 15 | along with this program. if not, write email to jorya.txj@gmail.com 16 | --- 17 | 18 | A special exception to the LGPL can be applied should you wish to distribute 19 | a combined work that includes raw os, without being obliged to provide 20 | the source code for any proprietary components. See the file exception.txt 21 | for full details of how and when the exception can be applied. 22 | */ 23 | 24 | 25 | /* 2012-7 Created by jorya_txj 26 | * xxxxxx please added here 27 | */ 28 | 29 | #ifndef RAW_PAGE_H 30 | #define RAW_PAGE_H 31 | 32 | #ifdef __cplusplus 33 | extern "C" { 34 | #endif 35 | 36 | 37 | /* 38 | * Page 39 | */ 40 | typedef struct page{ 41 | 42 | RAW_U8 mem[2048]; 43 | 44 | } PAGE; 45 | 46 | 47 | #define PAGE_SIZE (sizeof(PAGE)) 48 | 49 | 50 | /* 51 | * Page management queue 52 | */ 53 | typedef struct page_descriptor { 54 | RAW_S8 cont; /* 1 if multiple pages in succession */ 55 | RAW_S8 use; /* 1 if page in use */ 56 | RAW_S32 next; 57 | RAW_S32 prev; 58 | } PAGE_DESCRIPTOR; 59 | 60 | 61 | #define USE 1 /* In use */ 62 | #define FREE 0 /* Free */ 63 | #define CONT 1 /* Continuation (multiple blocks in succession) */ 64 | #define ONE 0 /* Independent */ 65 | 66 | 67 | /* Number of successive pages */ 68 | #define PAGE_NUMBERS(q) ( ( (q)->cont )? ((q)+1)->next: 1 ) 69 | 70 | 71 | /* 72 | * Page management table 73 | * Top of pageque is used for freeque. 74 | * freeque is sorted in order from the smallest number of 75 | * successive free pages. 76 | */ 77 | typedef struct pagetbl{ 78 | 79 | RAW_S32 maxpage; /* Total number of pages */ 80 | RAW_S32 freepage; /* Number of free pages */ 81 | PAGE_DESCRIPTOR *pageque; /* Array of management information for 82 | all pages */ 83 | PAGE *top_page; /* Top page address */ 84 | RAW_MUTEX mem_lock; 85 | 86 | } PAGETBL; 87 | 88 | 89 | RAW_U16 raw_page_init(void *start, void *end); 90 | void *raw_page_allocate(RAW_S32 pages); 91 | RAW_S32 raw_page_free(void *adr); 92 | PAGETBL *system_page_table_get(void); 93 | 94 | 95 | #ifdef __cplusplus 96 | } 97 | #endif 98 | 99 | 100 | #endif 101 | 102 | -------------------------------------------------------------------------------- /extension/include/mm/raw_tlsf.h: -------------------------------------------------------------------------------- 1 | /* 2 | * Two Levels Segregate Fit memory allocator (TLSF) 3 | * Version 2.4.6 4 | * 5 | * Written by Miguel Masmano Tello 6 | * 7 | * Thanks to Ismael Ripoll for his suggestions and reviews 8 | * 9 | * Copyright (C) 2008, 2007, 2006, 2005, 2004 10 | * 11 | * This code is released using a dual license strategy: GPL/LGPL 12 | * You can choose the licence that better fits your requirements. 13 | * 14 | * Released under the terms of the GNU General Public License Version 2.0 15 | * Released under the terms of the GNU Lesser General Public License Version 2.1 16 | * 17 | */ 18 | 19 | #ifndef _TLSF_H_ 20 | #define _TLSF_H_ 21 | 22 | RAW_U32 init_memory_pool(RAW_U32, void *); 23 | RAW_U32 get_used_size(void *); 24 | RAW_U32 get_max_size(void *); 25 | void destroy_memory_pool(void *); 26 | RAW_U32 add_new_area(void *, RAW_U32, void *); 27 | void *malloc_ex(RAW_U32, void *); 28 | void free_ex(void *, void *); 29 | void *realloc_ex(void *, RAW_U32, void *); 30 | void *calloc_ex(RAW_U32, RAW_U32, void *); 31 | 32 | void *tlsf_malloc(RAW_U32 size); 33 | void tlsf_free(void *ptr); 34 | void *tlsf_realloc(void *ptr, RAW_U32 size); 35 | void *tlsf_calloc(RAW_U32 nelem, RAW_U32 elem_size); 36 | 37 | #endif 38 | -------------------------------------------------------------------------------- /extension/include/mm/slab/arch.h: -------------------------------------------------------------------------------- 1 | /* 2 | raw os - Copyright (C) Lingjun Chen(jorya_txj). 3 | 4 | This file is part of raw os. 5 | 6 | raw os is free software; you can redistribute it it under the terms of the 7 | GNU General Public License as published by the Free Software Foundation; 8 | either version 3 of the License, or (at your option) any later version. 9 | 10 | raw os is distributed in the hope that it will be useful, but WITHOUT ANY WARRANTY; 11 | without even the implied warranty of MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. 12 | See the GNU General Public License for more details. 13 | 14 | You should have received a copy of the GNU Lesser General Public License 15 | along with this program. if not, write email to jorya.txj@gmail.com 16 | --- 17 | 18 | A special exception to the LGPL can be applied should you wish to distribute 19 | a combined work that includes raw os, without being obliged to provide 20 | the source code for any proprietary components. See the file exception.txt 21 | for full details of how and when the exception can be applied. 22 | */ 23 | 24 | 25 | #ifndef KERN_ARCH_H_ 26 | #define KERN_ARCH_H_ 27 | 28 | RAW_INLINE void atomic_inc(atomic_t *val) 29 | { 30 | val->count++; 31 | } 32 | 33 | 34 | RAW_INLINE void atomic_dec(atomic_t *val) 35 | { 36 | val->count--; 37 | } 38 | 39 | #endif 40 | 41 | /** @} 42 | */ 43 | -------------------------------------------------------------------------------- /extension/include/mm/slab/buddy.h: -------------------------------------------------------------------------------- 1 | /* 2 | raw os - Copyright (C) Lingjun Chen(jorya_txj). 3 | 4 | This file is part of raw os. 5 | 6 | raw os is free software; you can redistribute it it under the terms of the 7 | GNU General Public License as published by the Free Software Foundation; 8 | either version 3 of the License, or (at your option) any later version. 9 | 10 | raw os is distributed in the hope that it will be useful, but WITHOUT ANY WARRANTY; 11 | without even the implied warranty of MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. 12 | See the GNU General Public License for more details. 13 | 14 | You should have received a copy of the GNU Lesser General Public License 15 | along with this program. if not, write email to jorya.txj@gmail.com 16 | --- 17 | 18 | A special exception to the LGPL can be applied should you wish to distribute 19 | a combined work that includes raw os, without being obliged to provide 20 | the source code for any proprietary components. See the file exception.txt 21 | for full details of how and when the exception can be applied. 22 | */ 23 | 24 | 25 | 26 | /* 27 | * 2012-9 Slab Memory Managment 28 | * by Hu Zhigang 29 | */ 30 | 31 | 32 | #ifndef KERN_BUDDY_H_ 33 | #define KERN_BUDDY_H_ 34 | 35 | #define BUDDY_SYSTEM_INNER_BLOCK 0xff 36 | 37 | struct buddy_system; 38 | 39 | /** Buddy system operations to be implemented by each implementation. */ 40 | typedef struct { 41 | /** 42 | * Return pointer to left-side or right-side buddy for block passed as 43 | * argument. 44 | */ 45 | link_t *(* find_buddy)(struct buddy_system *, link_t *); 46 | /** 47 | * Bisect the block passed as argument and return pointer to the new 48 | * right-side buddy. 49 | */ 50 | link_t *(* bisect)(struct buddy_system *, link_t *); 51 | /** Coalesce two buddies into a bigger block. */ 52 | link_t *(* coalesce)(struct buddy_system *, link_t *, link_t *); 53 | /** Set order of block passed as argument. */ 54 | void (*set_order)(struct buddy_system *, link_t *, RAW_U8); 55 | /** Return order of block passed as argument. */ 56 | RAW_U8 (*get_order)(struct buddy_system *, link_t *); 57 | /** Mark block as busy. */ 58 | void (*mark_busy)(struct buddy_system *, link_t *); 59 | /** Mark block as available. */ 60 | void (*mark_available)(struct buddy_system *, link_t *); 61 | /** Find parent of block that has given order */ 62 | link_t *(* find_block)(struct buddy_system *, link_t *, RAW_U8); 63 | } buddy_system_operations_t; 64 | 65 | typedef struct buddy_system { 66 | /** Maximal order of block which can be stored by buddy system. */ 67 | RAW_U8 max_order; 68 | link_t *order; 69 | buddy_system_operations_t *op; 70 | /** Pointer to be used by the implementation. */ 71 | void *data; 72 | } buddy_system_t; 73 | 74 | extern void buddy_system_create(buddy_system_t *, RAW_U8, 75 | buddy_system_operations_t *, void *); 76 | extern link_t *buddy_system_alloc(buddy_system_t *, RAW_U8); 77 | extern bool buddy_system_can_alloc(buddy_system_t *, RAW_U8); 78 | extern void buddy_system_free(buddy_system_t *, link_t *); 79 | extern size_t buddy_conf_size(size_t); 80 | extern link_t *buddy_system_alloc_block(buddy_system_t *, link_t *); 81 | 82 | #endif 83 | 84 | /** @} 85 | */ 86 | -------------------------------------------------------------------------------- /extension/include/mm/slab/config.h: -------------------------------------------------------------------------------- 1 | /* 2 | raw os - Copyright (C) Lingjun Chen(jorya_txj). 3 | 4 | This file is part of raw os. 5 | 6 | raw os is free software; you can redistribute it it under the terms of the 7 | GNU General Public License as published by the Free Software Foundation; 8 | either version 3 of the License, or (at your option) any later version. 9 | 10 | raw os is distributed in the hope that it will be useful, but WITHOUT ANY WARRANTY; 11 | without even the implied warranty of MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. 12 | See the GNU General Public License for more details. 13 | 14 | You should have received a copy of the GNU Lesser General Public License 15 | along with this program. if not, write email to jorya.txj@gmail.com 16 | --- 17 | 18 | A special exception to the LGPL can be applied should you wish to distribute 19 | a combined work that includes raw os, without being obliged to provide 20 | the source code for any proprietary components. See the file exception.txt 21 | for full details of how and when the exception can be applied. 22 | */ 23 | 24 | 25 | 26 | /* 27 | * 2012-9 Slab Memory Managment 28 | * by Hu Zhigang 29 | */ 30 | 31 | 32 | 33 | #ifndef KERN_CONFIG_H_ 34 | #define KERN_CONFIG_H_ 35 | 36 | 37 | #define STACK_SIZE PAGE_SIZE 38 | 39 | #define CONFIG_INIT_TASKS 32 40 | #define CONFIG_TASK_NAME_BUFLEN 32 41 | 42 | 43 | typedef unsigned int uintptr_t; 44 | typedef unsigned int pfn_t; 45 | typedef unsigned int sysarg_t; 46 | typedef signed int native_t; 47 | typedef unsigned int atomic_count_t; 48 | 49 | 50 | #define raw_printk vc_port_printf 51 | 52 | typedef struct { 53 | uintptr_t addr; 54 | size_t size; 55 | char name[CONFIG_TASK_NAME_BUFLEN]; 56 | } init_task_t; 57 | 58 | typedef struct { 59 | size_t cnt; 60 | init_task_t tasks[CONFIG_INIT_TASKS]; 61 | } init_t; 62 | 63 | /** Boot allocations. 64 | * 65 | * Allocatations made by the boot that are meant to be used by the kernel 66 | * are all recorded in the ballocs_t type. 67 | */ 68 | typedef struct { 69 | uintptr_t base; 70 | size_t size; 71 | } ballocs_t; 72 | 73 | typedef struct { 74 | uintptr_t base; 75 | size_t kernel_size; /**< Size of memory in bytes taken by kernel and stack */ 76 | 77 | uintptr_t stack_base; /**< Base adddress of initial stack */ 78 | size_t stack_size; /**< Size of initial stack */ 79 | } config_t; 80 | 81 | 82 | #endif 83 | 84 | /** @} 85 | */ 86 | -------------------------------------------------------------------------------- /extension/include/mm/slab/list.h: -------------------------------------------------------------------------------- 1 | /* 2 | raw os - Copyright (C) Lingjun Chen(jorya_txj). 3 | 4 | This file is part of raw os. 5 | 6 | raw os is free software; you can redistribute it it under the terms of the 7 | GNU General Public License as published by the Free Software Foundation; 8 | either version 3 of the License, or (at your option) any later version. 9 | 10 | raw os is distributed in the hope that it will be useful, but WITHOUT ANY WARRANTY; 11 | without even the implied warranty of MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. 12 | See the GNU General Public License for more details. 13 | 14 | You should have received a copy of the GNU Lesser General Public License 15 | along with this program. if not, write email to jorya.txj@gmail.com 16 | --- 17 | 18 | A special exception to the LGPL can be applied should you wish to distribute 19 | a combined work that includes raw os, without being obliged to provide 20 | the source code for any proprietary components. See the file exception.txt 21 | for full details of how and when the exception can be applied. 22 | */ 23 | 24 | 25 | 26 | /* 27 | * 2012-9 Slab Memory Managment 28 | * by Hu Zhigang 29 | */ 30 | 31 | 32 | #ifndef KERN_LIST_H_ 33 | #define KERN_LIST_H_ 34 | 35 | 36 | /** Doubly linked list head and link type. */ 37 | typedef struct link { 38 | struct link *prev; /**< Pointer to the previous item in the list. */ 39 | struct link *next; /**< Pointer to the next item in the list. */ 40 | } link_t; 41 | 42 | /** Initialize doubly-linked circular list link 43 | * 44 | * Initialize doubly-linked list link. 45 | * 46 | * @param link Pointer to link_t structure to be initialized. 47 | */ 48 | RAW_INLINE void link_initialize(link_t *link) 49 | { 50 | link->prev = NULL; 51 | link->next = NULL; 52 | } 53 | 54 | /** Initialize doubly-linked circular list 55 | * 56 | * Initialize doubly-linked circular list. 57 | * 58 | * @param head Pointer to link_t structure representing head of the list. 59 | */ 60 | RAW_INLINE void list_initialize(link_t *head) 61 | { 62 | head->prev = head; 63 | head->next = head; 64 | } 65 | 66 | /** Add item to the beginning of doubly-linked circular list 67 | * 68 | * Add item to the beginning of doubly-linked circular list. 69 | * 70 | * @param link Pointer to link_t structure to be added. 71 | * @param head Pointer to link_t structure representing head of the list. 72 | */ 73 | RAW_INLINE void list_prepend(link_t *link, link_t *head) 74 | { 75 | link->next = head->next; 76 | link->prev = head; 77 | head->next->prev = link; 78 | head->next = link; 79 | } 80 | 81 | /** Add item to the end of doubly-linked circular list 82 | * 83 | * Add item to the end of doubly-linked circular list. 84 | * 85 | * @param link Pointer to link_t structure to be added. 86 | * @param head Pointer to link_t structure representing head of the list. 87 | */ 88 | RAW_INLINE void list_append(link_t *link, link_t *head) 89 | { 90 | link->prev = head->prev; 91 | link->next = head; 92 | head->prev->next = link; 93 | head->prev = link; 94 | } 95 | 96 | /** Remove item from doubly-linked circular list 97 | * 98 | * Remove item from doubly-linked circular list. 99 | * 100 | * @param link Pointer to link_t structure to be removed from the list it is 101 | * contained in. 102 | */ 103 | RAW_INLINE void list_remove(link_t *link) 104 | { 105 | link->next->prev = link->prev; 106 | link->prev->next = link->next; 107 | link_initialize(link); 108 | } 109 | 110 | /** Query emptiness of doubly-linked circular list 111 | * 112 | * Query emptiness of doubly-linked circular list. 113 | * 114 | * @param head Pointer to link_t structure representing head of the list. 115 | */ 116 | RAW_INLINE bool list_empty(link_t *head) 117 | { 118 | return head->next == head ? true : false; 119 | } 120 | 121 | 122 | /** Split or concatenate headless doubly-linked circular list 123 | * 124 | * Split or concatenate headless doubly-linked circular list. 125 | * 126 | * Note that the algorithm works both directions: 127 | * concatenates splitted lists and splits concatenated lists. 128 | * 129 | * @param part1 Pointer to link_t structure leading the first (half of the 130 | * headless) list. 131 | * @param part2 Pointer to link_t structure leading the second (half of the 132 | * headless) list. 133 | */ 134 | RAW_INLINE void headless_list_split_or_concat(link_t *part1, link_t *part2) 135 | { 136 | link_t *hlp; 137 | 138 | part1->prev->next = part2; 139 | part2->prev->next = part1; 140 | hlp = part1->prev; 141 | part1->prev = part2->prev; 142 | part2->prev = hlp; 143 | } 144 | 145 | 146 | /** Split headless doubly-linked circular list 147 | * 148 | * Split headless doubly-linked circular list. 149 | * 150 | * @param part1 Pointer to link_t structure leading the first half of the 151 | * headless list. 152 | * @param part2 Pointer to link_t structure leading the second half of the 153 | * headless list. 154 | */ 155 | RAW_INLINE void headless_list_split(link_t *part1, link_t *part2) 156 | { 157 | headless_list_split_or_concat(part1, part2); 158 | } 159 | 160 | /** Concatenate two headless doubly-linked circular lists 161 | * 162 | * Concatenate two headless doubly-linked circular lists. 163 | * 164 | * @param part1 Pointer to link_t structure leading the first headless list. 165 | * @param part2 Pointer to link_t structure leading the second headless list. 166 | */ 167 | RAW_INLINE void headless_list_concat(link_t *part1, link_t *part2) 168 | { 169 | headless_list_split_or_concat(part1, part2); 170 | } 171 | 172 | #define list_get_instance(link, type, member) \ 173 | ((type *)(((RAW_U8 *)(link)) - ((RAW_U8 *)&(((type *)NULL)->member)))) 174 | 175 | extern bool list_member(const link_t *link, const link_t *head); 176 | extern void list_concat(link_t *head1, link_t *head2); 177 | 178 | #endif 179 | 180 | /** @} 181 | */ 182 | -------------------------------------------------------------------------------- /extension/include/mm/slab/misc.h: -------------------------------------------------------------------------------- 1 | /* 2 | raw os - Copyright (C) Lingjun Chen(jorya_txj). 3 | 4 | This file is part of raw os. 5 | 6 | raw os is free software; you can redistribute it it under the terms of the 7 | GNU General Public License as published by the Free Software Foundation; 8 | either version 3 of the License, or (at your option) any later version. 9 | 10 | raw os is distributed in the hope that it will be useful, but WITHOUT ANY WARRANTY; 11 | without even the implied warranty of MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. 12 | See the GNU General Public License for more details. 13 | 14 | You should have received a copy of the GNU Lesser General Public License 15 | along with this program. if not, write email to jorya.txj@gmail.com 16 | --- 17 | 18 | A special exception to the LGPL can be applied should you wish to distribute 19 | a combined work that includes raw os, without being obliged to provide 20 | the source code for any proprietary components. See the file exception.txt 21 | for full details of how and when the exception can be applied. 22 | */ 23 | 24 | 25 | 26 | /* 27 | * 2012-9 Slab Memory Managment 28 | * by Hu Zhigang 29 | */ 30 | 31 | 32 | 33 | 34 | /** Align to the nearest lower address. 35 | * 36 | * @param s Address or size to be aligned. 37 | * @param a Size of alignment, must be power of 2. 38 | */ 39 | #define ALIGN_DOWN(s, a) ((s) & ~((a) - 1)) 40 | 41 | 42 | /** Align to the nearest higher address. 43 | * 44 | * @param s Address or size to be aligned. 45 | * @param a Size of alignment, must be power of 2. 46 | */ 47 | #define ALIGN_UP(s, a) (((s) + ((a) - 1)) & ~((a) - 1)) 48 | 49 | #ifndef ATOMIC_TYPE 50 | #define ATOMIC_TYPE 51 | 52 | typedef RAW_U32 atomic_count_t; 53 | 54 | typedef struct { 55 | volatile atomic_count_t count; 56 | } atomic_t; 57 | 58 | RAW_INLINE void atomic_set(atomic_t *val, atomic_count_t i) 59 | { 60 | val->count = i; 61 | } 62 | 63 | RAW_INLINE atomic_count_t atomic_get(atomic_t *val) 64 | { 65 | return val->count; 66 | } 67 | 68 | #endif 69 | 70 | 71 | #define SLAB_CPU_32 1 72 | 73 | #if (SLAB_CPU_32 > 0) 74 | 75 | #define fnzb(arg) fnzb32(arg) 76 | 77 | #else 78 | 79 | #define fnzb(arg) fnzb64(arg) 80 | #endif 81 | 82 | 83 | /** Return position of first non-zero bit from left (32b variant). 84 | * 85 | * @return 0 (if the number is zero) or [log_2(arg)]. 86 | * 87 | */ 88 | RAW_INLINE RAW_U8 fnzb32(RAW_U32 arg) 89 | { 90 | RAW_U8 n = 0; 91 | 92 | if (arg >> 16) { 93 | arg >>= 16; 94 | n += 16; 95 | } 96 | 97 | if (arg >> 8) { 98 | arg >>= 8; 99 | n += 8; 100 | } 101 | 102 | if (arg >> 4) { 103 | arg >>= 4; 104 | n += 4; 105 | } 106 | 107 | if (arg >> 2) { 108 | arg >>= 2; 109 | n += 2; 110 | } 111 | 112 | if (arg >> 1) 113 | n += 1; 114 | 115 | return n; 116 | } 117 | 118 | /** Return position of first non-zero bit from left (64b variant). 119 | * 120 | * @return 0 (if the number is zero) or [log_2(arg)]. 121 | * 122 | */ 123 | RAW_INLINE RAW_U8 fnzb64(RAW_U64 arg) 124 | { 125 | RAW_U8 n = 0; 126 | 127 | if (arg >> 32) { 128 | arg >>= 32; 129 | n += 32; 130 | } 131 | 132 | return n + fnzb32((RAW_U32) arg); 133 | } 134 | 135 | 136 | #ifndef OVERLAPS 137 | #define OVERLAPS 138 | /** Return true if the intervals overlap. 139 | * 140 | * @param s1 Start address of the first interval. 141 | * @param sz1 Size of the first interval. 142 | * @param s2 Start address of the second interval. 143 | * @param sz2 Size of the second interval. 144 | * 145 | */ 146 | RAW_INLINE int overlaps(RAW_U64 s1, RAW_U64 sz1, RAW_U64 s2, 147 | RAW_U64 sz2) 148 | { 149 | RAW_U64 e1 = s1 + sz1; 150 | RAW_U64 e2 = s2 + sz2; 151 | 152 | return ((s1 < e2) && (s2 < e1)); 153 | } 154 | 155 | /** Return true if the second interval is within the first interval. 156 | * 157 | * @param s1 Start address of the first interval. 158 | * @param sz1 Size of the first interval. 159 | * @param s2 Start address of the second interval. 160 | * @param sz2 Size of the second interval. 161 | * 162 | */ 163 | RAW_INLINE int iswithin(RAW_U64 s1, RAW_U64 sz1, RAW_U64 s2, 164 | RAW_U64 sz2) 165 | { 166 | RAW_U64 e1 = s1 + sz1; 167 | RAW_U64 e2 = s2 + sz2; 168 | 169 | return ((s1 <= s2) && (e1 >= e2)); 170 | } 171 | 172 | #endif 173 | 174 | #define min3(a, b, c) ((a) < (b) ? (min(a, c)) : (min(b, c))) 175 | #define max3(a, b, c) ((a) > (b) ? (max(a, c)) : (max(b, c))) 176 | 177 | #define SIZE2KB(size) ((size) >> 10) 178 | #define SIZE2MB(size) ((size) >> 20) 179 | 180 | #define KB2SIZE(kb) ((kb) << 10) 181 | #define MB2SIZE(mb) ((mb) << 20) 182 | 183 | #define PAGE_SIZE_SLAB FRAME_SIZE 184 | 185 | #ifndef NULL 186 | #define NULL ((void *) 0) 187 | #endif 188 | 189 | #define false 0 190 | #define true 1 191 | 192 | typedef void (* function)(); 193 | 194 | #define panic vc_port_printf 195 | 196 | #define ASSERT RAW_ASSERT 197 | 198 | -------------------------------------------------------------------------------- /extension/include/mm/slab/slab.h: -------------------------------------------------------------------------------- 1 | /* 2 | raw os - Copyright (C) Lingjun Chen(jorya_txj). 3 | 4 | This file is part of raw os. 5 | 6 | raw os is free software; you can redistribute it it under the terms of the 7 | GNU General Public License as published by the Free Software Foundation; 8 | either version 3 of the License, or (at your option) any later version. 9 | 10 | raw os is distributed in the hope that it will be useful, but WITHOUT ANY WARRANTY; 11 | without even the implied warranty of MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. 12 | See the GNU General Public License for more details. 13 | 14 | You should have received a copy of the GNU Lesser General Public License 15 | along with this program. if not, write email to jorya.txj@gmail.com 16 | --- 17 | 18 | A special exception to the LGPL can be applied should you wish to distribute 19 | a combined work that includes raw os, without being obliged to provide 20 | the source code for any proprietary components. See the file exception.txt 21 | for full details of how and when the exception can be applied. 22 | */ 23 | 24 | 25 | 26 | /* 27 | * 2012-9 Slab Memory Managment 28 | * by Hu Zhigang 29 | */ 30 | 31 | 32 | 33 | #ifndef KERN_SLAB_H_ 34 | #define KERN_SLAB_H_ 35 | 36 | 37 | 38 | /** Minimum size to be allocated by malloc */ 39 | #define SLAB_MIN_MALLOC_W 4 40 | 41 | /** Maximum size to be allocated by malloc */ 42 | #define SLAB_MAX_MALLOC_W 22 43 | 44 | /** Initial Magazine size (TODO: dynamically growing magazines) */ 45 | #define SLAB_MAG_SIZE 4 46 | 47 | /** If object size is less, store control structure inside SLAB */ 48 | #define SLAB_INSIDE_SIZE (PAGE_SIZE_SLAB >> 3) 49 | 50 | /** Maximum wasted space we allow for cache */ 51 | #define SLAB_MAX_BADNESS(cache) \ 52 | (((unsigned int) PAGE_SIZE_SLAB << (cache)->order) >> 2) 53 | 54 | /* slab_reclaim constants */ 55 | 56 | /** Reclaim all possible memory, because we are in memory stress */ 57 | #define SLAB_RECLAIM_ALL 0x01 58 | 59 | /* cache_create flags */ 60 | 61 | /** Do not use per-cpu cache */ 62 | #define SLAB_CACHE_NOMAGAZINE 0x01 63 | /** Have control structure inside SLAB */ 64 | #define SLAB_CACHE_SLINSIDE 0x02 65 | /** We add magazine cache later, if we have this flag */ 66 | #define SLAB_CACHE_MAGDEFERRED (0x04 | SLAB_CACHE_NOMAGAZINE) 67 | 68 | typedef struct { 69 | link_t link; 70 | size_t busy; /**< Count of full slots in magazine */ 71 | size_t size; /**< Number of slots in magazine */ 72 | void *objs[]; /**< Slots in magazine */ 73 | } slab_magazine_t; 74 | 75 | typedef struct { 76 | slab_magazine_t *current; 77 | slab_magazine_t *last; 78 | SPINLOCK_DECLARE(lock); 79 | } slab_mag_cache_t; 80 | 81 | typedef struct { 82 | const char *name; 83 | 84 | link_t link; 85 | 86 | /* Configuration */ 87 | /** Size of slab position - align_up(sizeof(obj)) */ 88 | size_t size; 89 | 90 | int (*constructor)(void *obj, unsigned int kmflag); 91 | size_t (*destructor)(void *obj); 92 | 93 | /** Flags changing behaviour of cache */ 94 | unsigned int flags; 95 | 96 | /* Computed values */ 97 | RAW_U8 order; /**< Order of frames to be allocated */ 98 | size_t objects; /**< Number of objects that fit in */ 99 | 100 | /* Statistics */ 101 | atomic_t allocated_slabs; 102 | atomic_t allocated_objs; 103 | atomic_t cached_objs; 104 | /** How many magazines in magazines list */ 105 | atomic_t magazine_counter; 106 | 107 | /* Slabs */ 108 | link_t full_slabs; /**< List of full slabs */ 109 | link_t partial_slabs; /**< List of partial slabs */ 110 | SPINLOCK_DECLARE(slablock); 111 | /* Magazines */ 112 | link_t magazines; /**< List of full magazines */ 113 | SPINLOCK_DECLARE(maglock); 114 | 115 | /* Mutex*/ 116 | RAW_MUTEX mutex_slab_alloc; 117 | RAW_MUTEX mutex_slab_free; 118 | 119 | /** CPU cache */ 120 | slab_mag_cache_t *mag_cache; 121 | } slab_cache_t; 122 | 123 | extern slab_cache_t *slab_cache_create(const char *, size_t, size_t, 124 | int (*)(void *, unsigned int), size_t (*)(void *), unsigned int); 125 | extern void slab_cache_destroy(slab_cache_t *); 126 | 127 | extern void *slab_alloc(slab_cache_t *, unsigned int); 128 | extern void slab_free(slab_cache_t *, void *); 129 | extern size_t slab_reclaim(unsigned int); 130 | 131 | /* slab subsytem initialization */ 132 | extern void slab_cache_init(void); 133 | extern void slab_enable_cpucache(void); 134 | 135 | /* kconsole debug */ 136 | extern void slab_print_list(void); 137 | 138 | /* malloc support */ 139 | extern void *raw_malloc_flag(size_t, unsigned int); 140 | extern void *raw_slab_malloc(size_t size); 141 | extern void *raw_slab_realloc(void *, size_t, unsigned int); 142 | extern int raw_slab_free(void *); 143 | 144 | #endif 145 | 146 | /** @} 147 | */ 148 | -------------------------------------------------------------------------------- /extension/include/mm/slab/spinlock.h: -------------------------------------------------------------------------------- 1 | /* 2 | raw os - Copyright (C) Lingjun Chen(jorya_txj). 3 | 4 | This file is part of raw os. 5 | 6 | raw os is free software; you can redistribute it it under the terms of the 7 | GNU General Public License as published by the Free Software Foundation; 8 | either version 3 of the License, or (at your option) any later version. 9 | 10 | raw os is distributed in the hope that it will be useful, but WITHOUT ANY WARRANTY; 11 | without even the implied warranty of MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. 12 | See the GNU General Public License for more details. 13 | 14 | You should have received a copy of the GNU Lesser General Public License 15 | along with this program. if not, write email to jorya.txj@gmail.com 16 | --- 17 | 18 | A special exception to the LGPL can be applied should you wish to distribute 19 | a combined work that includes raw os, without being obliged to provide 20 | the source code for any proprietary components. See the file exception.txt 21 | for full details of how and when the exception can be applied. 22 | */ 23 | 24 | 25 | 26 | /* 27 | * 2012-9 Slab Memory Managment 28 | * by Hu Zhigang 29 | */ 30 | 31 | 32 | 33 | 34 | typedef struct { 35 | atomic_t val; 36 | const char *name; 37 | } spinlock_t; 38 | 39 | #define SPINLOCK_DECLARE(lock_name) spinlock_t lock_name 40 | 41 | /*Non-SMP architecture.*/ 42 | #define SPINLOCK_EXTERN(name) 43 | 44 | #define SPINLOCK_INITIALIZE(name) 45 | #define SPINLOCK_STATIC_INITIALIZE(name) 46 | 47 | #define SPINLOCK_INITIALIZE_NAME(name, desc_name) 48 | #define SPINLOCK_STATIC_INITIALIZE_NAME(name, desc_name) 49 | 50 | #define ASSERT_SPINLOCK(expr, lock) ASSERT(expr) 51 | #define ASSERT_IRQ_SPINLOCK(expr, irq_lock) \ 52 | ASSERT_SPINLOCK(expr, NULL) 53 | 54 | #define spinlock_initialize(lock, name) 55 | 56 | #define spinlock_lock(lock) 57 | #define spinlock_trylock(lock) 58 | #define spinlock_locked(lock) 59 | #define spinlock_unlocked(lock) 60 | #define spinlock_unlock(lock) 61 | 62 | 63 | typedef char bool; 64 | 65 | typedef struct { 66 | SPINLOCK_DECLARE(lock); /**< Spinlock */ 67 | bool guard; /**< Flag whether ipl is valid */ 68 | 69 | } irq_spinlock_t; 70 | 71 | #define IRQ_SPINLOCK_DECLARE(lock_name) irq_spinlock_t lock_name 72 | 73 | #define IRQ_SPINLOCK_STATIC_INITIALIZE_NAME(lock_name, desc_name) 74 | 75 | 76 | RAW_INLINE void irq_spinlock_initialize(irq_spinlock_t *lock, const char *name) 77 | { 78 | 79 | 80 | } 81 | 82 | RAW_INLINE void irq_spinlock_lock(irq_spinlock_t *lock, bool irq_dis) 83 | { 84 | 85 | } 86 | 87 | RAW_INLINE void irq_spinlock_unlock(irq_spinlock_t *lock, bool irq_res) 88 | { 89 | 90 | 91 | } 92 | 93 | -------------------------------------------------------------------------------- /extension/include/posix/mqueue.h: -------------------------------------------------------------------------------- 1 | #ifndef MQUEUE_H 2 | #define MQUEUE_H 3 | 4 | 5 | 6 | struct mqd 7 | { 8 | RAW_MQUEUE mqueue_posix; 9 | }; 10 | 11 | typedef struct mqd *mqd_t; 12 | 13 | 14 | #endif 15 | 16 | -------------------------------------------------------------------------------- /extension/include/posix/pthread.h: -------------------------------------------------------------------------------- 1 | #ifndef PTHREAD_H 2 | #define PTHREAD_H 3 | 4 | 5 | #ifdef __cplusplus 6 | extern "C" { 7 | #endif 8 | 9 | typedef RAW_S32 clockid_t; 10 | typedef RAW_S32 key_t; /* Used for interprocess communication. */ 11 | typedef RAW_S32 pid_t; /* Used for process IDs and process group IDs. */ 12 | typedef RAW_S32 ssize_t; /* Used for a count of bytes or an error indication. */ 13 | typedef unsigned int size_t; 14 | 15 | 16 | typedef RAW_S32 pthread_condattr_t; 17 | typedef long pthread_mutexattr_t; 18 | typedef struct pthread_struct *pthread_t; 19 | 20 | 21 | #define __SIZEOF_PTHREAD_ATTR_T 36 22 | 23 | #define PTHREAD_CREATE_JOINABLE 0x1 24 | #define PTHREAD_CREATE_DETACHED 0x2 25 | 26 | 27 | typedef struct 28 | { 29 | int detachstate; 30 | int schedpolicy; 31 | 32 | int inheritsched; 33 | int scope; 34 | unsigned int guardsize; 35 | int stackaddr_set; 36 | void *stackaddr; 37 | unsigned int stacksize; 38 | 39 | }pthread_attr_t; 40 | 41 | 42 | typedef struct pthread_struct { 43 | 44 | RAW_TASK_OBJ task_obj; 45 | RAW_SEMAPHORE task_sem; 46 | 47 | RAW_U8 detachstate; 48 | pthread_attr_t attr; 49 | void *ret; 50 | 51 | } pthread_struct; 52 | 53 | 54 | 55 | struct timespec { 56 | long tv_sec; 57 | long tv_nsec; 58 | }; 59 | 60 | struct timeval { 61 | RAW_S32 tv_sec; 62 | RAW_S32 tv_usec; 63 | }; 64 | 65 | 66 | 67 | struct timezone { 68 | int tz_minuteswest; /* minutes west of Greenwich */ 69 | int tz_dsttime; /* type of dst correction */ 70 | }; 71 | 72 | 73 | struct tm { 74 | int tm_sec; /* Seconds. [0-60] (1 leap second) */ 75 | int tm_min; /* Minutes. [0-59] */ 76 | int tm_hour; /* Hours. [0-23] */ 77 | int tm_mday; /* Day. [1-31] */ 78 | int tm_mon; /* Month. [0-11] */ 79 | int tm_year; /* Year - 1900. */ 80 | int tm_wday; /* Day of week. [0-6] */ 81 | int tm_yday; /* Days in year.[0-365] */ 82 | int tm_isdst; /* DST. [-1/0/1]*/ 83 | 84 | long int tm_gmtoff; /* Seconds east of UTC. */ 85 | const char *tm_zone; /* Timezone abbreviation. */ 86 | }; 87 | 88 | 89 | 90 | typedef struct pthread_mutex_t { 91 | 92 | RAW_S32 attr; 93 | RAW_MUTEX mutex_lock; 94 | 95 | } pthread_mutex_t; 96 | 97 | 98 | 99 | typedef struct pthread_cond_t 100 | { 101 | RAW_S32 attr; 102 | RAW_SEMAPHORE sem_lock; 103 | 104 | } pthread_cond_t; 105 | 106 | 107 | 108 | 109 | unsigned int calculate_ticks(const struct timespec *time); 110 | int clock_gettime(clockid_t clockid, struct timespec *tp); 111 | 112 | int pthread_create(pthread_t *thread, const pthread_attr_t *attr, void * (*start_routine)(void *), void *arg); 113 | 114 | 115 | #ifdef __cplusplus 116 | } 117 | #endif 118 | 119 | 120 | #endif 121 | 122 | 123 | -------------------------------------------------------------------------------- /extension/include/posix/semphore.h: -------------------------------------------------------------------------------- 1 | #ifndef SEMEPHORE_H 2 | #define SEMEPHORE_H 3 | 4 | 5 | typedef struct posix_sem sem_t; 6 | 7 | 8 | struct posix_sem 9 | { 10 | RAW_SEMAPHORE sem_posix; 11 | 12 | }; 13 | 14 | 15 | 16 | int sem_close(sem_t *sem); 17 | int sem_destroy(sem_t *sem); 18 | int sem_getvalue(sem_t *sem, int *sval); 19 | int sem_init(sem_t *sem, int pshared, unsigned int value); 20 | sem_t *sem_open(const char *name, int oflag, ...); 21 | int sem_post(sem_t *sem); 22 | int sem_timedwait(sem_t *sem, const struct timespec *abs_timeout); 23 | int sem_trywait(sem_t *sem); 24 | int sem_unlink(const char *name); 25 | int sem_wait(sem_t *sem); 26 | 27 | 28 | 29 | #endif 30 | -------------------------------------------------------------------------------- /extension/include/protothread/cc.h: -------------------------------------------------------------------------------- 1 | /** 2 | * \file 3 | * Default definitions of C compiler quirk work-arounds. 4 | * \author Adam Dunkels 5 | * 6 | * This file is used for making use of extra functionality of some C 7 | * compilers used for Contiki, and defining work-arounds for various 8 | * quirks and problems with some other C compilers. 9 | */ 10 | 11 | /* 12 | * Copyright (c) 2003, Adam Dunkels. 13 | * All rights reserved. 14 | * 15 | * Redistribution and use in source and binary forms, with or without 16 | * modification, are permitted provided that the following conditions 17 | * are met: 18 | * 1. Redistributions of source code must retain the above copyright 19 | * notice, this list of conditions and the following disclaimer. 20 | * 2. Redistributions in binary form must reproduce the above 21 | * copyright notice, this list of conditions and the following 22 | * disclaimer in the documentation and/or other materials provided 23 | * with the distribution. 24 | * 3. The name of the author may not be used to endorse or promote 25 | * products derived from this software without specific prior 26 | * written permission. 27 | * 28 | * THIS SOFTWARE IS PROVIDED BY THE AUTHOR ``AS IS'' AND ANY EXPRESS 29 | * OR IMPLIED WARRANTIES, INCLUDING, BUT NOT LIMITED TO, THE IMPLIED 30 | * WARRANTIES OF MERCHANTABILITY AND FITNESS FOR A PARTICULAR PURPOSE 31 | * ARE DISCLAIMED. IN NO EVENT SHALL THE AUTHOR BE LIABLE FOR ANY 32 | * DIRECT, INDIRECT, INCIDENTAL, SPECIAL, EXEMPLARY, OR CONSEQUENTIAL 33 | * DAMAGES (INCLUDING, BUT NOT LIMITED TO, PROCUREMENT OF SUBSTITUTE 34 | * GOODS OR SERVICES; LOSS OF USE, DATA, OR PROFITS; OR BUSINESS 35 | * INTERRUPTION) HOWEVER CAUSED AND ON ANY THEORY OF LIABILITY, 36 | * WHETHER IN CONTRACT, STRICT LIABILITY, OR TORT (INCLUDING 37 | * NEGLIGENCE OR OTHERWISE) ARISING IN ANY WAY OUT OF THE USE OF THIS 38 | * SOFTWARE, EVEN IF ADVISED OF THE POSSIBILITY OF SUCH DAMAGE. 39 | * 40 | * This file is part of the Contiki desktop OS 41 | * 42 | * $Id: cc.h,v 1.6 2008/07/02 08:35:29 adamdunkels Exp $ 43 | * 44 | */ 45 | #ifndef __CC_H__ 46 | #define __CC_H__ 47 | 48 | 49 | 50 | typedef unsigned int clock_time_t; 51 | 52 | /** 53 | * Configure if the C compiler supports the "register" keyword for 54 | * function arguments. 55 | */ 56 | #if CC_CONF_REGISTER_ARGS 57 | #define CC_REGISTER_ARG register 58 | #else /* CC_CONF_REGISTER_ARGS */ 59 | #define CC_REGISTER_ARG 60 | #endif /* CC_CONF_REGISTER_ARGS */ 61 | 62 | /** 63 | * Configure if the C compiler supports the arguments for function 64 | * pointers. 65 | */ 66 | #if CC_CONF_FUNCTION_POINTER_ARGS 67 | #define CC_FUNCTION_POINTER_ARGS 1 68 | #else /* CC_CONF_FUNCTION_POINTER_ARGS */ 69 | #define CC_FUNCTION_POINTER_ARGS 0 70 | #endif /* CC_CONF_FUNCTION_POINTER_ARGS */ 71 | 72 | /** 73 | * Configure if the C compiler supports fastcall function 74 | * declarations. 75 | */ 76 | #ifdef CC_CONF_FASTCALL 77 | #define CC_FASTCALL CC_CONF_FASTCALL 78 | #else /* CC_CONF_FASTCALL */ 79 | #define CC_FASTCALL 80 | #endif /* CC_CONF_FASTCALL */ 81 | 82 | /** 83 | * Configure if the C compiler have problems with const function pointers 84 | */ 85 | #ifdef CC_CONF_CONST_FUNCTION_BUG 86 | #define CC_CONST_FUNCTION 87 | #else /* CC_CONF_FASTCALL */ 88 | #define CC_CONST_FUNCTION const 89 | #endif /* CC_CONF_FASTCALL */ 90 | 91 | /** 92 | * Configure work-around for unsigned char bugs with sdcc. 93 | */ 94 | #if CC_CONF_UNSIGNED_CHAR_BUGS 95 | #define CC_UNSIGNED_CHAR_BUGS 1 96 | #else /* CC_CONF_UNSIGNED_CHAR_BUGS */ 97 | #define CC_UNSIGNED_CHAR_BUGS 0 98 | #endif /* CC_CONF_UNSIGNED_CHAR_BUGS */ 99 | 100 | /** 101 | * Configure if C compiler supports double hash marks in C macros. 102 | */ 103 | #if CC_CONF_DOUBLE_HASH 104 | #define CC_DOUBLE_HASH 1 105 | #else /* CC_CONF_DOUBLE_HASH */ 106 | #define CC_DOUBLE_HASH 0 107 | #endif /* CC_CONF_DOUBLE_HASH */ 108 | 109 | #ifdef CC_CONF_INLINE 110 | #define CC_INLINE CC_CONF_INLINE 111 | #else /* CC_CONF_INLINE */ 112 | #define CC_INLINE 113 | #endif /* CC_CONF_INLINE */ 114 | 115 | /** 116 | * Configure if the C compiler supports the assignment of struct value. 117 | */ 118 | #ifdef CC_CONF_ASSIGN_AGGREGATE 119 | #define CC_ASSIGN_AGGREGATE(dest, src) CC_CONF_ASSIGN_AGGREGATE(dest, src) 120 | #else /* CC_CONF_ASSIGN_AGGREGATE */ 121 | #define CC_ASSIGN_AGGREGATE(dest, src) *dest = *src 122 | #endif /* CC_CONF_ASSIGN_AGGREGATE */ 123 | 124 | #if CC_CONF_NO_VA_ARGS 125 | #define CC_NO_VA_ARGS CC_CONF_VA_ARGS 126 | #endif 127 | 128 | #ifndef NULL 129 | #define NULL 0 130 | #endif /* NULL */ 131 | 132 | #define CC_CONCAT2(s1, s2) s1##s2 133 | /** 134 | * A C preprocessing macro for concatenating to 135 | * strings. 136 | * 137 | * We need use two macros (CC_CONCAT and CC_CONCAT2) in order to allow 138 | * concatenation of two #defined macros. 139 | */ 140 | #define CC_CONCAT(s1, s2) CC_CONCAT2(s1, s2) 141 | 142 | #endif /* __CC_H__ */ 143 | -------------------------------------------------------------------------------- /extension/include/protothread/clock.h: -------------------------------------------------------------------------------- 1 | #ifndef CLOCK_H 2 | #define CLOCK_H 3 | 4 | clock_time_t clock_time(void); 5 | 6 | 7 | unsigned int clock_seconds(void); 8 | 9 | #define CLOCK_SECOND RAW_TICKS_PER_SECOND 10 | 11 | #endif 12 | 13 | -------------------------------------------------------------------------------- /extension/include/protothread/lc-switch.h: -------------------------------------------------------------------------------- 1 | /* 2 | * Copyright (c) 2004-2005, Swedish Institute of Computer Science. 3 | * All rights reserved. 4 | * 5 | * Redistribution and use in source and binary forms, with or without 6 | * modification, are permitted provided that the following conditions 7 | * are met: 8 | * 1. Redistributions of source code must retain the above copyright 9 | * notice, this list of conditions and the following disclaimer. 10 | * 2. Redistributions in binary form must reproduce the above copyright 11 | * notice, this list of conditions and the following disclaimer in the 12 | * documentation and/or other materials provided with the distribution. 13 | * 3. Neither the name of the Institute nor the names of its contributors 14 | * may be used to endorse or promote products derived from this software 15 | * without specific prior written permission. 16 | * 17 | * THIS SOFTWARE IS PROVIDED BY THE INSTITUTE AND CONTRIBUTORS ``AS IS'' AND 18 | * ANY EXPRESS OR IMPLIED WARRANTIES, INCLUDING, BUT NOT LIMITED TO, THE 19 | * IMPLIED WARRANTIES OF MERCHANTABILITY AND FITNESS FOR A PARTICULAR PURPOSE 20 | * ARE DISCLAIMED. IN NO EVENT SHALL THE INSTITUTE OR CONTRIBUTORS BE LIABLE 21 | * FOR ANY DIRECT, INDIRECT, INCIDENTAL, SPECIAL, EXEMPLARY, OR CONSEQUENTIAL 22 | * DAMAGES (INCLUDING, BUT NOT LIMITED TO, PROCUREMENT OF SUBSTITUTE GOODS 23 | * OR SERVICES; LOSS OF USE, DATA, OR PROFITS; OR BUSINESS INTERRUPTION) 24 | * HOWEVER CAUSED AND ON ANY THEORY OF LIABILITY, WHETHER IN CONTRACT, STRICT 25 | * LIABILITY, OR TORT (INCLUDING NEGLIGENCE OR OTHERWISE) ARISING IN ANY WAY 26 | * OUT OF THE USE OF THIS SOFTWARE, EVEN IF ADVISED OF THE POSSIBILITY OF 27 | * SUCH DAMAGE. 28 | * 29 | * This file is part of the Contiki operating system. 30 | * 31 | * Author: Adam Dunkels 32 | * 33 | * $Id: lc-switch.h,v 1.3 2008/10/14 12:46:39 nvt-se Exp $ 34 | */ 35 | 36 | /** 37 | * \addtogroup lc 38 | * @{ 39 | */ 40 | 41 | /** 42 | * \file 43 | * Implementation of local continuations based on switch() statement 44 | * \author Adam Dunkels 45 | * 46 | * This implementation of local continuations uses the C switch() 47 | * statement to resume execution of a function somewhere inside the 48 | * function's body. The implementation is based on the fact that 49 | * switch() statements are able to jump directly into the bodies of 50 | * control structures such as if() or while() statements. 51 | * 52 | * This implementation borrows heavily from Simon Tatham's coroutines 53 | * implementation in C: 54 | * http://www.chiark.greenend.org.uk/~sgtatham/coroutines.html 55 | */ 56 | 57 | #ifndef __LC_SWITCH_H__ 58 | #define __LC_SWITCH_H__ 59 | 60 | /* WARNING! lc implementation using switch() does not work if an 61 | LC_SET() is done within another switch() statement! */ 62 | 63 | /** \hideinitializer */ 64 | typedef unsigned short lc_t; 65 | 66 | #define LC_INIT(s) s = 0; 67 | 68 | #define LC_RESUME(s) switch(s) { case 0: 69 | 70 | #define LC_SET(s) s = __LINE__; case __LINE__: 71 | 72 | #define LC_END(s) } 73 | 74 | #endif /* __LC_SWITCH_H__ */ 75 | 76 | /** @} */ 77 | -------------------------------------------------------------------------------- /extension/include/protothread/protothread.h: -------------------------------------------------------------------------------- 1 | #ifndef PROTOTHREAD_H 2 | 3 | #define PROTOTHREAD_H 4 | 5 | #include 6 | #include 7 | #include 8 | #include 9 | #include 10 | #include 11 | #include 12 | #include 13 | #include 14 | 15 | #endif 16 | 17 | -------------------------------------------------------------------------------- /extension/include/protothread/stimer.h: -------------------------------------------------------------------------------- 1 | /** \addtogroup sys 2 | * @{ */ 3 | 4 | /** 5 | * \defgroup stimer Seconds timer library 6 | * 7 | * The stimer library provides functions for setting, resetting and 8 | * restarting timers, and for checking if a timer has expired. An 9 | * application must "manually" check if its timers have expired; this 10 | * is not done automatically. 11 | * 12 | * A timer is declared as a \c struct \c stimer and all access to the 13 | * timer is made by a pointer to the declared timer. 14 | * 15 | * \note The stimer library is not able to post events when a timer 16 | * expires. The \ref etimer "Event timers" should be used for this 17 | * purpose. 18 | * 19 | * \note The stimer library uses the \ref clock "Clock library" to 20 | * measure time. Intervals should be specified in the seconds. 21 | * 22 | * \sa \ref etimer "Event timers" 23 | * 24 | * @{ 25 | */ 26 | 27 | 28 | /** 29 | * \file 30 | * Second timer library header file. 31 | * \author 32 | * Adam Dunkels , Nicolas Tsiftes 33 | */ 34 | 35 | /* 36 | * Copyright (c) 2004, 2008, Swedish Institute of Computer Science. 37 | * All rights reserved. 38 | * 39 | * Redistribution and use in source and binary forms, with or without 40 | * modification, are permitted provided that the following conditions 41 | * are met: 42 | * 1. Redistributions of source code must retain the above copyright 43 | * notice, this list of conditions and the following disclaimer. 44 | * 2. Redistributions in binary form must reproduce the above copyright 45 | * notice, this list of conditions and the following disclaimer in the 46 | * documentation and/or other materials provided with the distribution. 47 | * 3. Neither the name of the Institute nor the names of its contributors 48 | * may be used to endorse or promote products derived from this software 49 | * without specific prior written permission. 50 | * 51 | * THIS SOFTWARE IS PROVIDED BY THE INSTITUTE AND CONTRIBUTORS ``AS IS'' AND 52 | * ANY EXPRESS OR IMPLIED WARRANTIES, INCLUDING, BUT NOT LIMITED TO, THE 53 | * IMPLIED WARRANTIES OF MERCHANTABILITY AND FITNESS FOR A PARTICULAR PURPOSE 54 | * ARE DISCLAIMED. IN NO EVENT SHALL THE INSTITUTE OR CONTRIBUTORS BE LIABLE 55 | * FOR ANY DIRECT, INDIRECT, INCIDENTAL, SPECIAL, EXEMPLARY, OR CONSEQUENTIAL 56 | * DAMAGES (INCLUDING, BUT NOT LIMITED TO, PROCUREMENT OF SUBSTITUTE GOODS 57 | * OR SERVICES; LOSS OF USE, DATA, OR PROFITS; OR BUSINESS INTERRUPTION) 58 | * HOWEVER CAUSED AND ON ANY THEORY OF LIABILITY, WHETHER IN CONTRACT, STRICT 59 | * LIABILITY, OR TORT (INCLUDING NEGLIGENCE OR OTHERWISE) ARISING IN ANY WAY 60 | * OUT OF THE USE OF THIS SOFTWARE, EVEN IF ADVISED OF THE POSSIBILITY OF 61 | * SUCH DAMAGE. 62 | * 63 | * This file is part of the Contiki operating system. 64 | * 65 | * Author: Adam Dunkels , Nicolas Tsiftes 66 | * 67 | * $Id: stimer.h,v 1.4 2010/03/15 15:53:57 joxe Exp $ 68 | */ 69 | #ifndef __STIMER_H__ 70 | #define __STIMER_H__ 71 | 72 | 73 | 74 | /** 75 | * A timer. 76 | * 77 | * This structure is used for declaring a timer. The timer must be set 78 | * with stimer_set() before it can be used. 79 | * 80 | * \hideinitializer 81 | */ 82 | struct stimer { 83 | unsigned long start; 84 | unsigned long interval; 85 | }; 86 | 87 | void stimer_set(struct stimer *t, unsigned long interval); 88 | void stimer_reset(struct stimer *t); 89 | void stimer_restart(struct stimer *t); 90 | int stimer_expired(struct stimer *t); 91 | unsigned long stimer_remaining(struct stimer *t); 92 | unsigned long stimer_elapsed(struct stimer *t); 93 | 94 | 95 | #endif /* __STIMER_H__ */ 96 | 97 | /** @} */ 98 | /** @} */ 99 | -------------------------------------------------------------------------------- /extension/include/protothread/timer.h: -------------------------------------------------------------------------------- 1 | /** \addtogroup sys 2 | * @{ */ 3 | 4 | /** 5 | * \defgroup timer Timer library 6 | * 7 | * The Contiki kernel does not provide support for timed 8 | * events. Rather, an application that wants to use timers needs to 9 | * explicitly use the timer library. 10 | * 11 | * The timer library provides functions for setting, resetting and 12 | * restarting timers, and for checking if a timer has expired. An 13 | * application must "manually" check if its timers have expired; this 14 | * is not done automatically. 15 | * 16 | * A timer is declared as a \c struct \c timer and all access to the 17 | * timer is made by a pointer to the declared timer. 18 | * 19 | * \note The timer library is not able to post events when a timer 20 | * expires. The \ref etimer "Event timers" should be used for this 21 | * purpose. 22 | * 23 | * \note The timer library uses the \ref clock "Clock library" to 24 | * measure time. Intervals should be specified in the format used by 25 | * the clock library. 26 | * 27 | * \sa \ref etimer "Event timers" 28 | * 29 | * @{ 30 | */ 31 | 32 | 33 | /** 34 | * \file 35 | * Timer library header file. 36 | * \author 37 | * Adam Dunkels 38 | */ 39 | 40 | /* 41 | * Copyright (c) 2004, Swedish Institute of Computer Science. 42 | * All rights reserved. 43 | * 44 | * Redistribution and use in source and binary forms, with or without 45 | * modification, are permitted provided that the following conditions 46 | * are met: 47 | * 1. Redistributions of source code must retain the above copyright 48 | * notice, this list of conditions and the following disclaimer. 49 | * 2. Redistributions in binary form must reproduce the above copyright 50 | * notice, this list of conditions and the following disclaimer in the 51 | * documentation and/or other materials provided with the distribution. 52 | * 3. Neither the name of the Institute nor the names of its contributors 53 | * may be used to endorse or promote products derived from this software 54 | * without specific prior written permission. 55 | * 56 | * THIS SOFTWARE IS PROVIDED BY THE INSTITUTE AND CONTRIBUTORS ``AS IS'' AND 57 | * ANY EXPRESS OR IMPLIED WARRANTIES, INCLUDING, BUT NOT LIMITED TO, THE 58 | * IMPLIED WARRANTIES OF MERCHANTABILITY AND FITNESS FOR A PARTICULAR PURPOSE 59 | * ARE DISCLAIMED. IN NO EVENT SHALL THE INSTITUTE OR CONTRIBUTORS BE LIABLE 60 | * FOR ANY DIRECT, INDIRECT, INCIDENTAL, SPECIAL, EXEMPLARY, OR CONSEQUENTIAL 61 | * DAMAGES (INCLUDING, BUT NOT LIMITED TO, PROCUREMENT OF SUBSTITUTE GOODS 62 | * OR SERVICES; LOSS OF USE, DATA, OR PROFITS; OR BUSINESS INTERRUPTION) 63 | * HOWEVER CAUSED AND ON ANY THEORY OF LIABILITY, WHETHER IN CONTRACT, STRICT 64 | * LIABILITY, OR TORT (INCLUDING NEGLIGENCE OR OTHERWISE) ARISING IN ANY WAY 65 | * OUT OF THE USE OF THIS SOFTWARE, EVEN IF ADVISED OF THE POSSIBILITY OF 66 | * SUCH DAMAGE. 67 | * 68 | * This file is part of the Contiki operating system. 69 | * 70 | * Author: Adam Dunkels 71 | * 72 | * $Id: timer.h,v 1.2 2008/09/21 08:58:05 adamdunkels Exp $ 73 | */ 74 | #ifndef __TIMER_H__ 75 | #define __TIMER_H__ 76 | 77 | 78 | 79 | /** 80 | * A timer. 81 | * 82 | * This structure is used for declaring a timer. The timer must be set 83 | * with timer_set() before it can be used. 84 | * 85 | * \hideinitializer 86 | */ 87 | struct timer { 88 | clock_time_t start; 89 | clock_time_t interval; 90 | }; 91 | 92 | void timer_set(struct timer *t, clock_time_t interval); 93 | void timer_reset(struct timer *t); 94 | void timer_restart(struct timer *t); 95 | int timer_expired(struct timer *t); 96 | clock_time_t timer_remaining(struct timer *t); 97 | 98 | 99 | #endif /* __TIMER_H__ */ 100 | 101 | /** @} */ 102 | /** @} */ 103 | -------------------------------------------------------------------------------- /extension/include/raw_ff.h: -------------------------------------------------------------------------------- 1 | #ifndef RAW_FF_H 2 | #define RAW_FF_H 3 | 4 | typedef struct _Files { 5 | int fileNo; 6 | int b; 7 | } _FileType; 8 | 9 | 10 | typedef _FileType raw_FILE; 11 | 12 | typedef struct _EnvS { 13 | /* Each "Task" should at least have a set of std file handles */ 14 | _FileType *_stdin; 15 | _FileType *_stdout; 16 | _FileType *_stderr; 17 | } _EnvType; 18 | 19 | extern _EnvType *_EnvPtr; 20 | int fileno(raw_FILE *); 21 | 22 | 23 | /* File handles */ 24 | #define raw_stdin (_EnvPtr->_stdin) 25 | #define raw_stdout (_EnvPtr->_stdout) 26 | #define raw_stderr (_EnvPtr->_stderr) 27 | 28 | 29 | raw_FILE *raw_fopen(const char *path, const char *mode); 30 | 31 | RAW_PROCESSOR_UINT raw_fread(void *ptr, RAW_PROCESSOR_UINT size, RAW_PROCESSOR_UINT nmemb, raw_FILE *stream); 32 | 33 | RAW_PROCESSOR_UINT raw_fwrite(const char *ptr, RAW_PROCESSOR_UINT size, RAW_PROCESSOR_UINT nmemb, raw_FILE *stream); 34 | 35 | RAW_S32 raw_fclose(raw_FILE *fp); 36 | 37 | RAW_S32 raw_ferror(raw_FILE *fp); 38 | 39 | raw_FILE *raw_freopen(const char *pathpath, const char *mode, raw_FILE *stream); 40 | 41 | RAW_PROCESSOR_INT raw_fseek(raw_FILE *stream, RAW_PROCESSOR_INT offset, RAW_PROCESSOR_INT whence); 42 | 43 | RAW_PROCESSOR_INT raw_getc(raw_FILE *stream); 44 | 45 | int raw_feof(raw_FILE *stream); 46 | 47 | long raw_ftell(raw_FILE *stream); 48 | 49 | 50 | int raw_ungetc(int c, raw_FILE *stream); 51 | 52 | 53 | int raw_fflush(raw_FILE *fp); 54 | 55 | int raw_setvbuf(raw_FILE *stream, char *buf, int type, unsigned size); 56 | 57 | 58 | #endif 59 | 60 | -------------------------------------------------------------------------------- /extension/include/raw_mlock.h: -------------------------------------------------------------------------------- 1 | /* 2 | raw os - Copyright (C) Lingjun Chen(jorya_txj). 3 | 4 | This file is part of raw os. 5 | 6 | raw os is free software; you can redistribute it it under the terms of the 7 | GNU General Public License as published by the Free Software Foundation; 8 | either version 3 of the License, or (at your option) any later version. 9 | 10 | raw os is distributed in the hope that it will be useful, but WITHOUT ANY WARRANTY; 11 | without even the implied warranty of MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. 12 | See the GNU General Public License for more details. 13 | 14 | You should have received a copy of the GNU Lesser General Public License 15 | along with this program. if not, write email to jorya.txj@gmail.com 16 | --- 17 | 18 | A special exception to the LGPL can be applied should you wish to distribute 19 | a combined work that includes raw os, without being obliged to provide 20 | the source code for any proprietary components. See the file exception.txt 21 | for full details of how and when the exception can be applied. 22 | */ 23 | 24 | 25 | /* 2012-10 Created by jorya_txj 26 | * xxxxxx please added here 27 | */ 28 | 29 | #ifndef RAW_MLOCK_H 30 | #define RAW_MLOCK_H 31 | 32 | typedef struct RAW_MLOCK{ 33 | 34 | RAW_EVENT event_ptr; 35 | 36 | } RAW_MLOCK; 37 | 38 | RAW_U16 raw_mlock(RAW_MLOCK *mlock, RAW_U8 num, RAW_TICK_TYPE wait_option); 39 | RAW_U16 raw_munlock(RAW_MLOCK *mlock, RAW_U8 num); 40 | RAW_U16 raw_mlock_create(RAW_MLOCK *mlock, RAW_U8 *name_ptr); 41 | RAW_U16 raw_mlock_delete(RAW_MLOCK *mlock); 42 | 43 | #endif 44 | 45 | -------------------------------------------------------------------------------- /extension/include/raw_work_queue.h: -------------------------------------------------------------------------------- 1 | /* 2 | raw os - Copyright (C) Lingjun Chen(jorya_txj). 3 | 4 | This file is part of raw os. 5 | 6 | raw os is free software; you can redistribute it it under the terms of the 7 | GNU General Public License as published by the Free Software Foundation; 8 | either version 3 of the License, or (at your option) any later version. 9 | 10 | raw os is distributed in the hope that it will be useful, but WITHOUT ANY WARRANTY; 11 | without even the implied warranty of MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. 12 | See the GNU General Public License for more details. 13 | 14 | You should have received a copy of the GNU Lesser General Public License 15 | along with this program. if not, write email to jorya.txj@gmail.com 16 | --- 17 | 18 | A special exception to the LGPL can be applied should you wish to distribute 19 | a combined work that includes raw os, without being obliged to provide 20 | the source code for any proprietary components. See the file exception.txt 21 | for full details of how and when the exception can be applied. 22 | */ 23 | 24 | 25 | /* 2013-1 Created by jorya_txj 26 | * xxxxxx please added here 27 | */ 28 | 29 | #ifndef WORK_QUEUE_H 30 | #define WORK_QUEUE_H 31 | 32 | typedef void (*WORK_QUEUE_HANDLER)(RAW_U32 arg, void *msg); 33 | 34 | typedef struct OBJECT_WORK_QUEUE_MSG { 35 | 36 | struct OBJECT_WORK_QUEUE_MSG *next; 37 | WORK_QUEUE_HANDLER handler; 38 | void *msg; 39 | RAW_U32 arg; 40 | 41 | } OBJECT_WORK_QUEUE_MSG; 42 | 43 | 44 | typedef struct WORK_QUEUE_STRUCT { 45 | 46 | RAW_QUEUE queue; 47 | RAW_TASK_OBJ work_queue_task_obj; 48 | 49 | } WORK_QUEUE_STRUCT; 50 | 51 | 52 | 53 | #endif 54 | 55 | 56 | void tick_work_handler(RAW_U32 arg, void *msg); 57 | 58 | RAW_OS_ERROR work_queue_create(WORK_QUEUE_STRUCT *wq, RAW_U8 work_task_priority, RAW_U32 work_queue_stack_size, 59 | PORT_STACK *work_queue_stack_base, void **msg_start, RAW_U32 work_msg_size); 60 | 61 | RAW_OS_ERROR sche_work_queue(WORK_QUEUE_STRUCT *wq, RAW_U32 arg, void *msg, WORK_QUEUE_HANDLER handler); 62 | 63 | void global_work_queue_init(OBJECT_WORK_QUEUE_MSG *work_queue_msg, RAW_U32 size); 64 | 65 | 66 | -------------------------------------------------------------------------------- /extension/include/rb_tree.h: -------------------------------------------------------------------------------- 1 | /* 2 | Red Black Trees 3 | (C) 1999 Andrea Arcangeli 4 | 5 | This program is free software; you can redistribute it and/or modify 6 | it under the terms of the GNU General Public License as published by 7 | the Free Software Foundation; either version 2 of the License, or 8 | (at your option) any later version. 9 | 10 | This program is distributed in the hope that it will be useful, 11 | but WITHOUT ANY WARRANTY; without even the implied warranty of 12 | MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the 13 | GNU General Public License for more details. 14 | 15 | You should have received a copy of the GNU General Public License 16 | along with this program; if not, write to the Free Software 17 | Foundation, Inc., 59 Temple Place, Suite 330, Boston, MA 02111-1307 USA 18 | 19 | linux/include/linux/rbtree.h 20 | 21 | To use rbtrees you'll have to implement your own insert and search cores. 22 | This will avoid us to use callbacks and to drop drammatically performances. 23 | I know it's not the cleaner way, but in C (not in C++) to get 24 | performances and genericity... 25 | 26 | Some example of insert and search follows here. The search is a plain 27 | normal search over an ordered tree. The insert instead must be implemented 28 | in two steps: First, the code must insert the element in order as a red leaf 29 | in the tree, and then the support library function rb_insert_color() must 30 | be called. Such function will do the not trivial work to rebalance the 31 | rbtree, if necessary. 32 | */ 33 | 34 | #ifndef _RBTREE_H 35 | #define _RBTREE_H 36 | 37 | struct rb_node 38 | { 39 | RAW_U32 rb_parent_color; 40 | #define RB_RED 0 41 | #define RB_BLACK 1 42 | struct rb_node *rb_right; 43 | struct rb_node *rb_left; 44 | }; 45 | 46 | struct rb_root 47 | { 48 | struct rb_node *rb_node; 49 | }; 50 | 51 | 52 | #define rb_parent(r) ((struct rb_node *)((r)->rb_parent_color & ~3)) 53 | #define rb_color(r) ((r)->rb_parent_color & 1) 54 | #define rb_is_red(r) (!rb_color(r)) 55 | #define rb_is_black(r) rb_color(r) 56 | #define rb_set_red(r) do { (r)->rb_parent_color &= ~1; } while (0) 57 | #define rb_set_black(r) do { (r)->rb_parent_color |= 1; } while (0) 58 | 59 | /* get data by address */ 60 | #define offset_of(type, memb) ((RAW_U32)(&((type *)0)->memb)) 61 | #define rb_entry(obj, type, memb) ((type *)(((RAW_S8 *)obj) - offset_of(type, memb))) 62 | 63 | static void rb_set_parent(struct rb_node *rb, struct rb_node *p) 64 | { 65 | rb->rb_parent_color = (rb->rb_parent_color & 3) | (unsigned long)p; 66 | } 67 | 68 | static void rb_set_color(struct rb_node *rb, RAW_S32 color) 69 | { 70 | rb->rb_parent_color = (rb->rb_parent_color & ~1) | color; 71 | } 72 | 73 | #define RB_ROOT (struct rb_root) { NULL, } 74 | #define RB_EMPTY_ROOT(root) ((root)->rb_node == NULL) 75 | #define RB_EMPTY_NODE(node) (rb_parent(node) == node) 76 | #define RB_CLEAR_NODE(node) (rb_set_parent(node, node)) 77 | 78 | extern void rb_insert_color(struct rb_node *, struct rb_root *); 79 | extern void rb_erase(struct rb_node *, struct rb_root *); 80 | 81 | /* Find logical next and previous nodes in a tree */ 82 | extern struct rb_node *rb_next(const struct rb_node *); 83 | extern struct rb_node *rb_prev(const struct rb_node *); 84 | extern struct rb_node *rb_first(const struct rb_root *); 85 | extern struct rb_node *rb_last(const struct rb_root *); 86 | 87 | /* Fast replacement of a single node without remove/rebalance/add/rebalance */ 88 | extern void rb_replace_node(struct rb_node *victim, struct rb_node *new, 89 | struct rb_root *root); 90 | 91 | static void rb_link_node(struct rb_node * node, struct rb_node * parent, 92 | struct rb_node ** rb_link) 93 | { 94 | node->rb_parent_color = (unsigned long )parent; 95 | node->rb_left = node->rb_right = NULL; 96 | 97 | *rb_link = node; 98 | } 99 | 100 | #endif 101 | -------------------------------------------------------------------------------- /extension/include/rf/active_memory.h: -------------------------------------------------------------------------------- 1 | /* 2 | raw os - Copyright (C) Lingjun Chen(jorya_txj). 3 | 4 | This file is part of raw os. 5 | 6 | raw os is free software; you can redistribute it it under the terms of the 7 | GNU General Public License as published by the Free Software Foundation; 8 | either version 3 of the License, or (at your option) any later version. 9 | 10 | raw os is distributed in the hope that it will be useful, but WITHOUT ANY WARRANTY; 11 | without even the implied warranty of MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. 12 | See the GNU General Public License for more details. 13 | 14 | You should have received a copy of the GNU Lesser General Public License 15 | along with this program. if not, write email to jorya.txj@gmail.com 16 | --- 17 | 18 | A special exception to the LGPL can be applied should you wish to distribute 19 | a combined work that includes raw os, without being obliged to provide 20 | the source code for any proprietary components. See the file exception.txt 21 | for full details of how and when the exception can be applied. 22 | */ 23 | 24 | 25 | /* 2012-9 Created by jorya_txj 26 | * xxxxxx please added here 27 | */ 28 | 29 | 30 | 31 | #ifndef ACTIVE_MEMORY_H 32 | #define ACTIVE_MEMORY_H 33 | 34 | void *active_event_memory_allocate(MEM_POOL *pool, RAW_U16 sig); 35 | void active_memory_collect(STATE_EVENT *event); 36 | 37 | 38 | #endif 39 | -------------------------------------------------------------------------------- /extension/include/rf/active_object.h: -------------------------------------------------------------------------------- 1 | /* 2 | raw os - Copyright (C) Lingjun Chen(jorya_txj). 3 | 4 | This file is part of raw os. 5 | 6 | raw os is free software; you can redistribute it it under the terms of the 7 | GNU General Public License as published by the Free Software Foundation; 8 | either version 3 of the License, or (at your option) any later version. 9 | 10 | raw os is distributed in the hope that it will be useful, but WITHOUT ANY WARRANTY; 11 | without even the implied warranty of MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. 12 | See the GNU General Public License for more details. 13 | 14 | You should have received a copy of the GNU Lesser General Public License 15 | along with this program. if not, write email to jorya.txj@gmail.com 16 | --- 17 | 18 | A special exception to the LGPL can be applied should you wish to distribute 19 | a combined work that includes raw os, without being obliged to provide 20 | the source code for any proprietary components. See the file exception.txt 21 | for full details of how and when the exception can be applied. 22 | */ 23 | 24 | 25 | /* 2012-9 Created by jorya_txj 26 | * xxxxxx please added here 27 | */ 28 | 29 | 30 | #ifndef ACTIVE_OBJECT_H 31 | 32 | #define ACTIVE_OBJECT_H 33 | 34 | typedef struct active_object_struct { 35 | /*State machine*/ 36 | STM_STRUCT father; 37 | 38 | RAW_QUEUE active_queue; 39 | 40 | RAW_TASK_OBJ thread; 41 | 42 | /*broadcast queue list*/ 43 | LIST active_queue_list[ACTIVE_MAX_BROADCAST_SIGNAL]; 44 | 45 | RAW_U8 prio; 46 | RAW_U8 user_data; 47 | 48 | } ACTIVE_OBJECT_STRUCT; 49 | 50 | 51 | #endif 52 | 53 | 54 | void active_event_post_end(ACTIVE_OBJECT_STRUCT *me, STATE_EVENT *event); 55 | void active_event_post_front(ACTIVE_OBJECT_STRUCT *me, STATE_EVENT *event); 56 | STATE_EVENT *active_event_get(ACTIVE_OBJECT_STRUCT *me); 57 | void active_object_create(ACTIVE_OBJECT_STRUCT *me, RAW_U8 prio, 58 | void **msg_start, RAW_U32 qLen, 59 | void *stkSto, RAW_U32 stkSize, 60 | STATE_EVENT *event); 61 | 62 | void active_object_delete(ACTIVE_OBJECT_STRUCT *me); 63 | 64 | void active_event_defer_post(RAW_QUEUE *q, STATE_EVENT *event); 65 | 66 | RAW_U16 active_event_recall(ACTIVE_OBJECT_STRUCT *me, RAW_QUEUE *q); 67 | 68 | -------------------------------------------------------------------------------- /extension/include/rf/active_queue_broadcast.h: -------------------------------------------------------------------------------- 1 | /* 2 | raw os - Copyright (C) Lingjun Chen(jorya_txj). 3 | 4 | This file is part of raw os. 5 | 6 | raw os is free software; you can redistribute it it under the terms of the 7 | GNU General Public License as published by the Free Software Foundation; 8 | either version 3 of the License, or (at your option) any later version. 9 | 10 | raw os is distributed in the hope that it will be useful, but WITHOUT ANY WARRANTY; 11 | without even the implied warranty of MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. 12 | See the GNU General Public License for more details. 13 | 14 | You should have received a copy of the GNU Lesser General Public License 15 | along with this program. if not, write email to jorya.txj@gmail.com 16 | --- 17 | 18 | A special exception to the LGPL can be applied should you wish to distribute 19 | a combined work that includes raw os, without being obliged to provide 20 | the source code for any proprietary components. See the file exception.txt 21 | for full details of how and when the exception can be applied. 22 | */ 23 | 24 | 25 | /* 2012-9 Created by jorya_txj 26 | * xxxxxx please added here 27 | */ 28 | 29 | 30 | #ifndef ATIVE_QUEUE_BROADCAST_H 31 | 32 | #define ATIVE_QUEUE_BROADCAST_H 33 | 34 | 35 | void active_broadcast_queue_init(void); 36 | void active_broadcast_queue_register(ACTIVE_OBJECT_STRUCT *me, RAW_U16 sig); 37 | void active_queue_event_broadcast(STATE_EVENT *e); 38 | 39 | void active_broadcast_queue_unregister(ACTIVE_OBJECT_STRUCT *me, RAW_U16 sig); 40 | 41 | #endif 42 | 43 | -------------------------------------------------------------------------------- /extension/include/rf/active_time_event.h: -------------------------------------------------------------------------------- 1 | /* 2 | raw os - Copyright (C) Lingjun Chen(jorya_txj). 3 | 4 | This file is part of raw os. 5 | 6 | raw os is free software; you can redistribute it it under the terms of the 7 | GNU General Public License as published by the Free Software Foundation; 8 | either version 3 of the License, or (at your option) any later version. 9 | 10 | raw os is distributed in the hope that it will be useful, but WITHOUT ANY WARRANTY; 11 | without even the implied warranty of MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. 12 | See the GNU General Public License for more details. 13 | 14 | You should have received a copy of the GNU Lesser General Public License 15 | along with this program. if not, write email to jorya.txj@gmail.com 16 | --- 17 | 18 | A special exception to the LGPL can be applied should you wish to distribute 19 | a combined work that includes raw os, without being obliged to provide 20 | the source code for any proprietary components. See the file exception.txt 21 | for full details of how and when the exception can be applied. 22 | */ 23 | 24 | 25 | /* 2012-9 Created by jorya_txj 26 | * xxxxxx please added here 27 | */ 28 | 29 | 30 | 31 | #ifndef ACTIVE_TIME_EVENT_H 32 | #define ACTIVE_TIME_EVENT_H 33 | 34 | typedef struct time_event_struct { 35 | 36 | STATE_EVENT father; 37 | 38 | ACTIVE_OBJECT_STRUCT *active_object; 39 | RAW_TIMER timer; 40 | 41 | } TIME_EVENT_STRUCT; 42 | 43 | 44 | void active_time_event_create(TIME_EVENT_STRUCT *me, RAW_U16 sig); 45 | void active_time_event_fire(TIME_EVENT_STRUCT *me, ACTIVE_OBJECT_STRUCT *active_object, RAW_TICK_TYPE ticks, RAW_U8 once); 46 | RAW_U16 active_time_event_deactivate(TIME_EVENT_STRUCT *me); 47 | 48 | 49 | #endif 50 | 51 | 52 | -------------------------------------------------------------------------------- /extension/include/rf/rf_config.h: -------------------------------------------------------------------------------- 1 | /* 2 | raw os - Copyright (C) Lingjun Chen(jorya_txj). 3 | 4 | This file is part of raw os. 5 | 6 | raw os is free software; you can redistribute it it under the terms of the 7 | GNU General Public License as published by the Free Software Foundation; 8 | either version 3 of the License, or (at your option) any later version. 9 | 10 | raw os is distributed in the hope that it will be useful, but WITHOUT ANY WARRANTY; 11 | without even the implied warranty of MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. 12 | See the GNU General Public License for more details. 13 | 14 | You should have received a copy of the GNU Lesser General Public License 15 | along with this program. if not, write email to jorya.txj@gmail.com 16 | --- 17 | 18 | A special exception to the LGPL can be applied should you wish to distribute 19 | a combined work that includes raw os, without being obliged to provide 20 | the source code for any proprietary components. See the file exception.txt 21 | for full details of how and when the exception can be applied. 22 | */ 23 | 24 | 25 | /* 2012-9 Created by jorya_txj 26 | * xxxxxx please added here 27 | */ 28 | 29 | 30 | #ifndef RF_CONFIG_H 31 | 32 | #define RF_CONFIG_H 33 | 34 | #define ACTIVE_MAX_BROADCAST_SIGNAL 10 35 | 36 | #endif 37 | 38 | -------------------------------------------------------------------------------- /extension/include/rsh.h: -------------------------------------------------------------------------------- 1 | /* 2 | raw os - Copyright (C) Lingjun Chen(jorya_txj). 3 | 4 | This file is part of raw os. 5 | 6 | raw os is free software; you can redistribute it it under the terms of the 7 | GNU General Public License as published by the Free Software Foundation; 8 | either version 3 of the License, or (at your option) any later version. 9 | 10 | raw os is distributed in the hope that it will be useful, but WITHOUT ANY WARRANTY; 11 | without even the implied warranty of MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. 12 | See the GNU General Public License for more details. 13 | 14 | You should have received a copy of the GNU Lesser General Public License 15 | along with this program. if not, write email to jorya.txj@gmail.com 16 | --- 17 | 18 | A special exception to the LGPL can be applied should you wish to distribute 19 | a combined work that includes raw os, without being obliged to provide 20 | the source code for any proprietary components. See the file exception.txt 21 | for full details of how and when the exception can be applied. 22 | */ 23 | 24 | 25 | /* 2012-8 Created by jorya_txj 26 | * xxxxxx please added here 27 | */ 28 | 29 | 30 | #ifndef RSH_H 31 | #define RSH_H 32 | 33 | #define configCOMMAND_INT_MAX_OUTPUT_SIZE 4096 34 | 35 | /* The prototype to which callback functions used to process command line 36 | commands must comply. pcWriteBuffer is a buffer into which the output from 37 | executing the command can be written, xWriteBufferLen is the length, in bytes of 38 | the pcWriteBuffer buffer, and pcCommandString is the entire string as input by 39 | the user (from which parameters can be extracted).*/ 40 | typedef RAW_S32 (*pdCOMMAND_LINE_CALLBACK)( RAW_S8 *pcWriteBuffer, RAW_U32 xWriteBufferLen, const RAW_S8 * pcCommandString ); 41 | 42 | /* The structure that defines command line commands. A command line command 43 | should be defined by declaring a const structure of this type. */ 44 | typedef struct xCOMMAND_LINE_INPUT 45 | { 46 | const RAW_S8 * const pcCommand; /* The command that causes pxCommandInterpreter to be executed. For example "help". Must be all lower case. */ 47 | const RAW_S8 * const pcHelpString; /* String that describes how to use the command. Should start with the command itself, and end with "\r\n". For example "help: Returns a list of all the commands\r\n". */ 48 | const pdCOMMAND_LINE_CALLBACK pxCommandInterpreter; /* A pointer to the callback function that will return the output generated by the command. */ 49 | RAW_S8 cExpectedNumberOfParameters; /* Commands expect a fixed number of parameters, which may be zero. */ 50 | } xCommandLineInput; 51 | 52 | 53 | typedef struct xCOMMAND_INPUT_LIST 54 | { 55 | const xCommandLineInput *pxCommandLineDefinition; 56 | struct xCOMMAND_INPUT_LIST *pxNext; 57 | } xCommandLineInputListItem; 58 | 59 | 60 | /* 61 | * Register the command passed in using the pxCommandToRegister parameter. 62 | * Registering a command adds the command to the list of commands that are 63 | * handled by the command interpreter. Once a command has been registered it 64 | * can be executed from the command line. 65 | */ 66 | void rsh_register_command(const xCommandLineInput * const pxCommandToRegister, xCommandLineInputListItem *pxNewListItem); 67 | 68 | /* 69 | * Runs the command interpreter for the command string "pcCommandInput". Any 70 | * output generated by running the command will be placed into pcWriteBuffer. 71 | * xWriteBufferLen must indicate the size, in bytes, of the buffer pointed to 72 | * by pcWriteBuffer. 73 | * 74 | * rsh_process_command should be called repeatedly until it returns pdFALSE. 75 | * 76 | * pcCmdIntProcessCommand is not reentrant. It must not be called from more 77 | * than one task - or at least - by more than one task at a time. 78 | */ 79 | RAW_S32 rsh_process_command( const RAW_S8 * const pcCommandInput, RAW_S8 * pcWriteBuffer, RAW_U32 xWriteBufferLen ); 80 | 81 | /*-----------------------------------------------------------*/ 82 | 83 | 84 | /* 85 | * Return a pointer to the xParameterNumber'th word in pcCommandString. 86 | */ 87 | const RAW_S8 *rsh_get_parameter( const RAW_S8 *pcCommandString, RAW_S32 uxWantedParameter, RAW_S32 *pxParameterStringLength ); 88 | 89 | #endif /* COMMAND_INTERPRETER_H */ 90 | 91 | 92 | 93 | -------------------------------------------------------------------------------- /extension/include/simple_printf.h: -------------------------------------------------------------------------------- 1 | /* 2 | raw os - Copyright (C) Lingjun Chen(jorya_txj). 3 | 4 | This file is part of raw os. 5 | 6 | raw os is free software; you can redistribute it it under the terms of the 7 | GNU General Public License as published by the Free Software Foundation; 8 | either version 3 of the License, or (at your option) any later version. 9 | 10 | raw os is distributed in the hope that it will be useful, but WITHOUT ANY WARRANTY; 11 | without even the implied warranty of MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. 12 | See the GNU General Public License for more details. 13 | 14 | You should have received a copy of the GNU Lesser General Public License 15 | along with this program. if not, write email to jorya.txj@gmail.com 16 | --- 17 | 18 | A special exception to the LGPL can be applied should you wish to distribute 19 | a combined work that includes raw os, without being obliged to provide 20 | the source code for any proprietary components. See the file exception.txt 21 | for full details of how and when the exception can be applied. 22 | */ 23 | 24 | 25 | /* 2014-1 Created by jorya_txj 26 | * xxxxxx please added here 27 | */ 28 | 29 | 30 | 31 | #ifndef SIMPLE_PRINTF_H 32 | #define SIMPLE_PRINTF_H 33 | 34 | void simple_printf_lock(void); 35 | void simple_printf_unlock(void); 36 | 37 | int raw_printf(const char *format, ...); 38 | int raw_sprintf(char *out, const char *format, ...); 39 | int raw_snprintf( char *buf, unsigned int count, const char *format, ... ); 40 | 41 | void user_put_char(unsigned char c); 42 | 43 | void raw_printf_init(void); 44 | 45 | #endif 46 | 47 | 48 | 49 | 50 | -------------------------------------------------------------------------------- /extension/lib/fifo.c: -------------------------------------------------------------------------------- 1 | #include 2 | #include 3 | 4 | 5 | /* 6 | * internal helper to calculate the unused elements in a fifo 7 | */ 8 | static RAW_U32 fifo_unused(struct raw_fifo *fifo) 9 | { 10 | return (fifo->mask + 1) - (fifo->in - fifo->out); 11 | } 12 | 13 | 14 | 15 | static RAW_S8 is_power_of_2(RAW_U32 n) 16 | { 17 | return (n != 0 && ((n & (n - 1)) == 0)); 18 | } 19 | 20 | 21 | /*static fifio alloc do not need raw_malloc*/ 22 | 23 | RAW_S8 fifo_init(struct raw_fifo *fifo, void *buffer, RAW_U32 size) 24 | { 25 | /* 26 | * round down to the next power of 2, since our 'let the indices 27 | * wrap' technique works only in this case. 28 | */ 29 | if (!is_power_of_2(size)) { 30 | 31 | RAW_ASSERT(0); 32 | } 33 | 34 | fifo->in = 0; 35 | fifo->out = 0; 36 | fifo->data = buffer; 37 | 38 | if (size < 2) { 39 | fifo->mask = 0; 40 | return 1; 41 | } 42 | 43 | fifo->mask = size - 1; 44 | fifo->free_bytes = size; 45 | fifo->size = size; 46 | 47 | return 0; 48 | } 49 | 50 | 51 | static void fifo_copy_in(struct raw_fifo *fifo, const void *src, 52 | RAW_U32 len, RAW_U32 off) 53 | { 54 | RAW_U32 l; 55 | 56 | RAW_U32 size = fifo->mask + 1; 57 | 58 | off &= fifo->mask; 59 | 60 | l = fifo_min(len, size - off); 61 | 62 | raw_memcpy((unsigned char *)fifo->data + off, src, l); 63 | raw_memcpy(fifo->data, (unsigned char *)src + l, len - l); 64 | 65 | 66 | } 67 | 68 | /*fifo write in*/ 69 | RAW_U32 fifo_in(struct raw_fifo *fifo, 70 | const void *buf, RAW_U32 len) 71 | { 72 | RAW_U32 l; 73 | 74 | RAW_SR_ALLOC(); 75 | 76 | RAW_CPU_DISABLE(); 77 | 78 | l = fifo_unused(fifo); 79 | if (len > l) 80 | len = l; 81 | 82 | fifo_copy_in(fifo, buf, len, fifo->in); 83 | fifo->in += len; 84 | 85 | fifo->free_bytes -= len; 86 | 87 | RAW_CPU_ENABLE(); 88 | return len; 89 | } 90 | 91 | static void kfifo_copy_out(struct raw_fifo *fifo, void *dst, 92 | RAW_U32 len, RAW_U32 off) 93 | { 94 | RAW_U32 l; 95 | RAW_U32 size = fifo->mask + 1; 96 | 97 | off &= fifo->mask; 98 | 99 | l = fifo_min(len, size - off); 100 | 101 | raw_memcpy(dst, (unsigned char *)fifo->data + off, l); 102 | raw_memcpy((unsigned char *)dst + l, fifo->data, len - l); 103 | 104 | } 105 | 106 | static RAW_U32 internal_fifo_out_peek(struct raw_fifo *fifo, 107 | void *buf, RAW_U32 len) 108 | { 109 | RAW_U32 l; 110 | 111 | l = fifo->in - fifo->out; 112 | if (len > l) 113 | len = l; 114 | 115 | kfifo_copy_out(fifo, buf, len, fifo->out); 116 | return len; 117 | } 118 | 119 | /*fifo read out but data remain in fifo*/ 120 | 121 | RAW_U32 fifo_out_peek(struct raw_fifo *fifo, 122 | void *buf, RAW_U32 len) 123 | { 124 | 125 | RAW_U32 ret_len; 126 | 127 | RAW_SR_ALLOC(); 128 | 129 | RAW_CPU_DISABLE(); 130 | 131 | ret_len = internal_fifo_out_peek(fifo, buf, len); 132 | 133 | RAW_CPU_ENABLE(); 134 | 135 | return ret_len; 136 | 137 | } 138 | 139 | /*fifo read out*/ 140 | 141 | RAW_U32 fifo_out(struct raw_fifo *fifo, void *buf, RAW_U32 len) 142 | { 143 | RAW_SR_ALLOC(); 144 | 145 | RAW_CPU_DISABLE(); 146 | 147 | len = internal_fifo_out_peek(fifo, buf, len); 148 | fifo->out += len; 149 | 150 | fifo->free_bytes += len; 151 | 152 | RAW_CPU_ENABLE(); 153 | 154 | return len; 155 | } 156 | 157 | /*fifo read out all*/ 158 | 159 | RAW_U32 fifo_out_all(struct raw_fifo *fifo, void *buf) 160 | { 161 | RAW_U32 len; 162 | 163 | RAW_SR_ALLOC(); 164 | 165 | RAW_CPU_DISABLE(); 166 | 167 | len = fifo->size - fifo->free_bytes; 168 | 169 | if (len == 0) { 170 | 171 | RAW_CPU_ENABLE(); 172 | return 0; 173 | } 174 | 175 | len = internal_fifo_out_peek(fifo, buf, len); 176 | fifo->out += len; 177 | 178 | fifo->free_bytes += len; 179 | 180 | RAW_CPU_ENABLE(); 181 | 182 | return len; 183 | 184 | } 185 | 186 | -------------------------------------------------------------------------------- /extension/lib/fifo_lock.c: -------------------------------------------------------------------------------- 1 | #include 2 | #include 3 | 4 | 5 | /* 6 | * internal helper to calculate the unused elements in a fifo 7 | */ 8 | static RAW_U32 fifo_unused(struct raw_fifo_lock *fifo) 9 | { 10 | return (fifo->mask + 1) - (fifo->in - fifo->out); 11 | } 12 | 13 | 14 | 15 | static RAW_S8 is_power_of_2(RAW_U32 n) 16 | { 17 | return (n != 0 && ((n & (n - 1)) == 0)); 18 | } 19 | 20 | 21 | /*static fifio alloc do not need raw_malloc*/ 22 | 23 | RAW_S8 fifo_lock_init(struct raw_fifo_lock *fifo, void *buffer, RAW_U32 size) 24 | { 25 | /* 26 | * round down to the next power of 2, since our 'let the indices 27 | * wrap' technique works only in this case. 28 | */ 29 | if (!is_power_of_2(size)) { 30 | 31 | RAW_ASSERT(0); 32 | } 33 | 34 | fifo->in = 0; 35 | fifo->out = 0; 36 | fifo->data = buffer; 37 | 38 | if (size < 2) { 39 | fifo->mask = 0; 40 | return 1; 41 | } 42 | 43 | fifo->mask = size - 1; 44 | fifo->free_bytes = size; 45 | fifo->size = size; 46 | 47 | return 0; 48 | } 49 | 50 | 51 | static void fifo_copy_in(struct raw_fifo_lock *fifo, const void *src, 52 | RAW_U32 len, RAW_U32 off) 53 | { 54 | RAW_U32 l; 55 | 56 | RAW_U32 size = fifo->mask + 1; 57 | 58 | off &= fifo->mask; 59 | 60 | l = fifo_lock_min(len, size - off); 61 | 62 | raw_memcpy((unsigned char *)fifo->data + off, src, l); 63 | raw_memcpy(fifo->data, (unsigned char *)src + l, len - l); 64 | 65 | 66 | } 67 | 68 | /*fifo write in*/ 69 | RAW_U32 fifo_lock_in(struct raw_fifo_lock *fifo, 70 | const void *buf, RAW_U32 len, void (*user_lock)(void), void (*user_unlock)(void)) 71 | { 72 | RAW_U32 l; 73 | 74 | user_lock(); 75 | 76 | l = fifo_unused(fifo); 77 | if (len > l) 78 | len = l; 79 | 80 | fifo_copy_in(fifo, buf, len, fifo->in); 81 | fifo->in += len; 82 | 83 | fifo->free_bytes -= len; 84 | 85 | user_unlock(); 86 | 87 | return len; 88 | } 89 | 90 | static void kfifo_copy_out(struct raw_fifo_lock *fifo, void *dst, 91 | RAW_U32 len, RAW_U32 off) 92 | { 93 | RAW_U32 l; 94 | RAW_U32 size = fifo->mask + 1; 95 | 96 | off &= fifo->mask; 97 | 98 | l = fifo_lock_min(len, size - off); 99 | 100 | raw_memcpy(dst, (unsigned char *)fifo->data + off, l); 101 | raw_memcpy((unsigned char *)dst + l, fifo->data, len - l); 102 | 103 | } 104 | 105 | static RAW_U32 internal_fifo_out_peek(struct raw_fifo_lock *fifo, 106 | void *buf, RAW_U32 len) 107 | { 108 | RAW_U32 l; 109 | 110 | l = fifo->in - fifo->out; 111 | if (len > l) 112 | len = l; 113 | 114 | kfifo_copy_out(fifo, buf, len, fifo->out); 115 | return len; 116 | } 117 | 118 | /*fifo read out but data remain in fifo*/ 119 | 120 | RAW_U32 fifo_lock_out_peek(struct raw_fifo_lock *fifo, 121 | void *buf, RAW_U32 len, void (*user_lock)(void), void (*user_unlock)(void)) 122 | { 123 | 124 | RAW_U32 ret_len; 125 | 126 | user_lock(); 127 | 128 | ret_len = internal_fifo_out_peek(fifo, buf, len); 129 | 130 | user_unlock(); 131 | 132 | return ret_len; 133 | 134 | } 135 | 136 | /*fifo read out*/ 137 | 138 | RAW_U32 fifo_lock_out(struct raw_fifo_lock *fifo, void *buf, RAW_U32 len, void (*user_lock)(void), void (*user_unlock)(void)) 139 | { 140 | user_lock(); 141 | 142 | len = internal_fifo_out_peek(fifo, buf, len); 143 | fifo->out += len; 144 | 145 | fifo->free_bytes += len; 146 | 147 | user_unlock(); 148 | 149 | return len; 150 | } 151 | 152 | /*fifo read out all*/ 153 | 154 | RAW_U32 fifo_lock_out_all(struct raw_fifo_lock *fifo, void *buf, void (*user_lock)(void), void (*user_unlock)(void)) 155 | { 156 | RAW_U32 len; 157 | 158 | user_lock(); 159 | 160 | len = fifo->size - fifo->free_bytes; 161 | 162 | if (len == 0) { 163 | 164 | user_unlock(); 165 | return 0; 166 | } 167 | 168 | len = internal_fifo_out_peek(fifo, buf, len); 169 | fifo->out += len; 170 | 171 | fifo->free_bytes += len; 172 | 173 | user_unlock(); 174 | 175 | return len; 176 | 177 | } 178 | 179 | -------------------------------------------------------------------------------- /extension/lib/raw_mlock.c: -------------------------------------------------------------------------------- 1 | /* 2 | raw os - Copyright (C) Lingjun Chen(jorya_txj). 3 | 4 | This file is part of raw os. 5 | 6 | raw os is free software; you can redistribute it it under the terms of the 7 | GNU General Public License as published by the Free Software Foundation; 8 | either version 3 of the License, or (at your option) any later version. 9 | 10 | raw os is distributed in the hope that it will be useful, but WITHOUT ANY WARRANTY; 11 | without even the implied warranty of MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. 12 | See the GNU General Public License for more details. 13 | 14 | You should have received a copy of the GNU Lesser General Public License 15 | along with this program. if not, write email to jorya.txj@gmail.com 16 | --- 17 | 18 | A special exception to the LGPL can be applied should you wish to distribute 19 | a combined work that includes raw os, without being obliged to provide 20 | the source code for any proprietary components. See the file exception.txt 21 | for full details of how and when the exception can be applied. 22 | */ 23 | 24 | 25 | /* 2012-10 Created by jorya_txj 26 | * xxxxxx please added here 27 | */ 28 | 29 | #include 30 | #include 31 | 32 | /*get mlock*/ 33 | RAW_U16 raw_mlock(RAW_MLOCK *mlock, RAW_U8 num, RAW_TICK_TYPE wait_option) 34 | { 35 | RAW_OS_ERROR ret; 36 | RAW_U32 flag; 37 | 38 | ret = raw_event_get(&mlock->event_ptr, 1 << num, RAW_AND_CLEAR, &flag, wait_option); 39 | 40 | return ret; 41 | 42 | } 43 | 44 | /* 45 | * mlock release 46 | * num Lock number 0 - 31 47 | */ 48 | RAW_U16 raw_munlock(RAW_MLOCK *mlock, RAW_U8 num) 49 | { 50 | RAW_OS_ERROR ret; 51 | 52 | ret = raw_event_set(&mlock->event_ptr, 1 << num, RAW_OR); 53 | return ret; 54 | } 55 | 56 | /* 57 | * Create multi-lock 58 | */ 59 | RAW_U16 raw_mlock_create(RAW_MLOCK *mlock, RAW_U8 *name_ptr) 60 | { 61 | RAW_OS_ERROR ret; 62 | 63 | ret = raw_event_create(&mlock->event_ptr, name_ptr, 0xffffffff); 64 | 65 | return ret; 66 | } 67 | 68 | /* 69 | * Delete multi-lock 70 | */ 71 | RAW_U16 raw_mlock_delete(RAW_MLOCK *mlock) 72 | { 73 | RAW_OS_ERROR ret; 74 | 75 | ret = raw_event_delete(&mlock->event_ptr); 76 | 77 | return ret; 78 | } 79 | 80 | -------------------------------------------------------------------------------- /extension/lib/simple_printf.c: -------------------------------------------------------------------------------- 1 | #include 2 | #include 3 | #include 4 | #include 5 | 6 | static RAW_MUTEX mutex_printf_obj; 7 | 8 | 9 | 10 | void simple_printf_lock(void) 11 | { 12 | 13 | raw_mutex_get(&mutex_printf_obj, RAW_WAIT_FOREVER); 14 | 15 | 16 | } 17 | 18 | 19 | void simple_printf_unlock(void) 20 | { 21 | 22 | raw_mutex_put(&mutex_printf_obj); 23 | 24 | } 25 | 26 | 27 | 28 | static void printchar(char **str, int c) 29 | { 30 | if (str) { 31 | **str = (char)c; 32 | ++(*str); 33 | } 34 | 35 | else { 36 | 37 | user_put_char(c); 38 | } 39 | } 40 | 41 | #define PAD_RIGHT 1 42 | #define PAD_ZERO 2 43 | 44 | static int prints(char **out, const char *string, int width, int pad) 45 | { 46 | register int pc = 0, padchar = ' '; 47 | 48 | if (width > 0) { 49 | register int len = 0; 50 | register const char *ptr; 51 | for (ptr = string; *ptr; ++ptr) ++len; 52 | if (len >= width) width = 0; 53 | else width -= len; 54 | if (pad & PAD_ZERO) padchar = '0'; 55 | } 56 | if (!(pad & PAD_RIGHT)) { 57 | for ( ; width > 0; --width) { 58 | printchar (out, padchar); 59 | ++pc; 60 | } 61 | } 62 | for ( ; *string ; ++string) { 63 | printchar (out, *string); 64 | ++pc; 65 | } 66 | for ( ; width > 0; --width) { 67 | printchar (out, padchar); 68 | ++pc; 69 | } 70 | 71 | return pc; 72 | } 73 | 74 | /* the following should be enough for 32 bit int */ 75 | #define PRINT_BUF_LEN 12 76 | 77 | static int printi(char **out, int i, int b, int sg, int width, int pad, int letbase) 78 | { 79 | char print_buf[PRINT_BUF_LEN]; 80 | register char *s; 81 | register int t, neg = 0, pc = 0; 82 | register unsigned int u = (unsigned int)i; 83 | 84 | if (i == 0) { 85 | print_buf[0] = '0'; 86 | print_buf[1] = '\0'; 87 | return prints (out, print_buf, width, pad); 88 | } 89 | 90 | if (sg && b == 10 && i < 0) { 91 | neg = 1; 92 | u = (unsigned int)-i; 93 | } 94 | 95 | s = print_buf + PRINT_BUF_LEN-1; 96 | *s = '\0'; 97 | 98 | while (u) { 99 | t = (unsigned int)u % b; 100 | if( t >= 10 ) 101 | t += letbase - '0' - 10; 102 | *--s = (char)(t + '0'); 103 | u /= b; 104 | } 105 | 106 | if (neg) { 107 | if( width && (pad & PAD_ZERO) ) { 108 | printchar (out, '-'); 109 | ++pc; 110 | --width; 111 | } 112 | else { 113 | *--s = '-'; 114 | } 115 | } 116 | 117 | return pc + prints (out, s, width, pad); 118 | } 119 | 120 | static int print( char **out, const char *format, va_list args ) 121 | { 122 | register int width, pad; 123 | register int pc = 0; 124 | char scr[2]; 125 | 126 | for (; *format != 0; ++format) { 127 | if (*format == '%') { 128 | ++format; 129 | width = pad = 0; 130 | if (*format == '\0') break; 131 | if (*format == '%') goto out; 132 | if (*format == '-') { 133 | ++format; 134 | pad = PAD_RIGHT; 135 | } 136 | while (*format == '0') { 137 | ++format; 138 | pad |= PAD_ZERO; 139 | } 140 | for ( ; *format >= '0' && *format <= '9'; ++format) { 141 | width *= 10; 142 | width += *format - '0'; 143 | } 144 | if( *format == 's' ) { 145 | register char *s = (char *)va_arg( args, int ); 146 | pc += prints (out, s?s:"(null)", width, pad); 147 | continue; 148 | } 149 | if( *format == 'd' ) { 150 | pc += printi (out, va_arg( args, int ), 10, 1, width, pad, 'a'); 151 | continue; 152 | } 153 | if( *format == 'x' ) { 154 | pc += printi (out, va_arg( args, int ), 16, 0, width, pad, 'a'); 155 | continue; 156 | } 157 | if( *format == 'X' ) { 158 | pc += printi (out, va_arg( args, int ), 16, 0, width, pad, 'A'); 159 | continue; 160 | } 161 | if( *format == 'u' ) { 162 | pc += printi (out, va_arg( args, int ), 10, 0, width, pad, 'a'); 163 | continue; 164 | } 165 | if( *format == 'c' ) { 166 | /* char are converted to int then pushed on the stack */ 167 | scr[0] = (char)va_arg( args, int ); 168 | scr[1] = '\0'; 169 | pc += prints (out, scr, width, pad); 170 | continue; 171 | } 172 | } 173 | else { 174 | out: 175 | printchar (out, *format); 176 | ++pc; 177 | } 178 | } 179 | if (out) **out = '\0'; 180 | va_end( args ); 181 | return pc; 182 | } 183 | 184 | 185 | int raw_printf(const char *format, ...) 186 | { 187 | int ret; 188 | 189 | va_list args; 190 | 191 | simple_printf_lock(); 192 | va_start( args, format ); 193 | ret = print( 0, format, args ); 194 | simple_printf_unlock(); 195 | 196 | return ret; 197 | } 198 | 199 | 200 | int raw_sprintf(char *out, const char *format, ...) 201 | { 202 | int ret; 203 | 204 | va_list args; 205 | 206 | simple_printf_lock(); 207 | va_start( args, format ); 208 | ret = print( &out, format, args ); 209 | simple_printf_unlock(); 210 | 211 | return ret; 212 | } 213 | 214 | 215 | 216 | int raw_snprintf( char *buf, unsigned int count, const char *format, ... ) 217 | { 218 | int ret; 219 | 220 | va_list args; 221 | 222 | ( void ) count; 223 | 224 | simple_printf_lock(); 225 | va_start( args, format ); 226 | ret = print( &buf, format, args ); 227 | simple_printf_unlock(); 228 | 229 | return ret; 230 | } 231 | 232 | 233 | void raw_printf_init(void) 234 | { 235 | 236 | raw_mutex_create(&mutex_printf_obj, (RAW_U8 *)"mutex_printf", RAW_MUTEX_INHERIT_POLICY, 0); 237 | 238 | } 239 | 240 | -------------------------------------------------------------------------------- /extension/mm/heap_3.c: -------------------------------------------------------------------------------- 1 | /* 2 | FreeRTOS V7.6.0 - Copyright (C) 2013 Real Time Engineers Ltd. 3 | All rights reserved 4 | 5 | VISIT http://www.FreeRTOS.org TO ENSURE YOU ARE USING THE LATEST VERSION. 6 | 7 | *************************************************************************** 8 | * * 9 | * FreeRTOS provides completely free yet professionally developed, * 10 | * robust, strictly quality controlled, supported, and cross * 11 | * platform software that has become a de facto standard. * 12 | * * 13 | * Help yourself get started quickly and support the FreeRTOS * 14 | * project by purchasing a FreeRTOS tutorial book, reference * 15 | * manual, or both from: http://www.FreeRTOS.org/Documentation * 16 | * * 17 | * Thank you! * 18 | * * 19 | *************************************************************************** 20 | 21 | This file is part of the FreeRTOS distribution. 22 | 23 | FreeRTOS is free software; you can redistribute it and/or modify it under 24 | the terms of the GNU General Public License (version 2) as published by the 25 | Free Software Foundation >>!AND MODIFIED BY!<< the FreeRTOS exception. 26 | 27 | >>! NOTE: The modification to the GPL is included to allow you to distribute 28 | >>! a combined work that includes FreeRTOS without being obliged to provide 29 | >>! the source code for proprietary components outside of the FreeRTOS 30 | >>! kernel. 31 | 32 | FreeRTOS is distributed in the hope that it will be useful, but WITHOUT ANY 33 | WARRANTY; without even the implied warranty of MERCHANTABILITY or FITNESS 34 | FOR A PARTICULAR PURPOSE. Full license text is available from the following 35 | link: http://www.freertos.org/a00114.html 36 | 37 | 1 tab == 4 spaces! 38 | 39 | *************************************************************************** 40 | * * 41 | * Having a problem? Start by reading the FAQ "My application does * 42 | * not run, what could be wrong?" * 43 | * * 44 | * http://www.FreeRTOS.org/FAQHelp.html * 45 | * * 46 | *************************************************************************** 47 | 48 | http://www.FreeRTOS.org - Documentation, books, training, latest versions, 49 | license and Real Time Engineers Ltd. contact details. 50 | 51 | http://www.FreeRTOS.org/plus - A selection of FreeRTOS ecosystem products, 52 | including FreeRTOS+Trace - an indispensable productivity tool, a DOS 53 | compatible FAT file system, and our tiny thread aware UDP/IP stack. 54 | 55 | http://www.OpenRTOS.com - Real Time Engineers ltd license FreeRTOS to High 56 | Integrity Systems to sell under the OpenRTOS brand. Low cost OpenRTOS 57 | licenses offer ticketed support, indemnification and middleware. 58 | 59 | http://www.SafeRTOS.com - High Integrity Systems also provide a safety 60 | engineered and independently SIL3 certified version for use in safety and 61 | mission critical applications that require provable dependability. 62 | 63 | 1 tab == 4 spaces! 64 | */ 65 | 66 | 67 | 68 | /* 69 | * The simplest possible implementation of pvPortMalloc(). Note that this 70 | * implementation does NOT allow allocated memory to be freed again. 71 | * 72 | * See heap_2.c and heap_3.c for alternative implementations, and the memory 73 | * management pages of http://www.FreeRTOS.org for more information. 74 | */ 75 | 76 | #include 77 | #include 78 | #include 79 | 80 | 81 | /*-----------------------------------------------------------*/ 82 | 83 | void *mem_3_malloc(size_t xWantedSize) 84 | { 85 | void *pvReturn; 86 | 87 | raw_disable_sche(); 88 | { 89 | pvReturn = malloc(xWantedSize); 90 | 91 | } 92 | 93 | raw_enable_sche(); 94 | 95 | return pvReturn; 96 | } 97 | /*-----------------------------------------------------------*/ 98 | 99 | void mem_3_free(void *pv) 100 | { 101 | if (pv) { 102 | 103 | raw_disable_sche(); 104 | { 105 | free(pv); 106 | 107 | } 108 | 109 | raw_enable_sche(); 110 | } 111 | } 112 | 113 | 114 | -------------------------------------------------------------------------------- /extension/posix/pthread.c: -------------------------------------------------------------------------------- 1 | /* 2 | raw os - Copyright (C) Lingjun Chen(jorya_txj). 3 | 4 | This file is part of raw os. 5 | 6 | raw os is free software; you can redistribute it it under the terms of the 7 | GNU General Public License as published by the Free Software Foundation; 8 | either version 3 of the License, or (at your option) any later version. 9 | 10 | raw os is distributed in the hope that it will be useful, but WITHOUT ANY WARRANTY; 11 | without even the implied warranty of MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. 12 | See the GNU General Public License for more details. 13 | 14 | You should have received a copy of the GNU Lesser General Public License 15 | along with this program. if not, write email to jorya.txj@gmail.com 16 | --- 17 | 18 | A special exception to the LGPL can be applied should you wish to distribute 19 | a combined work that includes raw os, without being obliged to provide 20 | the source code for any proprietary components. See the file exception.txt 21 | for full details of how and when the exception can be applied. 22 | */ 23 | 24 | 25 | /* 2012-8 Created by jorya_txj 26 | * xxxxxx please added here 27 | */ 28 | 29 | 30 | #include 31 | #include 32 | #include 33 | #include 34 | #include 35 | 36 | 37 | #define DEFAULT_STACK_ELEMENT (10 * 1024) 38 | 39 | int pthread_create(pthread_t *thread, const pthread_attr_t *attr, void * (*start_routine)(void *), void *arg) 40 | { 41 | pthread_struct *thread_struct; 42 | void *stack_base; 43 | 44 | attr = attr; 45 | thread_struct = raw_malloc(sizeof(pthread_struct)); 46 | stack_base = raw_malloc(4 * DEFAULT_STACK_ELEMENT); 47 | 48 | *thread = thread_struct; 49 | 50 | raw_task_create(&thread_struct->task_obj, (RAW_U8 *)"task1", arg, 51 | 30, 0, stack_base, DEFAULT_STACK_ELEMENT, (RAW_TASK_ENTRY)start_routine, RAW_TASK_AUTO_START); 52 | 53 | raw_semaphore_create(&thread_struct->task_sem, "sem", 0); 54 | thread_struct->task_sem.common_block_obj.block_way = RAW_BLOCKED_WAY_FIFO; 55 | return 0; 56 | } 57 | 58 | 59 | 60 | int pthread_detach(pthread_t thread) 61 | { 62 | RAW_TASK_OBJ *task; 63 | task = &thread->task_obj; 64 | 65 | if (task->task_state == RAW_DELETED) { 66 | 67 | 68 | } 69 | 70 | else { 71 | 72 | RAW_CRITICAL_ENTER(); 73 | thread->attr.detachstate = PTHREAD_CREATE_DETACHED; 74 | RAW_CRITICAL_EXIT(); 75 | 76 | raw_semaphore_delete(&thread->task_sem); 77 | 78 | } 79 | 80 | return 0; 81 | } 82 | 83 | 84 | 85 | int pthread_join(pthread_t thread, void **thread_return) 86 | { 87 | RAW_TASK_OBJ *task; 88 | RAW_U16 ret; 89 | 90 | task = &thread->task_obj; 91 | 92 | 93 | if (task == raw_task_identify()) { 94 | 95 | return EDEADLK; 96 | } 97 | 98 | 99 | 100 | ret = raw_semaphore_get(&thread->task_sem, RAW_WAIT_FOREVER); 101 | 102 | if (ret == RAW_SUCCESS) { 103 | raw_task_delete(task); 104 | *thread_return = thread->ret; 105 | } 106 | 107 | else { 108 | 109 | return ESRCH; 110 | } 111 | 112 | return 0; 113 | } 114 | 115 | 116 | 117 | 118 | void pthread_exit(void *value) 119 | { 120 | RAW_TASK_OBJ *task; 121 | pthread_t thread; 122 | 123 | task = raw_task_identify(); 124 | thread = (pthread_t)task; 125 | 126 | if (thread->attr.detachstate == PTHREAD_CREATE_JOINABLE) { 127 | 128 | /* release the joinable pthread */ 129 | raw_semaphore_put(&thread->task_sem); 130 | return; 131 | } 132 | 133 | raw_task_delete(task); 134 | raw_semaphore_delete(&thread->task_sem); 135 | 136 | } 137 | 138 | 139 | -------------------------------------------------------------------------------- /extension/posix/pthread_cond.c: -------------------------------------------------------------------------------- 1 | /* 2 | raw os - Copyright (C) Lingjun Chen(jorya_txj). 3 | 4 | This file is part of raw os. 5 | 6 | raw os is free software; you can redistribute it it under the terms of the 7 | GNU General Public License as published by the Free Software Foundation; 8 | either version 3 of the License, or (at your option) any later version. 9 | 10 | raw os is distributed in the hope that it will be useful, but WITHOUT ANY WARRANTY; 11 | without even the implied warranty of MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. 12 | See the GNU General Public License for more details. 13 | 14 | You should have received a copy of the GNU Lesser General Public License 15 | along with this program. if not, write email to jorya.txj@gmail.com 16 | --- 17 | 18 | A special exception to the LGPL can be applied should you wish to distribute 19 | a combined work that includes raw os, without being obliged to provide 20 | the source code for any proprietary components. See the file exception.txt 21 | for full details of how and when the exception can be applied. 22 | */ 23 | 24 | 25 | /* 2012-8 Created by jorya_txj 26 | * xxxxxx please added here 27 | */ 28 | 29 | 30 | #include 31 | #include 32 | #include 33 | 34 | 35 | 36 | 37 | int pthread_cond_init(pthread_cond_t *cond, const pthread_condattr_t *attr) 38 | { 39 | RAW_U16 ret; 40 | attr = attr; 41 | 42 | ret = raw_semaphore_create(&cond->sem_lock,"cond", 0); 43 | 44 | if (ret != RAW_SUCCESS) { 45 | 46 | return EINVAL; 47 | } 48 | 49 | cond->attr = -1; 50 | return 0; 51 | } 52 | 53 | 54 | int pthread_cond_wait(pthread_cond_t *cond, pthread_mutex_t *mutex) 55 | { 56 | 57 | if (cond->attr != -1) { 58 | 59 | return EINVAL; 60 | 61 | } 62 | 63 | if (raw_task_active != mutex->mutex_lock.mtxtsk) { 64 | 65 | return EINVAL; 66 | } 67 | 68 | 69 | if (raw_mutex_put(&mutex->mutex_lock) != RAW_SUCCESS) { 70 | 71 | return EINVAL; 72 | } 73 | 74 | 75 | raw_semaphore_get(&cond->sem_lock, RAW_WAIT_FOREVER); 76 | 77 | 78 | raw_mutex_get(&mutex->mutex_lock, RAW_WAIT_FOREVER); 79 | 80 | 81 | return 0; 82 | 83 | } 84 | 85 | 86 | 87 | int pthread_cond_destroy(pthread_cond_t *cond) 88 | { 89 | 90 | 91 | RAW_U16 ret; 92 | 93 | if (cond->attr != -1) { 94 | 95 | return EINVAL; 96 | 97 | } 98 | 99 | cond->attr = 0; 100 | 101 | ret = raw_semaphore_delete(&cond->sem_lock); 102 | 103 | if (ret != RAW_SUCCESS) { 104 | return EBUSY; 105 | } 106 | 107 | 108 | return 0; 109 | 110 | } 111 | 112 | 113 | int pthread_cond_broadcast(pthread_cond_t *cond) 114 | { 115 | 116 | if (cond->attr != -1) { 117 | 118 | return EINVAL; 119 | 120 | } 121 | 122 | if (raw_semaphore_put_all(&cond->sem_lock) != RAW_SUCCESS) { 123 | 124 | return EINVAL; 125 | } 126 | 127 | return 0; 128 | } 129 | 130 | 131 | int pthread_cond_signal(pthread_cond_t *cond) 132 | { 133 | if (cond->attr != -1) { 134 | 135 | return EINVAL; 136 | 137 | } 138 | 139 | if (raw_semaphore_put(&cond->sem_lock) != RAW_SUCCESS) { 140 | 141 | return EINVAL; 142 | } 143 | 144 | return 0; 145 | } 146 | 147 | 148 | 149 | int pthread_cond_timedwait(pthread_cond_t *cond, pthread_mutex_t * mutex, const struct timespec *abstime) 150 | { 151 | 152 | RAW_U16 ret; 153 | RAW_U32 ticks; 154 | 155 | if (cond->attr != -1) { 156 | 157 | return EINVAL; 158 | 159 | } 160 | 161 | 162 | if (raw_task_active != mutex->mutex_lock.mtxtsk) { 163 | 164 | return EINVAL; 165 | } 166 | 167 | 168 | if (raw_mutex_put(&mutex->mutex_lock) != RAW_SUCCESS) { 169 | 170 | return EINVAL; 171 | } 172 | 173 | ticks = calculate_ticks(abstime); 174 | ret = raw_semaphore_get(&cond->sem_lock, ticks); 175 | 176 | 177 | raw_mutex_get(&mutex->mutex_lock, RAW_WAIT_FOREVER); 178 | 179 | if (ret == RAW_BLOCK_TIMEOUT) { 180 | 181 | return ETIMEDOUT; 182 | 183 | } 184 | 185 | if (ret != RAW_SUCCESS) { 186 | return EINVAL; 187 | } 188 | 189 | return 0; 190 | 191 | } 192 | 193 | 194 | -------------------------------------------------------------------------------- /extension/posix/pthread_mutex.c: -------------------------------------------------------------------------------- 1 | /* 2 | raw os - Copyright (C) Lingjun Chen(jorya_txj). 3 | 4 | This file is part of raw os. 5 | 6 | raw os is free software; you can redistribute it it under the terms of the 7 | GNU General Public License as published by the Free Software Foundation; 8 | either version 3 of the License, or (at your option) any later version. 9 | 10 | raw os is distributed in the hope that it will be useful, but WITHOUT ANY WARRANTY; 11 | without even the implied warranty of MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. 12 | See the GNU General Public License for more details. 13 | 14 | You should have received a copy of the GNU Lesser General Public License 15 | along with this program. if not, write email to jorya.txj@gmail.com 16 | --- 17 | 18 | A special exception to the LGPL can be applied should you wish to distribute 19 | a combined work that includes raw os, without being obliged to provide 20 | the source code for any proprietary components. See the file exception.txt 21 | for full details of how and when the exception can be applied. 22 | */ 23 | 24 | 25 | /* 2012-8 Created by jorya_txj 26 | * xxxxxx please added here 27 | */ 28 | 29 | 30 | #include 31 | #include 32 | #include 33 | 34 | 35 | int pthread_mutex_init(pthread_mutex_t *mutex, const pthread_mutexattr_t *attr) 36 | { 37 | RAW_U16 ret; 38 | attr = attr; 39 | 40 | ret = raw_mutex_create(&mutex->mutex_lock, (RAW_U8 *)"mutex", RAW_MUTEX_INHERIT_POLICY, 0); 41 | 42 | if (ret != RAW_SUCCESS) { 43 | 44 | return EINVAL; 45 | } 46 | 47 | 48 | return 0; 49 | } 50 | 51 | int pthread_mutex_destroy(pthread_mutex_t *mutex) 52 | { 53 | RAW_U16 ret; 54 | 55 | ret = raw_mutex_delete(&mutex->mutex_lock); 56 | 57 | if (ret != RAW_SUCCESS) { 58 | 59 | return EINVAL; 60 | } 61 | 62 | 63 | return 0; 64 | } 65 | 66 | int pthread_mutex_lock(pthread_mutex_t *mutex) 67 | { 68 | RAW_U16 ret; 69 | 70 | ret = raw_mutex_get(&mutex->mutex_lock, RAW_WAIT_FOREVER); 71 | 72 | if (ret != RAW_SUCCESS) { 73 | 74 | return EINVAL; 75 | } 76 | 77 | 78 | return 0; 79 | } 80 | 81 | int pthread_mutex_unlock(pthread_mutex_t *mutex) 82 | { 83 | RAW_U16 ret; 84 | 85 | ret = raw_mutex_put(&mutex->mutex_lock); 86 | 87 | if (ret != RAW_SUCCESS) { 88 | 89 | return EINVAL; 90 | } 91 | 92 | 93 | return 0; 94 | } 95 | 96 | int pthread_mutex_trylock(pthread_mutex_t *mutex) 97 | { 98 | RAW_U16 ret; 99 | 100 | ret = raw_mutex_get(&mutex->mutex_lock, RAW_NO_WAIT); 101 | 102 | if (ret == RAW_NO_PEND_WAIT) { 103 | return EBUSY; 104 | } 105 | 106 | if (ret != RAW_SUCCESS) { 107 | 108 | return EINVAL; 109 | } 110 | 111 | 112 | return 0; 113 | } 114 | 115 | -------------------------------------------------------------------------------- /extension/posix/pthread_rwlock.c: -------------------------------------------------------------------------------- 1 | 2 | 3 | 4 | -------------------------------------------------------------------------------- /extension/posix/semphore.c: -------------------------------------------------------------------------------- 1 | #include 2 | #include 3 | #include 4 | #include 5 | #include 6 | #include 7 | 8 | 9 | 10 | int sem_close(sem_t *sem) 11 | { 12 | 13 | 14 | return 0; 15 | } 16 | 17 | int sem_destroy(sem_t *sem) 18 | { 19 | 20 | raw_semaphore_delete(&sem->sem_posix); 21 | 22 | return 0; 23 | } 24 | 25 | int sem_unlink(const char *name) 26 | { 27 | 28 | return 0; 29 | } 30 | 31 | int sem_getvalue(sem_t *sem, int *sval) 32 | { 33 | 34 | *sval = (int)(sem->sem_posix.count); 35 | 36 | return 0; 37 | } 38 | 39 | int sem_init(sem_t *sem, int pshared, unsigned int value) 40 | { 41 | 42 | raw_semaphore_create(&sem->sem_posix ,"sem", value); 43 | return 0; 44 | } 45 | 46 | sem_t *sem_open(const char *name, int oflag, ...) 47 | { 48 | 49 | return 0; 50 | } 51 | 52 | 53 | 54 | int sem_post(sem_t *sem) 55 | { 56 | raw_semaphore_put(&sem->sem_posix); 57 | return 0; 58 | } 59 | 60 | 61 | 62 | int sem_timedwait(sem_t *sem, const struct timespec *abs_timeout) 63 | { 64 | RAW_U32 ticks; 65 | 66 | ticks = calculate_ticks(abs_timeout); 67 | raw_semaphore_get(&sem->sem_posix, ticks); 68 | return 0; 69 | } 70 | 71 | int sem_trywait(sem_t *sem) 72 | { 73 | RAW_U16 ret; 74 | 75 | ret = raw_semaphore_get(&sem->sem_posix, RAW_NO_WAIT); 76 | 77 | if (ret == RAW_NO_PEND_WAIT) { 78 | return EAGAIN; 79 | } 80 | 81 | return 0; 82 | } 83 | 84 | 85 | int sem_wait(sem_t *sem) 86 | { 87 | raw_semaphore_get(&sem->sem_posix, RAW_WAIT_FOREVER); 88 | return 0; 89 | } 90 | 91 | -------------------------------------------------------------------------------- /extension/posix/time.c: -------------------------------------------------------------------------------- 1 | /* 2 | raw os - Copyright (C) Lingjun Chen(jorya_txj). 3 | 4 | This file is part of raw os. 5 | 6 | raw os is free software; you can redistribute it it under the terms of the 7 | GNU General Public License as published by the Free Software Foundation; 8 | either version 3 of the License, or (at your option) any later version. 9 | 10 | raw os is distributed in the hope that it will be useful, but WITHOUT ANY WARRANTY; 11 | without even the implied warranty of MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. 12 | See the GNU General Public License for more details. 13 | 14 | You should have received a copy of the GNU Lesser General Public License 15 | along with this program. if not, write email to jorya.txj@gmail.com 16 | --- 17 | 18 | A special exception to the LGPL can be applied should you wish to distribute 19 | a combined work that includes raw os, without being obliged to provide 20 | the source code for any proprietary components. See the file exception.txt 21 | for full details of how and when the exception can be applied. 22 | */ 23 | 24 | 25 | /* 2012-8 Created by jorya_txj 26 | * xxxxxx please added here 27 | */ 28 | 29 | 30 | #include 31 | #include 32 | 33 | #define NANOSECOND_PER_SECOND 1000000000UL 34 | 35 | unsigned int calculate_ticks(const struct timespec *time) 36 | { 37 | unsigned int tick = 0; 38 | 39 | tick += time->tv_nsec * RAW_TICKS_PER_SECOND / NANOSECOND_PER_SECOND; 40 | tick += time->tv_sec * RAW_TICKS_PER_SECOND; 41 | 42 | return tick; 43 | } 44 | 45 | 46 | int clock_getres (clockid_t clockid, struct timespec *res) 47 | { 48 | clockid = clockid; 49 | res = res; 50 | 51 | return 0; 52 | } 53 | 54 | int clock_gettime (clockid_t clockid, struct timespec *tp) 55 | { 56 | clockid = clockid; 57 | tp->tv_sec = 0; 58 | tp->tv_nsec = 0; 59 | 60 | return 0; 61 | } 62 | 63 | int clock_settime (clockid_t clockid, const struct timespec *tp) 64 | { 65 | clockid = clockid; 66 | tp = tp; 67 | 68 | return 0; 69 | } 70 | 71 | -------------------------------------------------------------------------------- /extension/protothread/clock_port.c: -------------------------------------------------------------------------------- 1 | #include 2 | 3 | clock_time_t current_clock = 0; 4 | static volatile unsigned long current_seconds = 0; 5 | static unsigned int second_countdown = RAW_TICKS_PER_SECOND; 6 | 7 | 8 | void proto_tick_handler() 9 | { 10 | 11 | current_clock++; 12 | 13 | if(etimer_pending() && etimer_next_expiration_time() <= current_clock) { 14 | 15 | etimer_request_poll(); 16 | 17 | } 18 | 19 | if (--second_countdown == 0) { 20 | 21 | current_seconds++; 22 | second_countdown = RAW_TICKS_PER_SECOND; 23 | } 24 | } 25 | 26 | 27 | void clock_init() 28 | { 29 | 30 | } 31 | 32 | clock_time_t clock_time(void) 33 | { 34 | return current_clock; 35 | } 36 | 37 | 38 | 39 | unsigned int clock_seconds(void) 40 | { 41 | 42 | return current_seconds; 43 | 44 | } 45 | 46 | 47 | -------------------------------------------------------------------------------- /extension/protothread/stimer.c: -------------------------------------------------------------------------------- 1 | /** 2 | * \addtogroup stimer 3 | * @{ 4 | */ 5 | 6 | /** 7 | * \file 8 | * Timer of seconds library implementation. 9 | * \author 10 | * Adam Dunkels , Nicolas Tsiftes 11 | */ 12 | 13 | /* 14 | * Copyright (c) 2004, 2008, Swedish Institute of Computer Science. 15 | * All rights reserved. 16 | * 17 | * Redistribution and use in source and binary forms, with or without 18 | * modification, are permitted provided that the following conditions 19 | * are met: 20 | * 1. Redistributions of source code must retain the above copyright 21 | * notice, this list of conditions and the following disclaimer. 22 | * 2. Redistributions in binary form must reproduce the above copyright 23 | * notice, this list of conditions and the following disclaimer in the 24 | * documentation and/or other materials provided with the distribution. 25 | * 3. Neither the name of the Institute nor the names of its contributors 26 | * may be used to endorse or promote products derived from this software 27 | * without specific prior written permission. 28 | * 29 | * THIS SOFTWARE IS PROVIDED BY THE INSTITUTE AND CONTRIBUTORS ``AS IS'' AND 30 | * ANY EXPRESS OR IMPLIED WARRANTIES, INCLUDING, BUT NOT LIMITED TO, THE 31 | * IMPLIED WARRANTIES OF MERCHANTABILITY AND FITNESS FOR A PARTICULAR PURPOSE 32 | * ARE DISCLAIMED. IN NO EVENT SHALL THE INSTITUTE OR CONTRIBUTORS BE LIABLE 33 | * FOR ANY DIRECT, INDIRECT, INCIDENTAL, SPECIAL, EXEMPLARY, OR CONSEQUENTIAL 34 | * DAMAGES (INCLUDING, BUT NOT LIMITED TO, PROCUREMENT OF SUBSTITUTE GOODS 35 | * OR SERVICES; LOSS OF USE, DATA, OR PROFITS; OR BUSINESS INTERRUPTION) 36 | * HOWEVER CAUSED AND ON ANY THEORY OF LIABILITY, WHETHER IN CONTRACT, STRICT 37 | * LIABILITY, OR TORT (INCLUDING NEGLIGENCE OR OTHERWISE) ARISING IN ANY WAY 38 | * OUT OF THE USE OF THIS SOFTWARE, EVEN IF ADVISED OF THE POSSIBILITY OF 39 | * SUCH DAMAGE. 40 | * 41 | * This file is part of the Contiki operating system. 42 | * 43 | * Author: Adam Dunkels , Nicolas Tsiftes 44 | * 45 | * $Id: stimer.c,v 1.3 2010/03/15 15:53:57 joxe Exp $ 46 | */ 47 | 48 | 49 | #include 50 | 51 | #define SCLOCK_GEQ(a, b) ((unsigned long)((a) - (b)) < \ 52 | ((unsigned long)(~((unsigned long)0)) >> 1)) 53 | 54 | /*---------------------------------------------------------------------------*/ 55 | /** 56 | * Set a timer. 57 | * 58 | * This function is used to set a timer for a time sometime in the 59 | * future. The function stimer_expired() will evaluate to true after 60 | * the timer has expired. 61 | * 62 | * \param t A pointer to the timer 63 | * \param interval The interval before the timer expires. 64 | * 65 | */ 66 | void 67 | stimer_set(struct stimer *t, unsigned long interval) 68 | { 69 | t->interval = interval; 70 | t->start = clock_seconds(); 71 | } 72 | /*---------------------------------------------------------------------------*/ 73 | /** 74 | * Reset the timer with the same interval. 75 | * 76 | * This function resets the timer with the same interval that was 77 | * given to the stimer_set() function. The start point of the interval 78 | * is the exact time that the timer last expired. Therefore, this 79 | * function will cause the timer to be stable over time, unlike the 80 | * stimer_restart() function. 81 | * 82 | * \param t A pointer to the timer. 83 | * 84 | * \sa stimer_restart() 85 | */ 86 | void 87 | stimer_reset(struct stimer *t) 88 | { 89 | t->start += t->interval; 90 | } 91 | /*---------------------------------------------------------------------------*/ 92 | /** 93 | * Restart the timer from the current point in time 94 | * 95 | * This function restarts a timer with the same interval that was 96 | * given to the stimer_set() function. The timer will start at the 97 | * current time. 98 | * 99 | * \note A periodic timer will drift if this function is used to reset 100 | * it. For preioric timers, use the stimer_reset() function instead. 101 | * 102 | * \param t A pointer to the timer. 103 | * 104 | * \sa stimer_reset() 105 | */ 106 | void 107 | stimer_restart(struct stimer *t) 108 | { 109 | t->start = clock_seconds(); 110 | } 111 | /*---------------------------------------------------------------------------*/ 112 | /** 113 | * Check if a timer has expired. 114 | * 115 | * This function tests if a timer has expired and returns true or 116 | * false depending on its status. 117 | * 118 | * \param t A pointer to the timer 119 | * 120 | * \return Non-zero if the timer has expired, zero otherwise. 121 | * 122 | */ 123 | int 124 | stimer_expired(struct stimer *t) 125 | { 126 | return SCLOCK_GEQ(clock_seconds(), t->start + t->interval); 127 | } 128 | /*---------------------------------------------------------------------------*/ 129 | /** 130 | * The time until the timer expires 131 | * 132 | * This function returns the time until the timer expires. 133 | * 134 | * \param t A pointer to the timer 135 | * 136 | * \return The time until the timer expires 137 | * 138 | */ 139 | unsigned long 140 | stimer_remaining(struct stimer *t) 141 | { 142 | return t->start + t->interval - clock_seconds(); 143 | } 144 | /*---------------------------------------------------------------------------*/ 145 | /** 146 | * The time elapsed since the timer started 147 | * 148 | * This function returns the time elapsed. 149 | * 150 | * \param t A pointer to the timer 151 | * 152 | * \return The time elapsed since the last start of the timer 153 | * 154 | */ 155 | unsigned long 156 | stimer_elapsed(struct stimer *t) 157 | { 158 | return clock_seconds() - t->start; 159 | } 160 | 161 | /*---------------------------------------------------------------------------*/ 162 | 163 | /** @} */ 164 | -------------------------------------------------------------------------------- /extension/protothread/timer.c: -------------------------------------------------------------------------------- 1 | /** 2 | * \addtogroup timer 3 | * @{ 4 | */ 5 | 6 | /** 7 | * \file 8 | * Timer library implementation. 9 | * \author 10 | * Adam Dunkels 11 | */ 12 | 13 | /* 14 | * Copyright (c) 2004, Swedish Institute of Computer Science. 15 | * All rights reserved. 16 | * 17 | * Redistribution and use in source and binary forms, with or without 18 | * modification, are permitted provided that the following conditions 19 | * are met: 20 | * 1. Redistributions of source code must retain the above copyright 21 | * notice, this list of conditions and the following disclaimer. 22 | * 2. Redistributions in binary form must reproduce the above copyright 23 | * notice, this list of conditions and the following disclaimer in the 24 | * documentation and/or other materials provided with the distribution. 25 | * 3. Neither the name of the Institute nor the names of its contributors 26 | * may be used to endorse or promote products derived from this software 27 | * without specific prior written permission. 28 | * 29 | * THIS SOFTWARE IS PROVIDED BY THE INSTITUTE AND CONTRIBUTORS ``AS IS'' AND 30 | * ANY EXPRESS OR IMPLIED WARRANTIES, INCLUDING, BUT NOT LIMITED TO, THE 31 | * IMPLIED WARRANTIES OF MERCHANTABILITY AND FITNESS FOR A PARTICULAR PURPOSE 32 | * ARE DISCLAIMED. IN NO EVENT SHALL THE INSTITUTE OR CONTRIBUTORS BE LIABLE 33 | * FOR ANY DIRECT, INDIRECT, INCIDENTAL, SPECIAL, EXEMPLARY, OR CONSEQUENTIAL 34 | * DAMAGES (INCLUDING, BUT NOT LIMITED TO, PROCUREMENT OF SUBSTITUTE GOODS 35 | * OR SERVICES; LOSS OF USE, DATA, OR PROFITS; OR BUSINESS INTERRUPTION) 36 | * HOWEVER CAUSED AND ON ANY THEORY OF LIABILITY, WHETHER IN CONTRACT, STRICT 37 | * LIABILITY, OR TORT (INCLUDING NEGLIGENCE OR OTHERWISE) ARISING IN ANY WAY 38 | * OUT OF THE USE OF THIS SOFTWARE, EVEN IF ADVISED OF THE POSSIBILITY OF 39 | * SUCH DAMAGE. 40 | * 41 | * This file is part of the Contiki operating system. 42 | * 43 | * Author: Adam Dunkels 44 | * 45 | * $Id: timer.c,v 1.8 2010/06/21 19:07:24 joxe Exp $ 46 | */ 47 | 48 | #include 49 | 50 | 51 | /*---------------------------------------------------------------------------*/ 52 | /** 53 | * Set a timer. 54 | * 55 | * This function is used to set a timer for a time sometime in the 56 | * future. The function timer_expired() will evaluate to true after 57 | * the timer has expired. 58 | * 59 | * \param t A pointer to the timer 60 | * \param interval The interval before the timer expires. 61 | * 62 | */ 63 | void 64 | timer_set(struct timer *t, clock_time_t interval) 65 | { 66 | t->interval = interval; 67 | t->start = clock_time(); 68 | } 69 | /*---------------------------------------------------------------------------*/ 70 | /** 71 | * Reset the timer with the same interval. 72 | * 73 | * This function resets the timer with the same interval that was 74 | * given to the timer_set() function. The start point of the interval 75 | * is the exact time that the timer last expired. Therefore, this 76 | * function will cause the timer to be stable over time, unlike the 77 | * timer_restart() function. 78 | * 79 | * \param t A pointer to the timer. 80 | * 81 | * \sa timer_restart() 82 | */ 83 | void 84 | timer_reset(struct timer *t) 85 | { 86 | t->start += t->interval; 87 | } 88 | /*---------------------------------------------------------------------------*/ 89 | /** 90 | * Restart the timer from the current point in time 91 | * 92 | * This function restarts a timer with the same interval that was 93 | * given to the timer_set() function. The timer will start at the 94 | * current time. 95 | * 96 | * \note A periodic timer will drift if this function is used to reset 97 | * it. For preioric timers, use the timer_reset() function instead. 98 | * 99 | * \param t A pointer to the timer. 100 | * 101 | * \sa timer_reset() 102 | */ 103 | void 104 | timer_restart(struct timer *t) 105 | { 106 | t->start = clock_time(); 107 | } 108 | /*---------------------------------------------------------------------------*/ 109 | /** 110 | * Check if a timer has expired. 111 | * 112 | * This function tests if a timer has expired and returns true or 113 | * false depending on its status. 114 | * 115 | * \param t A pointer to the timer 116 | * 117 | * \return Non-zero if the timer has expired, zero otherwise. 118 | * 119 | */ 120 | int 121 | timer_expired(struct timer *t) 122 | { 123 | /* Note: Can not return diff >= t->interval so we add 1 to diff and return 124 | t->interval < diff - required to avoid an internal error in mspgcc. */ 125 | clock_time_t diff = (clock_time() - t->start) + 1; 126 | return t->interval < diff; 127 | 128 | } 129 | /*---------------------------------------------------------------------------*/ 130 | /** 131 | * The time until the timer expires 132 | * 133 | * This function returns the time until the timer expires. 134 | * 135 | * \param t A pointer to the timer 136 | * 137 | * \return The time until the timer expires 138 | * 139 | */ 140 | clock_time_t 141 | timer_remaining(struct timer *t) 142 | { 143 | return t->start + t->interval - clock_time(); 144 | } 145 | /*---------------------------------------------------------------------------*/ 146 | 147 | /** @} */ 148 | -------------------------------------------------------------------------------- /extension/rf/active_memory.c: -------------------------------------------------------------------------------- 1 | /* 2 | raw os - Copyright (C) Lingjun Chen(jorya_txj). 3 | 4 | This file is part of raw os. 5 | 6 | raw os is free software; you can redistribute it it under the terms of the 7 | GNU General Public License as published by the Free Software Foundation; 8 | either version 3 of the License, or (at your option) any later version. 9 | 10 | raw os is distributed in the hope that it will be useful, but WITHOUT ANY WARRANTY; 11 | without even the implied warranty of MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. 12 | See the GNU General Public License for more details. 13 | 14 | You should have received a copy of the GNU Lesser General Public License 15 | along with this program. if not, write email to jorya.txj@gmail.com 16 | --- 17 | 18 | A special exception to the LGPL can be applied should you wish to distribute 19 | a combined work that includes raw os, without being obliged to provide 20 | the source code for any proprietary components. See the file exception.txt 21 | for full details of how and when the exception can be applied. 22 | */ 23 | 24 | 25 | /* 2012-9 Created by jorya_txj 26 | * xxxxxx please added here 27 | */ 28 | 29 | 30 | #include 31 | #include 32 | #include 33 | #include 34 | #include 35 | #include 36 | 37 | 38 | /* 39 | ************************************************************************************************************************ 40 | * Allocate an event from pool 41 | * 42 | * Description: This function is called to allocate an event block from pool 43 | * 44 | * Arguments :pool is the address of memory block pool 45 | * --------- 46 | * sig is the event sig 47 | * 48 | * Returns 49 | * 50 | * Note(s) 51 | * 52 | * 53 | ************************************************************************************************************************ 54 | */ 55 | void *active_event_memory_allocate(MEM_POOL *pool, RAW_U16 sig) 56 | { 57 | 58 | STATE_EVENT *event; 59 | RAW_OS_ERROR ret; 60 | 61 | ret = raw_block_allocate(pool, (void **)&event); 62 | 63 | if (ret != RAW_SUCCESS) { 64 | 65 | RAW_ASSERT(0); 66 | 67 | } 68 | 69 | event->sig = sig; 70 | event->which_pool = pool; 71 | event->ref_count = 0; 72 | 73 | return (void *)event; 74 | 75 | } 76 | 77 | 78 | 79 | /* 80 | ************************************************************************************************************************ 81 | * Collect an event from pool 82 | * 83 | * Description: This function is Collect an event from pool 84 | * 85 | * Arguments :event is the event whichto be collected. 86 | * --------- 87 | * 88 | * 89 | * Returns 90 | * 91 | * Note(s) This is the internal function and should not be called by users. 92 | * 93 | * 94 | ************************************************************************************************************************ 95 | */ 96 | void active_memory_collect(STATE_EVENT *event) 97 | { 98 | RAW_OS_ERROR ret; 99 | 100 | RAW_SR_ALLOC(); 101 | 102 | if (event->which_pool) { 103 | 104 | RAW_CPU_DISABLE(); 105 | 106 | if (event->ref_count > 1) { 107 | event->ref_count--; 108 | 109 | RAW_CPU_ENABLE(); 110 | } 111 | 112 | else { 113 | 114 | RAW_CPU_ENABLE(); 115 | 116 | RAW_ASSERT(event->ref_count == 1); 117 | ret = raw_block_release(event->which_pool, event); 118 | 119 | if (ret != RAW_SUCCESS) { 120 | 121 | RAW_ASSERT(0); 122 | } 123 | 124 | } 125 | 126 | 127 | } 128 | 129 | } 130 | 131 | 132 | -------------------------------------------------------------------------------- /extension/rf/active_queue_broadcast.c: -------------------------------------------------------------------------------- 1 | /* 2 | raw os - Copyright (C) Lingjun Chen(jorya_txj). 3 | 4 | This file is part of raw os. 5 | 6 | raw os is free software; you can redistribute it it under the terms of the 7 | GNU General Public License as published by the Free Software Foundation; 8 | either version 3 of the License, or (at your option) any later version. 9 | 10 | raw os is distributed in the hope that it will be useful, but WITHOUT ANY WARRANTY; 11 | without even the implied warranty of MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. 12 | See the GNU General Public License for more details. 13 | 14 | You should have received a copy of the GNU Lesser General Public License 15 | along with this program. if not, write email to jorya.txj@gmail.com 16 | --- 17 | 18 | A special exception to the LGPL can be applied should you wish to distribute 19 | a combined work that includes raw os, without being obliged to provide 20 | the source code for any proprietary components. See the file exception.txt 21 | for full details of how and when the exception can be applied. 22 | */ 23 | 24 | 25 | /* 2012-9 Created by jorya_txj 26 | * xxxxxx please added here 27 | */ 28 | 29 | #include 30 | #include 31 | #include 32 | #include 33 | #include 34 | #include 35 | 36 | 37 | LIST active_queue_head[ACTIVE_MAX_BROADCAST_SIGNAL]; 38 | 39 | 40 | 41 | /* 42 | ************************************************************************************************************************ 43 | * Init the broadcast queue list 44 | * 45 | * Description: This function is to init the broadcast queue list 46 | * 47 | * Arguments : 48 | * 49 | * Returns 50 | * 51 | * Note(s) This function must be called before using active_broadcast_queue_register. 52 | * 53 | * 54 | ************************************************************************************************************************ 55 | */ 56 | void active_broadcast_queue_init() 57 | { 58 | 59 | RAW_U16 i; 60 | 61 | for (i = 0; i < ACTIVE_MAX_BROADCAST_SIGNAL; i++ ) { 62 | list_init(&active_queue_head[i]); 63 | } 64 | 65 | } 66 | 67 | 68 | /* 69 | ************************************************************************************************************************ 70 | * Register the sig for the specied active object 71 | * 72 | * Description: This function is to register the sig for the specied active object 73 | * 74 | * Arguments :me is the active object which is to be registered. 75 | * --------------------- 76 | * sig is the signal which is to be registered with 77 | * Returns 78 | * 79 | * Note(s) This function must be called before using active_queue_event_broadcast. 80 | * 81 | * 82 | ************************************************************************************************************************ 83 | */ 84 | void active_broadcast_queue_register(ACTIVE_OBJECT_STRUCT *me, RAW_U16 sig) 85 | { 86 | 87 | RAW_SR_ALLOC(); 88 | 89 | sig -= STM_USER_SIG; 90 | 91 | 92 | if (sig >= ACTIVE_MAX_BROADCAST_SIGNAL) { 93 | 94 | RAW_ASSERT(0); 95 | 96 | } 97 | 98 | RAW_CPU_DISABLE(); 99 | 100 | list_insert(&active_queue_head[sig], &me->active_queue_list[sig]); 101 | 102 | RAW_CPU_ENABLE(); 103 | 104 | 105 | } 106 | 107 | 108 | /* 109 | ************************************************************************************************************************ 110 | * Broadcast event 111 | * 112 | * Description: This function is called to broadcast event sig , if active object was register with this event sig, it will get this event. 113 | * 114 | * Arguments :e is the event to broadcast 115 | * 116 | * Returns 117 | * 118 | * Note(s) 119 | * 120 | * 121 | ************************************************************************************************************************ 122 | */ 123 | void active_queue_event_broadcast(STATE_EVENT *e) 124 | { 125 | LIST *iter; 126 | LIST *iter_temp; 127 | LIST *event_head_ptr; 128 | ACTIVE_OBJECT_STRUCT *me; 129 | RAW_U16 sig; 130 | 131 | RAW_SR_ALLOC(); 132 | 133 | sig = e->sig - STM_USER_SIG; 134 | 135 | event_head_ptr = &active_queue_head[sig]; 136 | 137 | iter = event_head_ptr->next; 138 | 139 | 140 | RAW_CPU_DISABLE(); 141 | 142 | if (e->which_pool) { 143 | 144 | e->ref_count++; 145 | } 146 | 147 | RAW_CPU_ENABLE(); 148 | 149 | while (iter != event_head_ptr) { 150 | 151 | iter_temp = iter->next; 152 | 153 | me = raw_list_entry(iter, ACTIVE_OBJECT_STRUCT, active_queue_list[sig]); 154 | 155 | active_event_post_end(me, e); 156 | iter = iter_temp; 157 | 158 | } 159 | 160 | active_memory_collect(e); 161 | 162 | } 163 | 164 | 165 | 166 | /* 167 | ************************************************************************************************************************ 168 | * Unregister the sig for the specied active object 169 | * 170 | * 171 | * Description: This function is to unregister the sig for the specied active object 172 | * 173 | * Arguments :me is the active object which is to be unregistered. 174 | * --------------------- 175 | * sig is the signal which is to be unregistered with 176 | * Returns 177 | * 178 | * Note(s) you need be great careful to call this function.It is suggested call this function after or before active_queue_event_broadcast! 179 | * 180 | * 181 | ************************************************************************************************************************ 182 | */ 183 | void active_broadcast_queue_unregister(ACTIVE_OBJECT_STRUCT *me, RAW_U16 sig) 184 | { 185 | RAW_SR_ALLOC(); 186 | 187 | RAW_CPU_DISABLE(); 188 | 189 | list_delete(&me->active_queue_list[sig]); 190 | 191 | RAW_CPU_ENABLE(); 192 | 193 | } 194 | 195 | -------------------------------------------------------------------------------- /extension/rf/active_time_event.c: -------------------------------------------------------------------------------- 1 | /* 2 | raw os - Copyright (C) Lingjun Chen(jorya_txj). 3 | 4 | This file is part of raw os. 5 | 6 | raw os is free software; you can redistribute it it under the terms of the 7 | GNU General Public License as published by the Free Software Foundation; 8 | either version 3 of the License, or (at your option) any later version. 9 | 10 | raw os is distributed in the hope that it will be useful, but WITHOUT ANY WARRANTY; 11 | without even the implied warranty of MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. 12 | See the GNU General Public License for more details. 13 | 14 | You should have received a copy of the GNU Lesser General Public License 15 | along with this program. if not, write email to jorya.txj@gmail.com 16 | --- 17 | 18 | A special exception to the LGPL can be applied should you wish to distribute 19 | a combined work that includes raw os, without being obliged to provide 20 | the source code for any proprietary components. See the file exception.txt 21 | for full details of how and when the exception can be applied. 22 | */ 23 | 24 | 25 | /* 2012-9 Created by jorya_txj 26 | * xxxxxx please added here 27 | */ 28 | 29 | 30 | 31 | #include 32 | #include 33 | #include 34 | #include 35 | #include 36 | #include 37 | 38 | 39 | 40 | static RAW_U16 active_time_event_post(void *para) 41 | { 42 | TIME_EVENT_STRUCT *me = para; 43 | 44 | active_event_post_end(me->active_object, &me->father); 45 | return TIMER_CALLBACK_CONTINUE; 46 | 47 | } 48 | 49 | 50 | 51 | 52 | /* 53 | ************************************************************************************************************************ 54 | * Init the time event for post specified sig 55 | * 56 | * Description: This function is to init the time event for post specified sig 57 | * 58 | * Arguments :me is the TIME_EVENT_STRUCT object 59 | * -------------- 60 | * sig is the timer want to fire 61 | * Returns 62 | * 63 | * Note(s) 64 | * 65 | * 66 | ************************************************************************************************************************ 67 | */ 68 | void active_time_event_create(TIME_EVENT_STRUCT *me, RAW_U16 sig) 69 | { 70 | RAW_OS_ERROR ret; 71 | 72 | if (sig < STM_USER_SIG) { 73 | 74 | RAW_ASSERT(0); 75 | } 76 | 77 | 78 | me->active_object= 0; 79 | me->father.sig = sig; 80 | me->father.which_pool = 0; 81 | 82 | ret = raw_timer_create(&me->timer, (RAW_U8 *)"timer", active_time_event_post, 0,1,0,0); 83 | 84 | if (ret != RAW_SUCCESS) { 85 | 86 | RAW_ASSERT(0); 87 | 88 | } 89 | 90 | } 91 | 92 | 93 | /* 94 | ************************************************************************************************************************ 95 | * Fire to active_object with the specified sig 96 | * 97 | * Description: This function is to fire to active_object with the specified sig 98 | * 99 | * Arguments :me is the TIME_EVENT_STRUCT object 100 | * -------------- 101 | * active_object is the timer want fire to 102 | * -------------- 103 | * ticks is how long need to fire. 104 | * ----------------------- 105 | * once is just fire once if once is set to 1. 106 | * Returns 107 | * 108 | * Note(s) If fire a once timer, just reuse this function every time, but you have to deactivate the timer if timer is not once before use it. 109 | * 110 | * 111 | ************************************************************************************************************************ 112 | */ 113 | void active_time_event_fire(TIME_EVENT_STRUCT *me, ACTIVE_OBJECT_STRUCT *active_object, RAW_TICK_TYPE ticks, RAW_U8 once) 114 | { 115 | RAW_OS_ERROR ret; 116 | 117 | me->active_object = active_object; 118 | 119 | 120 | if (once) { 121 | 122 | ret = raw_timer_change(&me->timer, ticks, 0); 123 | } 124 | 125 | else { 126 | 127 | ret = raw_timer_change(&me->timer, ticks, ticks); 128 | 129 | } 130 | 131 | if (ret != RAW_SUCCESS) { 132 | 133 | RAW_ASSERT(0); 134 | } 135 | 136 | ret = raw_timer_activate(&me->timer, me); 137 | 138 | if (ret != RAW_SUCCESS) { 139 | 140 | RAW_ASSERT(0); 141 | } 142 | 143 | } 144 | 145 | 146 | /* 147 | ************************************************************************************************************************ 148 | * Deactivate the timer 149 | * 150 | * Description: This function is to deactivate the timer 151 | * 152 | * Arguments :me is the TIME_EVENT_STRUCT object 153 | * -------------- 154 | * 155 | * Returns 156 | * 157 | * Note(s) 158 | * 159 | * 160 | ************************************************************************************************************************ 161 | */ 162 | RAW_U16 active_time_event_deactivate(TIME_EVENT_STRUCT *me) 163 | { 164 | RAW_OS_ERROR ret; 165 | ret = raw_timer_deactivate(&me->timer); 166 | 167 | return ret; 168 | } 169 | 170 | 171 | -------------------------------------------------------------------------------- /include/raw_api.h: -------------------------------------------------------------------------------- 1 | /* 2 | raw os - Copyright (C) Lingjun Chen(jorya_txj). 3 | 4 | This file is part of raw os. 5 | 6 | raw os is free software; you can redistribute it it under the terms of the 7 | GNU General Public License as published by the Free Software Foundation; 8 | either version 3 of the License, or (at your option) any later version. 9 | 10 | raw os is distributed in the hope that it will be useful, but WITHOUT ANY WARRANTY; 11 | without even the implied warranty of MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. 12 | See the GNU General Public License for more details. 13 | 14 | You should have received a copy of the GNU Lesser General Public License 15 | along with this program. if not, write email to jorya.txj@gmail.com 16 | --- 17 | 18 | A special exception to the LGPL can be applied should you wish to distribute 19 | a combined work that includes raw os, without being obliged to provide 20 | the source code for any proprietary components. See the file exception.txt 21 | for full details of how and when the exception can be applied. 22 | */ 23 | 24 | 25 | /* 2012-4 Created by jorya_txj 26 | * xxxxxx please added here 27 | */ 28 | 29 | 30 | 31 | #ifndef RAW_API_H 32 | #define RAW_API_H 33 | 34 | #ifdef __cplusplus 35 | extern "C" { 36 | #endif 37 | 38 | #include 39 | #include 40 | #include 41 | #include 42 | #include 43 | #include 44 | #include 45 | #include 46 | #include 47 | #include 48 | #include 49 | #include 50 | #include 51 | #include 52 | #include 53 | #include 54 | #include 55 | #include 56 | #include 57 | #include 58 | #include 59 | #include 60 | #include 61 | #include 62 | #include 63 | #include 64 | 65 | #ifdef __cplusplus 66 | } 67 | #endif 68 | 69 | #endif 70 | 71 | -------------------------------------------------------------------------------- /include/raw_block.h: -------------------------------------------------------------------------------- 1 | /* 2 | raw os - Copyright (C) Lingjun Chen(jorya_txj). 3 | 4 | This file is part of raw os. 5 | 6 | raw os is free software; you can redistribute it it under the terms of the 7 | GNU General Public License as published by the Free Software Foundation; 8 | either version 3 of the License, or (at your option) any later version. 9 | 10 | raw os is distributed in the hope that it will be useful, but WITHOUT ANY WARRANTY; 11 | without even the implied warranty of MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. 12 | See the GNU General Public License for more details. 13 | 14 | You should have received a copy of the GNU Lesser General Public License 15 | along with this program. if not, write email to jorya.txj@gmail.com 16 | --- 17 | 18 | A special exception to the LGPL can be applied should you wish to distribute 19 | a combined work that includes raw os, without being obliged to provide 20 | the source code for any proprietary components. See the file exception.txt 21 | for full details of how and when the exception can be applied. 22 | */ 23 | 24 | 25 | /* 2012-4 Created by jorya_txj 26 | * xxxxxx please added here 27 | */ 28 | 29 | 30 | #ifndef RAW_BLOCK_H 31 | #define RAW_BLOCK_H 32 | 33 | typedef struct mem_pool 34 | { 35 | RAW_COMMON_BLOCK_OBJECT common_block_obj; 36 | 37 | /* Define the number of available memory blocks in the pool. */ 38 | RAW_U32 raw_block_pool_available; 39 | RAW_U32 block_size; 40 | 41 | /* Define the head pointer of the available block pool. */ 42 | RAW_U8 *raw_block_pool_available_list; 43 | 44 | } MEM_POOL; 45 | 46 | 47 | RAW_OS_ERROR raw_block_pool_create(MEM_POOL *pool_ptr, RAW_U8 *name_ptr, RAW_U32 block_size, void *pool_start, RAW_U32 pool_size); 48 | RAW_OS_ERROR raw_block_allocate(MEM_POOL *pool_ptr, void **block_ptr); 49 | RAW_OS_ERROR raw_block_release(MEM_POOL *pool_ptr, void *block_ptr); 50 | 51 | 52 | #endif 53 | 54 | -------------------------------------------------------------------------------- /include/raw_byte.h: -------------------------------------------------------------------------------- 1 | /* 2 | raw os - Copyright (C) Lingjun Chen(jorya_txj). 3 | 4 | This file is part of raw os. 5 | 6 | raw os is free software; you can redistribute it it under the terms of the 7 | GNU General Public License as published by the Free Software Foundation; 8 | either version 3 of the License, or (at your option) any later version. 9 | 10 | raw os is distributed in the hope that it will be useful, but WITHOUT ANY WARRANTY; 11 | without even the implied warranty of MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. 12 | See the GNU General Public License for more details. 13 | 14 | You should have received a copy of the GNU Lesser General Public License 15 | along with this program. if not, write email to jorya.txj@gmail.com 16 | --- 17 | 18 | A special exception to the LGPL can be applied should you wish to distribute 19 | a combined work that includes raw os, without being obliged to provide 20 | the source code for any proprietary components. See the file exception.txt 21 | for full details of how and when the exception can be applied. 22 | */ 23 | 24 | 25 | /* 2012-7 Created by jorya_txj 26 | * xxxxxx please added here 27 | */ 28 | 29 | 30 | #ifndef RAW_BYTE_H 31 | #define RAW_BYTE_H 32 | 33 | 34 | typedef struct raw_byte_pool_struct 35 | { 36 | RAW_COMMON_BLOCK_OBJECT common_block_obj; 37 | 38 | /* Define the number of available bytes in the pool. */ 39 | RAW_U32 raw_byte_pool_available; 40 | 41 | /* Define the number of fragments in the pool. */ 42 | RAW_U32 raw_byte_pool_fragments; 43 | 44 | /* Define the search pointer used for initial searching for memory 45 | in a byte pool. */ 46 | RAW_U8 *raw_byte_pool_search; 47 | 48 | /*blocked task on this byte pool*/ 49 | RAW_TASK_OBJ *raw_byte_pool_owner; 50 | 51 | } RAW_BYTE_POOL_STRUCT; 52 | 53 | 54 | #define RAW_BYTE_BLOCK_ALLOC 0xABCDDCABUL 55 | #define RAW_BYTE_BLOCK_FREE 0xFEFDECDBUL 56 | #define RAW_BYTE_BLOCK_MIN 20u 57 | #define RAW_BYTE_POOL_MIN 100u 58 | 59 | RAW_OS_ERROR raw_byte_pool_create(RAW_BYTE_POOL_STRUCT *pool_ptr, RAW_U8 *name_ptr, void *pool_start, RAW_U32 pool_size); 60 | 61 | RAW_OS_ERROR raw_byte_allocate(RAW_BYTE_POOL_STRUCT *pool_ptr, void **memory_ptr, RAW_U32 memory_size); 62 | 63 | RAW_OS_ERROR raw_byte_release(RAW_BYTE_POOL_STRUCT *pool_ptr, void *memory_ptr); 64 | 65 | 66 | #endif 67 | 68 | -------------------------------------------------------------------------------- /include/raw_critical.h: -------------------------------------------------------------------------------- 1 | /* 2 | raw os - Copyright (C) Lingjun Chen(jorya_txj). 3 | 4 | This file is part of raw os. 5 | 6 | raw os is free software; you can redistribute it it under the terms of the 7 | GNU General Public License as published by the Free Software Foundation; 8 | either version 3 of the License, or (at your option) any later version. 9 | 10 | raw os is distributed in the hope that it will be useful, but WITHOUT ANY WARRANTY; 11 | without even the implied warranty of MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. 12 | See the GNU General Public License for more details. 13 | 14 | You should have received a copy of the GNU Lesser General Public License 15 | along with this program. if not, write email to jorya.txj@gmail.com 16 | --- 17 | 18 | A special exception to the LGPL can be applied should you wish to distribute 19 | a combined work that includes raw os, without being obliged to provide 20 | the source code for any proprietary components. See the file exception.txt 21 | for full details of how and when the exception can be applied. 22 | */ 23 | 24 | 25 | /* 2012-11 Created by jorya_txj 26 | * xxxxxx please added here 27 | */ 28 | 29 | 30 | #ifndef RAW_CRITICAL_H 31 | #define RAW_CRITICAL_H 32 | 33 | 34 | #if (RAW_CPU_INT_DIS_MEASURE_CHECK > 0) 35 | 36 | 37 | #define RAW_CPU_DISABLE() \ 38 | do { \ 39 | USER_CPU_INT_DISABLE(); \ 40 | int_disable_measure_start(); \ 41 | } while (0) 42 | 43 | #define RAW_CPU_ENABLE() \ 44 | do { \ 45 | int_disable_measure_stop(); \ 46 | USER_CPU_INT_ENABLE(); \ 47 | } while (0) 48 | 49 | 50 | #else 51 | 52 | #define RAW_CPU_DISABLE() \ 53 | do { \ 54 | USER_CPU_INT_DISABLE(); \ 55 | } while (0) 56 | 57 | #define RAW_CPU_ENABLE() \ 58 | do { \ 59 | USER_CPU_INT_ENABLE(); \ 60 | } while (0) 61 | 62 | #endif 63 | 64 | 65 | #define RAW_CRITICAL_ENTER() RAW_CPU_DISABLE() 66 | #define RAW_CRITICAL_EXIT() RAW_CPU_ENABLE() 67 | 68 | 69 | #define SYSTEM_LOCK_PROCESS() \ 70 | do {\ 71 | if (raw_sched_lock) {\ 72 | RAW_CRITICAL_EXIT();\ 73 | return RAW_SCHED_DISABLE;\ 74 | }\ 75 | } while (0) 76 | 77 | 78 | #define SYSTEM_LOCK_PROCESS_QUEUE() \ 79 | do {\ 80 | if (raw_sched_lock) {\ 81 | *msg = (void *)0;\ 82 | RAW_CRITICAL_EXIT();\ 83 | return RAW_SCHED_DISABLE;\ 84 | }\ 85 | } while (0) 86 | 87 | #define SYSTEM_LOCK_PROCESS_QUEUE_SIZE() \ 88 | do {\ 89 | if (raw_sched_lock) {\ 90 | *msg_ptr = 0;\ 91 | *receive_size = 0;\ 92 | RAW_CRITICAL_EXIT();\ 93 | return RAW_SCHED_DISABLE;\ 94 | }\ 95 | } while (0) 96 | 97 | 98 | #endif 99 | 100 | -------------------------------------------------------------------------------- /include/raw_event.h: -------------------------------------------------------------------------------- 1 | /* 2 | raw os - Copyright (C) Lingjun Chen(jorya_txj). 3 | 4 | This file is part of raw os. 5 | 6 | raw os is free software; you can redistribute it it under the terms of the 7 | GNU General Public License as published by the Free Software Foundation; 8 | either version 3 of the License, or (at your option) any later version. 9 | 10 | raw os is distributed in the hope that it will be useful, but WITHOUT ANY WARRANTY; 11 | without even the implied warranty of MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. 12 | See the GNU General Public License for more details. 13 | 14 | You should have received a copy of the GNU Lesser General Public License 15 | along with this program. if not, write email to jorya.txj@gmail.com 16 | --- 17 | 18 | A special exception to the LGPL can be applied should you wish to distribute 19 | a combined work that includes raw os, without being obliged to provide 20 | the source code for any proprietary components. See the file exception.txt 21 | for full details of how and when the exception can be applied. 22 | */ 23 | 24 | 25 | /* 2012-4 Created by jorya_txj 26 | * xxxxxx please added here 27 | */ 28 | 29 | #ifndef RAW_EVENT_H 30 | #define RAW_EVENT_H 31 | 32 | 33 | typedef struct raw_event 34 | { 35 | RAW_COMMON_BLOCK_OBJECT common_block_obj; 36 | RAW_U32 flags; 37 | 38 | } RAW_EVENT; 39 | 40 | 41 | 42 | #define RAW_FLAGS_AND_MASK 0x2u 43 | #define RAW_FLAGS_CLEAR_MASK 0x1u 44 | 45 | 46 | #define RAW_AND 0x02u 47 | #define RAW_AND_CLEAR 0x03u 48 | #define RAW_OR 0x00u 49 | #define RAW_OR_CLEAR 0x01u 50 | 51 | 52 | RAW_OS_ERROR raw_event_create(RAW_EVENT *event_ptr, RAW_U8 *name_ptr, RAW_U32 flags_init); 53 | RAW_OS_ERROR raw_event_get(RAW_EVENT *event_ptr, RAW_U32 requested_flags, RAW_U8 get_option, RAW_U32 *actual_flags_ptr, RAW_TICK_TYPE wait_option); 54 | RAW_OS_ERROR raw_event_set(RAW_EVENT *event_ptr, RAW_U32 flags_to_set, RAW_U8 set_option); 55 | RAW_OS_ERROR event_set(RAW_EVENT *event_ptr, RAW_U32 flags_to_set, RAW_U8 set_option); 56 | 57 | #if (CONFIG_RAW_EVENT_DELETE > 0) 58 | RAW_OS_ERROR raw_event_delete(RAW_EVENT *event_ptr); 59 | #endif 60 | 61 | #endif 62 | 63 | -------------------------------------------------------------------------------- /include/raw_idle_event.h: -------------------------------------------------------------------------------- 1 | /* 2 | raw os - Copyright (C) Lingjun Chen(jorya_txj). 3 | 4 | This file is part of raw os. 5 | 6 | raw os is free software; you can redistribute it it under the terms of the 7 | GNU General Public License as published by the Free Software Foundation; 8 | either version 3 of the License, or (at your option) any later version. 9 | 10 | raw os is distributed in the hope that it will be useful, but WITHOUT ANY WARRANTY; 11 | without even the implied warranty of MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. 12 | See the GNU General Public License for more details. 13 | 14 | You should have received a copy of the GNU Lesser General Public License 15 | along with this program. if not, write email to jorya.txj@gmail.com 16 | --- 17 | 18 | A special exception to the LGPL can be applied should you wish to distribute 19 | a combined work that includes raw os, without being obliged to provide 20 | the source code for any proprietary components. See the file exception.txt 21 | for full details of how and when the exception can be applied. 22 | */ 23 | 24 | /* 2012-12 Created by jorya_txj 25 | * xxxxxx please added here 26 | */ 27 | 28 | 29 | #ifndef RAW_IDLE_EVENT_H 30 | #define RAW_IDLE_EVENT_H 31 | 32 | typedef struct idle_queue_msg { 33 | 34 | RAW_U16 sig; 35 | void *para; 36 | 37 | } IDLE_QUEUE_MSG; 38 | 39 | 40 | typedef struct active_event_struct { 41 | 42 | STM_STRUCT super; 43 | 44 | RAW_TICK_TYPE tick_ctr; 45 | 46 | LIST idle_tick_list; 47 | 48 | RAW_U8 head; 49 | 50 | RAW_U8 prio; 51 | 52 | RAW_U8 tail; 53 | 54 | RAW_U8 nUsed; 55 | 56 | RAW_U8 priority_bit_x; 57 | RAW_U8 priority_bit_y; 58 | 59 | RAW_U8 priority_x; 60 | RAW_U8 priority_y; 61 | 62 | } ACTIVE_EVENT_STRUCT; 63 | 64 | 65 | typedef struct active_event_struct_cb { 66 | ACTIVE_EVENT_STRUCT *act; 67 | IDLE_QUEUE_MSG *queue; 68 | RAW_U8 end; 69 | 70 | } ACTIVE_EVENT_STRUCT_CB; 71 | 72 | 73 | #define ARRAY_SIZE(array) (sizeof(array) / sizeof(array[0])) 74 | #define RAW_IDLE_LOWEST_PRIO 63u 75 | #define RAW_IDLE_RDY_TBL_SIZE ((RAW_IDLE_LOWEST_PRIO) / 8u + 1u) 76 | 77 | void idle_event_init(void); 78 | RAW_OS_ERROR event_post(ACTIVE_EVENT_STRUCT *me, RAW_U16 sig, void *para, RAW_U8 opt_send_method); 79 | RAW_OS_ERROR idle_event_end_post(ACTIVE_EVENT_STRUCT *me, RAW_U16 sig, void *para); 80 | RAW_OS_ERROR idle_event_front_post(ACTIVE_EVENT_STRUCT *me, RAW_U16 sig, void *para); 81 | void idle_run(void); 82 | void idle_event_user(void); 83 | 84 | #endif 85 | 86 | -------------------------------------------------------------------------------- /include/raw_internal_type.h: -------------------------------------------------------------------------------- 1 | /* 2 | raw os - Copyright (C) Lingjun Chen(jorya_txj). 3 | 4 | This file is part of raw os. 5 | 6 | raw os is free software; you can redistribute it it under the terms of the 7 | GNU General Public License as published by the Free Software Foundation; 8 | either version 3 of the License, or (at your option) any later version. 9 | 10 | raw os is distributed in the hope that it will be useful, but WITHOUT ANY WARRANTY; 11 | without even the implied warranty of MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. 12 | See the GNU General Public License for more details. 13 | 14 | You should have received a copy of the GNU Lesser General Public License 15 | along with this program. if not, write email to jorya.txj@gmail.com 16 | --- 17 | 18 | A special exception to the LGPL can be applied should you wish to distribute 19 | a combined work that includes raw os, without being obliged to provide 20 | the source code for any proprietary components. See the file exception.txt 21 | for full details of how and when the exception can be applied. 22 | */ 23 | 24 | /* 2013-4 Created by jorya_txj 25 | * xxxxxx please added here 26 | */ 27 | 28 | 29 | #ifndef RAW_INTERNAL_TYPE_H 30 | #define RAW_INTERNAL_TYPE_H 31 | 32 | 33 | /* 34 | Be very careful here, you can modyfy the following code, if only you understand what yor are doing! 35 | 36 | */ 37 | 38 | #define RAW_INTERNAL_NO_WAIT 0u 39 | #define RAW_INTERNAL_WAIT_FOREVER 0xffffffffu /*32 bit value, if RAW_TICK_TYPE is 64 bit, you need change it to 64 bit*/ 40 | #define RAW_TASK_STACK_CHECK_WORD 0xdeadbeafu /*32 bit or 64 bit stack check value*/ 41 | 42 | typedef RAW_U32 RAW_TICK_TYPE; /*32 bit or 64 bit unsigned value*/ 43 | typedef RAW_U8 TASK_0_EVENT_TYPE; /*8 bit ,16 bit or 32 bit unsigned value*/ 44 | typedef RAW_U32 MSG_SIZE_TYPE; /*32 bit or 64 bit unsigned value*/ 45 | typedef RAW_U64 RAW_IDLE_COUNT_TYPE; /*32 bit or 64 bit unsigned value*/ 46 | typedef RAW_U64 RAW_SYS_TIME_TYPE; /*32 bit or 64 bit unsigned value*/ 47 | typedef RAW_U32 RAW_HARD_TIME_TYPE; /*32 bit or 64 bit unsigned value*/ 48 | typedef RAW_U8 RAW_MUTEX_NESTED_TYPE; /*8 bit or 16bit or 32bit unsigned value*/ 49 | 50 | #endif 51 | 52 | -------------------------------------------------------------------------------- /include/raw_list.h: -------------------------------------------------------------------------------- 1 | /* 2 | raw os - Copyright (C) Lingjun Chen(jorya_txj). 3 | 4 | This file is part of raw os. 5 | 6 | raw os is free software; you can redistribute it it under the terms of the 7 | GNU General Public License as published by the Free Software Foundation; 8 | either version 3 of the License, or (at your option) any later version. 9 | 10 | raw os is distributed in the hope that it will be useful, but WITHOUT ANY WARRANTY; 11 | without even the implied warranty of MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. 12 | See the GNU General Public License for more details. 13 | 14 | You should have received a copy of the GNU Lesser General Public License 15 | along with this program. if not, write email to jorya.txj@gmail.com 16 | --- 17 | 18 | A special exception to the LGPL can be applied should you wish to distribute 19 | a combined work that includes raw os, without being obliged to provide 20 | the source code for any proprietary components. See the file exception.txt 21 | for full details of how and when the exception can be applied. 22 | */ 23 | 24 | 25 | /* 2012-4 Created by jorya_txj 26 | * xxxxxx please added here 27 | */ 28 | 29 | 30 | #ifndef RAW_LIST_H 31 | #define RAW_LIST_H 32 | /* 33 | * Doubly-link list 34 | */ 35 | typedef struct list { 36 | struct list *next; 37 | struct list *previous; 38 | } LIST; 39 | 40 | 41 | #define raw_list_entry(node, type, member) ((type *)((RAW_U8 *)(node) - (RAW_U32)(&((type *)0)->member))) 42 | 43 | 44 | /* 45 | * List initialization 46 | */ 47 | RAW_INLINE void list_init(LIST *list_head) 48 | { 49 | list_head->next = list_head; 50 | list_head->previous = list_head; 51 | } 52 | 53 | /* 54 | * return TRUE if the list is empty 55 | */ 56 | RAW_INLINE RAW_BOOLEAN is_list_empty(LIST *list) 57 | { 58 | 59 | return (list->next == list); 60 | 61 | } 62 | 63 | /* 64 | * add element to list 65 | * add element before head. 66 | */ 67 | RAW_INLINE void list_insert(LIST *head, LIST *element) 68 | { 69 | 70 | element->previous = head->previous; 71 | element->next = head; 72 | 73 | head->previous->next = element; 74 | head->previous = element; 75 | } 76 | 77 | 78 | RAW_INLINE void list_delete(LIST *element) 79 | { 80 | 81 | element->previous->next = element->next; 82 | element->next->previous = element->previous; 83 | 84 | } 85 | 86 | 87 | #endif 88 | 89 | -------------------------------------------------------------------------------- /include/raw_mutex.h: -------------------------------------------------------------------------------- 1 | /* 2 | raw os - Copyright (C) Lingjun Chen(jorya_txj). 3 | 4 | This file is part of raw os. 5 | 6 | raw os is free software; you can redistribute it it under the terms of the 7 | GNU General Public License as published by the Free Software Foundation; 8 | either version 3 of the License, or (at your option) any later version. 9 | 10 | raw os is distributed in the hope that it will be useful, but WITHOUT ANY WARRANTY; 11 | without even the implied warranty of MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. 12 | See the GNU General Public License for more details. 13 | 14 | You should have received a copy of the GNU Lesser General Public License 15 | along with this program. if not, write email to jorya.txj@gmail.com 16 | --- 17 | 18 | A special exception to the LGPL can be applied should you wish to distribute 19 | a combined work that includes raw os, without being obliged to provide 20 | the source code for any proprietary components. See the file exception.txt 21 | for full details of how and when the exception can be applied. 22 | */ 23 | 24 | 25 | /* 2012-4 Created by jorya_txj 26 | * xxxxxx please added here 27 | */ 28 | 29 | 30 | #ifndef RAW_MUTEX_H 31 | #define RAW_MUTEX_H 32 | 33 | #define RAW_MUTEX_INHERIT_POLICY 0x00000002U /* Priority inherited protocol */ 34 | #define RAW_MUTEX_CEILING_POLICY 0x00000003U /* Upper limit priority protocol */ 35 | #define RAW_MUTEX_NONE_POLICY 0x00000004U /*None policy is used*/ 36 | 37 | typedef struct raw_mutex 38 | { 39 | RAW_COMMON_BLOCK_OBJECT common_block_obj; 40 | 41 | /*mutex owner task*/ 42 | RAW_TASK_OBJ *mtxtsk; 43 | 44 | struct raw_mutex *mtxlist; /* Mutex get list */ 45 | 46 | RAW_U8 policy; 47 | RAW_U8 ceiling_prio; 48 | RAW_U8 owner_nested; 49 | 50 | } RAW_MUTEX; 51 | 52 | RAW_OS_ERROR raw_mutex_create(RAW_MUTEX *mutex_ptr, RAW_U8 *name_ptr, RAW_U8 policy, RAW_U8 ceiling_prio); 53 | 54 | RAW_OS_ERROR raw_mutex_get(RAW_MUTEX *mutex_ptr, RAW_TICK_TYPE wait_option); 55 | RAW_OS_ERROR raw_mutex_put(RAW_MUTEX *mutex_ptr); 56 | 57 | #if (CONFIG_RAW_MUTEX_DELETE > 0) 58 | RAW_OS_ERROR raw_mutex_delete(RAW_MUTEX *mutex_ptr); 59 | #endif 60 | 61 | 62 | #endif 63 | 64 | 65 | -------------------------------------------------------------------------------- /include/raw_obj.h: -------------------------------------------------------------------------------- 1 | /* 2 | raw os - Copyright (C) Lingjun Chen(jorya_txj). 3 | 4 | This file is part of raw os. 5 | 6 | raw os is free software; you can redistribute it it under the terms of the 7 | GNU General Public License as published by the Free Software Foundation; 8 | either version 3 of the License, or (at your option) any later version. 9 | 10 | raw os is distributed in the hope that it will be useful, but WITHOUT ANY WARRANTY; 11 | without even the implied warranty of MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. 12 | See the GNU General Public License for more details. 13 | 14 | You should have received a copy of the GNU Lesser General Public License 15 | along with this program. if not, write email to jorya.txj@gmail.com 16 | --- 17 | 18 | A special exception to the LGPL can be applied should you wish to distribute 19 | a combined work that includes raw os, without being obliged to provide 20 | the source code for any proprietary components. See the file exception.txt 21 | for full details of how and when the exception can be applied. 22 | */ 23 | 24 | 25 | /* 2012-4 Created by jorya_txj 26 | * xxxxxx please added here 27 | */ 28 | 29 | #ifndef RAW_OBJECT_H 30 | #define RAW_OBJECT_H 31 | 32 | typedef enum raw_task_status 33 | { 34 | RAW_RDY = 0, 35 | RAW_PEND, 36 | RAW_PEND_TIMEOUT, 37 | RAW_PEND_TIMEOUT_SUSPENDED, 38 | RAW_SUSPENDED, 39 | RAW_PEND_SUSPENDED, 40 | RAW_DLY, 41 | RAW_DLY_SUSPENDED, 42 | RAW_DELETED, 43 | RAW_INVALID_STATE 44 | } RAW_TASK_STATUS; 45 | 46 | 47 | typedef struct raw_common_block_object { 48 | 49 | LIST block_list; 50 | RAW_U8 *name; 51 | RAW_U8 block_way; 52 | RAW_OBJECT_TYPE object_type; 53 | 54 | } RAW_COMMON_BLOCK_OBJECT; 55 | 56 | 57 | typedef struct raw_task_obj 58 | { 59 | void *task_stack; 60 | 61 | #if (CONFIG_RAW_MPU_ENABLE > 0) 62 | RAW_MPU_SETTINGS mpu_settings; 63 | #endif 64 | 65 | LIST task_list; 66 | 67 | #if (CONFIG_USER_DATA_POINTER > 0) 68 | /*for user data extension*/ 69 | void *user_data_pointer[CONFIG_USER_DATA_POINTER]; 70 | 71 | #endif 72 | 73 | #if (CONFIG_SCHED_FIFO_RR > 0) 74 | /*For task time slice*/ 75 | RAW_U32 time_slice; 76 | RAW_U32 time_total; 77 | RAW_U8 sched_way; 78 | #endif 79 | 80 | /* Current running priority */ 81 | RAW_U8 priority; 82 | /* Base priority */ 83 | RAW_U8 bpriority; 84 | 85 | #if (CONFIG_RAW_TASK_SUSPEND > 0) 86 | RAW_U8 suspend_count; 87 | #endif 88 | 89 | #if (CONFIG_RAW_MUTEX > 0) 90 | struct raw_mutex *mtxlist; 91 | #endif 92 | 93 | LIST task_debug_list; 94 | 95 | RAW_U32 stack_size; 96 | 97 | PORT_STACK *task_stack_base; 98 | LIST tick_list; 99 | 100 | RAW_TICK_TYPE tick_match; 101 | RAW_TICK_TYPE tick_remain; 102 | 103 | LIST *tick_head; 104 | 105 | void *msg; 106 | 107 | MSG_SIZE_TYPE msg_size; 108 | 109 | #if (CONFIG_RAW_QUEUE_BUFFER > 0) 110 | MSG_SIZE_TYPE qb_msg_size; 111 | #endif 112 | 113 | RAW_U8 *task_name; 114 | 115 | RAW_TASK_STATUS task_state; 116 | RAW_BLOCK_STATE block_status; 117 | 118 | /*Task block on mutex, queue, semphore, event*/ 119 | RAW_COMMON_BLOCK_OBJECT *block_obj; 120 | 121 | #if (CONFIG_RAW_TASK_QUEUE_SIZE > 0) 122 | struct raw_queue_size *task_queue_size_obj; 123 | #endif 124 | 125 | #if (CONFIG_RAW_TASK_SEMAPHORE > 0) 126 | struct raw_semaphore *task_semaphore_obj; 127 | #endif 128 | 129 | #if (CONFIG_RAW_EVENT > 0) 130 | RAW_U8 raw_suspend_option; 131 | RAW_U32 raw_suspend_flags; 132 | void *raw_additional_suspend_info; 133 | #endif 134 | 135 | #if (CONFIG_RAW_SYSTEM_STATISTICS > 0) 136 | RAW_U32 task_free_stack_size; 137 | RAW_SYS_TIME_TYPE task_time_total_run; 138 | RAW_SYS_TIME_TYPE task_time_total_run_prev; 139 | RAW_HARD_TIME_TYPE task_time_start; 140 | RAW_HARD_TIME_TYPE task_exec_time; 141 | #endif 142 | 143 | } RAW_TASK_OBJ; 144 | 145 | 146 | #define NUM_WORDS ((CONFIG_RAW_PRIO_MAX + 31) / 32) 147 | 148 | 149 | typedef struct raw_run_queue { 150 | 151 | RAW_U8 highest_priority; 152 | 153 | LIST task_ready_list[CONFIG_RAW_PRIO_MAX]; 154 | 155 | RAW_U32 task_bit_map[NUM_WORDS]; 156 | 157 | } RAW_RUN_QUEUE; 158 | 159 | 160 | typedef struct raw_object_debug { 161 | 162 | /*Debug task head*/ 163 | LIST task_head; 164 | 165 | } RAW_OBJECT_DEBUG; 166 | 167 | #endif 168 | 169 | -------------------------------------------------------------------------------- /include/raw_queue.h: -------------------------------------------------------------------------------- 1 | /* 2 | raw os - Copyright (C) Lingjun Chen(jorya_txj). 3 | 4 | This file is part of raw os. 5 | 6 | raw os is free software; you can redistribute it it under the terms of the 7 | GNU General Public License as published by the Free Software Foundation; 8 | either version 3 of the License, or (at your option) any later version. 9 | 10 | raw os is distributed in the hope that it will be useful, but WITHOUT ANY WARRANTY; 11 | without even the implied warranty of MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. 12 | See the GNU General Public License for more details. 13 | 14 | You should have received a copy of the GNU Lesser General Public License 15 | along with this program. if not, write email to jorya.txj@gmail.com 16 | --- 17 | 18 | A special exception to the LGPL can be applied should you wish to distribute 19 | a combined work that includes raw os, without being obliged to provide 20 | the source code for any proprietary components. See the file exception.txt 21 | for full details of how and when the exception can be applied. 22 | */ 23 | 24 | /* 2012-4 Created by jorya_txj 25 | * xxxxxx please added here 26 | */ 27 | 28 | 29 | #ifndef RAW_QUEUE_H 30 | #define RAW_QUEUE_H 31 | 32 | typedef struct raw_msg_q { 33 | 34 | void **queue_start; /* Pointer to start of queue data */ 35 | void **queue_end; /* Pointer to end of queue data */ 36 | void **write; /* Pointer to where next message will be inserted in the Q */ 37 | void **read; /* Pointer to where next message will be extracted from the Q */ 38 | MSG_SIZE_TYPE size; /* Size of queue (maximum number of entries) */ 39 | MSG_SIZE_TYPE current_numbers; /* Current number of entries in the queue */ 40 | MSG_SIZE_TYPE peak_numbers; /* Peak number of entries in the queue */ 41 | 42 | } RAW_MSG_Q; 43 | 44 | 45 | 46 | typedef struct raw_msg_info { 47 | 48 | RAW_MSG_Q msg_q; 49 | 50 | LIST *suspend_entry; 51 | 52 | } RAW_MSG_INFO; 53 | 54 | 55 | typedef struct raw_queue 56 | { 57 | RAW_COMMON_BLOCK_OBJECT common_block_obj; 58 | RAW_MSG_Q msg_q; 59 | void (*queue_send_notify)(struct raw_queue *queue_ptr); 60 | void (*queue_full_callback)(struct raw_queue *queue_ptr, void *queue_msg); 61 | 62 | } RAW_QUEUE; 63 | 64 | typedef void (*QUEUE_SEND_NOTIFY)(RAW_QUEUE *queue_ptr); 65 | typedef void (*QUEUE_FULL_CALLBACK)(RAW_QUEUE *queue_ptr, void *queue_msg); 66 | 67 | #define WAKE_ALL_QUEUE 0x1 68 | #define WAKE_ONE_QUEUE 0x0 69 | 70 | RAW_OS_ERROR raw_queue_create(RAW_QUEUE *p_q, RAW_U8 *p_name, void **msg_start, MSG_SIZE_TYPE number); 71 | RAW_OS_ERROR raw_queue_full_register(RAW_QUEUE *p_q, QUEUE_FULL_CALLBACK callback_full); 72 | RAW_OS_ERROR raw_queue_front_post(RAW_QUEUE *p_q, void *p_void); 73 | RAW_OS_ERROR raw_queue_end_post(RAW_QUEUE *p_q, void *p_void); 74 | RAW_OS_ERROR raw_queue_receive (RAW_QUEUE *p_q, RAW_TICK_TYPE wait_option, void **msg); 75 | RAW_OS_ERROR raw_queue_all_post(RAW_QUEUE *p_q, void *p_void, RAW_U8 opt); 76 | RAW_OS_ERROR raw_queue_send_notify(RAW_QUEUE *p_q, QUEUE_SEND_NOTIFY notify_function); 77 | RAW_OS_ERROR raw_queue_post_notify(RAW_QUEUE *p_q, void *p_void); 78 | RAW_OS_ERROR raw_queue_full_check(RAW_QUEUE *p_q); 79 | RAW_OS_ERROR msg_post(RAW_QUEUE *p_q, void *p_void, RAW_U8 opt_send_method, RAW_U8 opt_wake_all); 80 | 81 | #if (CONFIG_RAW_QUEUE_FLUSH > 0) 82 | RAW_OS_ERROR raw_queue_flush(RAW_QUEUE *p_q); 83 | #endif 84 | 85 | #if (CONFIG_RAW_QUEUE_DELETE > 0) 86 | RAW_OS_ERROR raw_queue_delete(RAW_QUEUE *p_q); 87 | #endif 88 | 89 | #if (CONFIG_RAW_QUEUE_GET_INFORMATION > 0) 90 | RAW_OS_ERROR raw_queue_get_information(RAW_QUEUE *p_q, RAW_MSG_INFO *msg_information); 91 | #endif 92 | 93 | 94 | 95 | #endif 96 | 97 | -------------------------------------------------------------------------------- /include/raw_queue_buffer.h: -------------------------------------------------------------------------------- 1 | /* 2 | raw os - Copyright (C) Lingjun Chen(jorya_txj). 3 | 4 | This file is part of raw os. 5 | 6 | raw os is free software; you can redistribute it it under the terms of the 7 | GNU General Public License as published by the Free Software Foundation; 8 | either version 3 of the License, or (at your option) any later version. 9 | 10 | raw os is distributed in the hope that it will be useful, but WITHOUT ANY WARRANTY; 11 | without even the implied warranty of MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. 12 | See the GNU General Public License for more details. 13 | 14 | You should have received a copy of the GNU Lesser General Public License 15 | along with this program. if not, write email to jorya.txj@gmail.com 16 | --- 17 | 18 | A special exception to the LGPL can be applied should you wish to distribute 19 | a combined work that includes raw os, without being obliged to provide 20 | the source code for any proprietary components. See the file exception.txt 21 | for full details of how and when the exception can be applied. 22 | */ 23 | 24 | 25 | /* 2013-6 Created by jorya_txj 26 | * xxxxxx please added here 27 | */ 28 | 29 | #ifndef RAW_QUEUE_BUFFER_H 30 | #define RAW_QUEUE_BUFFER_H 31 | 32 | 33 | typedef struct raw_queue_buffer 34 | { 35 | RAW_COMMON_BLOCK_OBJECT common_block_obj; 36 | 37 | MSG_SIZE_TYPE bufsz; /* Message buffer size */ 38 | MSG_SIZE_TYPE maxmsz; /* Maximum length of message */ 39 | MSG_SIZE_TYPE frbufsz; /* Free buffer size */ 40 | MSG_SIZE_TYPE head; /* First message store address */ 41 | MSG_SIZE_TYPE tail; /* Next to the last message store address */ 42 | void *buffer; /* Message buffer address */ 43 | 44 | } RAW_QUEUE_BUFFER; 45 | 46 | /* 47 | * Message header format 48 | */ 49 | typedef MSG_SIZE_TYPE HEADER; 50 | 51 | #define HEADERSZ (sizeof(HEADER)) 52 | 53 | #define ROUND_SIZE (sizeof(HEADER)) 54 | 55 | #define ROUND_BUFFER_SIZE(sz) (((sz) + (ROUND_SIZE - 1)) & ~(ROUND_SIZE - 1)) 56 | 57 | 58 | RAW_OS_ERROR raw_queue_buffer_create(RAW_QUEUE_BUFFER *q_b, RAW_U8 *p_name, void *msg_buffer, MSG_SIZE_TYPE buffer_size, MSG_SIZE_TYPE max_msg_size); 59 | RAW_OS_ERROR queue_buffer_post(RAW_QUEUE_BUFFER *q_b, void *p_void, MSG_SIZE_TYPE msg_size); 60 | RAW_OS_ERROR raw_queue_buffer_end_post(RAW_QUEUE_BUFFER *q_b, void *p_void, MSG_SIZE_TYPE msg_size); 61 | RAW_OS_ERROR raw_queue_buffer_receive(RAW_QUEUE_BUFFER *q_b, RAW_TICK_TYPE wait_option, void *msg, MSG_SIZE_TYPE *receive_size); 62 | 63 | #if (CONFIG_RAW_QUEUE_BUFFER_FLUSH > 0) 64 | RAW_OS_ERROR raw_queue_buffer_flush(RAW_QUEUE_BUFFER *q_b); 65 | #endif 66 | 67 | #if (CONFIG_RAW_QUEUE_BUFFER_DELETE > 0) 68 | RAW_OS_ERROR raw_queue_buffer_delete(RAW_QUEUE_BUFFER *q_b); 69 | #endif 70 | 71 | #if (CONFIG_RAW_QUEUE_BUFFER_GET_INFORMATION > 0) 72 | RAW_OS_ERROR raw_queue_buffer_info_get(RAW_QUEUE_BUFFER *q_b, RAW_U32 *queue_buffer_free_size, RAW_U32 *queue_buffer_size); 73 | #endif 74 | 75 | #endif 76 | 77 | -------------------------------------------------------------------------------- /include/raw_queue_size.h: -------------------------------------------------------------------------------- 1 | /* 2 | raw os - Copyright (C) Lingjun Chen(jorya_txj). 3 | 4 | This file is part of raw os. 5 | 6 | raw os is free software; you can redistribute it it under the terms of the 7 | GNU General Public License as published by the Free Software Foundation; 8 | either version 3 of the License, or (at your option) any later version. 9 | 10 | raw os is distributed in the hope that it will be useful, but WITHOUT ANY WARRANTY; 11 | without even the implied warranty of MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. 12 | See the GNU General Public License for more details. 13 | 14 | You should have received a copy of the GNU Lesser General Public License 15 | along with this program. if not, write email to jorya.txj@gmail.com 16 | --- 17 | 18 | A special exception to the LGPL can be applied should you wish to distribute 19 | a combined work that includes raw os, without being obliged to provide 20 | the source code for any proprietary components. See the file exception.txt 21 | for full details of how and when the exception can be applied. 22 | */ 23 | 24 | 25 | /* 2012-7 Created by jorya_txj 26 | * xxxxxx please added here 27 | */ 28 | 29 | #ifndef RAW_QUEUE_SIZE_H 30 | #define RAW_QUEUE_SIZE_H 31 | 32 | 33 | typedef struct raw_msg_size { 34 | 35 | struct raw_msg_size *next; 36 | void *msg_ptr; 37 | MSG_SIZE_TYPE msg_size; 38 | 39 | } RAW_MSG_SIZE; 40 | 41 | 42 | 43 | 44 | typedef struct raw_queue_size 45 | { 46 | RAW_COMMON_BLOCK_OBJECT common_block_obj; 47 | 48 | RAW_MSG_SIZE *free_msg; 49 | MSG_SIZE_TYPE number_free; 50 | MSG_SIZE_TYPE peak_numbers; /* Peak number of entries in the queue */ 51 | 52 | RAW_MSG_SIZE *write; 53 | RAW_MSG_SIZE *read; 54 | MSG_SIZE_TYPE queue_msg_size; 55 | MSG_SIZE_TYPE queue_current_msg; 56 | void (*queue_size_full_callback)(struct raw_queue_size *queue_size_ptr, void *queue_size_msg, MSG_SIZE_TYPE queue_msg_size); 57 | 58 | 59 | } RAW_QUEUE_SIZE; 60 | 61 | 62 | typedef void (*QUEUE_SIZE_FULL_CALLBACK)(RAW_QUEUE_SIZE *queue_size_ptr, void *queue_size_msg, MSG_SIZE_TYPE queue_msg_size); 63 | 64 | 65 | RAW_OS_ERROR raw_queue_size_create(RAW_QUEUE_SIZE *p_q, RAW_U8 *p_name, RAW_MSG_SIZE *msg_start, MSG_SIZE_TYPE number); 66 | RAW_OS_ERROR raw_queue_size_full_register(RAW_QUEUE_SIZE *p_q, QUEUE_SIZE_FULL_CALLBACK callback_full); 67 | RAW_OS_ERROR raw_queue_size_receive (RAW_QUEUE_SIZE *p_q, RAW_TICK_TYPE wait_option, void **msg_ptr, MSG_SIZE_TYPE *receive_size); 68 | RAW_OS_ERROR raw_queue_size_front_post(RAW_QUEUE_SIZE *p_q, void *p_void, MSG_SIZE_TYPE size); 69 | RAW_OS_ERROR raw_queue_size_end_post(RAW_QUEUE_SIZE *p_q, void *p_void, MSG_SIZE_TYPE size); 70 | RAW_OS_ERROR raw_queue_size_all_post(RAW_QUEUE_SIZE *p_q, void *p_void, MSG_SIZE_TYPE size, RAW_U8 opt); 71 | RAW_OS_ERROR raw_queue_size_full_check(RAW_QUEUE_SIZE *p_q); 72 | RAW_OS_ERROR msg_size_post(RAW_QUEUE_SIZE *p_q, RAW_MSG_SIZE *p_void, MSG_SIZE_TYPE size, RAW_U8 opt_send_method, RAW_U8 opt_wake_all); 73 | 74 | 75 | #if (CONFIG_RAW_QUEUE_SIZE_FLUSH > 0) 76 | RAW_OS_ERROR raw_queue_size_flush(RAW_QUEUE_SIZE *p_q); 77 | #endif 78 | 79 | 80 | #if (CONFIG_RAW_QUEUE_SIZE_DELETE > 0) 81 | RAW_OS_ERROR raw_queue_size_delete(RAW_QUEUE_SIZE *p_q); 82 | #endif 83 | 84 | #if (CONFIG_RAW_QUEUE_SIZE_GET_INFORMATION > 0) 85 | RAW_OS_ERROR raw_queue_size_get_information(RAW_QUEUE_SIZE *p_q, MSG_SIZE_TYPE *queue_free_msg_size, MSG_SIZE_TYPE *queue_peak_msg_size, MSG_SIZE_TYPE *queue_current_msg); 86 | #endif 87 | 88 | 89 | #endif 90 | 91 | 92 | -------------------------------------------------------------------------------- /include/raw_sem.h: -------------------------------------------------------------------------------- 1 | /* 2 | raw os - Copyright (C) Lingjun Chen(jorya_txj). 3 | 4 | This file is part of raw os. 5 | 6 | raw os is free software; you can redistribute it it under the terms of the 7 | GNU General Public License as published by the Free Software Foundation; 8 | either version 3 of the License, or (at your option) any later version. 9 | 10 | raw os is distributed in the hope that it will be useful, but WITHOUT ANY WARRANTY; 11 | without even the implied warranty of MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. 12 | See the GNU General Public License for more details. 13 | 14 | You should have received a copy of the GNU Lesser General Public License 15 | along with this program. if not, write email to jorya.txj@gmail.com 16 | --- 17 | 18 | A special exception to the LGPL can be applied should you wish to distribute 19 | a combined work that includes raw os, without being obliged to provide 20 | the source code for any proprietary components. See the file exception.txt 21 | for full details of how and when the exception can be applied. 22 | */ 23 | 24 | 25 | /* 2012-4 Created by jorya_txj 26 | * xxxxxx please added here 27 | */ 28 | 29 | #ifndef RAW_SEM_H 30 | #define RAW_SEM_H 31 | 32 | typedef struct raw_semaphore 33 | { 34 | RAW_COMMON_BLOCK_OBJECT common_block_obj; 35 | RAW_PROCESSOR_UINT count; 36 | RAW_PROCESSOR_UINT peak_count; 37 | void (*semphore_send_notify)(struct raw_semaphore *queue_ptr); 38 | 39 | } RAW_SEMAPHORE; 40 | 41 | 42 | typedef void (*SEMPHORE_SEND_NOTIFY)(RAW_SEMAPHORE *queue_ptr); 43 | 44 | #define WAKE_ALL_SEM 0x1u 45 | #define WAKE_ONE_SEM 0x0u 46 | 47 | RAW_OS_ERROR raw_semaphore_create(RAW_SEMAPHORE *semaphore_ptr, RAW_U8 *name_ptr, RAW_U32 initial_count); 48 | RAW_OS_ERROR raw_semaphore_put(RAW_SEMAPHORE *semaphore_ptr); 49 | RAW_OS_ERROR raw_semaphore_put_all(RAW_SEMAPHORE *semaphore_ptr); 50 | RAW_OS_ERROR raw_semphore_send_notify(RAW_SEMAPHORE *semaphore_ptr, SEMPHORE_SEND_NOTIFY notify_function); 51 | RAW_OS_ERROR raw_semaphore_put_notify(RAW_SEMAPHORE *semaphore_ptr); 52 | RAW_OS_ERROR raw_semaphore_get(RAW_SEMAPHORE *semaphore_ptr, RAW_TICK_TYPE wait_option); 53 | RAW_OS_ERROR semaphore_put(RAW_SEMAPHORE *semaphore_ptr, RAW_U8 opt_wake_all); 54 | 55 | #if (CONFIG_RAW_SEMAPHORE_SET > 0) 56 | RAW_OS_ERROR raw_semaphore_set(RAW_SEMAPHORE *semaphore_ptr, RAW_U32 sem_count); 57 | #endif 58 | 59 | #if (CONFIG_RAW_SEMAPHORE_DELETE > 0) 60 | RAW_OS_ERROR raw_semaphore_delete(RAW_SEMAPHORE *semaphore_ptr); 61 | #endif 62 | 63 | 64 | #endif 65 | -------------------------------------------------------------------------------- /include/raw_stat.h: -------------------------------------------------------------------------------- 1 | /* 2 | raw os - Copyright (C) Lingjun Chen(jorya_txj). 3 | 4 | This file is part of raw os. 5 | 6 | raw os is free software; you can redistribute it it under the terms of the 7 | GNU General Public License as published by the Free Software Foundation; 8 | either version 3 of the License, or (at your option) any later version. 9 | 10 | raw os is distributed in the hope that it will be useful, but WITHOUT ANY WARRANTY; 11 | without even the implied warranty of MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. 12 | See the GNU General Public License for more details. 13 | 14 | You should have received a copy of the GNU Lesser General Public License 15 | along with this program. if not, write email to jorya.txj@gmail.com 16 | --- 17 | 18 | A special exception to the LGPL can be applied should you wish to distribute 19 | a combined work that includes raw os, without being obliged to provide 20 | the source code for any proprietary components. See the file exception.txt 21 | for full details of how and when the exception can be applied. 22 | */ 23 | 24 | /* 2014-1 Created by jorya_txj 25 | * xxxxxx please added here 26 | */ 27 | 28 | #ifndef RAW_STAT_H 29 | #define RAW_STAT_H 30 | 31 | void raw_stack_check(void); 32 | void raw_task_time_check(void); 33 | void sche_disable_measure_start(void); 34 | void sche_disable_measure_stop(void); 35 | void int_disable_measure_start(void); 36 | void int_disable_measure_stop(void); 37 | void measure_overhead(void); 38 | void cpu_task_start(void); 39 | void cpu_task_init(void); 40 | 41 | #endif 42 | 43 | -------------------------------------------------------------------------------- /include/raw_stm.h: -------------------------------------------------------------------------------- 1 | /* 2 | raw os - Copyright (C) Lingjun Chen(jorya_txj). 3 | 4 | This file is part of raw os. 5 | 6 | raw os is free software; you can redistribute it it under the terms of the 7 | GNU General Public License as published by the Free Software Foundation; 8 | either version 3 of the License, or (at your option) any later version. 9 | 10 | raw os is distributed in the hope that it will be useful, but WITHOUT ANY WARRANTY; 11 | without even the implied warranty of MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. 12 | See the GNU General Public License for more details. 13 | 14 | You should have received a copy of the GNU Lesser General Public License 15 | along with this program. if not, write email to jorya.txj@gmail.com 16 | --- 17 | 18 | A special exception to the LGPL can be applied should you wish to distribute 19 | a combined work that includes raw os, without being obliged to provide 20 | the source code for any proprietary components. See the file exception.txt 21 | for full details of how and when the exception can be applied. 22 | */ 23 | 24 | /* 2012-9 Created by jorya_txj 25 | * xxxxxx please added here 26 | */ 27 | 28 | 29 | 30 | #ifndef RAW_STM_H 31 | #define RAW_STM_H 32 | 33 | 34 | typedef RAW_U16 STM_SIGNAL; 35 | 36 | 37 | typedef struct state_event { 38 | 39 | RAW_U16 sig; 40 | RAW_U8 ref_count; 41 | void *which_pool; 42 | 43 | 44 | 45 | 46 | } STATE_EVENT; 47 | 48 | 49 | typedef RAW_U16 (*stm_state_handler)(void *me, STATE_EVENT *e); 50 | 51 | 52 | typedef struct stm_struct { 53 | 54 | stm_state_handler state; 55 | stm_state_handler temp; 56 | 57 | } STM_STRUCT; 58 | 59 | #define STM_SUCCESS 0 60 | 61 | 62 | #define STM_STATE_CAST(handler) ((stm_state_handler)(handler)) 63 | 64 | 65 | #define STM_RET_HANDLED 1 66 | 67 | 68 | #define STM_RET_IGNORED 2 69 | 70 | 71 | #define STM_RET_TRAN 3 72 | 73 | 74 | #define STM_TRAN(state) (((STM_STRUCT *)me)->temp = STM_STATE_CAST(state), STM_RET_TRAN) 75 | 76 | 77 | #define STM_RET_FATHER 4 78 | 79 | 80 | #define STM_FATHER(father) (((STM_STRUCT *)me)->temp = STM_STATE_CAST(father), STM_RET_FATHER) 81 | 82 | 83 | 84 | #define STM_RET_UNHANDLED 5 85 | 86 | 87 | 88 | #define STM_EMPTY_SIG 0 89 | #define STM_MAX_NEST_DEPTH 6 90 | 91 | 92 | typedef enum raw_reserved_signals { 93 | 94 | STM_ENTRY_SIG = 1, 95 | STM_EXIT_SIG, 96 | STM_INIT_SIG, 97 | STM_TIMEOUT_SIG, 98 | STM_USER_SIG 99 | } RAW_RESERVED_SIGNALS; 100 | 101 | 102 | 103 | extern STATE_EVENT STM_GLOBAL_EVENT[4]; 104 | 105 | #define STM_TRIG(state, sig) ((*(state))(me, &STM_GLOBAL_EVENT[sig])) 106 | 107 | 108 | 109 | #define FSM_CONSTRUCTOR(me, initial) do { \ 110 | (me)->state = 0; \ 111 | (me)->temp = (initial); \ 112 | } while (0) 113 | 114 | 115 | RAW_U16 hsm_top(void *me, STATE_EVENT *e); 116 | 117 | 118 | #define HSM_CONSTRUCTOR(me, initial) do { \ 119 | (me)->state = hsm_top; \ 120 | (me)->temp = (initial); \ 121 | } while (0) 122 | 123 | 124 | #define STM_ENTER(state) STM_TRIG((state), STM_ENTRY_SIG) 125 | 126 | #define STM_EXIT(state) STM_TRIG((state), STM_EXIT_SIG) 127 | 128 | void fsm_init(STM_STRUCT *me, STATE_EVENT *e); 129 | void fsm_exceute(STM_STRUCT *me, STATE_EVENT *e); 130 | 131 | void hsm_init(STM_STRUCT *me, STATE_EVENT *e); 132 | void hsm_exceute(STM_STRUCT *me, STATE_EVENT *e); 133 | 134 | RAW_U16 is_hsm_in_state(STM_STRUCT *me, stm_state_handler state); 135 | 136 | #endif 137 | 138 | -------------------------------------------------------------------------------- /include/raw_task.h: -------------------------------------------------------------------------------- 1 | /* 2 | raw os - Copyright (C) Lingjun Chen(jorya_txj). 3 | 4 | This file is part of raw os. 5 | 6 | raw os is free software; you can redistribute it it under the terms of the 7 | GNU General Public License as published by the Free Software Foundation; 8 | either version 3 of the License, or (at your option) any later version. 9 | 10 | raw os is distributed in the hope that it will be useful, but WITHOUT ANY WARRANTY; 11 | without even the implied warranty of MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. 12 | See the GNU General Public License for more details. 13 | 14 | You should have received a copy of the GNU Lesser General Public License 15 | along with this program. if not, write email to jorya.txj@gmail.com 16 | --- 17 | 18 | A special exception to the LGPL can be applied should you wish to distribute 19 | a combined work that includes raw os, without being obliged to provide 20 | the source code for any proprietary components. See the file exception.txt 21 | for full details of how and when the exception can be applied. 22 | */ 23 | 24 | 25 | /* 2012-4 Created by jorya_txj 26 | * xxxxxx please added here 27 | */ 28 | 29 | 30 | #ifndef RAW_TASK_H 31 | #define RAW_TASK_H 32 | 33 | typedef void (*RAW_TASK_ENTRY)(void *p_arg); 34 | 35 | RAW_OS_ERROR raw_task_create(RAW_TASK_OBJ *task_obj, RAW_U8 *task_name, void *task_arg, 36 | RAW_U8 task_prio, RAW_U32 time_slice, PORT_STACK *task_stack_base, 37 | RAW_U32 stack_size, RAW_TASK_ENTRY task_entry, RAW_U8 auto_start); 38 | 39 | 40 | RAW_OS_ERROR raw_disable_sche(void); 41 | 42 | RAW_OS_ERROR raw_enable_sche(void); 43 | 44 | RAW_OS_ERROR raw_sleep(RAW_TICK_TYPE dly); 45 | RAW_OS_ERROR raw_time_sleep(RAW_U16 hours, RAW_U16 minutes, RAW_U16 seconds, RAW_U32 milli); 46 | 47 | #if (CONFIG_RAW_TASK_SUSPEND > 0) 48 | RAW_OS_ERROR raw_task_suspend(RAW_TASK_OBJ *task_ptr); 49 | RAW_OS_ERROR raw_task_resume(RAW_TASK_OBJ *task_ptr); 50 | RAW_OS_ERROR task_suspend(RAW_TASK_OBJ *task_ptr); 51 | RAW_OS_ERROR task_resume(RAW_TASK_OBJ *task_ptr); 52 | 53 | #endif 54 | 55 | #if (CONFIG_RAW_TASK_PRIORITY_CHANGE > 0) 56 | RAW_OS_ERROR raw_task_priority_change (RAW_TASK_OBJ *task_ptr, RAW_U8 new_priority, RAW_U8 *old_priority); 57 | #endif 58 | 59 | #if (CONFIG_RAW_TASK_DELETE > 0) 60 | RAW_OS_ERROR raw_task_delete(RAW_TASK_OBJ *task_ptr); 61 | #endif 62 | 63 | #if (CONFIG_RAW_TASK_WAIT_ABORT > 0) 64 | RAW_OS_ERROR raw_task_wait_abort(RAW_TASK_OBJ *task_ptr); 65 | #endif 66 | 67 | #if (CONFIG_SCHED_FIFO_RR > 0) 68 | RAW_OS_ERROR raw_task_time_slice_change(RAW_TASK_OBJ *task_ptr, RAW_U32 new_time_slice); 69 | RAW_OS_ERROR raw_set_sched_way(RAW_TASK_OBJ *task_ptr, RAW_U8 policy); 70 | RAW_OS_ERROR raw_get_sched_way(RAW_TASK_OBJ *task_ptr, RAW_U8 *policy_ptr); 71 | #endif 72 | 73 | RAW_TASK_OBJ *raw_task_identify(void); 74 | 75 | #if (CONFIG_RAW_TASK_STACK_CHECK > 0) 76 | RAW_OS_ERROR raw_task_stack_check(RAW_TASK_OBJ *task_obj, RAW_U32 *free_stack); 77 | #endif 78 | 79 | #if (CONFIG_USER_DATA_POINTER > 0) 80 | void raw_set_task_user_point(RAW_TASK_OBJ *task_ptr, void *user_point, RAW_U32 point_position); 81 | 82 | void *raw_get_task_user_point(RAW_TASK_OBJ *task_ptr, RAW_U32 point_position); 83 | #endif 84 | 85 | #if (CONFIG_RAW_DEBUG > 0) 86 | RAW_OS_ERROR raw_iter_block_task(LIST *object_head, void (*debug_function)(RAW_TASK_OBJ *arg), RAW_U8 opt); 87 | RAW_U32 raw_get_system_global_space(void); 88 | #endif 89 | 90 | #define RAW_TASK_AUTO_START 1 91 | #define RAW_TASK_DONT_START 0 92 | 93 | #endif 94 | -------------------------------------------------------------------------------- /include/raw_task_queue_size.h: -------------------------------------------------------------------------------- 1 | /* 2 | raw os - Copyright (C) Lingjun Chen(jorya_txj). 3 | 4 | This file is part of raw os. 5 | 6 | raw os is free software; you can redistribute it it under the terms of the 7 | GNU General Public License as published by the Free Software Foundation; 8 | either version 3 of the License, or (at your option) any later version. 9 | 10 | raw os is distributed in the hope that it will be useful, but WITHOUT ANY WARRANTY; 11 | without even the implied warranty of MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. 12 | See the GNU General Public License for more details. 13 | 14 | You should have received a copy of the GNU Lesser General Public License 15 | along with this program. if not, write email to jorya.txj@gmail.com 16 | --- 17 | 18 | A special exception to the LGPL can be applied should you wish to distribute 19 | a combined work that includes raw os, without being obliged to provide 20 | the source code for any proprietary components. See the file exception.txt 21 | for full details of how and when the exception can be applied. 22 | */ 23 | 24 | 25 | /* 2013-2 Created by jorya_txj 26 | * xxxxxx please added here 27 | */ 28 | 29 | #ifndef RAW_TASK_QUEUE_SIZE_H 30 | #define RAW_TASK_QUEUE_SIZE_H 31 | 32 | RAW_OS_ERROR raw_task_qsize_create(RAW_TASK_OBJ *task_obj, RAW_QUEUE_SIZE *queue_size_obj, RAW_U8 *p_name, RAW_MSG_SIZE *msg_start, RAW_U32 number); 33 | 34 | RAW_OS_ERROR raw_task_qsize_receive (RAW_TICK_TYPE wait_option, void **msg_ptr, RAW_U32 *receive_size); 35 | 36 | RAW_OS_ERROR raw_task_qsize_front_post(RAW_TASK_OBJ *task_obj, void *p_void, RAW_U32 size); 37 | 38 | RAW_OS_ERROR raw_task_qsize_end_post(RAW_TASK_OBJ *task_obj, void *p_void, RAW_U32 size); 39 | 40 | RAW_OS_ERROR raw_task_qsize_flush(RAW_TASK_OBJ *task_obj); 41 | 42 | RAW_OS_ERROR raw_task_qsize_delete(RAW_TASK_OBJ *task_obj); 43 | 44 | RAW_OS_ERROR raw_task_qsize_get_information(RAW_TASK_OBJ *task_obj, RAW_U32 *queue_free_msg_size, RAW_U32 *queue_peak_msg_size, RAW_U32 *queue_current_msg); 45 | 46 | #endif 47 | 48 | -------------------------------------------------------------------------------- /include/raw_task_sem.h: -------------------------------------------------------------------------------- 1 | /* 2 | raw os - Copyright (C) Lingjun Chen(jorya_txj). 3 | 4 | This file is part of raw os. 5 | 6 | raw os is free software; you can redistribute it it under the terms of the 7 | GNU General Public License as published by the Free Software Foundation; 8 | either version 3 of the License, or (at your option) any later version. 9 | 10 | raw os is distributed in the hope that it will be useful, but WITHOUT ANY WARRANTY; 11 | without even the implied warranty of MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. 12 | See the GNU General Public License for more details. 13 | 14 | You should have received a copy of the GNU Lesser General Public License 15 | along with this program. if not, write email to jorya.txj@gmail.com 16 | --- 17 | 18 | A special exception to the LGPL can be applied should you wish to distribute 19 | a combined work that includes raw os, without being obliged to provide 20 | the source code for any proprietary components. See the file exception.txt 21 | for full details of how and when the exception can be applied. 22 | */ 23 | 24 | 25 | /* 2013-3 Created by jorya_txj 26 | * xxxxxx please added here 27 | */ 28 | 29 | 30 | #ifndef RAW_TASK_SEM_H 31 | #define RAW_TASK_SEM_H 32 | 33 | RAW_OS_ERROR raw_task_semaphore_create(RAW_TASK_OBJ *task_obj, RAW_SEMAPHORE *semaphore_ptr, RAW_U8 *name_ptr, RAW_U32 initial_count); 34 | 35 | RAW_OS_ERROR raw_task_semaphore_put(RAW_TASK_OBJ *task_obj); 36 | 37 | RAW_OS_ERROR raw_task_semaphore_get(RAW_TICK_TYPE wait_option); 38 | 39 | RAW_OS_ERROR raw_task_semaphore_set(RAW_TASK_OBJ *task_obj, RAW_U32 sem_count); 40 | 41 | RAW_OS_ERROR raw_task_semaphore_delete(RAW_TASK_OBJ *task_obj); 42 | 43 | #endif 44 | 45 | 46 | -------------------------------------------------------------------------------- /include/raw_timer.h: -------------------------------------------------------------------------------- 1 | /* 2 | raw os - Copyright (C) Lingjun Chen(jorya_txj). 3 | 4 | This file is part of raw os. 5 | 6 | raw os is free software; you can redistribute it it under the terms of the 7 | GNU General Public License as published by the Free Software Foundation; 8 | either version 3 of the License, or (at your option) any later version. 9 | 10 | raw os is distributed in the hope that it will be useful, but WITHOUT ANY WARRANTY; 11 | without even the implied warranty of MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. 12 | See the GNU General Public License for more details. 13 | 14 | You should have received a copy of the GNU Lesser General Public License 15 | along with this program. if not, write email to jorya.txj@gmail.com 16 | --- 17 | 18 | A special exception to the LGPL can be applied should you wish to distribute 19 | a combined work that includes raw os, without being obliged to provide 20 | the source code for any proprietary components. See the file exception.txt 21 | for full details of how and when the exception can be applied. 22 | */ 23 | 24 | /* 2012-4 Created by jorya_txj 25 | * xxxxxx please added here 26 | */ 27 | 28 | #ifndef RAW_TIMER_H 29 | #define RAW_TIMER_H 30 | 31 | typedef struct raw_timer { 32 | 33 | LIST timer_list; 34 | LIST *to_head; 35 | RAW_U8 *name; 36 | RAW_U16 (*raw_timeout_function)(void *arg); 37 | RAW_TICK_TYPE match; 38 | RAW_TICK_TYPE remain; 39 | RAW_TICK_TYPE init_count; 40 | RAW_TICK_TYPE reschedule_ticks; 41 | void *raw_timeout_param; 42 | RAW_U8 timer_state; 43 | RAW_OBJECT_TYPE object_type; 44 | 45 | }RAW_TIMER; 46 | 47 | 48 | #define TIMER_DEACTIVE 1 49 | #define TIMER_ACTIVE 2 50 | #define TIMER_DELETED 3 51 | #define TIMER_CALLBACK_CONTINUE 4 52 | #define TIMER_CALLBACK_STOP 0x88 53 | 54 | 55 | typedef struct raw_timer_head { 56 | struct raw_timer *first_timer_ptr; 57 | }RAW_TIMER_HEAD; 58 | 59 | 60 | 61 | RAW_OS_ERROR raw_timer_create(RAW_TIMER *timer_ptr, RAW_U8 *name_ptr, 62 | RAW_U16 (*expiration_function)(void *expiration_input), void *expiration_input, 63 | RAW_TICK_TYPE initial_ticks, RAW_TICK_TYPE reschedule_ticks, RAW_U8 auto_activate); 64 | 65 | 66 | RAW_OS_ERROR raw_timer_activate(RAW_TIMER *timer_ptr, void *expiration_input); 67 | 68 | 69 | #if (CONFIG_RAW_TIMER_DEACTIVATE > 0) 70 | RAW_OS_ERROR raw_timer_deactivate(RAW_TIMER *timer_ptr); 71 | #endif 72 | 73 | #if (CONFIG_RAW_TIMER_DELETE > 0) 74 | RAW_OS_ERROR raw_timer_delete(RAW_TIMER *timer_ptr); 75 | #endif 76 | 77 | #if (CONFIG_RAW_TIMER_CHANGE > 0) 78 | RAW_OS_ERROR raw_timer_change(RAW_TIMER *timer_ptr, RAW_TICK_TYPE initial_ticks, RAW_TICK_TYPE reschedule_ticks); 79 | #endif 80 | 81 | #endif 82 | 83 | -------------------------------------------------------------------------------- /raw-os.c: -------------------------------------------------------------------------------- 1 | /* 2 | raw os - Copyright (C) Lingjun Chen(jorya_txj). 3 | 4 | This file is part of raw os. 5 | 6 | raw os is free software; you can redistribute it it under the terms of the 7 | GNU General Public License as published by the Free Software Foundation; 8 | either version 3 of the License, or (at your option) any later version. 9 | 10 | raw os is distributed in the hope that it will be useful, but WITHOUT ANY WARRANTY; 11 | without even the implied warranty of MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. 12 | See the GNU General Public License for more details. 13 | 14 | You should have received a copy of the GNU Lesser General Public License 15 | along with this program. if not, write email to jorya.txj@gmail.com 16 | --- 17 | 18 | A special exception to the LGPL can be applied should you wish to distribute 19 | a combined work that includes raw os, without being obliged to provide 20 | the source code for any proprietary components. See the file exception.txt 21 | for full details of how and when the exception can be applied. 22 | */ 23 | 24 | 25 | /* 2014-7 Created by jorya_txj 26 | * xxxxxx please added here 27 | */ 28 | 29 | #include "raw_obj.c" 30 | #include "raw_sched.c" 31 | #include "raw_pend.c" 32 | #include "raw_task.c" 33 | #include "raw_block.c" 34 | #include "raw_byte.c" 35 | #include "raw_event.c" 36 | #include "raw_idle.c" 37 | #include "raw_idle_event.c" 38 | #include "raw_mutex.c" 39 | #include "raw_queue.c" 40 | #include "raw_queue_buffer.c" 41 | #include "raw_queue_size.c" 42 | #include "raw_sem.c" 43 | #include "raw_stat.c" 44 | #include "raw_stm.c" 45 | #include "raw_system.c" 46 | #include "raw_task_queue_size.c" 47 | #include "raw_task_sem.c" 48 | #include "raw_tick.c" 49 | #include "raw_timer.c" 50 | 51 | 52 | 53 | 54 | -------------------------------------------------------------------------------- /raw_idle.c: -------------------------------------------------------------------------------- 1 | /* 2 | raw os - Copyright (C) Lingjun Chen(jorya_txj). 3 | 4 | This file is part of raw os. 5 | 6 | raw os is free software; you can redistribute it it under the terms of the 7 | GNU General Public License as published by the Free Software Foundation; 8 | either version 3 of the License, or (at your option) any later version. 9 | 10 | raw os is distributed in the hope that it will be useful, but WITHOUT ANY WARRANTY; 11 | without even the implied warranty of MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. 12 | See the GNU General Public License for more details. 13 | 14 | You should have received a copy of the GNU Lesser General Public License 15 | along with this program. if not, write email to jorya.txj@gmail.com 16 | --- 17 | 18 | A special exception to the LGPL can be applied should you wish to distribute 19 | a combined work that includes raw os, without being obliged to provide 20 | the source code for any proprietary components. See the file exception.txt 21 | for full details of how and when the exception can be applied. 22 | */ 23 | 24 | 25 | /* 2012-9 Created by jorya_txj 26 | * xxxxxx please added here 27 | */ 28 | 29 | #include 30 | 31 | void raw_idle_task (void *p_arg) 32 | { 33 | RAW_SR_ALLOC(); 34 | 35 | p_arg = p_arg; /* Make compiler happy ^_^ */ 36 | 37 | while (1) { 38 | 39 | USER_CPU_INT_DISABLE(); 40 | 41 | raw_idle_count++; 42 | 43 | USER_CPU_INT_ENABLE(); 44 | 45 | #if (CONFIG_RAW_USER_HOOK > 0) 46 | raw_idle_coroutine_hook(); 47 | #endif 48 | } 49 | 50 | } 51 | 52 | -------------------------------------------------------------------------------- /raw_obj.c: -------------------------------------------------------------------------------- 1 | /* 2 | raw os - Copyright (C) Lingjun Chen(jorya_txj). 3 | 4 | This file is part of raw os. 5 | 6 | raw os is free software; you can redistribute it it under the terms of the 7 | GNU General Public License as published by the Free Software Foundation; 8 | either version 3 of the License, or (at your option) any later version. 9 | 10 | raw os is distributed in the hope that it will be useful, but WITHOUT ANY WARRANTY; 11 | without even the implied warranty of MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. 12 | See the GNU General Public License for more details. 13 | 14 | You should have received a copy of the GNU Lesser General Public License 15 | along with this program. if not, write email to jorya.txj@gmail.com 16 | --- 17 | 18 | A special exception to the LGPL can be applied should you wish to distribute 19 | a combined work that includes raw os, without being obliged to provide 20 | the source code for any proprietary components. See the file exception.txt 21 | for full details of how and when the exception can be applied. 22 | */ 23 | 24 | 25 | /* 2012-4 Created by jorya_txj 26 | * xxxxxx please added here 27 | */ 28 | 29 | #include 30 | 31 | RAW_OS_ERROR raw_os_active; 32 | RAW_U8 idle_task_exit; 33 | 34 | RAW_RUN_QUEUE raw_ready_queue; 35 | 36 | /*System lock*/ 37 | RAW_U8 raw_sched_lock; 38 | RAW_U8 raw_int_nesting; 39 | 40 | /*highest ready task object*/ 41 | RAW_TASK_OBJ *high_ready_obj; 42 | 43 | /*current active task*/ 44 | RAW_TASK_OBJ *raw_task_active; 45 | 46 | /*idle attribute*/ 47 | RAW_TASK_OBJ raw_idle_obj; 48 | PORT_STACK idle_stack[IDLE_STACK_SIZE]; 49 | RAW_IDLE_COUNT_TYPE raw_idle_count; 50 | 51 | 52 | /*tick attribute*/ 53 | RAW_TICK_TYPE raw_tick_count; 54 | LIST tick_head; 55 | 56 | #if (CONFIG_RAW_TIMER > 0) 57 | 58 | LIST timer_head; 59 | RAW_TICK_TYPE raw_timer_count; 60 | RAW_U32 raw_timer_ctrl; 61 | RAW_TASK_OBJ raw_timer_obj; 62 | PORT_STACK timer_task_stack[TIMER_STACK_SIZE]; 63 | RAW_SEMAPHORE timer_sem; 64 | RAW_MUTEX timer_mutex; 65 | 66 | #endif 67 | 68 | #if (CONFIG_RAW_MUTEX > 0) 69 | 70 | RAW_U8 mutex_recursion_levels; 71 | RAW_U8 mutex_recursion_max_levels; 72 | 73 | #endif 74 | 75 | #if (RAW_SCHE_LOCK_MEASURE_CHECK > 0) 76 | 77 | PORT_TIMER_TYPE raw_sche_disable_time_start; 78 | PORT_TIMER_TYPE raw_sche_disable_time_max; 79 | 80 | #endif 81 | 82 | #if (RAW_CPU_INT_DIS_MEASURE_CHECK > 0) 83 | 84 | RAW_U16 int_disable_times; 85 | PORT_TIMER_TYPE raw_int_disable_time_start; 86 | PORT_TIMER_TYPE raw_int_disable_time_max; 87 | 88 | #endif 89 | 90 | #if (RAW_CONFIG_CPU_TIME > 0) 91 | 92 | PORT_TIMER_TYPE system_meaure_overhead; 93 | 94 | #endif 95 | 96 | #if (RAW_CONFIG_CPU_TASK > 0) 97 | 98 | RAW_TASK_OBJ raw_cpu_obj; 99 | PORT_STACK cpu_task_stack[CPU_STACK_SIZE]; 100 | RAW_IDLE_COUNT_TYPE raw_idle_count_max; 101 | RAW_U32 cpu_usuage; 102 | RAW_U32 cpu_usuage_max; 103 | 104 | #endif 105 | 106 | RAW_OBJECT_DEBUG raw_task_debug; 107 | 108 | #if (CONFIG_RAW_TICK_TASK > 0) 109 | 110 | RAW_TASK_OBJ tick_task_obj; 111 | PORT_STACK tick_task_stack[TICK_TASK_STACK_SIZE]; 112 | RAW_SEMAPHORE tick_semaphore_obj; 113 | 114 | #endif 115 | 116 | 117 | #if (CONFIG_RAW_IDLE_EVENT > 0) 118 | 119 | /*public global event*/ 120 | STATE_EVENT STM_GLOBAL_EVENT[4] = { 121 | { STM_EMPTY_SIG, 0, 0 }, 122 | { STM_ENTRY_SIG, 0, 0 }, 123 | { STM_EXIT_SIG, 0, 0 }, 124 | { STM_INIT_SIG, 0, 0 } 125 | }; 126 | 127 | RAW_U8 raw_idle_rdy_grp; 128 | RAW_U8 raw_rdy_tbl[RAW_IDLE_RDY_TBL_SIZE]; 129 | LIST raw_idle_tick_head; 130 | 131 | const RAW_U8 raw_idle_map_table[256] = { 132 | 0u, 0u, 8u, 0u, 16u, 0u, 8u, 0u, 24u, 0u, 8u, 0u, 16u, 0u, 8u, 0u, 133 | 32u, 0u, 8u, 0u, 16u, 0u, 8u, 0u, 24u, 0u, 8u, 0u, 16u, 0u, 8u, 0u, 134 | 40u, 0u, 8u, 0u, 16u, 0u, 8u, 0u, 24u, 0u, 8u, 0u, 16u, 0u, 8u, 0u, 135 | 32u, 0u, 8u, 0u, 16u, 0u, 8u, 0u, 24u, 0u, 8u, 0u, 16u, 0u, 8u, 0u, 136 | 48u, 0u, 8u, 0u, 16u, 0u, 8u, 0u, 24u, 0u, 8u, 0u, 16u, 0u, 8u, 0u, 137 | 32u, 0u, 8u, 0u, 16u, 0u, 8u, 0u, 24u, 0u, 8u, 0u, 16u, 0u, 8u, 0u, 138 | 40u, 0u, 8u, 0u, 16u, 0u, 8u, 0u, 24u, 0u, 8u, 0u, 16u, 0u, 8u, 0u, 139 | 32u, 0u, 8u, 0u, 16u, 0u, 8u, 0u, 24u, 0u, 8u, 0u, 16u, 0u, 8u, 0u, 140 | 56u, 0u, 8u, 0u, 16u, 0u, 8u, 0u, 24u, 0u, 8u, 0u, 16u, 0u, 8u, 0u, 141 | 32u, 0u, 8u, 0u, 16u, 0u, 8u, 0u, 24u, 0u, 8u, 0u, 16u, 0u, 8u, 0u, 142 | 40u, 0u, 8u, 0u, 16u, 0u, 8u, 0u, 24u, 0u, 8u, 0u, 16u, 0u, 8u, 0u, 143 | 32u, 0u, 8u, 0u, 16u, 0u, 8u, 0u, 24u, 0u, 8u, 0u, 16u, 0u, 8u, 0u, 144 | 48u, 0u, 8u, 0u, 16u, 0u, 8u, 0u, 24u, 0u, 8u, 0u, 16u, 0u, 8u, 0u, 145 | 32u, 0u, 8u, 0u, 16u, 0u, 8u, 0u, 24u, 0u, 8u, 0u, 16u, 0u, 8u, 0u, 146 | 40u, 0u, 8u, 0u, 16u, 0u, 8u, 0u, 24u, 0u, 8u, 0u, 16u, 0u, 8u, 0u, 147 | 32u, 0u, 8u, 0u, 16u, 0u, 8u, 0u, 24u, 0u, 8u, 0u, 16u, 0u, 8u, 0u 148 | }; 149 | 150 | #endif 151 | 152 | 153 | --------------------------------------------------------------------------------