mdebug

cortex m series debugger
git clone http://frotz.net/git/mdebug.git
Log | Files | Refs | README | LICENSE

cc13xx.c (1736B)


      1 // agent-lpc15xx/main.c
      2 //
      3 // Copyright 2016 Brian Swetland <swetland@frotz.net>
      4 //
      5 // Licensed under the Apache License, Version 2.0 (the "License");
      6 // you may not use this file except in compliance with the License.
      7 // You may obtain a copy of the License at
      8 //
      9 //     http://www.apache.org/licenses/LICENSE-2.0
     10 //
     11 // Unless required by applicable law or agreed to in writing, software
     12 // distributed under the License is distributed on an "AS IS" BASIS,
     13 // WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied.
     14 // See the License for the specific language governing permissions and
     15 // limitations under the License.
     16 
     17 #include <agent/flash.h>
     18 #include "cc13xx-romapi.h"
     19 
     20 int flash_agent_setup(flash_agent *agent) {
     21 	return ERR_NONE;
     22 }
     23 
     24 int flash_agent_erase(u32 flash_addr, u32 length) {
     25 	if (flash_addr & 0xFFF) {
     26 		return ERR_ALIGNMENT;
     27 	}
     28 	while (length > 0) {
     29 		if (ROM_FlashSectorErase(flash_addr)) {
     30 			return ERR_FAIL;
     31 		}
     32 		if (length > 4096) {
     33 			length -= 4096;
     34 			flash_addr += 4096;
     35 		} else {
     36 			break;
     37 		}
     38 	}
     39 	return 0;
     40 }
     41 
     42 int flash_agent_write(u32 flash_addr, const void *data, u32 length) {
     43 	if (flash_addr & 0xFFF) {
     44 		return ERR_ALIGNMENT;
     45 	}
     46 	if (ROM_FlashProgram(data, flash_addr, length)) {
     47 		return ERR_FAIL;
     48 	}
     49 	return 0;
     50 }
     51 
     52 
     53 int flash_agent_ioctl(u32 op, void *ptr, u32 arg0, u32 arg1) {
     54 	return ERR_INVALID;
     55 }
     56 
     57 const flash_agent __attribute((section(".vectors"))) FlashAgent = {
     58 	.magic =	AGENT_MAGIC,
     59 	.version =	AGENT_VERSION,
     60 	.flags =	0,
     61 	.load_addr =	0x20000400,
     62 	.data_addr =	0x20001000,
     63 	.data_size =	0x1000,
     64 	.flash_addr =	0x00000000,
     65 	.flash_size =	0x00020000,
     66 	.setup =	flash_agent_setup,
     67 	.erase =	flash_agent_erase,
     68 	.write =	flash_agent_write,
     69 	.ioctl =	flash_agent_ioctl,
     70 };