You can not select more than 25 topics
			Topics must start with a letter or number, can include dashes ('-') and can be up to 35 characters long.
		
		
		
		
			
				
					68 lines
				
				1.4 KiB
			
		
		
			
		
	
	
					68 lines
				
				1.4 KiB
			| 
								 
											6 years ago
										 
									 | 
							
								// **** libc ****
							 | 
						||
| 
								 | 
							
								
							 | 
						||
| 
								 | 
							
								void delay(int a) {
							 | 
						||
| 
								 | 
							
								  volatile int i;
							 | 
						||
| 
								 | 
							
								  for (i = 0; i < a; i++);
							 | 
						||
| 
								 | 
							
								}
							 | 
						||
| 
								 | 
							
								
							 | 
						||
| 
								 | 
							
								void *memset(void *str, int c, unsigned int n) {
							 | 
						||
| 
								 
											6 years ago
										 
									 | 
							
								  uint8_t *s = str;
							 | 
						||
| 
								 | 
							
								  for (unsigned int i = 0; i < n; i++) {
							 | 
						||
| 
								 | 
							
								    *s = c;
							 | 
						||
| 
								 | 
							
								    s++;
							 | 
						||
| 
								 
											6 years ago
										 
									 | 
							
								  }
							 | 
						||
| 
								 | 
							
								  return str;
							 | 
						||
| 
								 | 
							
								}
							 | 
						||
| 
								 | 
							
								
							 | 
						||
| 
								 | 
							
								void *memcpy(void *dest, const void *src, unsigned int n) {
							 | 
						||
| 
								 
											6 years ago
										 
									 | 
							
								  uint8_t *d = dest;
							 | 
						||
| 
								 | 
							
								  const uint8_t *s = src;
							 | 
						||
| 
								 | 
							
								  for (unsigned int i = 0; i < n; i++) {
							 | 
						||
| 
								 | 
							
								    *d = *s;
							 | 
						||
| 
								 | 
							
								    d++;
							 | 
						||
| 
								 | 
							
								    s++;
							 | 
						||
| 
								 
											6 years ago
										 
									 | 
							
								  }
							 | 
						||
| 
								 | 
							
								  return dest;
							 | 
						||
| 
								 | 
							
								}
							 | 
						||
| 
								 | 
							
								
							 | 
						||
| 
								 | 
							
								int memcmp(const void * ptr1, const void * ptr2, unsigned int num) {
							 | 
						||
| 
								 | 
							
								  int ret = 0;
							 | 
						||
| 
								 
											6 years ago
										 
									 | 
							
								  const uint8_t *p1 = ptr1;
							 | 
						||
| 
								 | 
							
								  const uint8_t *p2 = ptr2;
							 | 
						||
| 
								 | 
							
								  for (unsigned int i = 0; i < num; i++) {
							 | 
						||
| 
								 | 
							
								    if (*p1 != *p2) {
							 | 
						||
| 
								 
											6 years ago
										 
									 | 
							
								      ret = -1;
							 | 
						||
| 
								 | 
							
								      break;
							 | 
						||
| 
								 | 
							
								    }
							 | 
						||
| 
								 
											6 years ago
										 
									 | 
							
								    p1++;
							 | 
						||
| 
								 | 
							
								    p2++;
							 | 
						||
| 
								 
											6 years ago
										 
									 | 
							
								  }
							 | 
						||
| 
								 | 
							
								  return ret;
							 | 
						||
| 
								 | 
							
								}
							 | 
						||
| 
								 | 
							
								
							 | 
						||
| 
								 | 
							
								// ********************* IRQ helpers *********************
							 | 
						||
| 
								 | 
							
								
							 | 
						||
| 
								 
											6 years ago
										 
									 | 
							
								volatile bool interrupts_enabled = false;
							 | 
						||
| 
								 | 
							
								
							 | 
						||
| 
								 
											6 years ago
										 
									 | 
							
								void enable_interrupts(void) {
							 | 
						||
| 
								 
											6 years ago
										 
									 | 
							
								  interrupts_enabled = true;
							 | 
						||
| 
								 
											6 years ago
										 
									 | 
							
								  __enable_irq();
							 | 
						||
| 
								 | 
							
								}
							 | 
						||
| 
								 | 
							
								
							 | 
						||
| 
								 
											6 years ago
										 
									 | 
							
								void disable_interrupts(void) {
							 | 
						||
| 
								 | 
							
								  interrupts_enabled = false;
							 | 
						||
| 
								 
											6 years ago
										 
									 | 
							
								  __disable_irq();
							 | 
						||
| 
								 | 
							
								}
							 | 
						||
| 
								 | 
							
								
							 | 
						||
| 
								 
											6 years ago
										 
									 | 
							
								uint8_t global_critical_depth = 0U;
							 | 
						||
| 
								 | 
							
								#define ENTER_CRITICAL()                                      \
							 | 
						||
| 
								 | 
							
								  __disable_irq();                                            \
							 | 
						||
| 
								 | 
							
								  global_critical_depth += 1U;
							 | 
						||
| 
								 | 
							
								
							 | 
						||
| 
								 | 
							
								#define EXIT_CRITICAL()                                       \
							 | 
						||
| 
								 | 
							
								  global_critical_depth -= 1U;                                \
							 | 
						||
| 
								 | 
							
								  if ((global_critical_depth == 0U) && interrupts_enabled) {  \
							 | 
						||
| 
								 | 
							
								    __enable_irq();                                           \
							 | 
						||
| 
								 
											6 years ago
										 
									 | 
							
								  }
							 | 
						||
| 
								 | 
							
								
							 |